I am trying the following code for deskewing an image but I am recieving error :
TypeError: unorderable types: tuple() > int()
The bug is in the following line :
coords = np.column_stack(np.where(thresh > 0))
The full code is :
import numpy as np
import argparse
import cv2
image= cv2.imread('das.jpg',0)
gray = cv2.bitwise_not(image)
thresh = cv2.threshold(gray, 0, 255,cv2.THRESH_BINARY | cv2.THRESH_OTSU)
coords = np.column_stack(np.where(thresh > 0))
angle = cv2.minAreaRect(coords)
if angle < -45:
angle = -(90 + angle)
else:
angle=-angle
(h, w) = image.shape[:2]
center = (w // 2, h // 2)
M = cv2.getRotationMatrix2D(center, angle, 1.0)
rotated = cv2.warpAffine(image, M, (w, h),flags=cv2.INTER_CUBIC, borderMode=cv2.BORDER_REPLICATE)
cv2.imwrite('a.jpg',rotated)