gpt4 book ai didi

OpenCV:读取视频序列

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

有没有办法在 OpenCV 中随机读取视频帧……就像使用索引访问数组一样?否则,如果我想在 CPU 或 GPU 中加载完整的视频,我该怎么做?

最佳答案

您可以在视频捕获中使用 set(int propId, double value) 方法(也可以查看 documentation ),其中 propId 可以是一个以下:

  • CV_CAP_PROP_POS_MSEC:视频文件的当前位置(以毫秒为单位)。
  • CV_CAP_PROP_POS_FRAMES:下一个要解码/捕获的帧的从 0 开始的索引。
  • CV_CAP_PROP_POS_AVI_RATIO:视频文件的相对位置:0 - 电影开始,1 - 电影结束。

播放视频 50 秒的小示例:

int main( int argc, char **argv )
{
namedWindow("Frame", CV_WINDOW_NORMAL);
Mat frame;

VideoCapture capture(argv[1]);
if (!capture.isOpened())
{
//error in opening the video input
cerr << "Unable to open video file: " << argv[1] << endl;
exit(EXIT_FAILURE);
}

capture.set(CV_CAP_PROP_POS_MSEC, 50000);
for (;;)
{
//read the current frame
if (!capture.read(frame))
{
cerr << "Unable to read next frame." << endl;
cerr << "Exiting program!" << endl;
exit(EXIT_FAILURE);
}
imshow("Frame", frame);
waitKey(20);
}
}

关于OpenCV:读取视频序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23615830/

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