Welcome Guest! To enable all features please Login or Register.



Go to last post Go to first unread
#1 Posted : Sunday, November 5, 2017 1:34:08 AM(UTC)

Rank: Member

Groups: Registered
Joined: 11/3/2017(UTC)
Posts: 7

Was thanked: 1 time(s) in 1 post(s)
I have an image with quite clear text on it, but OCR have a lot of false positives. For example:

It read 6 as 5
D as 0
E as £
B as 3
8 as S

I need to have recognised the second line (1 A0 D5 …)

image001.png (3kb) downloaded 30 time(s).

For best recognition, it is best to use pictures with black text on a white background. Therefore, you need to invert the image as follows:

image002.png (4kb) downloaded 30 time(s).

Using the following code, you can invert the image.

Image pix = Image.FromFile(@"C:\image001.png");
Bitmap mybitmap = new Bitmap(pix);
for (int x = 0; x < pix.Width; x++)
    for (int y = 0; y < pix.Height; y++)
        Color mypixel = mybitmap.GetPixel(x, y);
        mybitmap.SetPixel(x, y, Color.FromArgb(mypixel.A, 0xFF - mypixel.R, 0xFF - mypixel.G, 0xFF - mypixel.B));

After all you can use the GetTextFromImage method to find the text you need. In this case, we read a second line:


using (var api = OcrApi.Create())
    api.Init(Patagames.Ocr.Enums.Languages.English, null, Patagames.Ocr.Enums.OcrEngineMode.OEM_CUBE_ONLY);
    using (var img = OcrPix.FromBitmap(mybitmap))
        string str = api.GetTextFromImage(img, new Point(20,30), new Size(350, 30));

Edited by user Monday, November 6, 2017 4:28:52 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.