Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Tesseract, OCR

views
     
Palindromes
post Apr 23 2020, 08:20 AM

Getting Started
**
Validating
157 posts

Joined: Jan 2020
I want to understand if it is possible to do OCR in C# without any third-party library.

I have limited success. For example, reading this image will resulting in: THRAANKKYGOCDUVEEEEEEEERRFYMUOCCHR222Z55509GEBBUOCCKK

user posted image

user posted image

Input: THANK YOU VERY MUCH 250 BUCK
Output: THRAANKKYGOCDUVEEEEEEEERRFYMUOCCHR222Z55509GEBBUOCCKK

Because I scan the image (pixel by pixel) too close to each other, there are duplicate characters.

Moreover, some characters are identical to each other, such as 2 and Z, O and C.

What I did is very primitive form:
1. Get the font bitmap (A..Z, a..z, 0..9)
2. Read the input image
3. Convert it to B/W bitmap
4. Scan B/W bitmap and compare with font bitmap

But it is difficult even to recognize the font bitmap generated by the C# program itself. So far only able to recognize 55 chars out of 62 in total.

Limitation:
Input: Must have spacing between characters, only 18-point Arial font type allowed (depends on the constant value in C#)
Output: No punctuation, no whitespace , etc.

So, I am having fun creating the basic form of OCR. What do you know about the logic behind OCR? I know OCR is far more complex than I thought or what I have achieved now.

Palindromes
post Apr 23 2020, 11:19 PM

Getting Started
**
Validating
157 posts

Joined: Jan 2020
QUOTE(basilpaschal @ Apr 23 2020, 08:22 AM)
optical character recogbition (ocr) - use google translate camera
*
That's instant OCR.... amazing. They have polished their product very well over the years.


QUOTE(jibpek @ Apr 23 2020, 08:27 AM)
It is possible, but don't waste your time.

You text is consider very nice, clean and perfectly aligned.

99% of the time your image will be dirty, not align or warp
*
Yes, you're definitely right. wink.gif


Palindromes
post Apr 23 2020, 11:28 PM

Getting Started
**
Validating
157 posts

Joined: Jan 2020
I think I will just throw this OCR project into the code museum... haha

If you find it interesting, here's the OCR.cs (rename OCR.txt to OCR.cs / Program.cs will do) C# source file that I did yesterday night until this early morning.

Except the getting font bitmap (g.DrawString(,myFont,,,)....) part was taken from StackOverflow, the rest of the code are my creative works.

Attached File  OCR.txt ( 12.11k ) Number of downloads: 19


This C# code will create 62 different font bitmap (A..Z, a..z, 0..9) in memory (with option to save each of them as image file on the user's desktop), then convert it to B/W bitmap, then match each of the font bitmap against 62 characters.

So far, you'll see the code managed to recognize 55 out of total 62 characters only. (It will loop by itself, until the end, where you'll be prompted to press Enter to exit)

It is not advisable to use this C# code to perform OCR on even the simplest image with characters....because (1) it is slow, (2) it is inaccurate.

But at least I have had fun creating this piece of basic form of OCR to recognize the 62 characters created by itself.



Palindromes
post Apr 23 2020, 11:33 PM

Getting Started
**
Validating
157 posts

Joined: Jan 2020
QUOTE(aBcD-| @ Apr 23 2020, 11:24 PM)
First, use Tesseract 4.0 supported both C++ mainly and python secondary. The output accuracy is quite decent and most of the time you have to deal with pre-processing image and provide a clean sample to tesseract engine.

Second, the methodology of image/text processing is not right, because the sample you provided is an ideal test case ^ see above comment. You can refer to opencv for that.

Third, when it comes to image processing task, consider C++ as primary choice, you need to deal with pipeline processing, instead of object oriented task, so yeah it pretty wasting a lot of time to implement something that is already exists in the first place.
*
Yes, I remember Tesseract engine. I think it is you the first person who inspired me to "create my own basic OCR", and alexa is the second person who finally inspired me to take swift coding action.

Python, along with Tesseract and OpenCV are very high-end development products.... As for C++, frankly I am not good in it after didn't use it since VC++ 6.0.

Thank you for your reasonable advice, I like your professionalism.

 

Change to:
| Lo-Fi Version
0.0159sec    0.42    7 queries    GZIP Disabled
Time is now: 14th December 2025 - 07:31 PM