繁体   English   中英

如何使用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循环,以便我只能得到一个循环,而不是一个接一个(例如视频)。 并且还删除了“ break”语句。

#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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM