如何在视频捕获对象(C++)中查找某个frame_no?
How to seek to a certain frame_no in VideoCapture object (C++)?
有没有办法在VideoCapture
对象中寻找某个索引? 我想在特定位置开始阅读流。
你必须使用
cap.set(CV_CAP_PROP_POS_FRAMES, index);
我下面的代码做你的目标
#include <iostream> // for standard I/O
#include <opencv2/core/core.hpp> // Basic OpenCV structures (cv::Mat, Scalar)
#include <opencv2/imgproc/imgproc.hpp> // Gaussian Blur
#include <opencv2/highgui/highgui.hpp> // OpenCV window I/O
using namespace std;
using namespace cv;
int main()
{
string sourceVideoPath;
sourceVideoPath = "C:\opencvVid\video.mp4";
VideoCapture cap(sourceVideoPath);
Mat frame;
char c;
cout << "Stream frame numbre : " << cap.get(CV_CAP_PROP_FRAME_COUNT)<<endl;
if (!cap.isOpened())
{
cout << "Could not open reference " << sourceVideoPath << endl;
return -1;
}
int seek_step = 750 ; // start at frame 750
int frameNum = 0;
cap.set(CV_CAP_PROP_POS_FRAMES, seek_step );
while (1){
cap >> frame;
if (frame.empty())
{
cout << " < < < Channel stream ended! > > > ";
break;
}
cv::putText(frame, "Frame "+to_string(frameNum+seek_step),
cvPoint(30,30), FONT_HERSHEY_COMPLEX_SMALL, 0.8, cvScalar(0,0,255), 1, CV_AA);
imshow("frameNum", frame );
c = (char)cvWaitKey(22);
if (c == 27) break;
++frameNum;
}
return 0;
}
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 在C++中查找文件
- 模板元程序查找相似的连续类型名称
- 在UNIX系统中使用DIR查找文件的字节大小
- 查找最接近的大于当前数字的数字的索引
- 有没有一种方法可以创建一个带有哈希表的数据库,该哈希表具有恒定时间查找功能
- 查找后更改类变量
- 使用正则表达式regex_search在字符串中查找字符串
- 使用gcc从静态链接的文件中查找可选符号
- 在C++中查找范围的长度
- 算法问题:查找从堆栈中弹出的所有序列
- 在Windows中查找扬声器输出的当前音量级别
- 如何在C++中使用X509证书模在令牌中查找私钥
- 使用.find函数在c++中查找字符和另一个字符之间的大小
- 在 Windows 上,是否可以让 dll 在不使用 PATH 环境变量的情况下在另一个文件夹中查找依赖项?
- 在 for 循环中查找问题时遇到困难
- 如何在文件中查找字节序列
- 试图创建一个多线程程序来查找0-100000000之间的总素数
- 使用堆查找第K个最大元素的时间复杂性
- 一个函数,用于查找字符串1包含字符串2 c++的次数