如何使用 C++ 在 OpenCV 中更改视频的分辨率?
我们使用了 OpenCV 的“set()”类。使用“set()”类,我们可以设置帧的高度和宽度。以下行正在我们的程序中设置视频的高度和宽度。
- set(CAP_PROP_FRAME_WIDTH, 320);
- set(CAP_PROP_FRAME_HEIGHT, 240);
第一行将帧的宽度设置为 320 个像素,第二行将帧的高度设置为 240 个像素。这两行共同形成一个 320 x 240 分辨率的视频流。这就是我们如何使用 OpenCV 简单更改视频分辨率的方法。
以下程序更改了从默认摄像头获取的视频流的分辨率 −
示例
#include<opencv2/opencv.hpp>//OpenCV header to use VideoCapture class//
#include<iostream>
using namespace std;
using namespace cv;
int main() {
Mat myImage;//Declaring a matrix to load the frames//
namedWindow("Video Player");//Declaring the video to show the video//
VideoCapture cap(0);//Declaring an object to capture stream of frames from default camera//
cap.set(CAP_PROP_FRAME_WIDTH, 320);//Setting the width of the video
cap.set(CAP_PROP_FRAME_HEIGHT, 240);//Setting the height of the video//
if (!cap.isOpened()){ //This section prompt an error message if no video stream is found//
cout << "No video stream detected" << endl;
system("pause");
return-1;
}
while (true){ //Taking an everlasting loop to show the video//
cap >> myImage;
if (myImage.empty()){ //Breaking the loop if no video frame is detected//
break;
}
imshow("Video Player", myImage);//Showing the video//
char c = (char)waitKey(25);//Allowing 25 milliseconds frame processing time and initiating break condition//
if (c == 27){ //If 'Esc' is entered break the loop//
break;
}
}
cap.release();//Releasing the buffer memory//
return 0;
}此程序将在 320 x 240 分辨率下播放视频。
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP