Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/opencv.hpp>
- #include <opencv2/viz.hpp>
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- using namespace cv;
- bool bCamView = false;
- void keyboard_callback(const viz::KeyboardEvent &event, void* cookie)
- {
- if (event.action == 0 && !event.symbol.compare("s"))
- bCamView = !bCamView;
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- /// Create 3D windows
- viz::Viz3d Window_3D("Estimation Coordinate Frame");
- Window_3D.setBackgroundColor(); // black by default
- Window_3D.registerKeyboardCallback(&keyboard_callback);
- // Create the pointcloud
- cout << "Reading the 3D points ... ";
- const int NoOfCamera = 10;
- const double fx = 1239.911,
- fy = 1239.911,
- cx = 519.909,
- cy = 246.656;
- Matx33d K = Matx33d(fx, 0, cx,
- 0, fy, cy,
- 0, 0, 1);
- vector<Affine3d> Cam_Trajectory;
- Mat RotationVector(1, 3, CV_64FC1, Scalar(0.0));
- Mat TranslationVector(3, 1, CV_64FC1, Scalar(1.0));
- for (size_t i = 0; i < NoOfCamera; ++i)
- {
- Cam_Trajectory.push_back(Affine3d(RotationVector, TranslationVector));
- TranslationVector.at<double>(2, 0) += 1.0;
- }
- Vec3d Pt3d_Object(0.10,0.10,15.0);
- /// Wait for key 'q' to close the window
- cout << endl << "Press: " << endl;
- cout << " 's' to switch the camera view" << endl;
- cout << " 'q' to close the windows " << endl;
- if (Cam_Trajectory.size() > 0)
- {
- // animated trajectory
- int idx = 0, forw = -1, n = static_cast<int>(Cam_Trajectory.size());
- while (!Window_3D.wasStopped())
- {
- /// Render a 3D cube
- Affine3d point_pose(Mat::eye(3, 3, CV_64F), Pt3d_Object);
- viz::WCube cube_widget(Point3f(0.1, 0.1, 0.0), Point3f(0.0, 0.0, -0.1), true, viz::Color::blue());
- cube_widget.setRenderingProperty(viz::LINE_WIDTH, 2.0);
- Window_3D.showWidget("Cube1", cube_widget, point_pose);
- Affine3d cam_pose = Cam_Trajectory[idx];
- viz::WCameraPosition cpw(0.25); // Coordinate axes
- viz::WCameraPosition cpw_frustum(K, 0.3, viz::Color::yellow()); // Camera frustum
- if (bCamView)
- {
- Window_3D.setViewerPose(cam_pose);
- }
- else
- {
- // render complete trajectory
- Window_3D.showWidget("cameras_frames_and_lines_est", viz::WTrajectory(Cam_Trajectory, viz::WTrajectory::PATH, 1.0, viz::Color::green()));
- Window_3D.showWidget("CPW", cpw, cam_pose);
- Window_3D.showWidget("CPW_FRUSTUM", cpw_frustum, cam_pose);
- }
- // update trajectory index (spring effect)
- forw *= (idx == n || idx == 0) ? -1 : 1;
- idx += forw;
- // frame rate 1s
- Window_3D.spinOnce(100, true);
- Window_3D.removeAllWidgets();
- }
- }
- Window_3D.close();
- return 0;
- }
Add Comment
Please, Sign In to add comment