Patagames Software Support Forum
»
Tesseract.Net SDK
»
F.A.Q.
»
How to invert an image for better recognition?
Rank: Member
Groups: Registered
Joined: 11/3/2017(UTC) Posts: 7
Was thanked: 1 time(s) in 1 post(s)
|
QuestionI 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).AnswerFor 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. Code:
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: Code:
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));
MessageBox.Show(str.ToUpper());
}
}
Edited by user Monday, November 6, 2017 4:28:52 AM(UTC)
| Reason: Not specified
|
|
|
|
Patagames Software Support Forum
»
Tesseract.Net SDK
»
F.A.Q.
»
How to invert an image for better recognition?
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.
Important Information:
The Patagames Software Support Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close