[Python] Remove overlapped line over text with opencv [duplicate]

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm processing images that have a line across the 4 letters. After some processing, i have get this result:

    [​IMG]

    The only thing I can't get to do is remove that black line, so it can be more clear to be recognized with some OCR library. The final image should look like this (not losing quality of text):

    [​IMG]

    I have tried to dilate the image, to try to fill the gaps, but I lose quality:

    import cv2
    from google.colab.patches import cv2_imshow
    import numpy as np

    image = cv2.imread("image.png", 0)
    cv2_imshow(imagen2)

    kernel = np.ones((0,0),np.uint8)
    dilation2 = cv2.dilate(imagen2,kernel,iterations = 1) # to remove blackline noise
    cv2_imshow(dilation2)


    [​IMG]

    After that, I have tried to erode the image, but this doesn't work well, and I lose more quality:

    kernel2 = np.ones((2,2),np.uint8)
    closing = cv2.morphologyEx(dilation2, cv2.MORPH_CLOSE, kernel2)
    cv2_imshow(closing)


    [​IMG]

    Continue reading...

Compartilhe esta Página