如何使用OpenCV和Eclipse从视频剪辑中获取单个帧
how to get a single frame from a video clip using opencv and eclipse
#include <iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace std;
using namespace cv;
int main(int argc, const char* argv[]) {
VideoCapture cap(0);
if(!cap.isOpened())
{
cout<<"can't open video file"<<endl;
return -1;
}
namedWindow("Myvideo",CV_WINDOW_AUTOSIZE);
while(1)
{
Mat frame;
bool bsuccess=cap.read(frame);
if(!bsuccess)
{
cout<<"can't read a frame"<<endl;
break;
}
imshow("Myvideo",frame);
if(waitKey(30)==27)
{
cout<<"Esc key is pressed by the user"<<endl;
break;
}
}
return 0;
}
上面的代码只是为了从相机捕获视频。但我想从这个视频中获取图像(即只有一帧(。有人可以告诉我如何做到这一点。我实际上试图删除 while 循环,这样我就可以只得到一个循环,而不是一个接一个地获取(即视频(。并且还删除了"中断"语句。
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/core/core.hpp>`
using namespace std;
using namespace cv;
int main(int argc, const char* argv[]) {
VideoCapture cap(0);
if(!cap.isOpened())
{
cout<<"can't open video file"<<endl;
return -1;
}
namedWindow("Myvideo",CV_WINDOW_AUTOSIZE);
Mat frame;
cap.read(frame);
imshow("Myvideo",frame);
if(waitKey(30)==27)
{
cout<<"Esc key is pressed by the user"<<endl;
}
return 0;
}
但不幸的是,它只是显示一个空白窗口。谁能帮我...提前致谢
第一个读取的帧通常(总是?(黑色/灰色,尝试显示下一帧 - 替换此代码
cap.read(frame);
imshow("Myvideo",frame);
有了这个:
cap.read(frame);
cap.read(frame);
imshow("Myvideo",frame);
相关文章:
- 获取 R 数据帧的内存地址
- 我们如何跳过帧,计算帧数并使用视频阅读器获取当前帧
- 如何从用户那里获取单个字符,直到他输入"."或输入
- 获取GIF帧数,而无需解码所有数据
- 获取单个文件的 Clang AST
- 如何从unordered_set获取单个项目
- 如何从文件中写入的UTF-8编码的URDU字符串中获取单个字符
- 如何使用 clang 获取单个 cpp 文件的 AST
- PROGMEM从字符串数组中获取单个字符
- 如何使用OpenCV和Eclipse从视频剪辑中获取单个帧
- CRITICAL_SECTION用于设置和获取单个布尔值
- 获取单个平面中两个矢量之间角度的有效方法
- 在Cocos Studio中创建的Node中跳到单个帧
- 从字符串中获取单个字符串字符
- 在openv中获取两帧之间的差异
- 获取单个非循环链表中指针后面节点的值
- 我如何从boost库(例如shared_pointer)中获取单个元素
- 从java中的多字节变量中获取单个字节
- Kinect SDK 2.0处理和获取深度帧
- OpenCV视频捕获:如何正确获取特定帧