# cv::error: (-215:Assertion failed) !blob.empty() in function 'cv::dnn::blobFromImage'

- **ID:** `opencv/dnn-blob-from-image-empty`
- **Domain:** opencv
- **Category:** assertion_error
- **Error Code:** `-215`
- **Verification:** ai_generated
- **Fix Rate:** 90%

## Root Cause

blobFromImage failed because the input image is empty (not loaded or corrupted), or the preprocessing parameters (e.g., size or mean subtraction) caused an empty blob.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 4.5.5 | active | — | — |
| 4.6.0 | active | — | — |
| 4.7.0 | active | — | — |
| 4.8.0 | active | — | — |
| 4.9.0 | active | — | — |

## Workarounds

1. **Verify image loading: img = cv2.imread('path'); if img is None: raise ValueError('Image not loaded'). Then check img.shape before calling blobFromImage.** (95% success)
   ```
   Verify image loading: img = cv2.imread('path'); if img is None: raise ValueError('Image not loaded'). Then check img.shape before calling blobFromImage.
   ```
2. **Ensure the blob size matches the model input. Example: blob = cv2.dnn.blobFromImage(img, 1.0, (224, 224), (104, 117, 123), swapRB=True, crop=False). Print blob.shape to confirm non-empty.** (90% success)
   ```
   Ensure the blob size matches the model input. Example: blob = cv2.dnn.blobFromImage(img, 1.0, (224, 224), (104, 117, 123), swapRB=True, crop=False). Print blob.shape to confirm non-empty.
   ```
3. **If using swapRB=True, ensure the image is in BGR order (default for imread). If the image is already RGB, set swapRB=False to avoid channel mismatch.** (85% success)
   ```
   If using swapRB=True, ensure the image is in BGR order (default for imread). If the image is already RGB, set swapRB=False to avoid channel mismatch.
   ```

## Dead Ends

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