我正在尝试运行opencv中包含的示例之一:find_obj.py。
OpenCV版本:2.4
操作系统:ArchLinx

该函数存在错误:

flann = cv2.flann_Index(desc2, flann_params)

错误是:
File "find_obj2.py", line 27, in match_flann
    flann = cv2.flann_Index(desc2, flann_params)
TypeError: <unknown> is not a numpy array

请任何人知道如何解决此问题?

最佳答案

找到的解决方案:我在find_obj.py中替换了以下行:

surf = cv2.SURF(1000)
kp1, desc1 = surf.detect(img1, None, False)
kp2, desc2 = surf.detect(img2, None, False)
desc1.shape = (-1, surf.descriptorSize())
desc2.shape = (-1, surf.descriptorSize())

和那些:
surf_det = cv2.FeatureDetector_create("SURF")
surf_ext = cv2.DescriptorExtractor_create("SURF")
kp1 = surf_det.detect(img1)
kp2 = surf_det.detect(img2)
kp1, desc1 = surf_ext.compute(img1, kp1)
kp2, desc2 = surf_ext.compute(img2, kp2)

希望这可以帮助其他人...:D

关于python - OpenCV Python示例错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10764895/

10-11 01:48