#### Howdy, Stranger!

We are about to switch to a new forum software. Until then we have removed the registration on this forum.

# how can I do optical character recognition using processing?

edited October 2017

plz guide me on this.

Tagged:

• edited October 2017

https://en.wikipedia.org/wiki/Optical_character_recognition

"[OCR is the] conversion of images of [...] text into machine-encoded text."

Essentially, you want to start with an image that has some text in it, and work out what that text is. So the first thing you need is an image with some text in it.

Processing can be used to generate such an image. So let's start with a sketch that does that:

``````void setup(){
size(200,200);
}

void draw(){
background( random(255), random(255), random(255) );
fill( random(255), random(255), random(255) );
int ts = int(random(10,64));
textSize(ts);
String t = "" + char(int(random('A','Z'+1)));
text( t, random(20,width-20-textWidth(t)),random(20+ts/2,height-20-ts/2) );
noLoop();
}

void mousePressed(){
redraw();
}
``````

If you run this, you will see that it generates a 200x200 pixel image that has a solid random background color and a single random capital letter of a random color somewhere in the frame. Since you are a person, you can look at the image and determine what the letter is easily (assuming the letter's color is different enough from the background). Chances are good that you have a lot of practice determining what letters are. Heck, you're doing it right now because you are reading this!

There are many different approaches you can take to go about this (see the wiki page!). And, quite frankly, your question is so broad that you haven't even mentioned what methods you want to try to use. So tell us more. What is your approach going to be? Are you going to just implement a classical method, or do you have a crazy new tactic in mind?

• edited October 2017

There is not a standard OCR library for Processing. You would need to find a Java OCR library and import it. For example, tesseract may have Java bindings.

• See, look, your question is so vague that I took it to mean you want to write the code to do it, and jeremydouglass took it to mean that you just want to be able to do it. So you need to give us some DETAILS.

• I want to implement it using KNN algorithm....

• @priyabratabasu -- re: "I want to implement it"

it = what?

not enough information....

• @Chrisir --

Yes, I know what KNN is, but to do what? Analyze handwriting samples through a laptop webcam? Process a directory of jpegs of textbook pages? Should the output be a stream of recognized letters, recognized words, or an identifier like "this font is Baskerville" or "this was probably written by Sally"...? If it is a character stream, do you want spatial maps of the locations / orientations of the letters?

If you want to "do OCR," then I would expect that you are processing either a webcam or an image stack, and want to produce a character stream from standard text documents in which text in a single font size is all oriented one way. Of course, you could be trying to do car license plate detection. There is Not. Enough. Information.