having trouble compiling one of the OpenCV tutorial examples

asked 2012-11-29 09:39:12 -0500

donotspamme gravatar image

updated 2012-11-29 09:41:26 -0500

Platform: Fedora 17 x86_64 with OpenCV packages installed via yum

What I want to do:
Build a simple OpenCV program to get started learning OpenCV.
I'm trying the 'DisplayImage' program from the OpenCV tutorial 'Using OpenCV with gcc and CMake' which I found at http://docs.opencv.org/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html#linux-gcc-usage

I have tried following the instructions (I believe) word-for-word. I am new to cmake and don't understand everything it's doing, but when I run it, it appears to work, and a Makefile is produced.

However, when I run make with the generated Makefile, I get:

[tim@vos di]$ make
Scanning dependencies of target DisplayImage
[100%] Building CXX object CMakeFiles/DisplayImage.dir/DisplayImage.o
/home/tim/cp3/proj/di/DisplayImage.cpp:5:16: fatal error: cv.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/DisplayImage.dir/DisplayImage.o] Error 1
make[1]: *** [CMakeFiles/DisplayImage.dir/all] Error 2
make: *** [all] Error 2

The supplied example CMakeLists.txt file is:

project( DisplayImage )
find_package( OpenCV REQUIRED )
add_executable( DisplayImage DisplayImage )
target_link_libraries( DisplayImage ${OpenCV_LIBS} )

Does '${OpenCV_LIBS}' refer to an environment variable that I should have set before running cmake? Or do I set it somewhere else? Or does cmake set it itself? If I need to set it explicitly, what do I set it to?

I tried "export OpenCV_LIBS=/usr/lib64" because I saw some opencv_*.so library files there. This did not fix my problem.

Looking at the error messages, it seems that cv.h is not being found (for #include <cv.h>). If I was compiling directly with g++ I would try adding "-I /usr/include/opencv" or similar to the compile command.

How essential is it that I use cmake as suggested in the tutorial?

Suggestions welcome.

Thanks, Tim

edit retag flag offensive close merge delete

Comments

I can get the code to compile and run if I change the #include paths from:

include <cv.h>

include <highgui.h>

to:

include "/usr/include/opencv2/opencv.hpp"

include <stdio.h>

I guess I can live with this if I need to, but it's a little messy: I'm writing code on my Fedora 17 laptop, but also pushing it up to run on a large parallel cluster where the OpenCV library is installed at a different path.

Still open to suggestions of the neat-and-tidy way to fix this.

donotspamme gravatar imagedonotspamme ( 2012-11-29 11:07:59 -0500 )edit

Well, I think I have an answer, but I can't post it as such until tomorrow, because "new members have to wait two days before answering their own question. <br>Well, here's the answer thus far: <br>Doh! Works if I do #include <opencv2/opencv.hpp>, since the system location for include files (/usr/include on my system) contains the 'opencv2' directory of opencv include files. <br>Maybe a small edit to the tutorial would help other newbies?

donotspamme gravatar imagedonotspamme ( 2012-11-30 08:11:11 -0500 )edit