简体   繁体   中英

OpenCV Python Sample Error

I'm trying to run one of the samples included in opencv: find_obj.py. OpenCV version: 2.4 OS: ArchLinx

There is an error at the function:

flann = cv2.flann_Index(desc2, flann_params)

The error is:

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

Please anyone knows how to fix this?

Solution found: i replaced the following line in 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())

with those:

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)

Hope this may help someone else... :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM