gpt4 book ai didi

python - OpenCV 中的 Flann KNN Matcher 只返回一个点而不是一对

转载 作者:行者123 更新时间:2023-12-02 16:39:03 25 4
gpt4 key购买 nike

当我运行 Flann KNN 匹配器时,有时 KNN 匹配器只返回一个点,因为依赖于两个点的匹配器之后的代码会失败:

flann = cv2.FlannBasedMatcher(index_params, search_params)

matches = flann.knnMatch(descriptors1, descriptors2, k=2)

# Retrieve good matches
good_matches = []

# ratio test as per Lowe's paper
for i, (m, n) in enumerate(matches):
if m.distance < 0.7*n.distance:
good_matches.append((m, n))

抛出这个错误:

Traceback (most recent call last):
File "main.py", line 161, in <module>
main(vid, video_file)
...
File "main.py", line 73, in consume_for_homography_error
matches = flann_matcher(descriptors1, descriptors2)
File "main.py", line 48, in flann_matcher
for i, (m, n) in enumerate(matches):
ValueError: need more than 1 value to unpack

这里似乎有什么问题?

最佳答案

问题是匹配项似乎填充为固定长度的列表列表,在本例中 len(matches) == 500 即使找到的匹配项数量少于该数量。

尝试添加这个:

matches = [match for match in matches if len(match) == 2]
(or even better)
good_matches = [match[0] for match in matches if len(match) == 2 and match[0].distance
< .7*match[1].distance]


before the for loop to delete these (empty lists?).

关于python - OpenCV 中的 Flann KNN Matcher 只返回一个点而不是一对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31291993/

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