2

I have an object, there are 2 code on it. text printed on it. The text is curve. half of text is in the top side, and another half is in bottom side of object. Here is my sample image

image

I am using OPENCV, and Deep learning approaches and tessract to OCR it's code. I logical approach(not Deep approach) I first used HoughCircles() andlogPloar() to align text in line then used tessract such this example sample code. But because of distortion in aligned text, tesseract fail to OCR it's text.

In Deep approach I cant find fine a optimum solution for curve text OCR in tensorflow or torch. There are many sources for text detection not recognition.

Regards,John

nathancy
  • 42,661
  • 14
  • 115
  • 137
s.john
  • 21
  • 4

2 Answers2

0

why not transform the circular text to linear? Similar to this De-skew characters in binary image just a bit more complicated. So detect (or manually select) the center of circle and convert the image to unrotated one ...

So create new image that has dimensions 6.28*max_radius , 2*max_radius and copy pixels using polar unwraping ... simply convert target pixel position into polar coordinates and convert that to Cartesian source pixel position.

I do not code in Python nor OpenCV but here is a simple C++ example of this:

//---------------------------------------------------------------------------
picture pic0,pic1;                          // pic0 - original input image,pic1 output
//---------------------------------------------------------------------------
void ExtractCircularText(int x0,int y0)     // pic0 -> pic1 center = (x0,y0)
    {
    int x,y,xx,yy,RR;
    float fx,fy,r,a,R;
    // resize target image
    x=       -x0; y=       -y0; a=sqrt((x*x)+(y*y));          R=a;
    x=pic0.xs-x0; y=       -y0; a=sqrt((x*x)+(y*y)); if (R<a) R=a;
    x=       -x0; y=pic0.ys-y0; a=sqrt((x*x)+(y*y)); if (R<a) R=a;
    x=pic0.xs-x0; y=pic0.ys-y0; a=sqrt((x*x)+(y*y)); if (R<a) R=a;
    R=ceil(R); RR=R;
    pic1.resize((628*RR)/100,RR<<1);

    for (yy=0;yy<pic1.ys;yy++)
     for (xx=0;xx<pic1.xs;xx++)
        {
        // pic1 position xx,yy -> polar coordinates a,r
        a=xx; a/=R; r=yy;
        // a,r -> pic0 position
        fx=r*cos(a); x=x0+fx;
        fy=r*sin(a); y=y0+fy;
        // copy pixel
        if ((x>=0)&&(x<pic0.xs))
         if ((y>=0)&&(y<pic0.ys))
            {
            pic1.p[          yy][pic1.xs-1-xx]=pic0.p[y][x];    // 2 mirrors as the text is not uniformly oriented
            pic1.p[pic1.ys-1-yy][          xx]=pic0.p[y][x];
            }
        }
    pic1.save("out.png");
    }
//---------------------------------------------------------------------------

I use my own picture class for images so some members are:


xs,ys is size of image in pixels
p[y][x].dd is pixel at (x,y) position as 32 bit integer type
clear(color) clears entire image with color
resize(xs,ys) resizes image to new resolution

And finally the resulting image:

result

I made a 2 copies of the un rotated image (hence 2*max_radius height) so I can copy image in 2 modes to made both orientations of the text readable (as they are mirrored to each other)

Text will be more straight if you chose the center (x0,y0)more precisely I did just click it by mouse on the center of the circle but I doubt the center of text has the same center as that circle/disc. After some clicking this is the best center I could found:

better center result

The result suggest that none of the two texts nor disc has the same center ...

The quality of input image is not good you should improve it before doing this (maybe even binarization is a good idea) also storing it as JPG is not a good idea as its lossy compression adding more noise to it. Take a look at these:

PS. The center could be computed geometrically from selected text (arc) simply find most distant points on it (edges) and point on the middle between them on the arc. From that you can compute arc center and radius... or even fit it ...

Spektre
  • 49,595
  • 11
  • 110
  • 380
0

The black dot is a perfect feature for centering, and the polar unwarping seems to work fine, the deformation of the characters is negligible.

enter image description here

The failure of Tesserac might be explained by the low image quality (blur).

  • thanks, but black dot is not in center always. I used bounding box and minarearect but they fail to bound thresholded image. – s.john May 21 '19 at 11:18