31#include "openvslam/publish/map_publisher.h"
32#include "openvslam/publish/frame_publisher.h"
33#include "openvslam/data/landmark.h"
39#define GetCurrentDir _getcwd
42#define GetCurrentDir getcwd
47 char buff[FILENAME_MAX];
49 std::string current_working_dir(buff);
51 for (
unsigned int i = 0; i < current_working_dir.length(); i++)
53 if (current_working_dir.substr(i, 1) ==
"\\")
54 current_working_dir.replace(i, 1,
"/");
56 return current_working_dir;
66 mCfgNode = YAML::Load(
71Camera.name: \"Default monocular\"\n\
72Camera.setup : \"monocular\"\n\
73Camera.model : \"perspective\"\n\
90Camera.color_order : \"Gray\"\n\
96Feature.max_num_keypoints: 1200\n\
97Feature.scale_factor : 1.2\n\
98Feature.num_levels : 8\n\
99Feature.ini_fast_threshold : 20\n\
100Feature.min_fast_threshold : 7\n\
102#=====================#\n\
103# Tracking Parameters #\n\
104#=====================#\n\
106depth_threshold: 35\n");
108 mCfg = std::make_shared<openvslam::config>(mCfgNode);
120 mSlam->abort_loop_BA();
121 while (mSlam->loop_BA_is_running())
122 boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
134void Sslam::BuildCameraParam(
const aruco::CameraParameters &camparam)
138 int maxsize = std::max(camparam.CamSize.width, camparam.CamSize.height);
140 mScale = 640 / (float)maxsize;
160 mCfgNode[
"Camera.cols"] = (int)((
float)camparam.CamSize.width * mScale);
161 mCfgNode[
"Camera.rows"] = (int)((
float)camparam.CamSize.height * mScale);
163 float f = std::max(camparam.CamSize.width, camparam.CamSize.height);
164 mCfgNode[
"Camera.fx"] = f * mScale;
165 mCfgNode[
"Camera.fy"] = f * mScale;
166 mCfgNode[
"Camera.cx"] =
static_cast<float>(camparam.CamSize.width) * mScale * 0.5f;
167 mCfgNode[
"Camera.cy"] =
static_cast<float>(camparam.CamSize.height) * mScale * 0.5f;
169 mCfg = std::make_shared<openvslam::config>(mCfgNode);
172void Sslam::InitDetector()
174 boost::unique_lock<boost::recursive_mutex> ld(mUpdateMutex);
178 mSlam->abort_loop_BA();
179 while (mSlam->loop_BA_is_running())
180 boost::this_thread::sleep_for(boost::chrono::milliseconds(100));
190 sdata = CopyFileFromAssetToSD(
"btdata/orb_vocab.dbow2",
"orb_vocab.dbow2",
"btdata");
196 mSlam =
new openvslam::system(mCfg, sdata);
199 mSlam->enable_mapping_module();
200 mSlam->disable_loop_detector();
202 catch (std::exception &)
222 if (mSlam && !image.empty())
224 std::shared_ptr<openvslam::publish::frame_publisher> frame = mSlam->get_frame_publisher();
225 frame->draw_frame(
true).copyTo(image);
231 std::chrono::steady_clock::time_point lastTimeStamp = std::chrono::steady_clock::now();
240 nsize.width = (int)((
float)mLastData.
gray.cols * mScale);
241 nsize.height = (int)((
float)mLastData.
gray.rows * mScale);
244 cv::resize(mLastData.
gray, mLastData.
gray, nsize, 0, 0, cv::INTER_LINEAR);
255 if (!mSlam || (((
int)((
float)mLastData.camParam.CamSize.width * mScale)) != mCfg->camera_->cols_ || ((
int)((
float)mLastData.camParam.CamSize.height * mScale)) != mCfg->camera_->rows_))
262 BuildCameraParam(mLastData.camParam);
267 if (!mLastData.
image.empty() && mSlam)
269 std::chrono::steady_clock::time_point t1 = std::chrono::steady_clock::now();
270 double ttrack = std::chrono::duration_cast<std::chrono::duration<double>>(t1 - lastTimeStamp).count();
271 mTimestamp += ttrack;
272 lastTimeStamp = std::chrono::steady_clock::now();
274 mSlam->feed_monocular_frame(mLastData.
gray, mTimestamp);
276 std::shared_ptr<openvslam::publish::map_publisher> map = mSlam->get_map_publisher();
277 openvslam::Mat44_t mat = map->get_current_cam_pose().inverse().eval();
283 if (!isnan(mat(0, 3)))
285 openvslam::Mat33_t rotation_matrix = mat.block<3, 3>(0, 0);
286 openvslam::Vec3_t translation_vector = mat.block<3, 1>(0, 3);
288 openvslam::Quat_t quat(rotation_matrix);
291 mLastCamPos =
Vector3(translation_vector(0), -translation_vector(1), -translation_vector(2));
313 mLastCamQuat = Quaternion(-quat.w(), (mLastData.
reversedBitmap) ? quat.x() : -quat.x(), quat.y(), quat.z());
320 boost::this_thread::sleep_for(boost::chrono::milliseconds(1));
void GetLastData(LASTDATA &data)
static ArManager * GetInstance()
Vector3 GetCameraPosition()
BtQuaternion GetCameraOrientation()
void DrawLandmarks(cv::Mat image)
std::string GetCurrentWorkingDir(void)
std::string GetCurrentWorkingDir(void)