【发布时间】:2016-06-05 11:09:55
【问题描述】:
我正在尝试编写一个程序,从视频中捕获 n 帧并将它们放入容器中以供进一步工作(之后我正在制作拼贴画)。但是我遇到了一个问题,当容器中的所有图像都相同时(它仅填充最后捕获的图像)。我检查了图像是否被正确捕获,因为我也在保存它们并且可以清楚地看到它们是不同的。
这是我的代码:
std::vector<cv::Mat> MY_framelist; //container for captured frames
cv::VideoCapture myvid;
cv::Mat MY_frame; //will capture frames here
myvid.open(pass_filename); //open video file(char* pass_filename=12.mp4)
if (!myvid.isOpened()) {
printf("Capture not open \n");
}
double x_length = myvid.get(CV_CAP_PROP_FRAME_COUNT); //get maxlength of the video
uint each_frame = uint(x_length) / 16; //capture every 16 frames
for (uint j = 0, current_frame = 1; (current_frame < x_length) && (j < 16); current_frame += each_frame, j++)
{
myvid.set(CV_CAP_PROP_POS_FRAMES, current_frame); //set frame
myvid.read(MY_frame); // then capture the next one
MY_framelist.push_back(MY_frame); //place it into the container
std::stringstream frameNum; //generating name for saved images
frameNum << j + 1;
if (j + 1 <= 9)
my_filename += "0";
my_filename += frameNum.str();
my_filename += ".jpg";
cv::imwrite(my_filename.c_str(), MY_frame); //saving images to prove that they are captured correctly
my_filename = "test";
printf(" and Image # ");
printf("%d", j + 1);
printf(" saved \n");
}
因此,MY_framelist 将包含 16 个上次捕获的相同图像。 我在做什么错here? 我在这里看到了一些解决方法,但我并不是很想这样做,因为它会导致结果不那么准确。 提前致谢!
【问题讨论】:
-
难道
cv::Mat是一个处理程序,只有那个处理程序被复制到向量中?
标签: c++ opencv vector std opencv3.0