[Python] Image loses quality with cv2.warpPerspective

Discussão em 'Python' iniciado por Stack, Agosto 15, 2025.

  1. Stack

    Stack Membro Participativo

    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:

    [​IMG]

    and then, here, the "rotated" image:

    [​IMG]

    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: [​IMG] and [​IMG]

    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:

    [​IMG]

    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.

    Continue reading...

Compartilhe esta Página