# AttributeError: module 'cv2.xfeatures2d' has no attribute 'SURF\_create'

**URL:** <https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450>\
**Category:** Uncategorized\
**Tags:** contrib\
**Created:** [August 7, 2024, 12:54pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450 "2024-08-07T12:54:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Andre\_Silva](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/andre_silva/32/10927_2.png) [@Andre\_Silva](https://forum.opencv.org/u/Andre_Silva)\
**Post date:** [August 7, 2024, 12:54pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450/1 "2024-08-07T12:54:40Z")

</div>

I’m trying to use the SURF feature extractor, but I’m encountering the error: “AttributeError: module ‘cv2.xfeatures2d’ has no attribute ‘SURF\_create’”. I’ve already tried manually compiling OpenCV to enable `OPENCV_ENABLE_NONFREE`, but I was unsuccessful. How can I resolve this issue?

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [August 7, 2024, 1:08pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450/2 "2024-08-07T13:08:29Z")

</div>

> [@Andre\_Silva](#):
>
> I’ve already tried manually compiling OpenCV to enable `OPENCV_ENABLE_NONFREE`, but I was unsuccessful.

so, tell us about it, what _exactly_ did you try, and to which result ?

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [August 7, 2024, 1:16pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450/3 "2024-08-07T13:16:19Z")

</div>

> [@berak](#):
>
> so, tell us about it, what _exactly_ did you try, and to which result ?

First this ☝

But as I was checking did you try the below?

> cv2.xfeatures2d.SURF\_create()

---

<div class="post-metadata">

**Author:** ![Andre\_Silva](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/andre_silva/32/10927_2.png) [@Andre\_Silva](https://forum.opencv.org/u/Andre_Silva)\
**Post date:** [August 7, 2024, 1:25pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450/4 "2024-08-07T13:25:12Z")

</div>

Yes, I’m trying to use

> surf = cv2.xfeatures2d.SURF\_create(800)

to extract features from an image

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [August 7, 2024, 1:45pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450/5 "2024-08-07T13:45:03Z")

</div>

Can you share your CMake flags and the configuration output? I don’t have non free in my install and I get the following output

```auto

>>> import cv2
>>> cv2.xfeatures2d.SURF.create(800)
terminating with uncaught exception of type cv::Exception: OpenCV(4.10.0) /home/b/repos/opencv/opencv-python/opencv_contrib/modules/xfeatures2d/src/surf.cpp:1026: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'

```

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [August 7, 2024, 2:43pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450/6 "2024-08-07T14:43:24Z")

</div>

> [@cudawarped](#):
>
> Can you share your CMake flags and the configuration output?

that is done like so:

```python
print(cv2.getBuildInformation())

```

I have `opencv-contrib-python`and get the same error as cudawarped. that package doesn’t contain the nonfree stuff.

you should just go with sift or akaze instead.

---

<div class="post-metadata">

**Author:** ![Andre\_Silva](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/andre_silva/32/10927_2.png) [@Andre\_Silva](https://forum.opencv.org/u/Andre_Silva)\
**Post date:** [August 7, 2024, 2:47pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450/7 "2024-08-07T14:47:18Z")

</div>

I’m Brazilian, my English is not good. I believe this is it

> General configuration for OpenCV 4.10.0 =====================================  
> Version control: 4.10.0
> 
> Platform:  
> Timestamp: 2024-06-17T17:58:36Z  
> Host: Windows 10.0.17763 AMD64  
> CMake: 3.24.2  
> CMake generator: Visual Studio 14 2015  
> CMake build tool: MSBuild.exe  
> MSVC: 1900  
> Configuration: Debug Release
> 
> CPU/HW features:  
> Baseline: SSE SSE2 SSE3  
> requested: SSE3  
> Dispatched code generation: SSE4\_1 SSE4\_2 FP16 AVX AVX2  
> requested: SSE4\_1 SSE4\_2 AVX FP16 AVX2 AVX512\_SKX  
> SSE4\_1 (16 files): + SSSE3 SSE4\_1  
> SSE4\_2 (1 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2  
> FP16 (0 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 FP16 AVX  
> AVX (8 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 AVX  
> AVX2 (36 files): + SSSE3 SSE4\_1 POPCNT SSE4\_2 FP16 FMA3 AVX AVX2
> 
> C/C++:  
> Built as dynamic libs?: NO  
> C++ standard: 11  
> C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86\_amd64/cl.exe (ver 19.0.24247.2)  
> C++ flags (Release): /DWIN32 /D\_WINDOWS /W4 /GR /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP /O2 /Ob2 /DNDEBUG  
> C++ flags (Debug): /DWIN32 /D\_WINDOWS /W4 /GR /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP /Zi /Ob0 /Od /RTC1  
> C Compiler: C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86\_amd64/cl.exe  
> C flags (Release): /DWIN32 /D\_WINDOWS /W3 /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /O2 /Ob2 /DNDEBUG  
> C flags (Debug): /DWIN32 /D\_WINDOWS /W3 /D \_CRT\_SECURE\_NO\_DEPRECATE /D \_CRT\_NONSTDC\_NO\_DEPRECATE /D \_SCL\_SECURE\_NO\_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /Zi /Ob0 /Od /RTC1  
> Linker flags (Release): /machine:x64 /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib  
> Linker flags (Debug): /machine:x64 /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib  
> ccache: NO  
> Precompiled headers: YES  
> Extra dependencies: wsock32 comctl32 gdi32 ole32 setupapi ws2\_32  
> 3rdparty dependencies: libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib ippiw ippicv
> 
> OpenCV modules:  
> To be built: calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio  
> Disabled: java world  
> Disabled by dependency: -  
> Unavailable: python2 ts  
> Applications: -  
> Documentation: NO  
> Non-free algorithms: NO
> 
> Windows RT support: NO
> 
> GUI: WIN32UI  
> Win32 UI: YES  
> VTK support: NO
> 
> Media I/O:  
> ZLib: build (ver 1.3.1)  
> JPEG: build-libjpeg-turbo (ver 3.0.3-70)  
> SIMD Support Request: YES  
> SIMD Support: NO  
> WEBP: build (ver encoder: 0x020f)  
> PNG: build (ver 1.6.43)  
> SIMD Support Request: YES  
> SIMD Support: YES (Intel SSE)  
> TIFF: build (ver 42 - 4.6.0)  
> JPEG 2000: build (ver 2.5.0)  
> OpenEXR: build (ver 2.3.0)  
> HDR: YES  
> SUNRASTER: YES  
> PXM: YES  
> PFM: YES
> 
> Video I/O:  
> DC1394: NO  
> FFMPEG: YES (prebuilt binaries)  
> avcodec: YES (58.134.100)  
> avformat: YES (58.76.100)  
> avutil: YES (56.70.100)  
> swscale: YES (5.9.100)  
> avresample: YES (4.0.0)  
> GStreamer: NO  
> DirectShow: YES  
> Media Foundation: YES  
> DXVA: YES
> 
> Parallel framework: Concurrency
> 
> Trace: YES (with Intel ITT)
> 
> Other third-party libraries:  
> Intel IPP: 2021.11.0 [2021.11.0]  
> at: D:/a/opencv-python/opencv-python/\_skbuild/win-amd64-3.9/cmake-build/3rdparty/ippicv/ippicv\_win/icv  
> Intel IPP IW: sources (2021.11.0)  
> at: D:/a/opencv-python/opencv-python/\_skbuild/win-amd64-3.9/cmake-build/3rdparty/ippicv/ippicv\_win/iw  
> Lapack: NO  
> Eigen: NO  
> Custom HAL: NO  
> Protobuf: build (3.19.1)  
> Flatbuffers: builtin/3rdparty (23.5.9)
> 
> OpenCL: YES (NVD3D11)  
> Include path: D:/a/opencv-python/opencv-python/opencv/3rdparty/include/opencl/1.2  
> Link libraries: Dynamic load
> 
> Python 3:  
> Interpreter: C:/hostedtoolcache/windows/Python/3.9.13/x64/python.exe (ver 3.9.13)  
> Libraries: C:/hostedtoolcache/windows/Python/3.9.13/x64/libs/python39.lib (ver 3.9.13)  
> Limited API: YES (ver 0x03060000)  
> numpy: C:/hostedtoolcache/windows/Python/3.9.13/x64/lib/site-packages/numpy/\_core/include (ver 2.0.0)  
> install path: python/cv2/python-3
> 
> Python (for build): C:\hostedtoolcache\windows\Python\3.9.13\x64\python.exe
> 
> Java:  
> ant: NO  
> Java: YES (ver 1.8.0.412)  
> JNI: C:/hostedtoolcache/windows/Java\_Temurin-Hotspot\_jdk/8.0.412-8/x64/include C:/hostedtoolcache/windows/Java\_Temurin-Hotspot\_jdk/8.0.412-8/x64/include/win32 C:/hostedtoolcache/windows/Java\_Temurin-Hotspot\_jdk/8.0.412-8/x64/include  
> Java wrappers: NO  
> Java tests: NO
> 
> ## Install to: D:/a/opencv-python/opencv-python/\_skbuild/win-amd64-3.9/cmake-install

the output is what you said

---

<div class="post-metadata">

**Author:** ![cudawarped](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@cudawarped](https://forum.opencv.org/u/cudawarped)\
**Post date:** [August 7, 2024, 3:10pm UTC](https://forum.opencv.org/t/attributeerror-module-cv2-xfeatures2d-has-no-attribute-surf-create/18450/8 "2024-08-07T15:10:57Z")

</div>

You haven’t built against the contrib module which includes the implementation for SURF.

As you are building a wheel using [GitHub - opencv/opencv-python: Automated CI toolchain to produce precompiled opencv-python, opencv-python-headless, opencv-contrib-python and opencv-contrib-python-headless packages.](https://github.com/opencv/opencv-python)  
you need to

> set ENABLE\_CONTRIB=1

before building.

You should then have the extra module path in your configuration output. e.g.

> General configuration for OpenCV 4.10.0 =====================================  
> Version control: 4.10.0
> 
> Extra modules:  
> Location (extra): D:/a/opencv-python/opencv-python/opencv\_contrib/modules  
> Version control (extra): 4.10.0
