利用OpenCV进行图像配准

最近项目上有一个步骤需要进行图像配准,因此在网上搜了下图像配准的资料,做了一个接口。
项目代码:GitHub:team79/ImageRegistration
图像配准类:
文件:
ImageRegistration.h
ImageRegistration.cpp

class ImageRegistration {
    Mat src1;
    Mat src2;
    void getRegistrationMat();
    Mat transMatrix;
public:
    void init(Mat,Mat);
    Point2f getXY(int,int);
    ~ImageRegistration();
};

其中src1为原图像,src2为待匹配图像。
初始化:

Mat src1 = imread("test-1.png", 1);
Mat src2 = imread("test-2.png", 1); 
ImageRegistration llll;
llll.init(src1, src2);

调用getXY函数即可得到原图中的点在src2中的坐标

Point2f temp = llll.getXY(i, j);

实际演示:
比如我们将src1中的(100,100)起的50*50的块涂黑,对应的src2中也在相应位置涂黑

for (int i = 100; i < 150; i++) {
    for (int j = 100; j < 150; j++) {
        Point2f temp = llll.getXY(i, j);
        int temp1 = temp.x;
        int temp2 = temp.y;
        src1.at<cv::Vec3b>(j, i)[0] = 0;
        src1.at<cv::Vec3b>(j, i)[1] = 0;
        src1.at<cv::Vec3b>(j, i)[2] = 0;

        src2.at<cv::Vec3b>(temp2, temp1)[0] = 0;
        src2.at<cv::Vec3b>(temp2, temp1)[1] = 0;
        src2.at<cv::Vec3b>(temp2, temp1)[2] = 0;
    }
}
//warpAffine(src1, src2, mat, src2.size());
cv::namedWindow("Display window1", cv::WINDOW_AUTOSIZE);
cv::imshow("Display window1", src1);
cv::namedWindow("Display window", cv::WINDOW_AUTOSIZE);
cv::imshow("Display window", src2);
waitKey(0);
src1.release();
src2.release();

效果:
这里写图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值