I am working on rotating the images by 5 degree using below OpenCV Python code:
def rotate_image(image, angle):
(h, w) = image.shape[:2]
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, -angle, 1.0)
rotated_image = cv2.warpAffine(image, M, (w, h), flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)
return rotated_image
It works fine for most of the images but for some of the images, it shows below error:
OpenCV(4.6.0) /io/opencv/modules/imgproc/src/imgwarp.cpp:2595: error: (-215:Assertion failed) src.cols > 0 && src.rows > 0 in function 'warpAffine'
I have checked the size of the image where this exception comes and it's all good. Why is this error happening?
Edit: Using OP's script.
Your code is working with no minor change. Using OpenCV 4.6.0.
Comment out
#return rotated_image
inrotate_image()
function.Snippet:
Screenshot: