View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Optical Character Recognition (OCR)

4.1 | 69 ratings Rate this file 370 Downloads (last 30 days) File Size: 95.6 KB File ID: #18169 Version: 1.4
image thumbnail

Optical Character Recognition (OCR)


Diego Barragán (view profile)


31 Dec 2007 (Updated )

The aim of OCR is to classify optical patterns corresponding to alphanumeric or other characters.

Editor's Notes:

Popular File 2011 2012 2013

| Watch this File

File Information

The aim of Optical Character Recognition (OCR) is to classify optical patterns (often contained in a digital image) corresponding to alphanumeric or other characters. The process of OCR involves several steps including segmentation, feature extraction, and classification. This program use Image Processing Toolbox to get it.
For more information, visit: (spanish).


This file inspired Optical Character Recognition(Lower Case And Space Included), Asphere Parameters, and Music Note Recogination.

Required Products Image Processing Toolbox
MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (114)
29 Jan 2017 Asma@

Asma@ (view profile)

i am new to this....
can somebody please tell me how to download this file?

Comment only
26 Jan 2017 David J. Mack

16 Dec 2016 11

11 (view profile)


20 Nov 2016 SHAOYU LI

Firstly,I convey my gratitude to you!secondly,i want to say that the ocr can not accomplish the recognition of plate number.SO,can you help me?

Comment only
20 Oct 2016 Sumita Das

When i try to run this exact code, it shows error.

Error using fprintf
Invalid file identifier. Use fopen to generate a valid file identifier.

Error in OCR (line 58)
fprintf(fid,'%s\n',word);%Write 'word' in text file (upper)

What should I do?

Comment only
19 Oct 2016 hyun-woo

Thank you very much, and Can I find any documents or papers about this method.

18 Oct 2016 Pornsuda Jareansuk


Comment only
08 Sep 2016 Duc Hoang

23 Aug 2016 Olek San

When can i get or generate letters for Cyrillic?

11 Aug 2016 Javineto

Really useful, but I think that the function "ocr.m" in Matlab is much simple and powerful.

06 Jul 2016 Haijian Zhang

04 Jul 2016 Jacob Berube

Ok, so how do I run this. I need to copy and paste something, but It wont let me do it on a certain program I use, so I went looking for something and I found this. It would be decent if you could add a .exe file!

04 Jul 2016 Arya Arya

Good job. How can I modify the code for other languages?

29 Jun 2016 Pablo Alejandro Guerrero

23 Jun 2016 Nivetha m

??? Undefined function or method
'detectMSERFeatures' for input arguments of type

Error in ==> OCRMETHOD at 8
[mserRegions, mserConnComp] = detectMSERFeatures(I,

Comment only
01 Jun 2016 sung youl kim

01 Apr 2016 Vishal Gupta

07 Mar 2016 Nandhini R

i am doing a project on extracting OCR from video,please guide me..

19 Sep 2015 Jan Simon

Jan Simon (view profile)

I miss a documentation.
Using a function would be more useful than a script, which disables all warnings (warnings are important to be considered!) and which kills all of my results in the Matlab workspace by a "clc, clear all, close all".

Comment only
29 Mar 2015 Venkata Apurupa Nagasuri

29 Mar 2015 Venkata Apurupa Nagasuri

please tell me how to create other fonts for templates.when I have changed my templates to my own it is not working properly
please guide me.
Also what is the font and process used to create template in the code.
Pls answer my question

Comment only
20 Mar 2015 Mohamed Meska

15 Mar 2015 Fmvelandia

Excellent contribution , thank you very much . Now how I can create other templates for use with sensitive or other text font.

07 Feb 2015 JIBU mathew

i am doing project on english handwritten recognition .please guide me ti this
thanks a lot

Comment only
03 Feb 2015 anh hoang

how to download this file

23 Dec 2014 amir abdi

very god link

Comment only
23 Dec 2014 amir abdi

22 Dec 2014 amir abdi


Comment only
21 Dec 2014 Ghaffar gh

21 Dec 2014 Ghaffar gh

08 Dec 2014 ekrem

ekrem (view profile)

Very simply perfect

18 Oct 2014 amandeep

26 Aug 2014 alex yang

Very simple but powerful idea.

08 Aug 2014 student s

from where can i download this code. I am under character recognition. Please help me for getting the code

27 May 2014 Lutful Kabir

12 May 2014 omveer

omveer (view profile)

please from where i get source cod?

21 Apr 2014 QUANG HUY

Please let me know, how can use this OCR with SVM. Thank a lot!

24 Feb 2014 hussein Ali

Good working

Comment only
24 Jan 2014 sad

sad (view profile)


25 Jul 2013 Angie

Angie (view profile)

07 Apr 2013 Wej

Wej (view profile)

Anyone can help, How to run this code ?

Comment only
27 Mar 2013 Chandra Shekhar

Nice work.

21 Jan 2013 msp

msp (view profile)

sir it is not able to detect the text from video frame. please help

Comment only
30 Dec 2012 thebohr

excuse me for all people,i'm newbie about this..i am a student of computer science departmen and i have an interest of making OCR buat read the character or text from hand writing. for example, i write something on the paper and convert it to it possible ?
thanks before

Comment only
04 Dec 2012 Latte

Latte (view profile)

29 Oct 2012 samira

samira (view profile)

Hola diego, tengo una pregunta estoy tratando de hacer un algoritmo que me reconozca las letras usando redes neuronales con una interfaz grafica, pero el manuscrito de prueba lo tengo que cargar, queria saber si habia alguna manera de crear un recuadro sobre el GUI que sea como "paint" y se pueda dibujar la letra directamente ahi con el mouse

Comment only
20 Oct 2012 shweta

shweta (view profile)

hav used this image and getting errors

Comment only
17 Oct 2012 tiago

tiago (view profile)

11 Sep 2012 sriharsha ponnathapura

Nice code. I used it to generate the templates for 187 fonts in english. I dont know where to upload it for everyone to use..

12 Jul 2012 OCR_try

nice code...

12 Jun 2012 imran

imran (view profile)

12 Jun 2012 imran

imran (view profile)

Sir its a nice code. i am getting little problem with understanding of this code. can you let me know how did you create the template.mat file from the letters. my is the same i also want to extend this code for lower case letters and local languages. one other thing is that when i replace
sem=corr2(templates{1,n},imagn); in read_letter.m to directly read the letters images and compare or find the correlation. but it does not gives the accurate results. if you read please must reply me.

31 May 2012 Shavi

Shavi (view profile)

Can anybody tell me that how to understand this code for character recognition?
or what is the way
please help.
Its Urgent!!

Comment only
09 May 2012 Wyfi Mcfly

maximum rather

Comment only
09 May 2012 Wyfi Mcfly

nicely done. for more robust results i found preforming a skeletal reduction of the input image text (when properly prepared), and making a template of skeletal comparisons for the correlation coefficient calculation can get around most font issues.
The next thing is properly aligning the input letter to that of the template. This can be accomplished in many ways, or you can simply preform an image rotation of all 360 degrees at take the minimum confidence coefficient of that process.

Comment only
03 May 2012 Shavi

Shavi (view profile)

Hello Diego...
Cheers for ur code..
I want to know that how to recognize special characters like +,/,| etc..??
Also your code is not applicable for lowercase letters so please give me some information that how to tackle this.


Comment only
14 Feb 2012 Pon Selvalingam

Hello sir
It is perfect code, really thanks
Please send this project pdf

01 Feb 2012 sidharth jhawar

hello sir,the code works well for majority of the images..perhaps doesnt work for joined text.sir,if u cud plz send a text file describing the objective if all the four .m files??

Comment only
23 Dec 2011 pankaj Durve

i use matlab 6.5,wheh i run oCR project,then templates loading error is come.why error is come?how to error is removed?

21 Dec 2011 kolayuyelik kolay

Quite good!

Comment only
03 Dec 2011 sanjana

plz anyone can give me the logic behind this program....on wht basis feature extraction has been done...nd hw Image proceesing tool box is used for simulatin...plz help me out asap....

08 Oct 2011 Mr Smart

04 Jul 2011 Fabio Bento

Quite good!

29 Jun 2011 Popescu

Hello! Did any one succeeded to add some new character templates? I am trying to add the OCR-B font templates but I don't know how to do it. I tried in photoshop but it didn't work. Does anyone know if is there a special program to do it?

Comment only
08 Jun 2011 Fukuo

Fukuo (view profile)

It helps me so much!

22 Apr 2011 Lamis zaki

Really good job , you helped me out :) thnx

Comment only
21 Apr 2011 Sadegh

Sadegh (view profile)

It is perfect code, really thanks

18 Apr 2011 King Lee

Hi, im planning to improve your code to be able to recognize about the small cases alphabet also,but i cannot access the thumb.db files in the letter number's folder...
Can you tell me it need what to open?

19 Feb 2011 SURYA

SURYA (view profile)

sir, nice your OCR project...i also using your code for my character recognition for my project...but i code some error because of edge of image...can sir look my project and suggest a solution...i need ur help sir..tq

here is my project

Comment only
05 Jan 2011 vipin vc

good program
Dear Bogdan

Suppose that we have an image with two lines of text. With "clip", only obtain one line and leave the rest.

Comment only
19 Dec 2010 Khaing Thaw

Hi Hannah,
these images of letters are in the letters_numbers folder. there are 36 image file, if u also want to recognize lower case letters u can add lower letter image files into that folder. and need to edit and add some coding in .m file in OCR folder.
clip is not built-in function, it is a sub function use in line.m function to crop the lines, u can see it lower part of line.m function.
good luck,

Comment only
19 Dec 2010 Claus Becker

08 Dec 2010 Hannah Whitby

Hi Diego and everyone,
Good program, but I have a few questions:
Where/how did you make these images of the letters that are in the template? I need to be able to identify lower case letters as well as upper case and have tried just using microsoft paint but although they are .bmp the appear the wrong format. Any ideas anyone?
Also - what is 'clip'? my matlab doesn't seem to support it but when i changed it to imcrop it stalls.

05 Dec 2010 Khaing Thaw

Hi Diego, Nice ur coding, complete in a few lines, functions, templates ,... except clip function :P

Hi Ashley, to find the spaces calculate the spacing of components in image Labeled,. it is my suggestion, how Diego?

Hi Priyanka, add some coding in create_templates.m and image files (BMP, 42x24) for lower characters,.

Thanks Diego,.

Comment only
12 Oct 2010 Ashley Figer

Dear sir,
how do we detect blank spaces between the characters?
and print them in the output

Comment only
04 Oct 2010 Theodoros Giannakopoulos

29 Aug 2010 pupu QQ

not very good for car plate in China.

Comment only
31 Jul 2010 mrudula sekhar

hi sir, ur work is really good.
i am too trying to implement the same as a part of my academics, so like to know more about the subject. can u please help me ?
i did like to know about the different steps involved in character recognition. can u provide me with some pdf documents which i can depend to complete my project.

Comment only
12 Jul 2010 Alexandru

Problem solved. The problem was the performance of my PC.

Thanks again for the program

Comment only
12 Jul 2010 Alexandru


i use Matlab 7.9.0 (R2009b) and i received an error "Segmentation violation detected" while i tried to run the OCR program. i'm beginner in matlab so can anyone help me please?

PS: thank you Diego for the OCR program

Comment only
11 Jul 2010 uet taxila

08 Jul 2010 Eurico

Eurico (view profile)

Hi Mr. Diego,
at the moment i'm developing a computer vision system to detect and recognize license plates.I experienced your project and works very well but i have a question. What method are you using to do the recognition? SVM's? Neural Networks?

kind regards

16 Jun 2010 Priyanka M

Hi Diego..
dis is priyanka,from India
It was a very nice job.Can u plz help me with dis project..???
Plz tell me how to recognize lower case letters..?? and also plz help me with how to obtain the bitmap images of the letters u place in letters_numbers folder so dat I can try for the regional languages...
Plz plz plz do reply me....

11 Jun 2010 Diego Barragán

Diego Barragán (view profile)

Dear Bogdan

Suppose that we have an image with two lines of text. With "clip", only obtain one line and leave the rest.

Kind regards.

Comment only
10 Jun 2010 blue

blue (view profile)

Thank you for answare, but I have a nother question : in lines.m file exist next line:
What exactly make cilp in this expresion?

10 Jun 2010 Diego Barragán

Diego Barragán (view profile)

Hello Bogdan

I use IMCROP instead CLIP.

Kind regards.

Comment only
10 Jun 2010 blue

blue (view profile)

I hava a question for Mr Diego Barragán.
In the Zip file I cannt find the function clip, but On this page link, exist!!!! Where is integrate this function?

Comment only
25 Apr 2010 vaibhav sharma

Please can anyone tell me how to implement this code on fpga??
Its urgent....mail me at

thank you very much

23 Mar 2010 nurul

nurul (view profile)

dear sir,
it was a very nice job. however for certain pics it cant read the image correctly. do u have any idea on how to add the image filtering codes to make this program read the image more accurate?
i really need ur help on this matter.

Comment only
23 Mar 2010 nurul

nurul (view profile)

17 Mar 2010 Thabit

Thabit (view profile)

Sid H, come on!

If you can do better, we are waiting!

Comment only
31 Jan 2010 Sid H

Sid H (view profile)

Amateur work, both code and concepts. Not robust. Cant support fonts, noise or files different from what the up-loader provides. But great as a concepts demo for undergrad-and-below classes.

19 Dec 2009 chaogui xia

thank you

11 Dec 2009 Hooman

Hooman (view profile)

Very nice job, I have 2 questions the code ignores white space which should not and also it does not detect lowercase letters.
how should we detect white spaces between words?

03 Nov 2009 Cong Zhou

good job!

Comment only
03 Nov 2009 Cong Zhou

10 Sep 2009 karthik sarma

this program is not working for other image files. i created some image files using paint in ariel and times new roman font. the program failed to give correct result

Comment only
07 Aug 2009 yusor

yusor (view profile)

Anybody can help me? My FYP is about converting an image to text. Image may be frim newpaper (anywhere) and should be converted into text and saved into Doc. or pdf but it must retain the oiginal format.

Thank u,

Comment only
25 Mar 2009 Rushmi

Rushmi (view profile)

It works great.But for images with dots or small patches the result is ambiguous.If the code can eliminate this problem,(not recognizing non characters) it will be a good algorithm for character recognition.

05 Dec 2008 athi rayan

hello sir please give me as a compltet report in ocr

Comment only
09 Sep 2008 ved vrath


Comment only
20 May 2008 firas aakroum


14 Apr 2008 manish arora

these files really works..
result not being 100%..

08 Apr 2008 minnal sagi


04 Apr 2008 Bilal KONUK

hi author
i am using matlab 6.5 version. Can i work your project my matlab?

20 Mar 2008 eklil alwrd

19 Mar 2008 Paul Paul

05 Mar 2008 raghav khanna

can u tell me wat feature algorithm r u using??

01 Mar 2008 Tran Dinh Vuong

Dear Sir, I'm doing handwritten english character recognition.Please guide me to progress this project. thanks lot.

26 Feb 2008 Pradeep Mapitigama

Dear Sir,
I'm doing handwritten english character recognition.Please guide me to progress this project.I'm doing this for fullfill the computer science.
thanks lot.

Comment only
16 Jan 2008 Vihang Patil

Nice work. Tried creating my own images of numbers and names alike and found sometimes some letters being wrongly identified, especially I, 1, O,0,Q
Other than that nice work!

08 Jan 2008 John Smith

Good application

07 Jan 2008 Diego Barragán

Hi, this is Diego Barragán, from Ecuador.

I appreciate your comments about OCR.

The error perhaps is due the version of MATLAB. I use version (R14) Service Pack 3.

And other restriction of OCR is the size of letter. The size must be bigger or equal to 42 x 24 pixels.


Comment only
07 Jan 2008 Austin K

this is a very good work.
a very good logic and simple to understand .
yet there are lot of sectors which can improve.
and i dont know why it happens is that there is a error while loading the templates.
always shows that the file was corrupted.
any way best wishes and once again good work.

02 Jan 2008


03 Jan 2008


23 Jun 2008


09 Feb 2009 1.1


07 Aug 2014 1.2


08 Aug 2014 1.3


08 Aug 2014 1.4


Contact us