1

I have been trying to extend python with a OpenCV module written in C++. I am encountering 2 problems during this.

1) Setup.py - How does one include cv.h library here?

libraries = ['opencv'],
library_dirs = ['/usr/local/lib'],

2) Importing the cv.h in the C++ module file?

#include "cv.h"
using namespace cv;

Throws compile time error - t1.cpp:3:16: fatal error: cv.h: No such file or directory

2 Answers 2

3

Got it to work

1) In Setup.py

include_dirs = ['/usr/local/include'],
libraries = ['opencv_core', 'opencv_highgui'],
library_dirs = ['/usr/local/lib'],

2) C++ module

#include <opencv/cv.h>

#include <opencv/highgui.h>

Sign up to request clarification or add additional context in comments.

Comments

1

The C++ header file is #include <opencv2/opencv.hpp>, if you have /usr/local/include on your header path. So what you should be doing is -

#include <opencv2/opencv.hpp>
using namespace cv;

As for including the OpenCV libarries for linking, you should look at the libraries in /usr/local/lib/libopencv*. There are several OpenCV libraries, each corresponding to one package, so you may not need to link all the libraries, if you are not using that package.

Personally, I would work by statically linking your module with a libopencv.a and the linking the entire module to Python. If you are bothered about extra code being linked, you can strip the unused symbols.

1 Comment

Thanks subzero, but I already got it to work. had an issue with the highgui.h as well. Thanks again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.