# cv::error: (-215：断言失败) !blob.empty() 在函数 'cv::dnn::blobFromImage' 中

- **ID:** `opencv/dnn-blob-from-image-empty`
- **领域:** opencv
- **类别:** assertion_error
- **错误码:** `-215`
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

blobFromImage 失败，因为输入图像为空（未加载或损坏），或者预处理参数（如尺寸或均值减法）导致 blob 为空。

## 版本兼容性

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

## 解决方案

1. ```
   验证图像加载：img = cv2.imread('path'); if img is None: raise ValueError('Image not loaded')。然后在调用 blobFromImage 前检查 img.shape。
   ```
2. ```
   确保 blob 尺寸匹配模型输入。示例：blob = cv2.dnn.blobFromImage(img, 1.0, (224, 224), (104, 117, 123), swapRB=True, crop=False)。打印 blob.shape 确认非空。
   ```
3. ```
   如果使用 swapRB=True，确保图像是 BGR 顺序（imread 默认）。如果图像已经是 RGB，设置 swapRB=False 以避免通道不匹配。
   ```

## 无效尝试

- **** — Changing the mean subtraction values arbitrarily without checking if the image was loaded correctly (35% 失败率)
- **** — Assuming the error is from the model architecture and re-downloading the model files (25% 失败率)
- **** — Increasing the blob size to a large value like (1, 3, 1000, 1000) hoping it will bypass the empty check (20% 失败率)
