OpenCV2.4.4 图像仿射变换



#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;

int main()
{
    Mat src = imread("pic3.png");
    Mat dst_warp,dst_warpRotateScale;
    Point2f srcPoints[3];//原图中的三点
    Point2f dstPoints[3];//目标图中的三点

    //三个点对的值
    srcPoints[0] = Point2f(0,0);
    srcPoints[1] = Point2f(0,src.rows-1);
    srcPoints[2] = Point2f(src.cols-1,0);
    dstPoints[0] = Point2f(0,src.rows*0.3);
    dstPoints[1] = Point2f(src.cols*0.25,src.rows*0.75);
    dstPoints[2] = Point2f(src.cols*0.75,src.rows*0.25);

    Mat M1 = getAffineTransform(srcPoints,dstPoints);//由三个点对计算变换矩阵
    warpAffine(src,dst_warp,M1,src.size());//仿射变换

    //旋转加缩放
    Point2f center(src.cols/2,src.rows/2);//旋转中心
    double angle = 45;//逆时针旋转45度
    double scale = 0.5;//缩放比例

    Mat M2 = getRotationMatrix2D(center,angle,scale);//计算旋转加缩放的变换矩阵
    warpAffine(dst_warp,dst_warpRotateScale,M2,src.size());//仿射变换

    imshow("src",src);
    imshow("dst_warp",dst_warp);
    imshow("dst_warpRotateScale",dst_warpRotateScale);
    waitKey(0);

    return 0;
}

效果图:


原图



仿射变换



旋转加缩放

参考

OpenCV2.4.4图像仿射变换

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值