I am working with OpenCV 3.1 and with Python.
My problem comes when I try to deskew (fix the tilt of) an image with text. I am using cv2.warpPerspective
to make it possible, but the image loses a lot of quality. You can see here the original part of the image:
and then, here, the "rotated" image:
it is like smoothed.
I was using morphological transformation like:
kernel = np.ones((2, 2), np.uint8)
blur_image = cv2.erode(tresh, kernel, iterations=1)
and
white_mask2 = cv2.morphologyEx(white_mask2, cv2.MORPH_OPEN, kernel)
to see if it improves something, but nothing.
I saw this example here in SO, but those guys had the same problem: and
So, I don't have idea what can I do. Maybe there is a way to not losing the quality of the image, or, there's another method to rotate the image without quality lost. I know this method:
root_mat = cv2.getRotationMatrix2D(to_rotate_center, angle, 1.0)
result = cv2.warpAffine(to_rotate, root_mat, to_rotate.shape, flags=cv2.INTER_LINEAR)
But it doesn't work for me, as I have to rotate every rectangle here:
and not the whole image. It means, the best way I found to do it, was warpPerspective
, and it works fine, but with quality loss. I would appreciate an advice to avoid the quality lost.