error: (-215:Assertion failed) !ssize.empty() in function 'resize' shows up when setting a cv2.resize for frame. What should be done?
Question:
I was following a tutorial to build facial recognition software:
small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25),
rgb_small_frame = small_frame[:,:,::-1]
when this error showed up:
cv2.error: OpenCV(4.6.0)
/Users/xperience/actions-runner/_work/opencv-python/opencv-python/opencv/modules/imgproc/src/resize.cpp:4052:
error: (-215:Assertion failed) !ssize.empty() in function ‘resize’
Answers:
This problem was few times on Stackoverflow.
When cv2
can’t get frame
from file or webcam then it doesn’t raise error but it returns status False
, and frame None
and you should check one of these values before you run rest of code
ret, frame = cap.read()
if ret: # if ret is True:
small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25)
# ... rest of code ...
or
ret, frame = cap.read()
if frame is not None: # it can't be `if frame:`
small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25)
# ... rest of code ...
I was following a tutorial to build facial recognition software:
small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25),
rgb_small_frame = small_frame[:,:,::-1]
when this error showed up:
cv2.error: OpenCV(4.6.0)
/Users/xperience/actions-runner/_work/opencv-python/opencv-python/opencv/modules/imgproc/src/resize.cpp:4052:
error: (-215:Assertion failed) !ssize.empty() in function ‘resize’
This problem was few times on Stackoverflow.
When cv2
can’t get frame
from file or webcam then it doesn’t raise error but it returns status False
, and frame None
and you should check one of these values before you run rest of code
ret, frame = cap.read()
if ret: # if ret is True:
small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25)
# ... rest of code ...
or
ret, frame = cap.read()
if frame is not None: # it can't be `if frame:`
small_frame = cv2.resize(frame, (0,0), fx=0.25,fy=0.25)
# ... rest of code ...