由于需要在完全断网的环境下安装opencv ,我看了很多教程但都不全面,无非就是教大家如何编译,但不能从实际解决问题.写这篇博客也是因为我走了很多弯路浪费了一些时间,希望写个教程能对大家有所帮助.安装过程并不复杂,主要是这些依赖包不太好弄
此次教程版本:openCV3.4.1
百度网盘:https://pan.baidu.com/s/1s660Dtw0aA8DyI6Rfts_oA 提取码 3wd6
1.创建/home/opencv文件夹,将网盘下载的opencv.zip解压缩
2. 完成后目录结构如下:
#进入gcc-c++目录,并执行命令
rpm -Uvh *.rpm --nodeps --force
#回到opencv目录,执行命令:
rpm -Uvh cmake-2.8.12.2-2.el7.x86_64.rpm --nodeps --force
#进入python-decel目录,执行命令:
rpm -Uvh *.rpm --nodeps --force
#进入numpy目录,执行命令:
rpm -Uvh *.rpm --nodeps --force
#回到opencv目录,执行命令:
rpm -Uvh ffmpeg-2.8.15-2.el7.nux.x86_64.rpm --nodeps --force
进入opencv-3.4.1/3rdparty/ippicv目录,修改ippicv.cmake,将第47行修改为你存放ippicv_2017u3_lnx_intel64_general_20170822.tgz的目录
cmake -D WITH_TBB=ON -D WITH_EIGEN=ON ..
cmake -D BUILD_DOCS=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_EXAMPLES=OFF .. cmake -D WITH_OPENCL=OFF -D WITH_CUDA=OFF -D BUILD_opencv_gpu=OFF -D BUILD_opencv_gpuarithm=OFF -D BUILD_opencv_gpubgsegm=OFF -D BUILD_opencv_gpucodec=OFF -D BUILD_opencv_gpufeatures2d=OFF -D BUILD_opencv_gpufilters=OFF -D BUILD_opencv_gpuimgproc=OFF -D BUILD_opencv_gpulegacy=OFF -D BUILD_opencv_gpuoptflow=OFF -D BUILD_opencv_gpustereo=OFF -D BUILD_opencv_gpuwarping=OFF ..
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
make install
#1. 编辑/etc/ld.so.conf文件,在末尾加入include /usr/loacal/lib
#为了保险,在/etc/ld.so.conf.d/文件夹下在创建一个conf文件
cd /etc/ld.so.conf.d/
echo "/usr/local/lib" > opencv.conf
#2. 修改后更新动态链接库
ldconfig
#3. 修改/etc/bashrc 在文件末尾加入pgk_config_path路径
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
#4. 让配置文件立即生效
source /etc/bashrc
#5. 更新数据
updatedb
#6. 创建文件夹
mkdir -p /usr/local/lib/pkgconfig
#7. 将opencv.pc 复制到刚刚创建的文件夹
cp /home/opencv/opencv-3.4.1/build/unix-install/opencv.pc /usr/local/lib/pkgconfig
#8. 进入opencv-3.4.1/samples/cpp/example_cmake目录
cd /home/opencv/opencv-3.4.1/samples/cpp/example_cmake
#9. 将/home/opencv/opencv-3.4.1/build/lib目录下全部文件复制到/usr/local/lib
cp -r /home/opencv/opencv-3.4.1/build/lib/** /usr/local/lib
#10. 更新动态链接库,更新数据
ldconfig
updatedb
#11. 编译测试代码,生成opencv_example可执行文件
make
#12. 执行测试代码
./opencv_example
No capture
OpenCV(3.4.1) Error: Unspecified error (The function is not implemented.
Rebuild the library with Windows, GTK+ 2.x or Carbon support.
If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config,
then re-run cmake or configure script) in cvShowImage,
file /home/opencv/opencv-3.4.1/opencv-3.4.1/modules/highgui/src/window.cpp,
line 636
terminate called after throwing an instance of 'cv::Exception'
what(): OpenCV(3.4.1) /home/opencv/opencv-3.4.1/opencv-
3.4.1/modules/highgui/src/window.cpp:636: error: (-2)
The function is not implemented. Rebuild
the library with Windows, GTK+ 2.x or Carbon support.
If you are on Ubuntu or Debian,
install libgtk2.0-dev and pkg-config,
then re-run cmake or configure script in function cvShowImage
解决方式:
由于是内网环境所以有两种方式