我有一个 H.264 视频流,我需要从中提取帧。但是,当我提取帧时,质量真的很差,因为我需要执行颜色分割!我想知道如何提取帧并将其转换为 BGR 以获得更好质量的图片。
这是我到目前为止的代码:
#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;
}