gpt4 book ai didi

video - 如何在 OpenCV 中保留 VideoCapture 提供的帧

转载 作者:太空宇宙 更新时间:2023-11-03 22:33:43 24 4
gpt4 key购买 nike

我想使用 opencv 编写一个函数,该函数读取一个视频文件,抓取单个帧并将它们存储在 std::vector> 中。问题在函数结束时出现,我在矢量的矢量中有图像,但是当发布 VideoCapture 时,所有数据都消失了。

vector<Mat>load_single_video(string path)
{
vector<Mat> one_video_vector;
Mat video_img;
VideoCapture Temp_video_capture(path);
Temp_video_capture.read(video_img);
while (!video_img.empty())
{
one_video_vector.push_back(video_img);
Temp_video_capture.read(video_img);
}

Temp_video_capture.release();

return one_video_vector;
}

最佳答案

来自OpenCV documentation :

Note: OpenCV 1.x functions cvRetrieveFrame and cv.RetrieveFrame return image stored inside the video capturing structure. It is not allowed to modify or release the image! You can copy the frame using cvCloneImage() and then do whatever you want with the copy.

虽然我们使用的是新的 OpenCV 2.x API,但 VideoCapture::read() 实际上是 cvRetrieveFrame() 的包装器。正如注释所说,您必须复制相框。

one_video_vector.push_back(video_img.clone());

关于video - 如何在 OpenCV 中保留 VideoCapture 提供的帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14321620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com