Ask Your Question

How can I solve this problem? module 'cv2.cv2' has no attribute 'SURF'

asked 2020-11-28 13:48:49 -0500

I run "surf=cv2.SURF(hessian)' in Python, and got AttributeError: module 'cv2.cv2' has no attribute 'SURF'.

how can I solve?


edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2020-11-28 14:02:25 -0500

berak gravatar image

updated 2020-11-30 03:19:02 -0500

you probably installed cv2 via pip, which does not contain any nonfree modules (SURF is still patented).

the only way to get cv2.xfeatures.SURF running is to build from src with the contrib modules and the OPENCV_ENABLE_NONFREE cmake flag set.

then, your code is simply wrong / outdated, you would have to invoke it like:

surf = cv2.xfeatures2d.SURF_create(500)


besides, the SIFT patent expired, so from opencv4.4.0 or 3.4.11 on you can use cv2.features2d.SIFT_create() as a good alternative to SURF

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2020-11-28 13:48:49 -0500

Seen: 238 times

Last updated: Nov 30 '20