Vitor Ferreira
Vitor Ferreira

Reputation: 163

OpenCV! How Capture videos?

I'm participating in a team project, and i've a source code. That code, need OPEN CV, because we are working in image processing.

We need to capture a video and then, do some functions. That video is located in the path of project.

Happens that for capture a video we, first define a path, like:

char *videofile = "video-tp2.avi";

And then we've the capture:

CvCapture *capture;
capture = cvCaptureFromFile(videofile);

Finally we check if, we have a capture, and supossedly, if we do not have a video file, system may alert. It is precisely the other way around, the system alerts when the video exists and is within the project

if (!capture)
    {
        fprintf(stderr, "Erro ao abrir o ficheiro de vídeo!\n");
        return 1;
    }

enter image description here

Upvotes: 0

Views: 134

Answers (1)

terence hill
terence hill

Reputation: 3454

cvCapture is a struct which the documentations refers as a black-box:

Note: In C API the black-box structure CvCapture is used instead of VideoCapture.

You can try cv.QueryFrame(capture). It will return NULL if it fails (see this example):

   IplImage* frame;
   frame = cvQueryFrame(capture);
   if(!frame) {
     // FAIL
   }

However you should switch to the C++ interface because the C API is deprecated (see here)

Upvotes: 1

Related Questions