我正在尝试找出两个图像之间的差异
db_image:
query_image:
abs_diff:
query_image比db_image大一点。我正在使用opencv SIFT来提取特征,并使用FlannBasedMatcher来找到Homography结局,我正在使用absdiff来提取差异区域。这是工作 !但是我认为有些图像不能够变形,并且具有一些抗锯齿的噪声像素。如何解决这个问题。 对不起,我英语不好!
这是我的源代码:
grayscale_db = cv2.cvtColor(db_img, cv2.COLOR_BGR2GRAY)
gray_scale_query = cv2.cvtColor(query_img, cv2.COLOR_BGR2GRAY)
# Initiate SIFT detector
sift = cv2.xfeatures2d.SIFT_create()
kp1, des1 = sift.detectAndCompute(grayscale_db, None)
kp2, des2 = sift.detectAndCompute(gray_scale_query, None)
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm=FLANN_INDEX_KDTREE, trees=5)
search_params = dict(checks=50)
flann = cv2.FlannBasedMatcher(index_params, search_params)
matches = flann.knnMatch(des1, des2, k=2)
good = [m for m, n in matches if m.distance < 0.9 * n.distance]
result_area = None
h, w = grayscale_db.shape
if len(good) > threshold:
dst_pts = np.float32([kp2[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)
if return_area:
return cv2.minAreaRect(dst_pts)
src_pts = np.float32([kp1[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
M, mask = cv2.findHomography(dst_pts, src_pts, cv2.RANSAC, 5.0)
result_area = cv2.warpPerspective(query_img, M, (w, h), borderMode=cv2.BORDER_CONSTANT,
borderValue=(255, 255, 255), flags=cv2.INTER_LINEAR)
diff = cv2.absdiff( db_img,result_area)