Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: OpenCV(4.1.0) error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

This is the error I get:

error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:3718: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'

Already checked for corrupted files.

cat is an array of 1000 images (RGB).

I am trying to compress these images to (50,50) grayscale.

def greyscale_compress(img):
    new_img = cv2.resize(img, (50,50))
    img_gray = cv2.cvtColor(new_img, cv2.COLOR_BGR2GRAY)
    return img_gray

cat_bin = []
for i in range(0, 100):
    cat_bin.append(greyscale_compress(cat[i]))
like image 813
palash behra Avatar asked Jul 30 '19 06:07

palash behra


2 Answers

Generally this problem occurs due to resizing of the image, I just apply try and catch statement for resizing the image so that any error handling. It is working fine and not getting error related to shape.

 img=cv2.imread(filename)
    print(img)
        try:
           img = cv2.resize(img, (1400, 1000), interpolation=cv2.INTER_AREA)
            print(img.shape)
        except:
        break
    height, width , layers = img.shape
    size=(width,height)
    print(size)
like image 124
Viresh Saini Avatar answered Nov 14 '22 21:11

Viresh Saini


I had the same issue when I was importing images into a list through label containing the name and path of images.

My problem arose due to an empty space in the list of labels.

I fixed this problem by just removing the space from my label list:

enter image description here

like image 26
Muhammad Saad Najib Avatar answered Nov 14 '22 21:11

Muhammad Saad Najib