# Save detected images error

**URL:** <https://forum.opencv.org/t/save-detected-images-error/2792>\
**Category:** Uncategorized\
**Created:** [April 16, 2021, 10:38am UTC](https://forum.opencv.org/t/save-detected-images-error/2792 "2021-04-16T10:38:11Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![khemakorn](https://avatars.discourse-cdn.com/v4/letter/k/73ab20/32.png) [@khemakorn](https://forum.opencv.org/u/khemakorn)\
**Post date:** [April 16, 2021, 11:35am UTC](https://forum.opencv.org/t/save-detected-images-error/2792/3 "2021-04-16T11:35:56Z")

</div>

```auto
if x < 0:
                    x = 1
                if y < 0:
                    y = 1
                if w < 0:
                    w = 1
                if h < 0:
                    h = 1
                print("x= "+str(x)+" y= "+str(y)+" w= "+str(w)+" h= "+str(h))

```

I just set things like this in each if condition ‘wearing’ and ‘notwearing’

even the value is no longer negative but it still shown error

```auto
x= 1 y= 193 w= 8 h= 12
Traceback (most recent call last):
  File "/Users/khemakorn/Desktop/model/test_yolo_object_detection.py", line 152, in <module>
    cv2.imwrite(os.path.join(output_crop_wearing,str(x)+'.jpg'),crop_img)
cv2.error: OpenCV(4.5.1) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-39p1qqfs/opencv/modules/imgcodecs/src/loadsave.cpp:753: error: (-215:Assertion failed) !_img.empty() in function 'imwrite'

```

---

_[View the full topic](https://forum.opencv.org/t/save-detected-images-error/2792)._
