ubuntu 16.04 + Qt5.7.1+VTK6.3.0 + opencv2.4.13-viz(3D可视化)安装教程

ubuntu 16.04 + Qt5.7.1+VTK6.3.0 + opencv2.4.13-viz(3D可视化)安装教程


author@jason_ql
http://blog.csdn.net/lql0716


  • Viz-OpenCV2.4.13官方文档

  • This section describes 3D visualization window as well as classes and methods that are used to interact with it.
    3D visualization window (see Viz3d) is used to display widgets (see Widget), and it provides several methods to interact with scene and widgets.

  • Vtk,(visualization toolkit)是一个开源的免费软件系统,主要用于三维计算机图形学、图像处理和可视化。Vtk是在面向对象原理的基础上设计和实现的,它的内核是用C++构建的,包含有大约250,000行代码,2000多个类。

  • OpenGL(全写Open Graphics Library)是指定义了一个跨编程语言、跨平台的编程接口规格的专业的图形程序接口。它用于三维图像(二维的亦可),是一个功能强大,调用方便的底层图形库。
    OpenGL™ 是行业领域中最为广泛接纳的 2D/3D 图形 API,其自诞生至今已催生了各种计算机平台及设备上的数千优秀应用程序。OpenGL™ 是独立于视窗操作系统或其它操作系统的,亦是网络透明的。在包含CAD、内容创作、能源、娱乐、游戏开发、制造业、制药业及虚拟现实等行业领域中,OpenGL™ 帮助程序员实现在 PC、工作站、超级计算机等硬件设备上的高性能、极具冲击力的高视觉表现力图形处理软件的开发。

1 安装可视化cmake-gui

sudo apt-get install cmake-curses-gui

2 安装Qt5

安装过程可参考以下链接的第3.1节
http://blog.csdn.net/lql0716/article/details/54564721

3 安装X11

sudo apt-get install libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev

4 安装OpenGL

sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev libglut-dev

  • 如果提示libglut-dev安装失败,则用如下命令安装libglut-dev:
    sudo apt-get install freeglut3-dev

5 编译VTK6.3

  • 下载VTK6.3,并解压,解压后的文件名一般为VTK-6.3.0

    下载网址:http://www.vtk.org/download/

  • 打开cmake-gui界面

    在终端输入:cmake-gui

  • cmake-gui界面进行如下操作:

    • 1、设置“where is the source code:”的路径为文件夹VTK-6.3.0所在路径,如/home/VTK-6.3.0
    • 2、设置“where to build the binaries:”的路径为/home/VTK-6.3.0/build,即在/home/VTK-6.3.0的路径下新建文件夹build
    • 3、点击“Configure”,在弹出对话框中选择“Current Generator”为“Unix MakeFiles”,完成之后会提示“Configuring done”
    • 4、由于安装的是Qt5,而VTK-6.3.0默认是Qt 4, 故需要在第3步完成之后,找到Qt Version,将4改为5,然后再次点击“Configure”,完成之后会提示“Configuring done”
    • 5、点击“Generate”,完成之后会提示“Generating done”
    • 6、在终端进入到文件夹build的路径下,输入以下命令:

      sudo make
      sudo make install

    • 7、图示:

      图示可参考下面opencv的图示

    • 以上步骤完成以后,VTK-6.3.0安装完成。

6 编译opencv2.4.13

  • 下载opencv-2.4.13,并解压,解压后的文件名一般为opencv-2.4.13

    下载网址:http://blog.csdn.net/lql0716/article/details/52474045

  • 打开cmake-gui界面

    在终端输入:cmake-gui

  • cmake-gui界面进行如下操作:

    • 1、设置“where is the source code:”的路径为文件夹opencv-2.4.13所在的路径,如/home/opencv-2.4.13
    • 2、设置“where to build the binaries:”的路径为/home/opencv-2.4.13/build,即在/home/opencv-2.4.13的路径下新建文件夹build
    • 3、点击“Configure”,完成之后会提示“Configuring done”
    • 4、将"WITH_VTK"勾选,然后再次点击“Configure”,完成之后会提示“Configuring done”
    • 5、点击“Generate”,完成之后会提示“Generating done”
    • 6、在终端进入到文件夹build的路径下,输入以下命令:

      sudo make
      sudo make install

    • 7、图示:
      ubuntu 16.04 + Qt5.7.1+VTK6.3.0 + opencv2.4.13-viz(3D可视化)安装教程_第1张图片

    • 以上步骤完成以后,带VTK-6.3.0的opencv安装完成。

7 配置Qt

  • 打开Qt以后,新建工程,将以下路径添加“.pro”文件中,详细过程请参考以下链接第3节内容:
    http://blog.csdn.net/lql0716/article/details/54564721
    (注意:请添加本文的路径,多了一条路径/usr/local/lib/libopencv_viz.so,一定要添加进去)
INCLUDEPATH += /usr/local/include \
/usr/local/include/opencv \
/usr/local/include/opencv2 \
/usr/local/include/vtk-6.3

LIBS += /usr/local/lib/libopencv_calib3d.so \
/usr/local/lib/libopencv_contrib.so \
/usr/local/lib/libopencv_core.so \
/usr/local/lib/libopencv_features2d.so \
/usr/local/lib/libopencv_flann.so \
/usr/local/lib/libopencv_gpu.so \
/usr/local/lib/libopencv_highgui.so \
#/usr/local/lib/libopencv_imgcodecs.so \
/usr/local/lib/libopencv_imgproc.so \
/usr/local/lib/libopencv_legacy.so \
/usr/local/lib/libopencv_ml.so \
/usr/local/lib/libopencv_nonfree.so \
/usr/local/lib/libopencv_objdetect.so \
/usr/local/lib/libopencv_ocl.so \
/usr/local/lib/libopencv_photo.so \
#/usr/local/lib/libopencv_shape.so \
/usr/local/lib/libopencv_stitching.so \
/usr/local/lib/libopencv_superres.so \
/usr/local/lib/libopencv_video.so \
/usr/local/lib/libopencv_videostab.so \
/usr/local/lib/libopencv_viz.so

8 配置OpenCV.conf

  • 若不配置OpenCV.conf,某些lib文件可能失效。

  • 配置过程:http://blog.csdn.net/lql0716/article/details/54434695

9 Viz-3D可视化测试

  • 测试代码:
    将以下代码直接复制到Qt工程里面,点击运行即可。
#include 
#include 
//#include 
#include 

using namespace cv;
using namespace std;


int main()
{
    /// Create a window
    viz::Viz3d myWindow("Coordinate Frame");
    /// Add coordinate axes
    myWindow.showWidget("Coordinate Widget", viz::WCoordinateSystem());
    /// Add line to represent (1,1,1) axis
    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);
    /// Construct a cube widget
    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);
    /// Display widget (update if already displayed)
    myWindow.showWidget("Cube Widget", cube_widget);
    /// Rodrigues vector
    Mat rot_vec = Mat::zeros(1, 3, CV_32F);
    float translation_phase = 0.0, translation = 0.0;
    while (!myWindow.wasStopped())
    {
        //* Rotation using rodrigues
        /// Rotate around (1,1,1)
        rot_vec.at<float>(0, 0) += CV_PI * 0.01f;
        rot_vec.at<float>(0, 1) += CV_PI * 0.01f;
        rot_vec.at<float>(0, 2) += CV_PI * 0.01f;
        /// Shift on (1,1,1)
        translation_phase += CV_PI * 0.01f;
        translation = sin(translation_phase);
        Mat rot_mat;
        Rodrigues(rot_vec, rot_mat);
        /// Construct pose
        Affine3f pose(rot_mat, Vec3f(translation, translation, translation));
        myWindow.setWidgetPose("Cube Widget", pose);
        myWindow.spinOnce(1, true);
    }
    return 0;
}
  • 3D效果截图:

    ubuntu 16.04 + Qt5.7.1+VTK6.3.0 + opencv2.4.13-viz(3D可视化)安装教程_第2张图片

参考资料:

  • ubuntu14.04安装opengl

  • vtk官网下载

  • Ubuntu 16.04编译VTK7.1

  • Installing OpenCV 2.4.9 in Ubuntu 14.04 LTS

  • OpenCV Viz 3D虚拟空间模块

  • 使用Opencv3.0新特征(Viz,TLD….)

  • 相关文章

    • 机器学习、深度学习、计算机视觉、自然语言处理及应用案例——干货分享(持续更新……)
      http://blog.csdn.net/lql0716/article/details/70479493
    • ubuntu 16.04 + Qt 5.7.1 无法输入中文的解决方法
      http://blog.csdn.net/lql0716/article/details/54973160
    • Ubuntu 16.04 64位+anaconda2+opencv 3.2.0 + opencv_contrib 3.2.0
      http://blog.csdn.net/lql0716/article/details/54910014
    • Ubuntu 16.04 64位+Qt 5.7.1+opencv 3.2.0 + opencv_contrib 3.2.0
      http://blog.csdn.net/lql0716/article/details/54564721

你可能感兴趣的:(Ubuntu,opencv,Qt)