全景缝线无法正常工作
我试图将两个图像缝合在一起,这两个图像都具有不同的角度。如下所示:
如您所见,有一些重叠。但是,当我缝合它们时,我会得到以下内容:
我使用以下算法:
- SIFT
- LOWE比率测试
- 同构型
- FlannBasedMatcher(RANSAC)
- 包装透视透视
降低比率测试
if len(item) < 2:
continue
(left, right) = item
if left.distance < 0.78 * right.distance:
good.append(left)
同型
# img_feature is an object containing the keypoints where 1 refer to image 1.
src_pts = np.float32([img_feature1.key_points[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
dst_pts = np.float32([img_feature2.key_points[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)
# Defining the Homography parameters
homog_method = cv2.RANSAC
homog_reprojthres = 5
homog_mask = None
homog_max_iter = 2000
homog_confidence = 0.995
homog_matrix, mask = cv2.findHomography(
dst_pts,
src_pts,
homog_method,
homog_reprojthres,
homog_mask,
homog_max_iter,
homog_confidence,
)
return homog_matrix, mask
flann Matcher
def compute_flann_matcher_sift(des1, des2):
"""Computing the flann matchers"""
# Defining the FlannMatcher parameters
flann_index_kdtree = 0
index_params = dict(algorithm=flann_index_kdtree, trees=5)
search_params = dict(checks=50)
# Set up the flannMatcher
flann = cv2.FlannBasedMatcher(index_params, search_params)
# Get the matches
matches = flann.knnMatch(des1, des2, k=2)
return matches
包裹透视
def blend_image(img1, img2, homog_matrix):
# Warp the image 2 (right) for image 1 (left)
dst = cv2.warpPerspective(
img2, homog_matrix, (img1.shape[1] + img2.shape[1], img1.shape[0])
)
# Concatenation
dst[0 : img1.shape[0], 0 : img1.shape[1]] = img1
return dst
I am trying to stitch two images together in which both images have different angles. Shown below:
As you can see, there are some overlaps. However, when I stitch them, I get the following:
I use the following algorithm:
- SIFT
- Lowe Ratio test
- Homography
- FlannBasedMatcher (RANSAC)
- Wrap Perspective
Lower Ratio Test
if len(item) < 2:
continue
(left, right) = item
if left.distance < 0.78 * right.distance:
good.append(left)
Homography
# img_feature is an object containing the keypoints where 1 refer to image 1.
src_pts = np.float32([img_feature1.key_points[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)
dst_pts = np.float32([img_feature2.key_points[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)
# Defining the Homography parameters
homog_method = cv2.RANSAC
homog_reprojthres = 5
homog_mask = None
homog_max_iter = 2000
homog_confidence = 0.995
homog_matrix, mask = cv2.findHomography(
dst_pts,
src_pts,
homog_method,
homog_reprojthres,
homog_mask,
homog_max_iter,
homog_confidence,
)
return homog_matrix, mask
Flann Matcher
def compute_flann_matcher_sift(des1, des2):
"""Computing the flann matchers"""
# Defining the FlannMatcher parameters
flann_index_kdtree = 0
index_params = dict(algorithm=flann_index_kdtree, trees=5)
search_params = dict(checks=50)
# Set up the flannMatcher
flann = cv2.FlannBasedMatcher(index_params, search_params)
# Get the matches
matches = flann.knnMatch(des1, des2, k=2)
return matches
Wrap perspective
def blend_image(img1, img2, homog_matrix):
# Warp the image 2 (right) for image 1 (left)
dst = cv2.warpPerspective(
img2, homog_matrix, (img1.shape[1] + img2.shape[1], img1.shape[0])
)
# Concatenation
dst[0 : img1.shape[0], 0 : img1.shape[1]] = img1
return dst
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论