Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

OCR for label inspection

Hi, I am working on a feasibility study for an automatic label inspection. I made a good expirience with vision, but less with OCR. I faced several problems and I cannot understand whether is a matter of settings or a matter of image quality.

The first problem is the splitting of the chars, the second is the stability and the repeatabilty of the reading.  

I fixed the splitting of the chars implementing a new algorithm. I was not able to find a configuration of settings  that was able to work properly. I think that the "Bounding Rect Width" does not work as it should.

The stability of the reading is still an open point. If I run continuously the test acquiring always the same images on the same pieces the results can be 80% pass and 20% fail. It happens that one char that for several previous run had a high score (about 910) suddenly fails (score 0)

Could you take a look to the images and tell me if they are good enough?

In Runtime I am using the same setting than I used for training: FixedThreshold, Read Strategy, Read Resolution, Acceptance Level.

Do you have any suggestion about the stability?

 

Thanks a lot.

 

Marry Christmas.

 

Download All
0 Kudos
Message 1 of 11
(5,290 Views)

Either the printing is blurry or the image is a little bit out of focus.  Better focus would probably help the separation algorithms and the recognition algorithms.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 2 of 11
(5,283 Views)

 I agree with Bruce. The insufficient sharpness of the pictures results in making the recognition performance strongly dependant on the threshold level and width settings. And although it is possible to reach a 100% score on the provided samples, I would not rely on the fine tuning of the OCR settings to handle the stability problem.

Some preprocessing should improve the situation at the price of a slower reading.

However, while playing with your samples, I ran into an unexpected problem : even with a perfect separation, some objects are not detected. In the image below, the third and fourth elements are not separated. Adjusting the char width settings is not a viable solution, since it creates later problems with the width of the H char.

Of course, it is possible to programmatically parse the image, and get a proper recognition for each separated char. However this would add another speed penalty to the overall process.

Can somebody explain why the 0 and 2 are not handled correctly in the image below ? 

 

undefined
Message Edité par chilly charly le 12-25-2008 06:25 AM
Chilly Charly    (aka CC)
Download All
0 Kudos
Message 3 of 11
(5,268 Views)

The problem with the 02 is called kerning.  The bottom of the 2 is just the next pixel over from the 0.  There is no empty column of pixels between the two characters, so the OCR algorithm combines them as a single character.

 

I vaguely remember there being an option for smart separation of characters.  That might help.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 4 of 11
(5,254 Views)

Well, then the image are not good enough. I am just preparing a demo and I do not have the best equipment. Then, do you know what are the minimum "image quality parameters/requirements"  for NI OCR? I mean, the minimum sharpness, the minimum contrast, the minimum size of each charracter (in terms of pixels) and so on?

 

Thanks a lot for your support.

 

 

0 Kudos
Message 5 of 11
(5,161 Views)

The spacing is really the issue here.  The slight focus problem is not really significant.  You have to have one or two pixels of vertical space between each character for OCR to work well.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 6 of 11
(5,158 Views)

Since the IMAQ OCR is not able to separate the characters when they are too close (the kerning problem discussed above - thanks to Bruce for making my education 😉 ), an alternative would be to develop your own piece of program to separate each character. This is not very complicated (get the rect around each char, add one pixel in each direction, extract the corresponding image chunk, remove border objects, then feed the isolated char to the OCR step), but will slow down considerably the whole process.

 

BTW, in the picture I posted above, there is one empty pixel column between the O and the 2 ! 😮 Means that the minimal distance should be two pixels ???

 

Message Edité par chilly charly le 01-07-2009 07:26 PM
Chilly Charly    (aka CC)
0 Kudos
Message 7 of 11
(5,150 Views)

I did to get the characters below to separate.  When training the font, I set the minimum element space to zero, then the minimum character space to zero.  It still requires a blank column between the characters, but it will work in the case below.  After changing the values in the training, you also have to change the values in the read routine.  I did all this in Vision Assistant.

 

FYI, the original OCR library that NI converted to LabVIEW had a subroutine that you could use to read a single character.  It was handy in a situation like this where you had to manually separate the characters.  I don't think that subroutine remains in their version, though.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 8 of 11
(5,144 Views)

Another option would be using classification instead of OCR.  You could define each character as a different class.  After it identifies all the characters, sort the results by their x position to get them in the right order, then combine all the characters to get your string.

 

Another possibility:  Upsample your image to increase the resolution by a factor of 2 to 4.  Then threshold, and if necessary erode the characters by one or two pixels.  This would increase the number of pixels separating the characters and improve the OCR results.

 

Bruce

Bruce Ammons
Ammons Engineering
0 Kudos
Message 9 of 11
(5,140 Views)

As I told in my first post, I developed on my own a new algorithm to separate the characters and it seems to work well. But, using this separation was not enough. For each chararacter of the string I had to use the text pattern (Set Valid Characters) and then the read function. Then, practically, I have a for loop with one iteration for each character. For sure it takes more time but the reading seems to be more stable.

Using only one text pattern and read function for all characters of the string gave worst results. I do not know whether it is possible or it was my fault.

 

Bruce, about your options:

  • I have never use the classification functions. It could be interesting; practically you can develope your own algorithm for OCR.
  • Is there an Upsample function into IMAQ?

 

 

Thanks guys. 

0 Kudos
Message 10 of 11
(5,121 Views)