Save detected images error

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

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'