文档章节

opencv2在centos6.5上开发

testwork
 testwork
发布于 2016/07/21 13:41
字数 1739
阅读 116
收藏 0

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

 

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目录里面. 

 

© 著作权归作者所有

testwork
粉丝 4
博文 75
码字总数 21164
作品 0
崇明
程序员
私信 提问
opencv3.0中与CUDA相关的头文件和库解释

目前,opencv中的cuda接口能够实现的算法还比较少,并不是很齐全,使用前需要先确定算法是否存在cuda接口 相对2.x的改动 * 不再使用cv::gpu的命名空间,改用cv::cuda * 头文件中需要单独引用...

sirius_0
2018/04/08
0
0
vs2010上配置opencv2.x

以下教程和网上大多数的都差不多,只是我发现配置opencv3.x和2.x还有一点不同的地方,所以做一个记录。 需要注意的地方如下: 在vs2010和opencv2的搭配中,链接器–>输入–>附加依赖项那里只...

qq_33414271
2018/02/05
0
0
Ubuntu上交叉编译opencv及opencv_contrib并移植到ARM板之二

按照上篇之一的进度,已经编译及安装好了opencv库及opencv_contrib扩展库。 安装好库之后,无非就还有两件事要做:1、配置环境 2、实例编译 3、移植至开发板 一、环境配置 说明:pkg-config是...

qq_30155503
2018/04/19
0
0
opencv测试代码

` include include include using namespace cv; int main() { std::cout<<"loading"<

KnightJun
2016/05/15
3
0
xcode配置opencv无效的问题

我用brew下载了opencv,目录在 /usr/local/Cellar/opencv/4.1.0_1 然后我在xcode里面配置了 但是我的include 的目录结构和网上的教程不一样 这是我include的文件结构,如果我用 #include 会找...

杨承宣
04/24
27
0

没有更多内容

加载失败,请刷新页面

加载更多

02.日志系统:一条SQL更新语句是如何执行的?

我们还是从一个表的一条更新语句说起,我们创建下面一张表: create table T(ID int primary key, c int); 如果要将ID=2这一行c的值加1,SQL可以这么写: update T set c=c+1 where ID=2; 前...

scgaopan
46分钟前
7
0
【五分钟系列】掌握vscode调试技巧

调试前端js 准备一个前端项目 index.html <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1......

aoping
47分钟前
4
0
PhotoShop 高级应用:USM锐化/S锐化/防抖

、 高反差锐化+混合模式:叠加模式 【将更多的边缘细节添加到图像中】

东方墨天
58分钟前
7
0
Python数据可视化之matplotlib

常用模块导入 import numpy as npimport matplotlibimport matplotlib.mlab as mlabimport matplotlib.pyplot as pltimport matplotlib.font_manager as fmfrom mpl_toolkits.mplot3d i......

松鼠大帝
昨天
5
0
我用Bash编写了一个扫雷游戏

我在编程教学方面不是专家,但当我想更好掌握某一样东西时,会试着找出让自己乐在其中的方法。比方说,当我想在 shell 编程方面更进一步时,我决定用 Bash 编写一个扫雷游戏来加以练习。 我在...

老孟的Linux私房菜
昨天
9
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部