//图像图像透视变换
#include <stdio.h>
#include <iostream>
#include <string>
#include <opencv2\opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
//图像的透视变换,需要3x3的旋转矩阵,总共9个参数,通过原图像和变换后的对应4个点就可以构造12个方程解出9个参数
Mat img = imread("noobcvqr.png");
//注意边界点不能用,图像为628*628,最大值为627,否则会报错
Point2f src[4] = { Point2f(94,374),Point2f(507,380),Point2f(1,623) ,Point2f(627,627) };
Point2f dst[4] = { Point2f(0,0),Point2f(627,0),Point2f(0,627) ,Point2f(627,627) };
Mat rotation, img_dst;
rotation = getPerspectiveTransform(src, dst);
warpPerspective(img, img_dst, rotation, Size(img.cols, img.rows));
namedWindow("原图", WINDOW_NORMAL);
imshow("原图", img);
namedWindow("透视变换", WINDOW_NORMAL);
imshow("透视变换", img_dst);
waitKey(0);
return 0;
}
初识Opencv4.X----图像透视变换
最新推荐文章于 2024-04-16 10:08:18 发布