OpenCV-র বিল্ট-ইন ফাংশন ব্যবহার করে ইমেজ রোটেট করা খুব সহজ। ইমেজ রোটেট করতে 'highgui.hpp' এবং 'imgproc.hpp' হেডার ফাইলগুলো ব্যবহার করতে হয় এবং এই প্রোগ্রামে ইমেজ রোটেশনের জন্য আরও ফাংশন পরিচিত করানো হয়েছে।
OpenCV-এ C++ ব্যবহার করে ইমেজ রোটেট করার প্রোগ্রাম
#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"); // ইমেজ একটি ম্যাট্রিক্সে লোড
namedWindow("BeforeRotation"); // আসল ইমেজ দেখানোর উইন্ডো
imshow("BeforeRotation", before_rotation); // রোটেশনের আগের ইমেজ দেখানো
namedWindow("AfterRotation"); // রোটেটেড ইমেজ দেখানোর উইন্ডো
int Rotation = 180; // প্রাথমিক রোটেশন কোণ
createTrackbar("Rotation", "AfterRotation", &Rotation, 360); // ট্র্যাকবার তৈরি
int Height = before_rotation.rows / 2; // সারির মিডপয়েন্ট
int Width = before_rotation.cols / 2; // কলামের মিডপয়েন্ট
while (true) {
Mat for_Rotation = getRotationMatrix2D(Point(Width, Height), (Rotation - 180), 1); // ২D রোটেশনের জন্য অ্যাফাইন ট্রান্সফরমেশন ম্যাট্রিক্স
Mat for_Rotated; // রোটেটেড ইমেজের ম্যাট্রিক্স
warpAffine(before_rotation, for_Rotated, for_Rotation, before_rotation.size()); // অ্যাফাইন ট্রান্সফরমেশন প্রয়োগ
imshow("AfterRotation", for_Rotated); // রোটেটেড ইমেজ দেখানো
int termination = waitKey(30); // সিস্টেমকে ৩০ মিলিসেকেন্ড সময় দেয়া রোটেশন ইফেক্টের জন্য
if (termination == 27) { // ESC বাটন চাপলে টার্মিনেট
break;
}
}
return 0;
}
আউটপুট
