-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:功能未实现) 此算法已申请专利且在此配置中被排除;请设置 OPENCV_ENABLE_NONFREE CMake 选项并重新编译库 在函数 'SIFT_create' 中

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

其他格式: JSON · Markdown 中文 · English
85%修复率
90%置信度
1证据数
2023-01-10首次发现

版本兼容性

版本状态引入弃用备注
4.5.5 active
4.6.0 active
4.7.0 active
4.8.0 active
4.9.0 active

根因分析

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

English

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

generic

官方文档

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

解决方案

  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)`

无效尝试

常见但无效的做法:

  1. 70% 失败

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

  2. 90% 失败

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

  3. 80% 失败

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