From 554c7e6083f546ccc525d14a8f47cc62262930c8 Mon Sep 17 00:00:00 2001 From: myh Date: Sat, 19 Apr 2025 20:09:17 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=86=97=E4=BD=99=E7=AE=97?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- image_fusion/Image_Registration_test.py | 42 ------------------------- 1 file changed, 42 deletions(-) diff --git a/image_fusion/Image_Registration_test.py b/image_fusion/Image_Registration_test.py index 4c67815..e5e5b71 100644 --- a/image_fusion/Image_Registration_test.py +++ b/image_fusion/Image_Registration_test.py @@ -14,48 +14,6 @@ yolo_model = YOLO("yolov8n.pt") # 可替换为yolov8s/m/l等 yolo_model.to('cuda') # 启用GPU加速 -def sift_registration(img1, img2): - img1gray = cv2.normalize(img1, dst=None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX).astype(np.uint8) - img2gray = img2 - - sift = cv2.SIFT_create() - # find the keypoints and descriptors with SIFT - kp1, des1 = sift.detectAndCompute(img1gray, None) - kp2, des2 = sift.detectAndCompute(img2gray, None) - # FLANN parameters - FLANN_INDEX_KDTREE = 1 - 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 = [] - pts1 = [] - pts2 = [] - - for i, (m, n) in enumerate(matches): - if m.distance < 0.75 * n.distance: - good.append(m) - pts2.append(kp2[m.trainIdx].pt) - pts1.append(kp1[m.queryIdx].pt) - - MIN_MATCH_COUNT = 4 - if len(good) > MIN_MATCH_COUNT: - src_pts = np.float32([kp1[m.queryIdx].pt for m in good]).reshape(-1, 1, 2) - dst_pts = np.float32([kp2[m.trainIdx].pt for m in good]).reshape(-1, 1, 2) - M, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC, 5.0) - else: - print("Not enough matches are found - {}/{}".format(len(good), MIN_MATCH_COUNT)) - M = np.array([[1, 0, 0], - [0, 1, 0], - [0, 0, 1]], dtype=np.float64) - if M is None: - M = np.array([[1, 0, 0], - [0, 1, 0], - [0, 0, 1]], dtype=np.float64) - return 1, M[0], len(pts2) - - # 裁剪线性RGB对比度拉伸:(去掉2%百分位以下的数,去掉98%百分位以上的数,上下百分位数一般相同,并设置输出上下限) def truncated_linear_stretch(image, truncated_value=2, maxout=255, min_out=0): """