undefined reference to `cv::fastFree(void*)' & 'cv::Mat::deallocate()'

asked 2015-05-19 03:51:08 -0600

shruti.arya gravatar image

I am doing template matching on eclipse CDT using C++ API.

The code is :

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/mat.hpp"
#include "opencv/cv.hpp"
using namespace cv;

#include <iostream>
#include <stdio.h>
using namespace std;


/// Global Variables
IplImage* img;
IplImage* templ;
IplImage* result;
char* image_window = "Source Image";
char* result_window = "Result window";

int match_method;
int max_Trackbar = 5;

int main( int argc, char** argv )
{
    img = cvLoadImage("C:\\Users\\..\\workspace\\OpenCV_CPP\\src\\myimg.png",true);
    templ = cvLoadImage("C:\\Users\\...\\workspace\\OpenCV_CPP\\src\\mytmp.png",true);

    /// Create windows
    cvNamedWindow( image_window, CV_WINDOW_AUTOSIZE );
    cvNamedWindow(result_window, CV_WINDOW_AUTOSIZE );
    Mat img_display;
    CvArr* msk2;
    cvCopy(&img,&img_display,&msk2);
      /// Create the result matrix
      int result_cols =  img->width - templ->width + 1;
      int result_rows = img->height - templ->height + 1;
      CvSize cs = cvSize(result_cols,result_rows);
      cvCreateImage(cs,CV_32FC1,3);
      match_method = 0;
      /// Do the Matching and Normalize
      cvMatchTemplate(&img,&templ,&result,match_method);
      CvArr* msk1;
      cvNormalize(&result,&result,0,1,NORM_MINMAX,&msk1);
      double minVal; double maxVal; CvPoint minLoc; CvPoint maxLoc;
      Point matchLoc;
      CvArr* msk;
      cvMinMaxLoc( &result, &minVal, &maxVal, &minLoc, &maxLoc, &msk);
      matchLoc = minLoc;
      if( match_method  == 0 || match_method == 1 )
        { matchLoc = minLoc; }
      else
        { matchLoc = maxLoc; }
      cvRectangle( &img_display, matchLoc, Point( matchLoc.x + templ->height , matchLoc.y + templ->height ), Scalar::all(0), 2, 8, 0 );
      cvRectangle( &result, matchLoc, Point( matchLoc.x + templ->width , matchLoc.y + templ->height ), Scalar::all(0), 2, 8, 0 );
      cvShowImage(image_window, &img_display);
      cvShowImage(result_window, &result);
      cvWaitKey(0);
      cvReleaseImage(&img );
      cvReleaseImage(&templ );
      cvReleaseImage(&result );
    return 0;
}

On compilation, I get 2 errors :-

C:/OpenCV-3.0/opencv/build/include/opencv2/core/mat.hpp:278: undefined reference to cv::fastFree(void*)' src\DisplayImage.o: In functionZN2cv3Mat7releaseEv': C:/OpenCV-3.0/opencv/build/include/opencv2/core/mat.hpp:367: undefined reference to `cv::Mat::deallocate()'

Please suggest on how to deal with them.

edit retag flag offensive close merge delete

Comments

1
  • please avoid using opencv's arcane c-api. code like that should no more be written. use cv::Mat, cv::imread(), etc. please have a look at the matching tutorial , too.

  • then, - you got a linker error, - you probably forgot to link opencv libs correctly, like -lopencv_core, -lopencv_imgproc, -lopencv_highgui, -lopencv_imgcodecs

  • last, but not least, if you're using eclipse/mingw on windows, you will have to build the opencv libs for mingw first, you cannot use the prebuild vs libs.

berak gravatar imageberak ( 2015-05-19 03:54:06 -0600 )edit
1

@berak , Now, I have compiled the opencv library using CMake. And, I am using C++ API.

The simple code for checking if the library has been set up fine is :

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv/cv.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
using namespace cv;
int main()
{
    cv::Mat image = cv::imread("error.png", 0);// read the file
    cv::namedWindow( "Display window", CV_WINDOW_AUTOSIZE );// create a window for display.
    cv::imshow( "Display window", image );// show our image inside it.
    cv::waitKey(0);// wait for a keystroke in the window
    return 0;
}

But, this is still giving an undefined reference error for `cv::imread(cv::String const&, int)' Can you tell me what can be wrong?

shruti.arya gravatar imageshruti.arya ( 2015-05-20 05:17:23 -0600 )edit
  • yes, code looks much better now
  • what are you linking ? -lopencv_imgcodecs is needed for imread()
berak gravatar imageberak ( 2015-05-20 05:29:46 -0600 )edit

Thanks @berak. I had not added imgcodecs. The code compiles successfully. But, on execution, the program stops working giving error: "Assertion failed (size.width>0 && size.height>0) in imshow, file C:\opencv\opencv-master\opencv-master\modules\highgui\src\window.cpp, line 271"

shruti.arya gravatar imageshruti.arya ( 2015-05-20 06:10:06 -0600 )edit

oh, good.

it simply did not load your image. try an absolute path, like "c:/my/files/img.png" and add a check after imread, like if (img.empty()) ...

berak gravatar imageberak ( 2015-05-20 06:15:01 -0600 )edit

I have tried using absolute path but still it is taking the image as an empty matrix. I have tried for .jpg image as well. But, that too is not appearing.

shruti.arya gravatar imageshruti.arya ( 2015-05-20 06:36:03 -0600 )edit
1

I made wrong entry for path. it's working now.

Thanks a lot!! :)

shruti.arya gravatar imageshruti.arya ( 2015-05-20 06:38:07 -0600 )edit