- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we change the resolution of a video in OpenCV using C++?
We used 'set()' class of OpenCV. Using 'set()' class, we can set the height and width of the frames. The following lines are setting the height and width of the video in our program.
- set(CAP_PROP_FRAME_WIDTH, 320);
- set(CAP_PROP_FRAME_HEIGHT, 240);
The first line is setting the width of the frames into 320 pixel and the second line is setting the height of the frames to 240 pixels. These two lines together is forming a 320 x 240 resolution video stream. This is how we can simply change the resolution of video using OpenCV.
The following program changes the resolution of the video stream taken from default camera −
Example
#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; }
This program will play the video at 320 x 240 resolution.
- Related Articles
- How to rotate a video in OpenCV using C++?
- Play a video in reverse mode using Python OpenCv
- How to change the resolution of a plot in base R?
- Change the resolution of analogRead in Arduino
- How to capture video from default camera in OpenCV using C++?
- How to capture video from other cameras in OpenCV using C++?
- How to load video from your computer in OpenCV using C++?
- How to store video on your computer in OpenCV using C++?
- How to Change Contrast in OpenCV using C++?
- How can we change the name of a MySQL table?
- How to change the brightness of an image in OpenCV using C++?
- How to change video playing speed using JavaScript?
- How can we change a field name in JSON using Jackson in Java?
- How to change the size of an image and add a border in OpenCV using C++?
- How to change the contrast and brightness of an image using OpenCV in Python?

Advertisements