#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace cv;
using namespace std;
int main(int argc, char** argv)
{
Point2f srcTri[3];
Point2f dstTri[3];
Mat rot_mat(2, 3, CV_32FC1);
Mat warp_mat(2, 3, CV_32FC1);
Mat src, warp_dst, warp_rotate_dst;
VideoCapture cap(0);
while (1)
{
cap >> src;
/// Set the dst image the same type and size as src
warp_dst = src.clone();
/// Set your 3 points to calculate the Affine Transform
srcTri[0] = Point2f(0, 0);
srcTri[1] = Point2f(src.cols - 1, 0);
srcTri[2] = Point2f(0, src.rows - 1);
dstTri[0] = Point2f(src.cols*0.0, src.rows*0.33);
dstTri[1] = Point2f(src.cols*0.85, src.rows*0.25);
dstTri[2] = Point2f(src.cols*0.15, src.rows*0.7);
/// Get the Affine Transform
warp_mat = getAffineTransform(srcTri, dstTri);
/// Apply the Affine Transform just found to the src image
warpAffine(src, warp_dst, warp_mat, warp_dst.size());
/** Rotating the image after Warp */
/// Compute a rotation matrix with respect to the center of the image
Point center = Point(warp_dst.cols / 2, warp_dst.rows / 2);
double angle = -50.0;
double scale = 0.6;
/// Get the rotation matrix with the specifications above
rot_mat = getRotationMatrix2D(center, angle, scale);
/// Rotate the warped image
warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size());
/// Show what you got
namedWindow("Source image", CV_WINDOW_AUTOSIZE);
imshow("Source image", src);
namedWindow("Warp", CV_WINDOW_AUTOSIZE);
imshow("Warp", warp_dst);
namedWindow("Warp + Rotate", CV_WINDOW_AUTOSIZE);
imshow("Warp + Rotate", warp_rotate_dst);
if (waitKey(30) == 27)
break;
}
return 0;
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น