-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscene_3d.cpp
48 lines (40 loc) · 1.43 KB
/
scene_3d.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "scene_3d.h"
#include "opencv2/core/eigen.hpp"
Scene3D::Scene3D(const PlaneWorldModel& world)
: vis_3d_{"3D visualization"}
, has_camera_{false}
{
// Show the world axes in 3D.
vis_3d_.showWidget("World-axes", cv::viz::WCoordinateSystem(world.gridSize()));
// Visualize the world plane as a 3D image.
vis_3d_.showWidget("World-plane", cv::viz::WImage3D(world.worldImage(),
world.worldSize(),
cv::Vec3d::all(0.0),
{0.0, 0.0, -1.0},
{0.0, -1.0, 0.0}));
}
bool Scene3D::update(const cv::Mat& image, const PoseEstimate& estimate, const Eigen::Matrix3d& K)
{
// Extract a reference to the camera pose.
const auto& pose = estimate.pose_W_C;
if (estimate.isFound())
{
// Convert pose to cv::Mat.
cv::Mat pose_W_C;
cv::eigen2cv(pose.matrix(), pose_W_C);
// Convert calibration matrix to cv::Mat.
cv::Matx33d K_cv;
cv::eigen2cv(K, K_cv);
// Visualize the camera in 3D.
vis_3d_.showWidget("Camera", cv::viz::WCameraPosition(K_cv, image, 0.05));
vis_3d_.setWidgetPose("Camera", cv::Affine3d{pose_W_C});
has_camera_ = true;
}
else if (has_camera_)
{
vis_3d_.removeWidget("Camera");
has_camera_ = false;
}
vis_3d_.spinOnce();
return vis_3d_.wasStopped();
}