当前位置:   article > 正文

0.OpenCV可视化(Viz)——Viz环境的配置_cv::viz 无法链接

cv::viz 无法链接

————————————————————————————

安装步骤

遵循先安装 VTK 再安装OpenCV 的原则执行:
VTK下载(我的版本是OpenCV4.5.0 + VTK9.0.1):
https://vtk.org/download/
OpenCV 需要安装Contrib模块。

# VTK
mkdir build && cd build
cmake .. 
make 
make install
#--------------------------------------------#

# OpenCV
mkdir build && cd build 
cmake-gui 
# 设置VTK路径(如果默认路径则会自己勾选)
# nonfree、extra_modules等库
make 
make install 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

如果一切正常,在cmake_gui输出窗口中可以看到:
Output_Windows

VTK_Support OK
然后可以运行示例测试一下:
路径:

./opencv_contrib-4.5.0/modules/viz/ # 在OpenCV_Contrib中

————————————————————————————

结果验证

  • 例程中的launching_viz.cpp
/**
 * @file launching_viz.cpp
 * @brief Launching visualization window
 * @author Ozan Cagri Tonkal
 */

#include <opencv2/viz.hpp>
#include <iostream>

using namespace cv;
using namespace std;

/**
 * @function help
 * @brief Display instructions to use this tutorial program
 */
static void help()
{
    cout
    << "--------------------------------------------------------------------------" << endl
    << "This program shows how to launch a 3D visualization window. You can stop event loop to continue executing. "
    << "You can access the same window via its name. You can run event loop for a given period of time. " << endl
    << "Usage:"                                                                     << endl
    << "./launching_viz"                                                            << endl
    << endl;
}

/**
 * @function main
 */
int main()
{
    help();
    /// Create a window
    viz::Viz3d myWindow("Viz Demo");

    /// Start event loop
    myWindow.spin();

    /// Event loop is over when pressed q, Q, e, E
    cout << "First event loop is over" << endl;

    /// Access window via its name
    viz::Viz3d sameWindow = viz::getWindowByName("Viz Demo");

    /// Start event loop
    sameWindow.spin();

    /// Event loop is over when pressed q, Q, e, E
    cout << "Second event loop is over" << endl;

    /// Event loop is over when pressed q, Q, e, E
    /// Start event loop once for 1 millisecond
    sameWindow.spinOnce(1, true);
    while(!sameWindow.wasStopped())
    {
        /// Interact with window

        /// Event loop for 1 millisecond
        sameWindow.spinOnce(1, true);
    }

    /// Once more event loop is stopped
    cout << "Last event loop is over" << endl;
    return 0;
}

  • 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
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • CmakeLists.txt
cmake_minimum_required(VERSION 3.16)
project(VTKLearning)

set(CMAKE_CXX_STANDARD 14)

find_package(VTK  REQUIRED)
message(STATUS "   VTK Version: ${VTK_VERSION}" )
include(${VTK_USE_FILE})
find_package(OpenCV 4 REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS "   OpenCV Version: ${OpenCV_VERSION}" )
include_directories(${OpenCV_INCLUDES})
find_package(Eigen3)

add_executable(VTKSample creating_widgets.cpp)
target_link_libraries(VTKSample ${OpenCV_LIBS}  ${VTK_LIBRARIES})
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 运行结果:
    Result
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/119761?site
推荐阅读
相关标签
  

闽ICP备14008679号