xyz
xyz

Reputation: 3409

Cannot compile OpenCV code (C++)

Okay, so I have been searching for this problem for a while, and I still am clueless as to how to solve it.

I am trying to run the sample code available here: http://docs.opencv.org/trunk/d1/dc5/tutorial_background_subtraction.html. I understand the code. I just cannot get it to compile! The problem is with library includes. Here's my Makefile:

CFLAGS = `pkg-config --cflags opencv`
LIBS = `pkg-config --libs opencv`

% : %.cpp
    g++ $(CFLAGS) $(LIBS) -o $@ $<

Here's the error:

prakhar@inS4n3 ~/dev/gender recognition $ make bs
g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` -o bs bs.cpp
bs.cpp:2:33: fatal error: opencv2/imgcodecs.hpp: No such file or directory
 #include "opencv2/imgcodecs.hpp"
                                 ^
compilation terminated.
Makefile:5: recipe for target 'bs' failed
make: *** [bs] Error 1

If I (for the time being) comment out this file, I get a similar error with imgproc.hpp. In another of my OpenCV code, the following compiles prefectly:

#include "opencv2/core/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include "opencv2/highgui/highgui.hpp"

As far as I can tell, replacing opencv2/core.hpp with opencv2/core/core.hpp or replacing opencv2/imgproc.hpp with opencv2/imgproc/imgproc.hpp does the job.

So I looked deeper and here's my opencv2 folder:

prakhar@inS4n3 /usr/include/opencv2 $ ll
total 84
drwxr-xr-x 2 root root 4096 Nov 14 19:42 calib3d
drwxr-xr-x 2 root root 4096 Nov 14 19:42 contrib
drwxr-xr-x 2 root root 4096 Nov 14 19:42 core
drwxr-xr-x 2 root root 4096 Nov 14 19:42 features2d
drwxr-xr-x 2 root root 4096 Nov 14 19:42 flann
drwxr-xr-x 3 root root 4096 Nov 14 19:42 gpu
drwxr-xr-x 2 root root 4096 Nov 14 19:42 highgui
drwxr-xr-x 2 root root 4096 Nov 14 19:42 imgproc
drwxr-xr-x 2 root root 4096 Nov 14 19:42 legacy
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ml
drwxr-xr-x 2 root root 4096 Nov 14 19:42 nonfree
drwxr-xr-x 2 root root 4096 Nov 14 19:42 objdetect
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ocl
-rw-r--r-- 1 root root 2751 Oct  1  2014 opencv.hpp
-rw-r--r-- 1 root root  672 Nov 12 00:02 opencv_modules.hpp
drwxr-xr-x 2 root root 4096 Nov 14 19:42 photo
drwxr-xr-x 3 root root 4096 Nov 14 19:42 stitching
drwxr-xr-x 2 root root 4096 Nov 14 19:42 superres
drwxr-xr-x 2 root root 4096 Nov 14 19:42 ts
drwxr-xr-x 2 root root 4096 Nov 14 19:42 video
drwxr-xr-x 2 root root 4096 Nov 14 19:42 videostab

Can anyone tell me why this is happening, and how do I get the imgcodecs.hpp and videoio.hpp modules? I am using OpenCV 2.4.10-2, on Arch Linux.

Upvotes: 3

Views: 7214

Answers (1)

xyz
xyz

Reputation: 3409

Okay, with help from @Micka, I finally realized that the doc is for OpenCV 3.0 beta, not 2.4.10. As such, making the changes in this solves the problem.

However, I simply installed the 3.0 beta, and that worked fine.

Here's the transtition guide, which for me was hard-to-find (still don't know why!).

Upvotes: 3

Related Questions