您当前的位置: 首页 >  opencv

鱼儿-1226

暂无认证

  • 0浏览

    0关注

    1100博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

利用OpenCV进行图像配准

鱼儿-1226 发布时间:2020-08-03 10:29:35 ,浏览量:0

项目代码: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();
};
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

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

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

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

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

实际演示:  比如我们将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(j, i)[0] = 0;
        src1.at(j, i)[1] = 0;
        src1.at(j, i)[2] = 0;

        src2.at(temp2, temp1)[0] = 0;
        src2.at(temp2, temp1)[1] = 0;
        src2.at(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();
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

效果: 

关注
打赏
1604459285
查看更多评论
立即登录/注册

微信扫码登录

0.0408s