Ask Your Question
0

video reading

asked 2014-01-27 04:15:56 -0500

blengabs gravatar image

updated 2018-02-04 08:17:05 -0500

Hi, I wanto to read a simple video file. Code is below, but i can not read the video file and always the compiler break the loop at the first step by the code if(!frame) break; where may i doing mistake? Thanks.

include <stdio.h>

include <opencv\cv.h>

include <opencv\highgui.h>

include <math.h>

include <iostream>

using namespace cv; using namespace std;

int main(int argc, char* argv) { CvCapture cap = cvCreateFileCapture("a.avi");

IplImage* img =0;
cvNamedWindow("a",CV_WINDOW_AUTOSIZE);


while(1){
    img = cvQueryFrame(cap);
    if(!img)
        break;

    cvShowImage("a",img);

    cvWaitKey(44);

}

cvWaitKey(0);
return 0;

}

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-01-27 14:45:55 -0500

keghn gravatar image

g++ p.cpp -o p `pkg-config --cflags --libs opencv`

#include <stdio.h>

#include <opencv/cv.h>

#include <opencv/highgui.h>

#include <math.h>

#include <iostream>

using namespace cv;

using namespace std;

int main(int argc, char* argv[]) {

VideoCapture cap("test.avi"); // open the video file for reading

IplImage* img =0;

cvNamedWindow("a",CV_WINDOW_AUTOSIZE);

while(1){

    Mat frame;

// img = cvQueryFrame(frame);

bool img = cap.read(frame); if(!img) break;

imshow("a",frame);

cvWaitKey(44);

}

cvWaitKey(0);

return 0;

}

edit flag offensive delete link more

Comments

Thanks. But i can not still show the video. where do you store the video "test.avi"?

blengabs gravatar imageblengabs ( 2014-01-28 04:03:37 -0500 )edit

I am using Windows 7 and Visual studio 2010

blengabs gravatar imageblengabs ( 2014-01-28 04:29:11 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-01-27 04:15:56 -0500

Seen: 121 times

Last updated: Jan 27 '14