kkd927
kkd927

Reputation: 337

How to configure Makefile to use OpenCV

I installed opencv in RaspberryPi and configured Makefile but it can't find header files. How to configure Makefile correctly?

I have 2 .cpp files and 1 .h file.

BlobLabeling.cpp  BlobLabeling.h  hand_tracking.cpp

When I run make, it returns the following:

pi@raspberrypi ~/test $ make
g++ BlobLabeling.cpp
In file included from BlobLabeling.cpp:2:0:
BlobLabeling.h:9:31: fatal error: highgui/highgui.hpp: No such file or directory
compilation terminated.
Makefile:11: recipe for target 'BlobLabeling.o' failed
make: *** [BlobLabeling.o] Error 1

in BlobLabeling.cpp

#include "BlobLabeling.h"

in hand_tracking.cpp

#include <stdio.h>
#include "cv.h"
#include "highgui.h"
#include "BlobLabeling.h"

in BlobLabeling.h

#include "highgui/highgui.hpp"
#include "opencv.hpp"

Makefile

CXX = g++

LDFLAGS = -lopencv_legacy -lopencv_highgui -lopencv_core -lopencv_ml -lopencv_video -lopencv_imgproc -lopencv_calib3d -lopencv_objdetect -L/usr/lib

CPPFLAGS = -g -I/usr/include/opencv -I/usr/include/opencv2

all: BlobLabeling.o hand_tracking.o
        g++ -o test BlobLabeling.o hand_tracking.o

BlobLabeling.o: BlobLabeling.cpp
        g++ BlobLabeling.cpp

hand_tracking.o: hand_tracking.cpp BlobLabeling.h
        g++ hand_tracking.cpp

in /usr/include/opencv2

pi@raspberrypi ~/test $ ls /usr/include/opencv2
calib3d  features2d  imgproc  objdetect   stitching  videostab
contrib  flann       legacy   opencv.hpp  ts
core     highgui     ml       photo       video

Upvotes: 0

Views: 3075

Answers (1)

berak
berak

Reputation: 39796

please use the proper c++ headers:

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

along with the include path:

-I/usr/include/opencv2

instead of the outdated "cv.h" and "highgui.h"

Upvotes: 2

Related Questions