Skip to content

Commit 380dc56

Browse files
JujuDelJulien Delclos
andauthored
r5.1.2 (#734)
Co-authored-by: Julien Delclos <julien.delclos@stereolabs.com>
1 parent 9daa908 commit 380dc56

File tree

1 file changed

+45
-15
lines changed
  • positional tracking/positional tracking/cpp/src

1 file changed

+45
-15
lines changed

positional tracking/positional tracking/cpp/src/main.cpp

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ struct Arguments {
4343
std::optional<std::string> roiFile = std::nullopt;
4444
bool customInitialPose = false;
4545
bool enable2dGroundMode = false;
46+
bool exportTUMFile = false;
4647
};
4748

4849
//
@@ -56,7 +57,7 @@ void printTrackingParameters(PositionalTrackingParameters trackingParameters);
5657
void print(std::string message, std::optional<ERROR_CODE> errorCode = std::nullopt, bool showErrorDetail = true);
5758

5859
cv::Mat slMat2cvMat(Mat& input);
59-
cv::Scalar interpolate_color(const cv::Scalar& color1, const cv::Scalar& color2, float ratio);
60+
cv::Scalar interpolate_color(const cv::Scalar& color1, const cv::Scalar& color2, float dynamic_confidence);
6061

6162
//
6263
// Main
@@ -90,14 +91,14 @@ int main(int argc, char** argv) {
9091
initParameters.depth_mode = DEPTH_MODE::NEURAL;
9192
initParameters.coordinate_units = UNIT::METER;
9293
initParameters.coordinate_system = COORDINATE_SYSTEM::RIGHT_HANDED_Y_UP;
94+
initParameters.camera_disable_self_calib = true;
9395

9496
if (args.resolution) {
9597
initParameters.camera_resolution = args.resolution.value();
9698
}
9799

98100
if (args.svoFile) {
99101
initParameters.input.setFromSVOFile(args.svoFile.value().c_str());
100-
initParameters.svo_real_time_mode = true;
101102
} else if (args.streamIP && args.streamPort) {
102103
initParameters.input.setFromStream(args.streamIP.value().c_str(), args.streamPort.value());
103104
} else if (args.streamIP) {
@@ -190,6 +191,13 @@ int main(int argc, char** argv) {
190191
uint64_t lastLandmarkUpdate = getCurrentTimeStamp().getSeconds();
191192
Resolution displayResolution = zed.getRetrieveMeasureResolution();
192193

194+
//
195+
// Prepare out file for TUM trajectory
196+
//
197+
std::ofstream out_tum;
198+
if (args.exportTUMFile)
199+
out_tum.open("out.tum");
200+
193201
//
194202
// Main loop
195203
//
@@ -222,18 +230,26 @@ int main(int argc, char** argv) {
222230
// Retrieve the calculated camera pose
223231
zed.getPosition(pose);
224232

233+
// Export the pose in TUM format
234+
if (args.exportTUMFile) {
235+
out_tum << std::fixed << std::setprecision(9) << pose.timestamp.getMilliseconds() << " " << pose.getTranslation().tx << " "
236+
<< pose.getTranslation().ty << " " << pose.getTranslation().tz << " " << pose.getOrientation().ox << " "
237+
<< pose.getOrientation().oy << " " << pose.getOrientation().oz << " " << pose.getOrientation().ow << std::endl;
238+
out_tum.flush();
239+
}
240+
225241
// Update display
226242
//
227243
view.updatePoseTransform(pose.pose_data);
228244
view.updatePositionalTrackingStatus(zed.getPositionalTrackingStatus());
229245

230-
if (getCurrentTimeStamp().getSeconds() - lastLandmarkUpdate > 1) {
246+
if (zed.getTimestamp(sl::TIME_REFERENCE::IMAGE).getSeconds() - lastLandmarkUpdate > 1) {
231247
zed.getPositionalTrackingLandmarks(landmarkMap);
232248
view.updateLandmarks(landmarkMap);
233-
lastLandmarkUpdate = getCurrentTimeStamp().getSeconds();
249+
lastLandmarkUpdate = zed.getTimestamp(sl::TIME_REFERENCE::IMAGE).getSeconds();
234250
}
235251

236-
if (view.isLandmarkModeEnabled() && landmarkMap.size()) {
252+
if (view.isLandmarkModeEnabled()) {
237253
zed.getPositionalTrackingLandmarks2D(landmarks2D);
238254

239255
static const cv::Scalar inlierLandmarkColor(63, 255, 67, 255);
@@ -245,7 +261,7 @@ int main(int argc, char** argv) {
245261

246262
cv::Mat leftImageCVMat = slMat2cvMat(leftImage);
247263
for (auto& landmark2D : landmarks2D) {
248-
cv::Scalar color = interpolate_color(inlierLandmarkColor, outlierLandmarkColor, 1 - landmark2D.dynamic_confidence);
264+
cv::Scalar color = interpolate_color(inlierLandmarkColor, outlierLandmarkColor, landmark2D.dynamic_confidence);
249265

250266
cv::circle(
251267
leftImageCVMat,
@@ -258,6 +274,9 @@ int main(int argc, char** argv) {
258274
}
259275
});
260276

277+
if (args.exportTUMFile)
278+
out_tum.close();
279+
261280
//
262281
// OpenGL cleanup
263282
//
@@ -403,6 +422,8 @@ bool parseArgs(int argc, char* argv[], Arguments& args) {
403422
args.customInitialPose = true;
404423
} else if (arg == "--2d-ground-mode") {
405424
args.enable2dGroundMode = true;
425+
} else if (arg == "--export-tum") {
426+
args.exportTUMFile = true;
406427
} else {
407428
print("Unrecognized or incomplete argument: " + arg, ERROR_CODE::FAILURE, false);
408429
return false;
@@ -482,6 +503,10 @@ void printArgs(const Arguments& args) {
482503
print("Enabled 2D ground mode");
483504
}
484505

506+
if (args.exportTUMFile) {
507+
print("Enabled TUM trajectory export to out.tum");
508+
}
509+
485510
std::cout << "\n";
486511
}
487512

@@ -564,19 +589,24 @@ cv::Mat slMat2cvMat(Mat& input) {
564589
return cv::Mat(input.getHeight(), input.getWidth(), cv_type, input.getPtr<sl::uchar1>(MEM::CPU));
565590
}
566591

567-
cv::Scalar interpolate_color(const cv::Scalar& color1, const cv::Scalar& color2, float ratio) {
568-
if (ratio < 0.0f) {
569-
ratio = 0.0f;
592+
cv::Scalar interpolate_color(const cv::Scalar& color1, const cv::Scalar& color2, float dynamic_confidence) {
593+
594+
if (dynamic_confidence == -1.f) {
595+
return cv::Scalar(240, 25, 25, 255);
596+
}
597+
598+
if (dynamic_confidence < 0.0f) {
599+
dynamic_confidence = 0.0f;
570600
}
571601

572-
if (ratio > 1.0f) {
573-
ratio = 1.0f;
602+
if (dynamic_confidence > 1.0f) {
603+
dynamic_confidence = 1.0f;
574604
}
575605

576606
return cv::Scalar(
577-
color1[0] * (1 - ratio) + color2[0] * ratio,
578-
color1[1] * (1 - ratio) + color2[1] * ratio,
579-
color1[2] * (1 - ratio) + color2[2] * ratio,
580-
color1[3] * (1 - ratio) + color2[3] * ratio
607+
color1[0] * dynamic_confidence + color2[0] * (1 - dynamic_confidence),
608+
color1[1] * dynamic_confidence + color2[1] * (1 - dynamic_confidence),
609+
color1[2] * dynamic_confidence + color2[2] * (1 - dynamic_confidence),
610+
color1[3] * dynamic_confidence + color2[3] * (1 - dynamic_confidence)
581611
);
582612
}

0 commit comments

Comments
 (0)