gpt4 book ai didi

python - OpenCV,Python : How to stitch two images of different sizes and transparent backgrounds

转载 作者:太空宇宙 更新时间:2023-11-03 21:42:47 24 4
gpt4 key购买 nike

我一直致力于一个项目,我将无人机以割草机模式飞行的图像拼接在一起。我能够将单次传递的图像拼接在一起(感谢 stackoverflow 上的许多答案),但是当我尝试横向将两个单独的传递拼接在一起时,我的方法产生的转换是荒谬的。这是我要拼接的两张图片:

enter image description here enter image description here

这是我用来估计两者之间单应性的代码,basecurr

base_gray = cv2.cvtColor(base, cv2.COLOR_BGRA2GRAY)
curr_gray = cv2.cvtColor(curr, cv2.COLOR_BGRA2GRAY)

detector = cv2.ORB_create()
base_keys, base_desc = detector.detectAndCompute(base_gray, None)
curr_keys, curr_desc = detector.detectAndCompute(curr_gray, None)

FLANN_INDEX_LSH = 6
flann_params = dict(algorithm = FLANN_INDEX_LSH,
table_number = 12,
key_size = 20,
multi_probe_level = 2)
search_params = dict(checks=100)
matcher = cv2.FlannBasedMatcher(flann_params, search_params)
matches = matcher.match(base_desc, curr_desc)

max_dist = 0.0
min_dist = 100.0

for match in matches:
dist = match.distance
min_dist = dist if dist < min_dist else min_dist
max_dist = dist if dist > max_dist else max_dist

good_matches = [match for match in matches if match.distance <= 10 * min_dist ]

base_matches = []
curr_matches = []
for match in good_matches:
base_matches.append(base_keys[match.queryIdx].pt)
curr_matches.append(curr_keys[match.trainIdx].pt)

bm_final = np.asarray(base_matches)
cm_final = np.asarray(curr_matches)

# find perspective transformation using the arrays of corresponding points
transformation, hom_stati = cv2.findHomography(cm_final, bm_final, method=cv2.RANSAC, ransacReprojThreshold=1)

正如我所说,它不起作用。是因为透明背景打乱了计算吗?

最佳答案

我认为 Flann 可能不是您想在这里进行匹配的对象。首先,事实上,由于您要转换为灰度,因此黑点、图像边缘等可能会包含在您不想要的功能集中。其次,Flann 使用方法来构建特定的描述符,以便通过图像数据库进行快速搜索;它用于 CBIR , 不适用于单应性估计。

相反,只需采用SIFTSURFORBBRISK 的常规方法。请注意,所有这些都允许为其关键点检测步骤添加一个掩码,以便您可以从 alpha channel 创建一个掩码以忽略其中的关键点。请参阅 OpenCV 文档以了解 SIFT and SURF。和 ORB and BRISK了解更多。

关于python - OpenCV,Python : How to stitch two images of different sizes and transparent backgrounds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45453306/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com