opencv2在centos6.5上开发

前端之家收集整理的这篇文章主要介绍了opencv2在centos6.5上开发前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

博客写的有点乱,一般都是工作中遇到的问题,做一下笔记

1) 因为之前opencv是在centos7上开发调试的.突然发现服务器是cents6.x的.只能移植

centos 直接使用

pip install pyopenssl
yum install opencv opencv-core -y
yum install gtk+-devel gtk2-devel -y
yum install python-devel -y

2) centos 6.x安装opencv2.4.9

下载 :

http://heanet.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip

解压缩到目录opencv-2.4.9,编译:

yum install cmake -y 

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_NEW_PYTHON_SUPPORT=NO .

make

编译之后,可以发现 opencv-2.4.9/lib目录下有好多东西

make install

其他: 为下一步做好准备:

1.配置

  新建文件 /etc/ld.so.conf.d/opencv.conf

  在文件添加  /usr/local/lib

   保存之后执行配置

   sudo ldconfig

2.环境变量配置

   sudo vim /etc/bashrc

   PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
   export PKG_CONFIG_PATH

   保存之后执行

    source /etc/bashrc

具体可以参考:
http://www.cnblogs.com/changingivan/archive/2013/01/17/2864076.html

3) 从centos7环境的/usr/include目录下,把opencv和opencv2的头文件目录拷贝至centos6.x的/usr/include目录下

可以参考:

http://blog.csdn.net/unixor/article/details/10894455

4) 因为开发的so库是提供给python的,所以需要安装python-devel.

但是python的运行环境是2.7,安装python2.7 编译.

下载:

https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz

解压缩

xz -d Python-2.7.12.tar.xz
会生成文件Python-2.7.12.tar

继续解压缩
tar xvf Python-2.7.12.tar

编译,安装(注意include文件夹下面有个Python2.7目录,如果没有,可以从centos7上复制)

./configure

make

make install

5) 编译项目源代码

g++ `pkg-config opencv --libs --cflags opencv` -fPIC -c -I/usr/include/python2.7 -I /usr/lib/python2.7/config 添加自己的cpp源代码以及h头文件

6) 测试验证

[root@vmpc opencvDemo]# ldd pyxxxxxx.so 
        linux-vdso.so.1 =>  (0x00007fffe73ff000)
        libopencv_calib3d.so.2.4 => /usr/local/lib/libopencv_calib3d.so.2.4 (0x00007f2c5cc5c000)
        libopencv_contrib.so.2.4 => /usr/local/lib/libopencv_contrib.so.2.4 (0x00007f2c5c970000)
        libopencv_core.so.2.4 => /usr/local/lib/libopencv_core.so.2.4 (0x00007f2c5c4d0000)
        libopencv_features2d.so.2.4 => /usr/local/lib/libopencv_features2d.so.2.4 (0x00007f2c5c223000)
        libopencv_flann.so.2.4 => /usr/local/lib/libopencv_flann.so.2.4 (0x00007f2c5bfaf000)
        libopencv_gpu.so.2.4 => /usr/local/lib/libopencv_gpu.so.2.4 (0x00007f2c5bd65000)
        libopencv_highgui.so.2.4 => /usr/local/lib/libopencv_highgui.so.2.4 (0x00007f2c5b938000)
        libopencv_imgproc.so.2.4 => /usr/local/lib/libopencv_imgproc.so.2.4 (0x00007f2c5b450000)
        libopencv_legacy.so.2.4 => /usr/local/lib/libopencv_legacy.so.2.4 (0x00007f2c5b130000)
        libopencv_ml.so.2.4 => /usr/local/lib/libopencv_ml.so.2.4 (0x00007f2c5aeac000)
        libopencv_nonfree.so.2.4 => /usr/local/lib/libopencv_nonfree.so.2.4 (0x00007f2c5ac6f000)
        libopencv_objdetect.so.2.4 => /usr/local/lib/libopencv_objdetect.so.2.4 (0x00007f2c5a9ed000)
        libopencv_ocl.so.2.4 => /usr/local/lib/libopencv_ocl.so.2.4 (0x00007f2c5a60a000)
        libopencv_photo.so.2.4 => /usr/local/lib/libopencv_photo.so.2.4 (0x00007f2c5a3ea000)
        libopencv_stitching.so.2.4 => /usr/local/lib/libopencv_stitching.so.2.4 (0x00007f2c5a178000)
        libopencv_superres.so.2.4 => /usr/local/lib/libopencv_superres.so.2.4 (0x00007f2c59f36000)
        libopencv_video.so.2.4 => /usr/local/lib/libopencv_video.so.2.4 (0x00007f2c59cdc000)
        libopencv_videostab.so.2.4 => /usr/local/lib/libopencv_videostab.so.2.4 (0x00007f2c59a9e000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f2c59896000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f2c59678000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f2c59474000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f2c5916b000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f2c58ee6000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f2c58cd0000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f2c5893c000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f2c58725000)
        libpng12.so.0 => /usr/lib64/libpng12.so.0 (0x00007f2c584ff000)
        libgthread-2.0.so.0 => /lib64/libgthread-2.0.so.0 (0x00007f2c582fa000)
        libglib-2.0.so.0 => /lib64/libglib-2.0.so.0 (0x00007f2c57fe3000)
        /lib64/ld-linux-x86-64.so.2 (0x000000337d000000)

使用python脚本测试.

一切ok

备注: 编译opencv / 安装opencv / 编译python源码,/ 安装python

涉及到了头文件,g++编译.

最后依赖的文件写成Makefile (有一些.a文件可能是多余的,没有去验证)

install:

	sudo chmod +x centos6.5lib/*

	echo "copy lib to /usr/local/lib/ "

	sudo cp centos6.5lib/libopencv_calib3d_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_calib3d.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_calib3d.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_calib3d.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_contrib_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_contrib.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_contrib.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_contrib.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_core_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_core.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_core.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_core.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_features2d_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_features2d.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_features2d.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_features2d.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_flann_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_flann.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_flann.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_flann.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_gpu_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_gpu.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_gpu.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_gpu.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_haartraining_engine.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_highgui_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_highgui.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_highgui.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_highgui.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_imgproc_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_imgproc.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_imgproc.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_imgproc.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_legacy_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_legacy.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_legacy.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_legacy.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ml_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ml.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ml.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ml.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_nonfree_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_nonfree.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_nonfree.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_nonfree.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_objdetect_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_objdetect.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_objdetect.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_objdetect.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ocl_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ocl.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ocl.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ocl.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_calib3d_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_core_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_features2d_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_gpu_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_highgui_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_imgproc_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_nonfree_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_objdetect_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_ocl_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_photo_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_stitching_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_superres_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_perf_video_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_photo_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_photo.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_photo.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_photo.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_stitching_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_stitching.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_stitching.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_stitching.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_superres_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_superres.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_superres.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_superres.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_calib3d_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_contrib_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_core_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_features2d_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_flann_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_gpu_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_highgui_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_imgproc_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_legacy_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_ml_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_nonfree_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_objdetect_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_ocl_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_photo_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_stitching_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_superres_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_test_video_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ts.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_ts_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_video_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_video.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_video.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_video.so.2.4.9 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_videostab_pch_dephelp.a /usr/local/lib/
	sudo cp centos6.5lib/libopencv_videostab.so /usr/local/lib/
	sudo cp centos6.5lib/libopencv_videostab.so.2.4 /usr/local/lib/
	sudo cp centos6.5lib/libopencv_videostab.so.2.4.9 /usr/local/lib/

	echo "copy finished..."

	echo "ln -s so to /lib64/ "

	sudo ln -s /usr/local/lib/libopencv_calib3d.so.2.4 /lib64/libopencv_calib3d.so.2.4
	sudo ln -s /usr/local/lib/libopencv_contrib.so.2.4 /lib64/libopencv_contrib.so.2.4
	sudo ln -s /usr/local/lib/libopencv_core.so.2.4  /lib64/libopencv_core.so.2.4
	sudo ln -s /usr/local/lib/libopencv_features2d.so.2.4 /lib64/libopencv_features2d.so.2.4
	sudo ln -s /usr/local/lib/libopencv_flann.so.2.4 /lib64/libopencv_flann.so.2.4
	sudo ln -s /usr/local/lib/libopencv_gpu.so.2.4 /lib64/libopencv_gpu.so.2.4
	sudo ln -s /usr/local/lib/libopencv_highgui.so.2.4 /lib64/libopencv_highgui.so.2.4
	sudo ln -s /usr/local/lib/libopencv_imgproc.so.2.4 /lib64/libopencv_imgproc.so.2.4
	sudo ln -s /usr/local/lib/libopencv_legacy.so.2.4 /lib64/libopencv_legacy.so.2.4
	sudo ln -s /usr/local/lib/libopencv_ml.so.2.4 /lib64/libopencv_ml.so.2.4
	sudo ln -s /usr/local/lib/libopencv_nonfree.so.2.4 /lib64/libopencv_nonfree.so.2.4
	sudo ln -s /usr/local/lib/libopencv_objdetect.so.2.4 /lib64/libopencv_objdetect.so.2.4
	sudo ln -s /usr/local/lib/libopencv_ocl.so.2.4 /lib64/libopencv_ocl.so.2.4
	sudo ln -s /usr/local/lib/libopencv_photo.so.2.4 /lib64/libopencv_photo.so.2.4
	sudo ln -s /usr/local/lib/libopencv_stitching.so.2.4 /lib64/libopencv_stitching.so.2.4
	sudo ln -s /usr/local/lib/libopencv_superres.so.2.4 /lib64/libopencv_superres.so.2.4
	sudo ln -s /usr/local/lib/libopencv_video.so.2.4 /lib64/libopencv_video.so.2.4
	sudo ln -s /usr/local/lib/libopencv_videostab.so.2.4 /lib64/libopencv_videostab.so.2.4


	echo "....finished...."

只需要在需要使用的环境,执行make,自动安装到lib64目录里面.

原文链接:https://www.f2er.com/centos/381528.html

猜你在找的CentOS相关文章