1. 显示--VIZ
曾经基于PCL 做过不少点云相关的开发,采样VTK进行有点云显示。后来基于OpenCV做了不少三维重建工作,总是将点云保存下来,然后借助CloudCompare等查看结果。如果能够将VIZ编译进来,预计会提升开发速度。
在Ubuntu下,VIZ的安装较为简单(珍爱生命,学习就用不要用Windows了)。在编译好OpenCV + Contrib之后(网上很多教程,这里不再赘述)。在build的目录内打开终端,输入下列命令行即可。
//安装VTK
sudo apt-get install libvtk6-dev
//打开vtk,生成及安装
cmake -DWITH_VTK=ON ..
make
sudo make install
//加载配置
ldconfig
测试VIZ,输入如下代码,测试、运行。
#include <opencv2/viz.hpp>
#include <opencv2/calib3d.hpp>
#include <iostream>using namespace cv;
using namespace std;static void help()
{cout<< "--------------------------------------------------------------------------" << endl<< "This program shows how to visualize a cube rotated around (1,1,1) and shifted "<< "using Rodrigues vector." << endl<< "Usage:" << endl<< "./widget_pose" << endl<< endl;
}int main()
{help();viz::Viz3d myWindow("Coordinate Frame");myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());viz::WLine axis(Point3f(-1.0f,-1.0f,-1.0f), Point3f(1.0f,1.0f,1.0f));axis.setRenderingProperty(viz::LINE_WIDTH, 4.0);myWindow.showWidget("Line Widget", axis);viz::WCube cube_widget(Point3f(0.5,0.5,0.0), Point3f(0.0,0.0,-0.5), true, viz::Color::blue());cube_widget.setRenderingProperty(viz::LINE_WIDTH, 4.0);myWindow.showWidget("Cube Widget", cube_widget);Mat rot_vec = Mat::zeros(1,3,CV_32F);float translation_phase = 0.0, translation = 0.0;rot_vec.at<float>(0, 0) += (float)CV_PI * 0.01f;rot_vec.at<float>(0, 1) += (float)CV_PI * 0.01f;rot_vec.at<float>(0, 2) += (float)CV_PI * 0.01f;translation_phase += (float)CV_PI * 0.01f;translation = sin(translation_phase);Mat rot_mat;Rodrigues(rot_vec, rot_mat);cout << "rot_mat = " << rot_mat << endl;Affine3f pose(rot_mat, Vec3f(translation, translation, translation));Affine3f pose2(pose.matrix);cout << "pose = " << pose.matrix << endl;cout << "pose = " << pose2.matrix << endl;while(!myWindow.wasStopped()){/* Rotation using rodrigues */rot_vec.at<float>(0,0) += (float)CV_PI * 0.01f;rot_vec.at<float>(0,1) += (float)CV_PI * 0.01f;rot_vec.at<float>(0,2) += (float)CV_PI * 0.01f;translation_phase += (float)CV_PI * 0.01f;translation = sin(translation_phase);Mat rot_mat1;Rodrigues(rot_vec, rot_mat1);Affine3f pose1(rot_mat1, Vec3f(translation, translation, translation));myWindow.setWidgetPose("Cube Widget", pose1);myWindow.spinOnce(1, true);}return 0;
}
运行上述代码之后,一个运动的正方体框会被展示出来。