无法将框架写入视频?

时间:2019-05-07 09:00:29

标签: c++ opencv

我是opencv的新手。我编写用于从帧写入和保存视频的代码,但是,只是创建了一个0kb的avi文件,没有将任何帧记下来。我的代码中有任何错误,我该如何解决?

Mat img; outp output;
int frames_num = (int)Cap.get(CV_CAP_PROP_FRAME_COUNT);
int frames_cnt = 0;

cv::VideoWriter outTrainVideos; 
int codec = cv::VideoWriter::fourcc('M', 'P', 'E','G');
string filename = "D:/AiMotionData/#Hammer/outVideos.avi";

bool out = outTrainVideos.open(filename, codec, 10, output.img.size(), true);

while (!mWorkerThStopReq && Cap.isOpened())
{
    if(frames_cnt++>= frames_num && frames_num > 0)
        break;

    // Read frame
    if (!Cap.read(img))
        continue;
    // Process frame
    if (!run(img, &output))
        continue;

    outTrainVideos<<output.img;
}   
outTrainVideos.release();
return 0;

}

0 个答案:

没有答案