opencv2.4.9 linux源码安装过程及问题

Ubuntu 12.04 安装opencv 2.4.9步骤:

1.安装依赖包。否则写openCV程序的时候虽然编译能通过,可能运行时出错。

sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev

2. 下载openCV的源码包并解压出来

3. 进入解压出来的目录

cd ~/opencv

mkdir release

cd release

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

4. sudo make

5. sudo make install

6. 测试代码运行

代码测试

DisplayImage.cpp

  1. #include   
  2. #include   
  3. #include   
  4. using namespace cv;  
  5. using namespace std;  
  6. int main(int argc,char **argv)  
  7. {  
  8.     Mat image;  
  9.     image = imread(argv[1],1);  
  10.   
  11.     if(argc != 2 || !image.data)  
  12.     {  
  13.         cout << "No image data\n";  
  14.         return -1;  
  15.     }  
  16.   
  17.     namedWindow("Display Image",CV_WINDOW_AUTOSIZE);  
  18.     imshow("Display Image",image);  
  19.     waitKey(0);  
  20.     return 0;  
  21. }  

g++ DisplayImage.cpp -o DisplayImage `pkg-config opencv --cflags --libs`

运行就可以看到显示出来的图片

./DisplayImage abc.jpg

至于`pkg-config opencv --cflags --libs` 什么意思,具体我也不知道,反正不加这个就编译通不过。其实就是提取build选项。qt中也可以这样指定,很方便。参考build_all.sh

追加: 列出编译选项作为gcc命令输入。ppeix:DLib$ pkg-config opencv --cflags --libs
-I/opt/ros/fuerte/include/opencv -I/opt/ros/fuerte/include  -L/opt/ros/fuerte/lib -lopencv_calib3d -lopencv_contrib -lopencv_core -lopencv_features2d -lopencv_flann -lopencv_gpu -lopencv_highgui -lopencv_imgproc -lopencv_legacy -lopencv_ml -lopencv_nonfree -lopencv_objdetect -lopencv_photo -lopencv_stitching -lopencv_ts -lopencv_video -lopencv_videostab

对于测试部分用的是:
终端下转到刚才解压的\samples\c文件夹下,里面有一个build_all.sh脚本,执行之:bash ./build_all.sh,成功之后,ls命令查看,生成了一个facedetect执行文件,./facedetect执行之!如果弹出一个捕捉脸 部的窗口,那么恭喜,你成功了。

期间可能遇到的问题:

Scanning dependencies of target opencv_core[ 10%] Building CXX object modules/core/CMakeFiles/opencv_core.dir/src/system.cpp.o
Linking CXX shared library ../../lib/libopencv_core.so
[ 15%] Built target opencv_core
[ 15%] Built target opencv_ts_pch_dephelp
[ 15%] Built target pch_Generate_opencv_ts
[ 15%] Built target opencv_imgproc_pch_dephelp
[ 15%] Built target pch_Generate_opencv_imgproc
Linking CXX shared library ../../lib/libopencv_imgproc.so
/usr/bin/ld: ../../../3rdparty/ippicv/unpack/ippicv_lnx/lib/ia32/libippicv.a(jmp_ippiResizeGetBufferSize_16s_as.s.o): relocation R_386_GOTOFF against undefined symbol `ippicvJumpIndexForMergedLibs' can not be used when making a shared object
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
make[2]: *** [lib/libopencv_imgproc.so.3.0.0] Error 1
make[1]: *** [modules/imgproc/CMakeFiles/opencv_imgproc.dir/all] Error 2
make: *** [all] Error 2


cmake时 添加-D  WITH_IPP=OFF即可。

完整命令:cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX= /usr/local/ -D WITH_IPP=OFF ../

参考:http://answers.opencv.org/question/37115/opencv-249-make-error/

问题2:ocl不支持。在进行opencv_createsamples训练的时候,会提示opencl错误。这里对于在非gpu上运行情况,建议关闭opencl。

ppeix:release$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX= /usr/local/ -D WITH_IPP=OFF -D WITH_OPENCL=OFF ../

--   Other third-party libraries:
--     Use IPP:                     NO
--     Use Eigen:                   YES (ver 3.0.5)
--     Use TBB:                     NO
--     Use OpenMP:                  NO
--     Use GCD                      NO
--     Use Concurrency              NO
--     Use C=:                      NO
--     Use Cuda:                    NO
--     Use OpenCL:                  NO


你可能感兴趣的:(opencv)