赞
踩
————————————————————————————
遵循先安装 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
如果一切正常,在cmake_gui输出窗口中可以看到:
然后可以运行示例测试一下:
路径:
./opencv_contrib-4.5.0/modules/viz/ # 在OpenCV_Contrib中
————————————————————————————
/** * @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; }
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})
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。