I have set of images taken from right side of object like image1. I need to rotate it about vertical axis and change it tobe like image2.
Is that affine transformation useful to convert image1 to image2 ? I used affine transform and played with it, but didn't get desired results. What should I do? I used this part of code for image transformation.
cv::Mat shearedImage;
cv::Point2f srcPoints[3] = {cv::Point2f(0, 0), cv::Point2f(resizedImage.cols, 0), cv::Point2f(0, resizedImage.rows)};
cv::Point2f dstPoints[3] = {cv::Point2f(0, 0), cv::Point2f(resizedImage.cols, 0), cv::Point2f(0, resizedImage.rows)};
cv::Mat transformMatrix = cv::getAffineTransform(srcPoints, dstPoints);
cv::warpAffine(resizedImage, shearedImage, transformMatrix, resizedImage.size());
Here is the complete code in Qt
#include "mainwindow.h"
#include <QApplication>
#include <opencv2/opencv.hpp>
#include <QDebug>
#include <QLabel>
int main(int argc, char* argv[])
{
QApplication a(argc, argv);
// Load the original image
cv::Mat originalImage = cv::imread("Pic1.jpg");
// Crop the image
cv::Rect roi(200, 300, 1350, 850);
cv::Mat croppedImage = originalImage(roi);
// Resize the cropped image
cv::Mat resizedImage;
cv::resize(croppedImage, resizedImage, cv::Size(), 0.4, 0.4);
// Shear the resized image
cv::Mat shearedImage;
cv::Point2f srcPoints[3] = {cv::Point2f(0, 0), cv::Point2f(resizedImage.cols, 0), cv::Point2f(0, resizedImage.rows)};
cv::Point2f dstPoints[3] = {cv::Point2f(0, 0), cv::Point2f(resizedImage.cols, 0), cv::Point2f(0, resizedImage.rows)};
cv::Mat transformMatrix = cv::getAffineTransform(srcPoints, dstPoints);
cv::warpAffine(resizedImage, shearedImage, transformMatrix, resizedImage.size());
// Display the shear image
cv::namedWindow("Transformed Image");
cv::imshow("Transformed Image", shearedImage);
MainWindow w;
w.show();
return a.exec();
}


I searched more and found more details, based on this Question, I should use
cv::warpPerspectiveinstead of affine transform to change the image perspective.