-213 opencv build_error ai_generated true

cv2.error: OpenCV(4.5.5) /tmp/opencv-4.5.5/modules/xfeatures2d/src/sift.cpp:120: 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 'SIFT_create'

ID: opencv/sift-patent-expired-license

Also available as: JSON · Markdown · 中文
85%Fix Rate
90%Confidence
1Evidence
2023-01-10First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
4.5.5 active
4.6.0 active
4.7.0 active
4.8.0 active
4.9.0 active

Root Cause

SIFT algorithm is disabled by default in OpenCV builds due to patent restrictions; non-free modules must be enabled at compile time.

generic

中文

由于专利限制,SIFT 算法在 OpenCV 构建中默认禁用;必须在编译时启用非免费模块。

Official Documentation

https://docs.opencv.org/4.x/da/df5/tutorial_py_sift_intro.html

Workarounds

  1. 90% success Install opencv-contrib-python which includes non-free modules by default: `pip install opencv-contrib-python`
    Install opencv-contrib-python which includes non-free modules by default: `pip install opencv-contrib-python`
  2. 85% success Rebuild OpenCV from source with CMake flag: `cmake -DOPENCV_ENABLE_NONFREE=ON ..` then `make -j8` and `sudo make install`
    Rebuild OpenCV from source with CMake flag: `cmake -DOPENCV_ENABLE_NONFREE=ON ..` then `make -j8` and `sudo make install`
  3. 70% success Use AKAZE or ORB as patent-free alternatives: `akaze = cv2.AKAZE_create(); kp, des = akaze.detectAndCompute(img, None)`
    Use AKAZE or ORB as patent-free alternatives: `akaze = cv2.AKAZE_create(); kp, des = akaze.detectAndCompute(img, None)`

中文步骤

  1. Install opencv-contrib-python which includes non-free modules by default: `pip install opencv-contrib-python`
  2. Rebuild OpenCV from source with CMake flag: `cmake -DOPENCV_ENABLE_NONFREE=ON ..` then `make -j8` and `sudo make install`
  3. Use AKAZE or ORB as patent-free alternatives: `akaze = cv2.AKAZE_create(); kp, des = akaze.detectAndCompute(img, None)`

Dead Ends

Common approaches that don't work:

  1. 70% fail

    Pip install opencv-python-headless doesn't include non-free modules; SIFT remains unavailable.

  2. 90% fail

    Setting OPENCV_ENABLE_NONFREE=ON via environment variable won't affect pre-built binary packages.

  3. 80% fail

    Using cv2.xfeatures2d.SIFT_create() still requires non-free build; the function name doesn't change behavior.