NCC匹配原理公式:
1.旋转的情况使用圆投影的旋转不变性原理匹配
2.通过对图像进行降采样,从降采样的高层开始匹配筛选匹配点极大地减少了运算量
3.差分简化运算数据量(但是目前实现的差分貌似没有起到加速的效果,主要是计算src的累积和会消耗太多的时间)
4.gitee代码持续改进中gitee代码地址https://gitee.com/lzj12321/ncc_match.git,欢迎交流,最后希望可以实现一个可工业化应用的NCC匹配(1.带旋转,2.不规则模板匹配,3.实时性高)
5.微信同号,支持帮忙做付费项目(哈哈)
注意:
不支持缩放匹配,圆投影匹配目前不输出匹配角度,只是NCC匹配的初步实现,还需很多优化,目前的实现对规则矩形不旋转的匹配还是挺友好的
import math
import numpy as np
import cv2
from PyQt5.QtCore import QTime
'''
1.二维数组降维
2.圆投影匹配算法
'''
def calculate_unrotate_temp_data(temp):
####使用圆投影匹配算法####
temp_mean = np.mean(temp)
temp_sub_avg = temp - temp_mean
temp_deviation = np.vdot(temp_sub_avg, temp_sub_avg)
return temp_deviation, temp_sub_avg
def calculate_rotate_temp_data(temp):
temp_column = temp.shape[1]
temp_row = temp.shape[0]
if temp_column < temp_row:
diameter = temp_row
else:
diameter = temp_column
max_radius = math.floor(diameter / 2)
circle_center = (temp_row / 2, temp_column / 2)
circle_ring_point = {}
###统计每个点到中心的半径,并分类###
for i in range(temp_column):
for j in range(temp_row):
radius = round(np.sqrt((i - circle_center[0]) ** 2 + (j - circle_center[1]) ** 2))
if radius > max_radius:
continue
if radius in circle_ring_point.keys():
circle_ring_point[radius].append(j * temp_column + i)
else:
circle_ring_point[radius] = [j * temp_column + i]
###排序获取每个环上的点###
circle_ring_point = sorted(circle_ring_point.items(), key=lambda item: item[0])
circular_projection_data = []
for item in circle_ring_point:
circular_p