在Opencv中更改提取帧的分辨率

时间:2013-11-09 06:39:34

标签: c++ opencv video frame h.264

我有H.264视频流,我需要从中提取帧。然而,当我提取帧时,质量非常差,因为我需要执行颜色分割!我想知道如何提取帧并将其转换为B G R以便获得更好的画质。

这是我到目前为止的代码:

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>

using namespace cv;
using namespace std;

int main(){
    VideoCapture capture("1.dv4");
    if(!capture.isOpened())
        return 1;

    double rate=capture.get(CV_CAP_PROP_FPS);

    bool stop(false);

    Mat frame;
    namedWindow("Extracted Frame",CV_WINDOW_NORMAL);

    cout <<"Rate is="<<rate;

    int delay=1000/rate;

    while(!stop){
        if(!capture.read(frame))
            break;

            imshow("Extracted Frame",frame);
            imwrite("C:/Users/DELL/Documents/Visual Studio 2010/Projects/VideoFrameCapture/VideoFrameCapture/frame.jpg",frame);

        if(waitKey(delay)>=0)
            stop=true;
    }
    capture.release();
    waitKey(0);
    return 1;
}

1 个答案:

答案 0 :(得分:0)

打开VideoCapture后,添加:

 capture.set(CV_CAP_PROP_CONVERT_RGB, 1);