图像配准方法(一)

一:选取ROI与图像进行匹配
openv的aircv库中提供了图像匹配的方法:
以下是demo:

import cv2
import aircv as ac

def draw_rectangle(img, pos_1, pos_4, color, line_width):
    cv2.rectangle(img, pos_1, pos_4, color, line_width)
    cv2.imshow('objDetect', imsrc) 
    cv2.waitKey(0)
    cv2.destroyAllWindows()

if __name__ == "__main__":
    imsrc = ac.imread('D:\\python_opencv\\source_image\\image_match\\1.jpg')
    imobj = imsrc[248:328, 187:261] #第一个参数代表y方向,第二个参数代表x方向,因此在这里取的是(224±37, 288±40)
    imsrc = ac.imread('D:\\python_opencv\\source_image\\image_match\\2.jpg')

    # find the match position
    pos = ac.find_template(imsrc, imobj)
    print(pos)

    circle_center_pos = pos['result']
    color = (0, 255, 0)
    line_width = 3

    # draw rectangle
    draw_rectangle(imsrc, (int(circle_center_pos[0])-50, int(circle_center_pos[1])-50), (int(circle_center_pos[0])+ 50, int(circle_center_pos[1])+50), (0, 255, 0), 2)

结果为:
这里写图片描述

这里写图片描述

以下是拍摄的一组照片,其中7、8、9为特意偏移一段距离后拍摄的。 可以得知对于照片1中所取的ROI(Region Of Interest),图片1-10所对应的坐标为:
1: (224.0, 288.0)
2: (228.0, 291.0)
3: (232.0, 292.0)
4: (228.0, 289.0)
5: (230.0, 291.0)
6: (232.0, 290.0)
7: (230.0, 292.0)
8: (259.0, 290.0)
9: (259.0, 286.0)
10: (265.0, 284.0)
但是假如所取区域为特征不明显区域结果会怎么样呢?
假如取的区域如下图所示:
这里写图片描述
那么得到的1-10图像匹配结果为:
1: (310.0, 240.0)
2: (314.0, 243.0)
3: (350.0, 229.0)
4: (313.0, 241.0)
5: (316.0, 242.0)
6: (339.0, 232.0)
7: (345.0, 248.0)
8: (35.0, 425.0)
9: (376.0, 233.0)
10:(384.0, 202.0)
容易出现很明显的误匹配,如图8与ROI匹配结果为:

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值