简体   繁体   中英

Video Capture : Frame always empty - opencv

I am working with openCV Version 2.4.9, and on Mac OSX. I have written this code for loading and displaying a video on my desktop. But it never seems to work. I always get the output as "frame empty". Thus it does not complain about reading the video using VideoCapture.It is NOT able to capture any frames, and thus 'frame' is always EMPTY. Any idea what the problem might be? Note: I have tried both ways to capture a frame - commented as try 1 and try2.

int main(int argc, const char * argv[])
{
    Mat frame;
    VideoCapture capture_ir("/Users/shreyatandon/Desktop/resize_ir.avi");


    if ( !capture_ir.isOpened() )  // if not success, exit program
    {
        cout << "Cannot open the video file" << endl;
        return -1;
    }

    for (;;){
       // capture_ir.read(frame); //try1
          capture_ir>>frame;       //try2
        if(frame.empty()){
            std::cerr<<"frame is empty"<<std::endl;
            break;
        }
        imshow("", frame);

        waitKey(10);

            break;
    }

    return 0;
}

Just made it work.

Mat current_frame;
VideoCapture video("video.avi");
while(true)
{
    video.read(current_frame);
    imshow("Image",current_frame);
}

If you keep having problems using avi format have a look at your links to the ffmpeg libraries and it dependencies. I tried to install it from scratch using homebrew and it is working without problems. Cheers

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM