a = np.matmul(get_t2,get_scale) b = np.matmul(a,get_rot) c = np.matmul(b,get_t1) transMx = c[:2,:]
# Call the warp affine function to do the mapping # It expects a 2x3 matrix destImage = cv2.warpAffine(grayImage, transMx, (windowSize, windowSize), flags=cv2.INTER_LINEAR) mean = np.mean(destImage) variance = np.std(destImage) newdest = np.zeros(destImage.shape) if variance<0.00001: pass else: newdest = (destImage-mean)/variance desc[i]=newdest.flatten() return desc
de = spatial.distance.cdist(desc1, desc2, metric='euclidean') for n, dee inenumerate(de): d = cv2.DMatch() d.queryIdx = n m = np.argmin(de[n]) d.trainIdx = int(m) d.distance = de[n][m] matches.append(d) return matches
如果是比例测试,则用最小除以第二小作为距离
1 2 3 4 5 6 7 8 9 10 11 12 13
de = spatial.distance.cdist(desc1, desc2, metric='euclidean') for n, dee inenumerate(de): d = cv2.DMatch() d.queryIdx = n m = np.argmin(de[n]) d.trainIdx = int(m) f1 = de[n][m] de[n][m] = float("inf") m = np.argmin(de[n]) f2 = de[n][m] d.distance = f1/f2 matches.append(d) return matches