Search code examples
c++qtopencvhighgui

Why do I get this error when using OpenCV? error: undefined reference to `cvCreateFileCapture'


I'm trying to run a simple code using openCV but I keep getting this errors.

error: undefined reference to `cvCreateFileCapture'

error: undefined reference to `cvQueryFrame'

error: undefined reference to `cvReleaseCapture'

As far as I know these functions are defined in 'highgui' component which I included it's header to my code and also included it's path to my library paths.

INCLUDEPATH += /usr/local/include/opencv
LIBS += -L/usr/local/lib -lopencv_core -lopencv_imgcodecs -lopencv_highgui

I successfully used other functions of 'highgui' component without any error. ex: 'cvLoadImage' Also my IDE's intellisense keeps suggesting these functions to me which I think it means that I had included the library path correctly.

Why am I getting these errors?

for more information I'm using openCV 3.0.0, Qt creator 3.1.1 on linux mint 17.2

the full simple code I'm trying to run is:

#include <iostream>
#include <highgui.h>
#include <cv.h>

using namespace std;

int main()
{
    CvCapture* capture = cvCreateFileCapture("/home/ali/drop.avi");
    cvNamedWindow("t2",CV_WINDOW_AUTOSIZE);
    IplImage* frame;
    while(1) 
    {
        frame = cvQueryFrame(capture);
        if(!frame) break;
        cvShowImage("t2",frame);
        char c = cvWaitKey(33);
        if(c==27) break;
    }
    cvReleaseCapture(&capture);
    cvDestroyWindow("t2");

    return 0;
}

Thank you in advance.


Solution

  • Your source of study for openCV is outdated. That is the old C api. Study some of the documentation here

    EDIT: Also, follow the advice from @berak to use cv::Mat and cv::VideoCapture

    Replace <cv.h> with <opencv2/core.hpp>

    And with my openCV installation, I include highgui like this <opencv2/highgui.hpp>