逆投影变换的opencv实现

参数含义:

  • range:投影范围,可取6-20
  • gridsize:每个像素代表的实际距离,单位为米
  • L:生成的逆投影图像大小,计算公式为2*range/gridsize
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
Point2f p1;
Point2f p2;
Point2f p3;
Point2f p4;

Point2f p1r;
Point2f p2r;
Point2f p3r;
Point2f p4r;

vector<Point2f> capturePoint_R;
vector<Point2f> corners_R;
Mat tansfor_pR;

p1 = Point2f(((double)range - 0.5) / gridsize, (2.0 * (double)range - 4.0) / gridsize);
p2 = Point2f(((double)range - 0.5) / gridsize, (2.0 * (double)range - 5.0) / gridsize);
p3 = Point2f(((double)range + 0.5) / gridsize, (2.0 * (double)range - 5.0) / gridsize);
p4 = Point2f(((double)range + 0.5) / gridsize, (2.0 * (double)range - 4.0) / gridsize);

corners_R.push_back(p1);
corners_R.push_back(p2);
corners_R.push_back(p3);
corners_R.push_back(p4);

p1r = Point2f(619,780);
p2r = Point2f(625,750);
p3r = Point2f(738,750);
p4r = Point2f(748,779);

capturePoint_R.push_back(p1r);
capturePoint_R.push_back(p2r);
capturePoint_R.push_back(p3r);
capturePoint_R.push_back(p4r);
tansfor_pR = cv::getPerspectiveTransform(capturePoint_R, corners_R);

cv::warpPerspective(InImg, OutImg, tansfor_pR, Perspective_img_size);

Done!