Dieter
Dieter

Reputation: 2659

c++ openCV 3.1 - can't use Mat or most of the openCV things like in the tutorials

Best

I'm trying to create a project in C++, which relays most of the time on the open-cv library.

Therefore, I've installed open-cv3.1.0 on my windows machine and connected the library and include map/files to my netbeans c++ project.


Succes

Overall I think that I've managed to do this correctly because I don't receive any errors when I compile/run the application with the next piece of code in it.

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

++ I can read an images in and visualize it :)

CvMat *img = cvLoadImageM(location.c_str(),CV_LOAD_IMAGE_GRAYSCALE);
cvNamedWindow( "My Window", 1 );
cvShowImage( "My Window", img );
cvWaitKey();

Problem

But as soon as I take a random tutorial. E.g.

// create a big 8Mb matrix
Mat A(1000, 1000, CV_64F);

http://docs.opencv.org/3.0-last-rst/modules/core/doc/intro.html

Or even

Mat A;

Then I get immediately an compile error :

g++     -o dist/Debug/Cygwin-Windows/ai4 build/Debug/Cygwin-Windows/PrincipalComponentAnalysis.o build/Debug/Cygwin-Windows/ReadInImage.o build/Debug/Cygwin-Windows/main.o -L../../../netbeans/OpenCV/opencv/build/x64/vc14/bin -lopencv_world310 -lopencv_world310d
build/Debug/Cygwin-Windows/PrincipalComponentAnalysis.o: In function `cv::Mat::~Mat()':
/cygdrive/d/fun/ai/ai4/../../../netbeans/OpenCV/opencv/build/include/opencv2/core/mat.inl.hpp:571: undefined reference to `cv::fastFree(void*)'
...

The only things which doesn't give me an error are :

CvMat A;
CvMat *B;
IplImage *C;
IplImage D;

Which s***t because most (all) the tutorials, and stackoverflow issues are using the Mat A or cv::Mat A version.


Question

Thus the question : Did you've ever had the same kind of problem or issue? and are you willing to help me? + How can I solve it.


edit : Configuration steps - OpenCV 3.1

Tools --> Options --> c/c++ --> Code Assistance :

R-click Project --> Properties --> build --> C++ Compiler --> include directories

R-click Project --> Properties --> build --> linker --> Additional Library Directories

R-click Project --> Properties --> build --> linker --> Libraries --> Add Labrary


Solution

  1. Download CMake
  2. Download OpenCV
  3. Download MinGW <-- Use this as compiler instead of cygwin
  4. Install MinGW
  5. Follow this link --> http://eyalarubas.com/opencv-installation-on-windows-netbeans-mingw.html

Upvotes: 3

Views: 2320

Answers (2)

GPPK
GPPK

Reputation: 6666

you are compiling with cygwin and linking to the VC14 libs.

That's your error. VC14 is for MSVC14 (Visual Studio Compiler), you will need to compile OpenCV yourself to use cygwin. OpenCV does not come with other pre-built libraries.

There are multiple tutorials online of how to do it but effectively you need to use cmake in order to compile OpenCV for your particular tool chain.

Upvotes: 4

Humam Helfawi
Humam Helfawi

Reputation: 20264

You have problem while calling the destructor of cv::Mat. I faced this problem onced. It was related to mismatch between the library and the program. For example 64 and 32 ,debug and release or mt and md something like these. So, the first thing that you have to do is to make sure that everything are matched between OpenCV built and your calling program.

Upvotes: 0

Related Questions