I wrote a simple opencv project containing only a main.cpp file:
// main.cpp
#include <opencv/cv.h>
#include <opencv2/opencv.hpp>
int main()
{
cv::Mat I = cv::imread("img.png");
cv::imshow("img",I);
cv::waitKey(0);
return 0;
}
Then to build it, I wrote a CMakeLists.txt like this, which is actually copied from http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html
cmake_minimum_required(VERSION 2.8)
project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage main.cpp )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )
In terminal, first I ran cmake . and a Makefile was generated. Then I ran make and got the following error:
fatal error:
'opencv2/opencv.hpp' file not found
#include <opencv2/opencv.hpp>
^
......
It seems the compiler cannot find OpenCV include dir. But I don't know where to add it to the CMakeLists.txt. My platform is Mac OS X 10.10, and OpenCV include and lib files have been installed at /usr/local/include and /usr/local/lib already. However, in Ubuntu, the compiler can find it and successfully build the project.
So what is a correct CMakeLists.txt in Mac OS X?
opencv/cv.hhas been processed successfully). But either that OpenCV installation is too old, or not all OpenCV components are installed, so include fileopencv2/opencv.hppdoes not exist. You can check existence of both include files manually under/usr/local/include.