// 如果是倾斜的 变换菱形 放正 Mat wrapTransfrom(const Mat &gray,const RotatedRect &rect){ int width = rect.size.width; int height = rect.size.height; Mat result(Size(width,height),gray.type());
// 矩阵怎么获取 vector<Point> srcPoints; Point2f pts[4]; rect.points(pts); for (int i = 0; i < 4; i++) { srcPoints.push_back(pts[i]); } vector<Point> dstPoints; dstPoints.push_back(Point(0,0)); dstPoints.push_back(Point(width, 0)); dstPoints.push_back(Point(width, height)); dstPoints.push_back(Point(0, height)); Mat M = findHomography(srcPoints,dstPoints); warpPerspective(gray,result,M,result.size());