Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1054399
  • 博文数量: 228
  • 博客积分: 474
  • 博客等级: 下士
  • 技术积分: 1930
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-19 18:40
文章分类

全部博文(228)

文章存档

2019年(3)

2018年(12)

2017年(13)

2016年(11)

2015年(55)

2014年(75)

2013年(39)

2012年(2)

2011年(18)

我的朋友

分类: LINUX

2014-12-18 10:02:17

1. 先从sourceforge上下载OpenCV的源码

  1. http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.0/  


2. 解压到任意目录

  1. tar xvfj OpenCV-2.4.3.tar.bz2  

3. 进入源码目录,创建release目录

  1. cd OpenCV-2.4.3  
  2. mkdir release  


4. 可以看到在OpenCV目录下,有个CMakeLists.txt文件,需要事先安装一些软件

  1. sudo apt-get install build-essential cmake libgtk2.0-dev pkg-config python-dev python-numpy libavcodec-dev libavformat-dev libswscale-dev  


5.  进入release目录,安装OpenCV是所有的文件都会被放到这个release目录下

  1. cd release  


6. cmake编译OpenCV源码,安装所有的lib文件都会被安装到/usr/local目录下

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

7. 安装
  1. sudo make install  


8. 测试,在某个目录下建立一个DisplayImage.cpp文件

  1. #include   
  2. #include   
  3.   
  4. using namespace cv;  
  5.   
  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.         printf("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. }  


9. 从网上下那个著名的lena.jpg放在cpp目录下


10. 写一个cmake的makefile,也叫CMakeLists.txt

  1. project(DisplayImage)  
  2. find_package(OpenCV REQUIRED)  
  3. add_executable(DisplayImage DisplayImage)  
  4. target_link_libraries(DisplayImage ${OpenCV_LIBS})  
  5. cmake_minimum_required(VERSION 2.8)  

11. 编译+运行
  1. cmake .  
  2. make  
  3. ./DisplayImage lena.jpg  

12. 完成




1,ERROR:I wrote a CMakeLists.txt for a project in C++, which uses OpenCV libraries. When I try to create the project using cmake, I get the next configuration problem:
CMake Error at CMakeLists.txt:15 (find_package):
  Could not find module FindOpenCV.cmake or a configuration file for package
  OpenCV.

  Adjust CMAKE_MODULE_PATH to find FindOpenCV.cmake or set OpenCV_DIR to the
  directory containing a CMake configuration file for OpenCV.  The file will
  have one of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake 

The fact is that I have an environment variable for the path which I use in Visual Studio with no problems. If I don't include OpenCV, then I can configure and generate with no problem, but I need to solve the problem. I don't understand why cmake cannot find the OpenCV path or how to fix it.

I also used the recommendations mentioned in this link: FindOpenCV.cmake

Does anybody had this problem too?

解决:
export OpenCV_DIR=

阅读(1236) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
评论热议
请登录后评论。

登录 注册