# 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' 中

- **ID:** `opencv/sift-patent-expired-license`
- **领域:** opencv
- **类别:** build_error
- **错误码:** `-213`
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 4.5.5 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## 解决方案

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

## 无效尝试

- **** — Pip install opencv-python-headless doesn't include non-free modules; SIFT remains unavailable. (70% 失败率)
- **** — Setting OPENCV_ENABLE_NONFREE=ON via environment variable won't affect pre-built binary packages. (90% 失败率)
- **** — Using cv2.xfeatures2d.SIFT_create() still requires non-free build; the function name doesn't change behavior. (80% 失败率)
