RotatedRect CCorrectMath::FindMminRect(std::vector<Point> verpts)
{
// 寻找最小外接矩形
std::vector<Point> contours;
contours.push_back(verpts.at(0));
contours.push_back(verpts.at(1));
contours.push_back(verpts.at(2));
contours.push_back(verpts.at(3));
return minAreaRect(contours);
}
//rect为最小外接矩形
void CCorrectMath::SetAffinePerTF(Mat mat2,Mat &result,RotatedRect rect,std::vector<Point> verpts)
{
int width = rect.size.width;
int height = rect.size.height;
Mat src = mat2;
Mat dst_warpRotateScale, dst_warpTransformation, dst_warpFlip;
Point2f srcPoints[4];//原图中的四点 ,一个包含三维点(x,y)的数组,其中x、y是浮点型数
Point2f dstPoints[4];//目标图中的四点
srcPoints[0] = Point2f(verpts.at(0).x, verpts.at(0).y);
srcPoints[1] = Point2f(verpts.at(1).x, verpts.at(1).y);
srcPoints[2] = Point2f(verpts.at(2).x, verpts.at(2).y);
srcPoints[3] = Point2f(verpts.at(3).x, verpts.at(3).y);
//映射后的四个坐标值
dstPoints[0]= Point2f(0, 0);
dstPoints[1] = Point2f(width, 0);
dstPoints[2] = Point2f(width,height);
dstPoints[3] = Point2f(0, height);
Mat M1 = getPerspectiveTransform(srcPoints, dstPoints);//由四个点对计算透视变换矩阵
warpPerspective(src, result, M1, Size(width,height));//仿射变换
imshow("perspective transformation1", result);
waitKey(0);
}
opencv变换(二)
最新推荐文章于 2024-07-22 21:21:23 发布