我有一个 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;
}
最佳答案
打开 VideoCapture 后,添加以下内容:
capture.set(CV_CAP_PROP_CONVERT_RGB, 1);
关于c++ - 在 Opencv 中更改提取帧的分辨率,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19873208/