Chinaunix首页 | 论坛 | 博客
  • 博客访问: 480854
  • 博文数量: 98
  • 博客积分: 3265
  • 博客等级: 中校
  • 技术积分: 1227
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-23 00:29
文章分类

全部博文(98)

文章存档

2012年(6)

2011年(83)

2010年(9)

分类: LINUX

2011-12-27 21:08:44

opencv for pc:
1.下载opencv for linux,这里选择新版本opencv version 2.3

2,初步安装opencv
[]tar jxvf OpenCV-2.3.0.tar.bz2
[]cd OpenCV-2.3.0/
[]mkdir release
[]cd release //编译的东西放一个目录,防止和源文件换乱
[]cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
//提示没有cmake,那就首先安装cmake

3,小插曲,下载cmake来安装,
[]tar xvzf cmake-2.8.6.tar.gz
[]cd cmake-2.8.6
[]./configure
[]make
[]make install //安装在/usr/local/目录下

4,继续安装opencv
[]cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON ..
[]make
[]make install //安装在/usr/local/目录下

5,添加库路径
[]gedit /etc/ld.so.conf.d/opencv.conf
加入
/usr/local/lib

6,更新系统库
[]ldconfig

7,设置环境变量
[]export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

8,测试
[]cd ~/OpenCV-2.3.0/samples/c
[]chmod +x build_all.sh
[]./build_all.sh
[]./facedetect --cascade="/usr/local/share/opencv/haarcascades/haarcascade_frontalface_alt.xml" --scale=1.5 lena.jpg

9,成功的话,将会出现那个熟悉的大眼睛女人被识别出了妩媚的面容

10,刚才编译的是C的例子,现在编译一个CPP的例子,自然要使用g++编译了
[]cd ..../OpenCV-2.3.0/samples/cpp
[]g++ `pkg-config --cflags --libs opencv` drawing.cpp -o drawing
[]./drawing

11,成功的话,五彩缤纷的画线出现了


=====================================================================
另一种简便的配置,针对PC机,对Cmake的配置如下,指定编译release版本和安装路径即可:
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-pc ..

[root@bangde ~]# cd opencv_pc/OpenCV-2.3.0/release/
[root@bangde release]# cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-pc ..
-- The C compiler identification is GNU
-- The CXX compiler identification is GNU
-- Check for working C compiler: /usr/lib/ccache/gcc
-- Check for working C compiler: /usr/lib/ccache/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/lib/ccache/c++
-- Check for working CXX compiler: /usr/lib/ccache/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Extracting svn version, please wait...
-- SVNVERSION: 
-- Detected version of GNU GCC: 45 (405)
-- checking for module 'gtk+-2.0'
--   found gtk+-2.0, version 2.22.0
-- checking for module 'gthread-2.0'
--   found gthread-2.0, version 2.26.0
-- checking for module 'gstreamer-base-0.10'
--   package 'gstreamer-base-0.10' not found
-- checking for module 'gstreamer-app-0.10'
--   package 'gstreamer-app-0.10' not found
-- checking for module 'gstreamer-video-0.10'
--   package 'gstreamer-video-0.10' not found
-- checking for module 'libavcodec'
--   package 'libavcodec' not found
-- checking for module 'libavformat'
--   package 'libavformat' not found
-- checking for module 'libavutil'
--   package 'libavutil' not found
-- checking for module 'libswscale'
--   package 'libswscale' not found
-- Looking for libavformat/avformat.h
-- Looking for libavformat/avformat.h - not found
-- Looking for ffmpeg/avformat.h
-- Looking for ffmpeg/avformat.h - not found
-- checking for module 'libdc1394-2'
--   package 'libdc1394-2' not found
-- checking for module 'libdc1394'
--   package 'libdc1394' not found
-- Found ZLIB: /usr/include
-- Found PNG: /usr/lib/libpng.so
-- Looking for /usr/include/png.h
-- Looking for /usr/include/png.h - found
-- Looking for /usr/include/libpng/png.h
-- Looking for /usr/include/libpng/png.h - not found
-- Found TIFF: /usr/lib/libtiff.so
-- Found JPEG: /usr/lib/libjpeg.so
-- Could NOT find Jasper  (missing:  JASPER_LIBRARY JASPER_INCLUDE_DIR)
-- Looking for alloca.h
-- Looking for alloca.h - found
-- Looking for alloca
-- Looking for alloca - not found
-- Looking for unistd.h
-- Looking for unistd.h - found
-- Looking for pthread.h
-- Looking for pthread.h - found
-- checking for module 'libv4l1'
--   package 'libv4l1' not found
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Found PythonInterp: /usr/bin/python
-- Found PythonLibs: /usr/lib/libpython2.7.so
Traceback (most recent call last):
  File "", line 1, in
ImportError: No module named numpy.distutils
Traceback (most recent call last):
  File "", line 1, in
ImportError: No module named sphinx
CUDA_TOOLKIT_ROOT_DIR not found or specified
Requested CUDA version 4.0, but found unacceptable version 
-- Could NOT find CUDA  (missing:  CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY _cuda_version_acceptable)
-- Parsing 'cvconfig.h.cmake'
-- 
-- General configuration for opencv 2.3.0 =====================================
-- 
--     Built as dynamic libs?:     ON
--     Compiler:                   
--     C++ flags (Release):          -Wall -pthread -march=i686 -ffunction-sections  -O3 -DNDEBUG  -fomit-frame-pointer -ffast-math -msse -msse2 -mfpmath=387 -DNDEBUG 
--     C++ flags (Debug):            -Wall -pthread -march=i686 -ffunction-sections  -g  -O0 -DDEBUG -D_DEBUG -ggdb3 
--     Linker flags (Release):      
--     Linker flags (Debug):        
-- 
--   GUI: 
--     GTK+ 2.x:                   1
--     GThread:                    1
-- 
--   Media I/O: 
--     ZLib:                       TRUE
--     JPEG:                       TRUE
--     PNG:                        TRUE
--     TIFF:                       TRUE
--     JPEG 2000:                  build
--     OpenEXR:                    NO
--     OpenNI:                     FALSE
-- 
--   Video I/O: 
--     DC1394 1.x:                 0
--     DC1394 2.x:                 0
--     FFMPEG:                     0
--       codec:                    0
--       format:                   0
--       util:                     0
--       swscale:                  0
--       gentoo-style:             
--     GStreamer:                  0
--     UniCap:                     FALSE
--     PvAPI:                      
--     V4L/V4L2:                   1/1
--     Xine:                       FALSE
-- 
--   Interfaces: 
--     Python:                     ON
--     Python interpreter:         /usr/bin/python
--     Python numpy:               NO (Python interface will not cover OpenCV 2.x API)
--     Use IPP:                    NO
--     Use TBB:                    NO
--     Use ThreadingFramework:     NO
--     Use Cuda:                   NO
--     Use Eigen:                  NO
-- 
--   Documentation: 
--     Build Documentation:        NO
-- 
--     Install path:               /usr/local/opencv-pc
-- 
--     cvconfig.h is in:           /root/opencv_pc/OpenCV-2.3.0/release
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /root/opencv_pc/OpenCV-2.3.0/release


==================================================================
opencv for arm:
需要对opencv进行裁剪,opencv的GUI部分都是基于GTK的,arm上不被支持,要进行裁剪。
a,对Cmake的配置如下:cmake的参数可是应用cmake help查看。
cmake -DCMAKE_SYSTEM_NAME=arm-linux -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local/opencv-arm -D CMAKE_C_COMPILER=arm-linux-gcc -D CMAKE_CXX_COMPILER=arm-linux-g++ -D CMAKE_EXE_LINKER_FLAGS="-lpthread -lrt" -D WITH_TIFF=OFF ..

b,把opencv for arm的库/usr/local/opencv-arm/lib拷贝到开发板,一般拷贝到开发板的/lib目录或者/usr/lib目录。

c,编译应用程序测试:说明这里仅仅是一种编译的方法,drawing.cpp包含GUI部分,编译后放在开发板上跑不起来,所以对于GUI部分考虑先移植QT,用QT来显示。
arm-linux-g++ -I/usr/local/opencv-arm/include -L/usr/local/opencv-arm/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann -lpthread -lrt drawing.cpp -o drawing
等同:下面这个使用PKG-CONFIG来管理opencv的头文件和库文件。
=============================================================
arm-linux-g++ `pkg-config --cflags --libs opencv-arm` drawing.cpp
=================================================================

d,若在开发板上运行程序,提示缺少xxopencv库,而该库已经拷贝到开发板,此种情况需要更改库的软连接,或者重命名库的名字。

ldd drawing //see the dynmic link object, drawing is a example of excutable 
file drawing //see drawing's platform that is gcc build or arm-linux-gcc build.

Variable Name: OPENCV_CONFIG_FILE_INCLUDE_DIR
Description: Where to create the platform-dependant cvconfig.h
Current Value: /root/opencv_arm/OpenCV-2.3.0

Variable Name: CMAKE_CXX_COMPILER
Description: CXX compiler.
Current Value: /usr/lib/ccache/c++

Variable Name: CMAKE_C_COMPILER
Description: C compiler.
Current Value: /usr/lib/ccache/gcc

g++ -I/usr/local/opencv-pc/include -L/usr/local/opencv-pc/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann drawing.cpp
===============================================================
g++ `pkg-config --cflags --libs opencv` drawing.cpp
===============================================================
linux-gate.so.1 =>  (0x00ce2000)
libopencv_core.so.2.3 => /usr/local/opencv-pc/lib/libopencv_core.so.2.3 (0x004c0000)
libopencv_imgproc.so.2.3 => /usr/local/opencv-pc/lib/libopencv_imgproc.so.2.3 (0x00110000)
libopencv_highgui.so.2.3 => /usr/local/opencv-pc/lib/libopencv_highgui.so.2.3 (0x006f4000)
libopencv_ml.so.2.3 => /usr/local/opencv-pc/lib/libopencv_ml.so.2.3 (0x0036c000)
libopencv_video.so.2.3 => /usr/local/opencv-pc/lib/libopencv_video.so.2.3 (0x003e2000)
libopencv_features2d.so.2.3 => /usr/local/opencv-pc/lib/libopencv_features2d.so.2.3 (0x00776000)
libopencv_calib3d.so.2.3 => /usr/local/opencv-pc/lib/libopencv_calib3d.so.2.3 (0x0086d000)
libopencv_objdetect.so.2.3 => /usr/local/opencv-pc/lib/libopencv_objdetect.so.2.3 (0x00e26000)
libopencv_contrib.so.2.3 => /usr/local/opencv-pc/lib/libopencv_contrib.so.2.3 (0x00f04000)
libopencv_legacy.so.2.3 => /usr/local/opencv-pc/lib/libopencv_legacy.so.2.3 (0x00922000)
libopencv_flann.so.2.3 => /usr/local/opencv-pc/lib/libopencv_flann.so.2.3 (0x0041f000)
libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x07ed2000)
libm.so.6 => /lib/libm.so.6 (0x00d61000)
libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x00d8d000)
libc.so.6 => /lib/libc.so.6 (0x00f44000)
libpthread.so.0 => /lib/libpthread.so.0 (0x00d19000)
libdl.so.2 => /lib/libdl.so.2 (0x00d37000)
librt.so.1 => /lib/librt.so.1 (0x00d55000)
libz.so.1 => /lib/libz.so.1 (0x00d3e000)
libjpeg.so.62 => /usr/lib/libjpeg.so.62 (0x02858000)
libpng12.so.0 => /usr/lib/libpng12.so.0 (0x00426000)
libtiff.so.3 => /usr/lib/libtiff.so.3 (0x0044e000)
libgtk-x11-2.0.so.0 => /usr/lib/libgtk-x11-2.0.so.0 (0x07a2d000)
libgdk-x11-2.0.so.0 => /usr/lib/libgdk-x11-2.0.so.0 (0x009d0000)
libatk-1.0.so.0 => /usr/lib/libatk-1.0.so.0 (0x006b0000)
libgio-2.0.so.0 => /lib/libgio-2.0.so.0 (0x00b82000)
libpangoft2-1.0.so.0 => /usr/lib/libpangoft2-1.0.so.0 (0x00a8a000)
libpangocairo-1.0.so.0 => /usr/lib/libpangocairo-1.0.so.0 (0x004af000)
libgdk_pixbuf-2.0.so.0 => /usr/lib/libgdk_pixbuf-2.0.so.0 (0x006cf000)
libcairo.so.2 => /usr/lib/libcairo.so.2 (0x097f4000)
libpango-1.0.so.0 => /usr/lib/libpango-1.0.so.0 (0x00ab7000)
libfreetype.so.6 => /usr/lib/libfreetype.so.6 (0x09150000)
libfontconfig.so.1 => /usr/lib/libfontconfig.so.1 (0x00b00000)
libgobject-2.0.so.0 => /lib/libgobject-2.0.so.0 (0x00daa000)
libgmodule-2.0.so.0 => /lib/libgmodule-2.0.so.0 (0x004bb000)
libgthread-2.0.so.0 => /lib/libgthread-2.0.so.0 (0x00b35000)
libglib-2.0.so.0 => /lib/libglib-2.0.so.0 (0x08789000)
/lib/ld-linux.so.2 (0x00b60000)
libX11.so.6 => /usr/lib/libX11.so.6 (0x010d7000)
libXfixes.so.3 => /usr/lib/libXfixes.so.3 (0x00b3a000)
libXext.so.6 => /usr/lib/libXext.so.6 (0x00b3f000)
libXrender.so.1 => /usr/lib/libXrender.so.1 (0x00b50000)
libXinerama.so.1 => /usr/lib/libXinerama.so.1 (0x00dfb000)
libXi.so.6 => /usr/lib/libXi.so.6 (0x00c9c000)
libXrandr.so.2 => /usr/lib/libXrandr.so.2 (0x00cab000)
libXcursor.so.1 => /usr/lib/libXcursor.so.1 (0x00cb3000)
libXcomposite.so.1 => /usr/lib/libXcomposite.so.1 (0x006f0000)
libXdamage.so.1 => /usr/lib/libXdamage.so.1 (0x00b59000)
libresolv.so.2 => /lib/libresolv.so.2 (0x00cbd000)
libselinux.so.1 => /lib/libselinux.so.1 (0x00ce3000)
libpixman-1.so.0 => /usr/lib/libpixman-1.so.0 (0x00e7f000)
libexpat.so.1 => /lib/libexpat.so.1 (0x00dfe000)
libxcb.so.1 => /usr/lib/libxcb.so.1 (0x068ac000)
libXau.so.6 => /usr/lib/libXau.so.6 (0x00b5c000)


///////////////////////////
when tell can't find xxx.so, sometimes needs a rename for shared object(.so),that is link. see below:
///////////////////////////////
[root@bangde lib]# pwd
/usr/local/opencv-pc/lib
[root@bangde lib]# ll
total 9584
lrwxrwxrwx  1 root root      24 Feb 26 14:08 libopencv_calib3d.so -> libopencv_calib3d.so.2.3
lrwxrwxrwx  1 root root      26 Feb 26 14:08 libopencv_calib3d.so.2.3 -> libopencv_calib3d.so.2.3.0
-rwxr-xr-x. 1 root root  793676 Feb 24 14:06 libopencv_calib3d.so.2.3.0
lrwxrwxrwx  1 root root      24 Feb 26 14:08 libopencv_contrib.so -> libopencv_contrib.so.2.3
lrwxrwxrwx  1 root root      26 Feb 26 14:08 libopencv_contrib.so.2.3 -> libopencv_contrib.so.2.3.0
-rwxr-xr-x. 1 root root  294006 Feb 24 14:06 libopencv_contrib.so.2.3.0
lrwxrwxrwx  1 root root      21 Feb 26 14:08 libopencv_core.so -> libopencv_core.so.2.3
lrwxrwxrwx  1 root root      23 Feb 26 14:08 libopencv_core.so.2.3 -> libopencv_core.so.2.3.0
-rwxr-xr-x. 1 root root 2170262 Feb 24 14:06 libopencv_core.so.2.3.0
lrwxrwxrwx  1 root root      27 Feb 26 14:08 libopencv_features2d.so -> libopencv_features2d.so.2.3
lrwxrwxrwx  1 root root      29 Feb 26 14:08 libopencv_features2d.so.2.3 -> libopencv_features2d.so.2.3.0
-rwxr-xr-x. 1 root root 1131452 Feb 24 14:06 libopencv_features2d.so.2.3.0
lrwxrwxrwx  1 root root      22 Feb 26 14:08 libopencv_flann.so -> libopencv_flann.so.2.3
lrwxrwxrwx  1 root root      24 Feb 26 14:08 libopencv_flann.so.2.3 -> libopencv_flann.so.2.3.0
-rwxr-xr-x. 1 root root   34457 Feb 24 14:06 libopencv_flann.so.2.3.0
lrwxrwxrwx  1 root root      20 Feb 26 14:08 libopencv_gpu.so -> libopencv_gpu.so.2.3
lrwxrwxrwx  1 root root      22 Feb 26 14:08 libopencv_gpu.so.2.3 -> libopencv_gpu.so.2.3.0
-rwxr-xr-x. 1 root root  204764 Feb 24 14:06 libopencv_gpu.so.2.3.0
lrwxrwxrwx  1 root root      24 Feb 26 14:08 libopencv_highgui.so -> libopencv_highgui.so.2.3
lrwxrwxrwx  1 root root      26 Feb 26 14:08 libopencv_highgui.so.2.3 -> libopencv_highgui.so.2.3.0
-rwxr-xr-x. 1 root root  567146 Feb 24 14:06 libopencv_highgui.so.2.3.0
lrwxrwxrwx  1 root root      24 Feb 26 14:08 libopencv_imgproc.so -> libopencv_imgproc.so.2.3
lrwxrwxrwx  1 root root      26 Feb 26 14:08 libopencv_imgproc.so.2.3 -> libopencv_imgproc.so.2.3.0
-rwxr-xr-x. 1 root root 2006789 Feb 24 14:06 libopencv_imgproc.so.2.3.0
lrwxrwxrwx  1 root root      23 Feb 26 14:08 libopencv_legacy.so -> libopencv_legacy.so.2.3
lrwxrwxrwx  1 root root      25 Feb 26 14:08 libopencv_legacy.so.2.3 -> libopencv_legacy.so.2.3.0
-rwxr-xr-x. 1 root root  784264 Feb 24 14:06 libopencv_legacy.so.2.3.0
lrwxrwxrwx  1 root root      19 Feb 26 14:08 libopencv_ml.so -> libopencv_ml.so.2.3
lrwxrwxrwx  1 root root      21 Feb 26 14:08 libopencv_ml.so.2.3 -> libopencv_ml.so.2.3.0
-rwxr-xr-x. 1 root root  531097 Feb 24 14:06 libopencv_ml.so.2.3.0
lrwxrwxrwx  1 root root      26 Feb 26 14:08 libopencv_objdetect.so -> libopencv_objdetect.so.2.3
lrwxrwxrwx  1 root root      28 Feb 26 14:08 libopencv_objdetect.so.2.3 -> libopencv_objdetect.so.2.3.0
-rwxr-xr-x. 1 root root  400837 Feb 24 14:06 libopencv_objdetect.so.2.3.0
lrwxrwxrwx  1 root root      19 Feb 26 14:08 libopencv_ts.so -> libopencv_ts.so.2.3
lrwxrwxrwx  1 root root      21 Feb 26 14:08 libopencv_ts.so.2.3 -> libopencv_ts.so.2.3.0
-rwxr-xr-x. 1 root root  603548 Feb 24 14:06 libopencv_ts.so.2.3.0
lrwxrwxrwx  1 root root      22 Feb 26 14:08 libopencv_video.so -> libopencv_video.so.2.3
lrwxrwxrwx  1 root root      24 Feb 26 14:08 libopencv_video.so.2.3 -> libopencv_video.so.2.3.0
-rwxr-xr-x. 1 root root  263935 Feb 24 14:06 libopencv_video.so.2.3.0
drwxr-xr-x. 2 root root    4096 Feb 24 14:06 pkgconfig
drwxr-xr-x. 3 root root    4096 Feb 24 14:06 python2.7
阅读(6880) | 评论(0) | 转发(1) |
0

上一篇:strcpy自己实现

下一篇:vmware-linux-磁盘压缩

给主人留下些什么吧!~~