逆投影变换的opencv实现 发表于 2017-07-11 | 分类于 OpenCV 参数含义: range:投影范围,可取6-20 gridsize:每个像素代表的实际距离,单位为米 L:生成的逆投影图像大小,计算公式为2*range/gridsize 123456789101112131415161718192021222324252627282930313233343536Point2f 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!