- 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 to rotate an image in OpenCV using C++?
Rotating image using built-in functions of OpenCV is an effortless task. To rotate image, we have to use 'highgui.hpp' and 'imgproc.hpp' header files and we will introduce more functions in this program which deal with image rotation.
The following program how to rotate an image in OpenCV using C++.
Example
#include<iostream> #include<opencv2/highgui/highgui.hpp> #include<opencv2/imgproc/imgproc.hpp> using namespace std; using namespace cv; int main(int argc, char** argv) { Mat before_rotation = imread("bright.jpg");//loading image to a matrix namedWindow("BeforeRotation");//Declaring window to show the original image// imshow("BeforeRotation", before_rotation);//showing the image before rotation// namedWindow("AfterRotation");//declaring window to show rotated image// int Rotation = 180;//initialization rotation angle// createTrackbar("Rotation", "AfterRotation", &Rotation, 360);//creating trackbar// int Height = before_rotation.rows / 2;//getting middle point of rows// int Width = before_rotation.cols / 2;//getting middle point of height// while (true) { Mat for_Rotation = getRotationMatrix2D(Point(Width, Height), (Rotation - 180), 1);//affine transformation matrix for 2D rotation// Mat for_Rotated;//declaring a matrix for rotated image warpAffine(before_rotation, for_Rotated, for_Rotation, before_rotation.size());//applying affine transformation// imshow("AfterRotation", for_Rotated);//show rotated image// int termination = waitKey(30);//allow system 30 millisecond time to create the rottion effect// if (termination == 27){ //terminate if Esc button is pressed// break; } } return 0; }
Output
- Related Articles
- How to rotate an image with OpenCV using Java?
- How to rotate an image in OpenCV Python?
- How to save an Image in OpenCV using C++?
- How to rotate a video in OpenCV using C++?
- How to put a text in an image in OpenCV using C++?
- How to resize an image in OpenCV using Python?
- How to change the brightness of an image in OpenCV using C++?
- How to decrease the Brightness of an image in OpenCV using C++?
- How to blur faces in an image using OpenCV Python?
- How to detect eyes in an image using OpenCV Python?
- How to convert an RGB image to HSV image using OpenCV Python?
- How to write an image using Java OpenCV library?
- How to flip an image using Java OpenCV library?
- Using OpenCV in Python to Cartoonize an Image
- Upsampling an image using OpenCV

Advertisements