Reputation: 49
I am receiving this error when running this line of code :
pixels.append( cv2.resize(cv2.imread(raw_folder + folder +"/" + file),dsize=(128,128)))**
Error:
cv2.error: OpenCV(4.5.2) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-vi271kac\opencv\modules\imgproc\src\resize.cpp:4051:
error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
Upvotes: 1
Views: 90239
Reputation: 273
Another situation that lead to this error was to input an image of the wrong shape. I had an RGB image of shape (3, 540, 960) and got the misleading 'ssize is not empty'. Changing the shape to (540, 960, 3) fixed my problem.
Upvotes: 0
Reputation: 143197
You may have common problem: when CV2 can't read file then it doesn't raise error but it returns None
and now you try to resize None
- empty image - and this shows !ssize.empty()
.
You should first read image, next check if you get None
and next try to resize it.
You should check if raw_folder + folder +"/" + file
creates correct path and if you can open it in any other program. Maybe you forgot some /
in path (ie. between raw_folder
and folder
) or forgot file extension or you create path to not existing file.
path = os.path.join(raw_folder, folder, file)
print('[DEBUG] path:', path)
img = cv2.imread(path)
if img is None:
print('Wrong path:', path)
else:
img = cv2.resize(img, dsize=(128,128))
pixels.append(img)
Upvotes: 11