Home > other >  Inpaint Skewed/Tilted Text Opencv
Inpaint Skewed/Tilted Text Opencv

Time:09-28

I'm running OCR on a image with python and then getting the coordinates of each word and performing masking and inpainting on it. Here is my current result Result

TOP

As you can see, on the top of image, the text is not inpainted correctly. I figured it out by plotting the coordinates of the text with OPENCV as well as manually. I noticed that Opencv only performs cropping in a horizontal or vertical rectangle manner or vertical rectangle like here :

TEXT CROPPED INCORRECTLY

If I plot the same image using same coordinates on a image-editing tool like paint, I'm getting the correct bounding box i.e., THIS

I don't want this to happen as it is affecting my results. How do I improve this?

CODE:


    textCoordinates = runOcr(img)
    for i in textCoordinates:
        tl[1],br[1],tl[0],br[0]]  = i.coordinates
        smImg = img[tl[1]:br[1],tl[0]:br[0]]
        inpaintedImg = inpaintAlgo(smImg) ## this function detects and creates a mask and inpaints by it.


CodePudding user response:

Supposing you have 4 points

[[x1,y1],[x2,y2],[x3,y3],[x4,y4]]

you need to calculate ymin, ymax, xmin, xmax as

ymin = min(y1,y2,y3,y4)
ymax = max(y1,y2,y3,y4)
xmin = min(x1,x2,x3,x4)
xmax = max(x1,x2,x3,x4)

ans then your crop will be

img[ymin:ymax,xmin:xmax]
  • Related