How to rotate video in OpenCV using C++?
Rotating a video is similar to rotating an image. The only difference is that instead of loading a static image into the image matrix, we load a video or get a video stream from the camera.
Here, instead of loading the video, we use the camera to capture the video. If you want to use a video file, just enter the address of the video file correctly.
The following program demonstrates how to rotate a video in OpenCV using C.
Example H2>#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main(int argc, char* argv[]) {
VideoCapture loadvideo(0);//capture video from default camera//
namedWindow("OriginalVideo");//declaring window to show original video stream//
namedWindow("RotatedVideo");//declaring window to show rotated video stream//
int rotating_angle = 180;//initial rotation angle//
createTrackbar("Rotation", "RotatedVideo", &rotating_angle, 360);//creating trackbar for rotation//
while (true) {
Mat before_Rotating;//declaring matrix for image before rotation//
bool temp = loadvideo.read(before_Rotating);//load frames from video source to matrix//
imshow("OriginalVideo", before_Rotating);//show image frames before rotation//
Mat for_Rotation = getRotationMatrix2D(Point(before_Rotating.cols / 2, before_Rotating.rows / 2), (rotating_angle - 180), 1);//affine transformation matrix for the 2D rotation//
Mat after_Rotating;//declaring matrix for image after rotation//
warpAffine(before_Rotating, after_Rotating, for_Rotation, before_Rotating.size());//applying affine transformation//
imshow("RotatedVideo", after_Rotating);//show image after rotating//
if (waitKey(30) == 27){ //wait till Esc key is pressed from keyboard//
break;
}
}
return 0;
}
Copy after loginOutput
#include<iostream> #include<opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp> using namespace std; using namespace cv; int main(int argc, char* argv[]) { VideoCapture loadvideo(0);//capture video from default camera// namedWindow("OriginalVideo");//declaring window to show original video stream// namedWindow("RotatedVideo");//declaring window to show rotated video stream// int rotating_angle = 180;//initial rotation angle// createTrackbar("Rotation", "RotatedVideo", &rotating_angle, 360);//creating trackbar for rotation// while (true) { Mat before_Rotating;//declaring matrix for image before rotation// bool temp = loadvideo.read(before_Rotating);//load frames from video source to matrix// imshow("OriginalVideo", before_Rotating);//show image frames before rotation// Mat for_Rotation = getRotationMatrix2D(Point(before_Rotating.cols / 2, before_Rotating.rows / 2), (rotating_angle - 180), 1);//affine transformation matrix for the 2D rotation// Mat after_Rotating;//declaring matrix for image after rotation// warpAffine(before_Rotating, after_Rotating, for_Rotation, before_Rotating.size());//applying affine transformation// imshow("RotatedVideo", after_Rotating);//show image after rotating// if (waitKey(30) == 27){ //wait till Esc key is pressed from keyboard// break; } } return 0; }
The above is the detailed content of How to rotate video in OpenCV using C++?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Use the pip command to easily install OpenCV tutorial, which requires specific code examples. OpenCV (OpenSource Computer Vision Library) is an open source computer vision library. It contains a large number of computer vision algorithms and functions, which can help developers quickly build image and video processing related applications. Before using OpenCV, we need to install it first. Fortunately, Python provides a powerful tool pip to manage third-party libraries

OpenCV is an open source library for computer vision and image processing, which is widely used in machine learning, image recognition, video processing and other fields. When developing using OpenCV, in order to better debug and run programs, many developers choose to use PyCharm, a powerful Python integrated development environment. This article will provide PyCharm users with an installation tutorial for OpenCV, with specific code examples. Step One: Install Python First, make sure you have Python installed

What are the video streaming processing methods in PHP? With the rapid development of the Internet, video streaming has become the main way for Internet users to watch and share videos. When developing web applications, handling video streaming through PHP has become a good choice. In this article, we will introduce several commonly used PHP video streaming processing methods and provide relevant code examples. Open local video files and output video streams Through PHP, you can open local video files and convert them into video streams. The following is a simple

The org.opencv.imgproc package of the JavaOpenCV library contains a class called Imgproc that provides various methods to process input images. It provides a set of methods for drawing geometric shapes on images. To draw an arrowed line, you need to call the arrowedLine() method of this class. The method accepts the following parameters: a Mat object representing the image on which the line is to be drawn. A Point object representing two points between lines. drawn. A Scalar object representing the line color. (BGR) An integer representing the thickness of the line (default: 1). Example importorg.opencv.core.Core;importo

A practical overview of using Golang and FFmpeg to achieve video de-flickering: Video flickering is a challenge often encountered in video processing. When the frame rate of the recorded video does not match the lighting frequency, it may cause flickering in the video. This article will introduce how to use Golang and FFmpeg libraries to achieve video de-flickering, and provide specific code examples. Steps: Install the FFmpeg library: First, we need to install the FFmpeg library in the Golang development environment. able to pass

PyCharm is a powerful Python integrated development environment (IDE) developed by JetBrains. It provides a wealth of functions and tools to help Python developers write code, debug programs and manage projects. Using OpenCV, a powerful computer vision library, in PyCharm, you can easily perform image processing, video processing and other tasks. This article will detail the steps to install and configure OpenCV in PyCharm and provide specific code examples. 1.An

Quick Start: Use Go language functions to implement simple video processing functions Introduction: In today's digital era, video has become an indispensable part of our lives. However, processing videos requires efficient algorithms and powerful computing power. As a simple and efficient programming language, Go language also shows its unique advantages in video processing. This article will introduce how to use Go language functions to implement simple video processing functions, and use code examples to let everyone understand the process more intuitively. Step 1: Import related packages for video processing

We all know numbers that are not the square of any number, such as 2, 3, 5, 7, 8, etc. There are N non-square numbers, and it is impossible to know every number. So, in this article, we will explain everything about squareless or non-square numbers and ways to find the Nth non-square number in C++. Nth non-square number If a number is the square of an integer, then the number is called a perfect square. Some examples of perfect square numbers are -1issquareof14issquareof29issquareof316issquareof425issquareof5 If a number is not the square of any integer, then the number is called non-square. For example, the first 15 non-square numbers are -2,3,5,6,
