使用opencv检索视频帧-未处理的异常

Retrieving video frames using opencv - unhandled exception

本文关键字:未处理 异常 opencv 检索 视频 使用      更新时间:2023-10-16

我正在使用cvQueryframes获得视频帧,但在avi文件的几个视频中,我得到:

Unhandled exception at 0x715c14f0 0xC0000005: 
    Access violation reading location 0x02f509f0.

我使用visual studio 2010与OpenCV 2.4.5Qt5

CvCapture* cap= cvCaptureFromFile(file);
frame = cvQueryFrame(capture);

可能有多种原因,链接错误的文件名,没有找到编解码器等。试着在打开文件之前输入debug printf,看看文件名是否正确,如果不是NULL,也检查一下cap。你可以试试这样写

int main(int argc, char*argv[])
{
    char *my_file = "C:\vid_an2\desp_me.avi";
    std::cout<<"Video File "<<my_file<<std::endl;
    cv::VideoCapture input_video;
    if(input_video.open(my_file))
    {
         std::cout<<"Video file open "<<std::endl;
    }
    else
    {
        std::cout<<"Not able to Video file open "<<std::endl;
    }
    namedWindow("My_Win",1);
    namedWindow("Segemented", 1);
    Mat cap_img;
    for(;;)
    {
         input_video >> cap_img;
         imshow("My_Win", cap_img);
          waitKey(0);
    }
   return 0;
 }