forked from ckxajd/tuxiangpeizhun
-
Notifications
You must be signed in to change notification settings - Fork 0
/
源代码.txt
57 lines (52 loc) · 1.64 KB
/
源代码.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat rimga,rimgb; // 640x480的图像
Mat imga=imread("./../ImageA.jpg");
if(imga.empty())
{
cout<<"Can not read ImageA.jpg!"<<endl;
return 1;
}
resize(imga,rimga,Size(640,480));
imshow("ImageA",rimga);
imwrite("./../Resize_A.jpg",rimga);
Mat imgb=imread("./../ImageB.jpg");
if(imgb.empty())
{
cout<<"Can not read ImageB.jpg!"<<endl;
return 1;
}
resize(imgb,rimgb,Size(640,480));
imshow("ImageB",rimgb);
imwrite("./../Resize_B.jpg",rimgb);
//计算矩阵H
vector<Point2f> pointa;
vector<Point2f> pointb;
pointa.push_back(Point2f(1697,1205));
pointa.push_back(Point2f(1908,979));
pointa.push_back(Point2f(2297,1326));
pointa.push_back(Point2f(2020,2573));
pointa.push_back(Point2f(1245,2139));
pointa.push_back(Point2f(1089,1972));
pointa.push_back(Point2f(1401,1597));
pointb.push_back(Point2f(1251,906));
pointb.push_back(Point2f(1398,633));
pointb.push_back(Point2f(1866,865));
pointb.push_back(Point2f(1927,2156));
pointb.push_back(Point2f(1056,1929));
pointb.push_back(Point2f(866,1826));
pointb.push_back(Point2f(1076,1370));
Mat H = findHomography(pointa, pointb, 0);// 计算矩阵H
Mat img_b_match,rimg_b_match;
warpPerspective(imgb,img_b_match,H,imgb.size());// 进行图像配准
resize(img_b_match,rimg_b_match,Size(640,480));
cout<<"变换矩阵H:"<<endl<<H<<endl;
imshow("Results",rimg_b_match);
imwrite("./../result.jpg",rimg_b_match);
waitKey(0);
return 0;
}