OpenCV resize fails on large image with "error: (-215) ssize.area() > 0 in function cv::resize" OpenCV resize fails on large image with "error: (-215) ssize.area() > 0 in function cv::resize" python python

OpenCV resize fails on large image with "error: (-215) ssize.area() > 0 in function cv::resize"


So it turns out that the problem comes from one line in modules\imgproc\src\imgwarp.cpp:

CV_Assert( ssize.area() > 0 );

When the product of rows and columns of the image to be resized is larger than 2^31, ssize.area() results in a negative number. This appears to be a bug in OpenCV and hopefully will be fixed in the future release. A temporary fix is to build OpenCV with this line commented out. While not ideal, it works for me.

And I just recently found out that the above applies only to image whose width is larger than height. For images with height larger than width, it's the following line that causes error:

CV_Assert( dsize.area() > 0 );

So this has to be commented out as well.


Turns out for me this error was actually telling the truth - I was trying to resize a Null image, which was usually the 'last' frame of a video file, so the assertion was valid.

Now I have an extra step before attempting the resize operation, which is to do the assertion myself:

def getSizedFrame(width, height):"""Function to return an image with the size I want"""        s, img = self.cam.read()    # Only process valid image frames    if s:            img = cv2.resize(img, (width, height), interpolation = cv2.INTER_AREA)    return s, img

Now I don't see the error.


Also pay attention to the object type of your numpy array, converting it using .astype('uint8') resolved the issue for me.