开发者

How to play a video file from my disk using OpenCV.? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can b开发者_StackOverflow社区e reopened, visit the help center. Closed 11 years ago.

Please help me in achieving above task.I'm newbie to openCV. I have OpenCV 2.2 installed in my system and using VC++ 2010 Express as IDE. I don't have inbuilt webcam in my laptop... just i learnt how to load image. I'm very eager to load a video file from my disk(preferably mp4 , flv format) and wish to play it using openCV.


Using the C interface of OpenCV (which have worked better for me on Windows boxes), the function to load the video file is cvCaptureFromAVI(). After that, you need to use the traditional loop to retrieve frames throughcvQueryFrame() and then cvShowImage() to display them on a window created with cvNamedWindow().

CvCapture *capture = cvCaptureFromAVI("video.avi");
if(!capture)
{   
    printf("!!! cvCaptureFromAVI failed (file not found?)\n");
    return -1; 
}   

int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);
printf("* FPS: %d\n", fps);

cvNamedWindow("display_video", CV_WINDOW_AUTOSIZE);

IplImage* frame = NULL;
char key = 0;

while (key != 'q')
{   
    frame = cvQueryFrame(capture);
    if (!frame)
    {   
        printf("!!! cvQueryFrame failed: no frame\n");
        break;
    }

    cvShowImage("display_video", frame);

    key = cvWaitKey(1000 / fps);
}

cvReleaseCapture(&capture);
cvDestroyWindow("display_video");

This blog post brings a little extra info on the task you are trying to accomplish.


(Hummm... you don't seem to be trying to do something by yourself but anyway)

From the docs:

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    //Mat edges;
    namedWindow("frames",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera
        //ignore below sample, since you only want to play
        //cvtColor(frame, edges, CV_BGR2GRAY);
        //GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        //Canny(edges, edges, 0, 30, 3);
        //imshow("edges", edges);
        imshow("frames", frame);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

This is the old way using opencv 1.x apis.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜