删除冗余算法
This commit is contained in:
parent
0d84bba234
commit
554c7e6083
@ -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):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user