opencv变换(二)

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);

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值