由于mac上 brew install opencv是不带viz模块的,所以需要源码编译
1、下载opencv和vtk源码
opencv:https://opencv.org/releases.html
vtkhttps://www.vtk.org/download/
当然也可以通过git clone
git clone https://gitlab.kitware.com/vtk/vtk.git VTK
cd VTK
git checkout vX.X.X
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout X.X.X
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib
git checkout X.X.X
2、编译
需要安装一个CMAKE
(1) 编译vtk
1、source code配置为vtk目录
2、binaries配置为vtk/build目录
3、配置 VTK_RENDERING_BACKEND为OpenGL
4、先configure再generate
5、然后打开xcode 需要修改/usr/local目录,所以需要root权限
6、得这么打开sudo /Applications/Xcode.app/Contents/MacOS/Xcode
7、然后在xocde里打开vtk/build,先跑ALL BUILD再跑install
(2) 编译opencv
1、source code配置为opencv目录
2、binaries配置为opencv/build目录
3、配置OPENCV_EXTRA_MOULES_PATH**设置为*/opencv_contrib/modules
4、配置VTK_DIR**设置为vtk/build
5、然后在xocde里打开vtk/build,先跑ALL BUILD再跑install
3、加环境变量
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
这里要特别注意了,因为默认opencv.pc是没有加入viz模块的所以在/usr/local/lib/pkgconfig/opencv.pc里的
Libs:后面加上-lopencv_viz
4、运行
1、如果是在命令行运行,MakeFile中加入
CFLAGS += `pkg-config --cflags --libs opencv`
2、如果是在xcode里运行,Build Settings-Other Linker Flags加入
opencv.pc里Libs后的内容,这是在我的xcode里加的
-L/usr/local/lib -lopencv_viz -lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn_objdetect -lopencv_dpm -lopencv_face -lopencv_photo -lopencv_fuzzy -lopencv_hfs -lopencv_img_hash -lopencv_line_descriptor -lopencv_optflow -lopencv_reg -lopencv_rgbd -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_phase_unwrapping -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_dnn -lopencv_plot -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ml -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_highgui -lopencv_videoio -lopencv_flann -lopencv_xobjdetect -lopencv_imgcodecs -lopencv_objdetect -lopencv_xphoto -lopencv_imgproc -lopencv_core
PS:centos服务器上按这个步骤也可以,只是编译的目录是在/usr/lib64下
如果运行带界面的demo会报错 DISPLAY(ABOUT)
网友评论