def rotateImg(img, deg): h, w = img.shape[:2] M = cv2.getRotationMatrix2D((w / 2, h / 2), deg, 1.0) rotated_img = cv2.warpAffine(img, M, (w, h)) return rotated_img