Ask Your Question
0

Detect numbers and calculate it in box

asked 2016-03-23 21:41:03 -0600

benz gravatar image

I'm a beginer for OpenCV, currently I'm working on a project to detect the numbers in a box on the banknote bundle. The objective for machine vision is to count the amount of numbers printed in the bundle.

A bundle has ten packages, which as 100 banknotes. Each package has an encapsulated with the printed number(1,2,...9), and the numbers are the same in one bundle. plus, there is a plastic film cover on the bundle.

Sample as follow

image description

There may be some reflected light on it under illumination condition.

A friend told me a method how to do it. The approach so far is the following:

  1. grayscale
  2. mean filter (boxFilter)
  3. binarization (adaptive threshold)
  4. remove noise in connected components, kernel less then 10 (I don't know how to do it)
  5. dilate (with structure Mat (-4, 4, -12, 12) )
  6. remove noise in connected components, (remove the little things)
  7. count connected components.

The followings are the steps. 1. gray 2. boxFilter(src, outMat, -1, Size(1, 1)); the channel is 1. 3. adaptiveThreshold(src, outMat, 255, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV, 35, 13); image description this result seems very good, if I dilate it right here, it seems I can easily get the connected components, then I can use findContours to calculate the amount of number "2".

However my friend prefers to follow his steps, and get a result like

image description

My questions list as follows,

  1. what is the good approach ? I'm care about the performance, the total calculate time should less then 300ms
  2. should I use connected components to do it, or use findCoutours ? Actually, I don't know how to calculate connected components, I think it use findContours also.
  3. how to remove noises ?
  4. should I use equalizeHist to equalize the source because different illumination condition ?

Thank you in advance, I'm very appreciated for your advices.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-03-23 23:34:27 -0600

Tetragramm gravatar image

I think in this case connected components is better for filtering. It's quite fast, so that's not a problem. The reason it's better is because you can more easily filter for properly sized objects. You simply remove any components with a height or width greater or less than a reasonable threshold. So you can remove long vertical lines, horizontal lines, or small specks but keep the numbers.

Then you can filter some more by the region of interest. Use find contours to find the boxes that are the paper with the numbers on them. There's a square detection tutorial somewhere around here. Only keep any of the connected components that are within the boxes.

Between these two, you shouldn't have much noise left. I would simply compare whatever is left to your numbers and just ignore anything that isn't a close match.

Equalize Hist may be useful, but you should be okay without it, if that's a normal image. Can't hurt to give it a try and see if it helps though.

edit flag offensive delete link more

Comments

the pic is taken by AVT Manta Camera, and the direction of bundle will change a little bit, so the vertical or horizontal lines are not that straight forward, sometimes inclined, I tried to remove lines, but morphologyEx give me too much of specks and some inclined line, seems hard to remove.

benz gravatar imagebenz ( 2016-03-29 01:34:23 -0600 )edit

There are several ways of detecting lines. Use them to find the orientation, then rotate the image. Now the lines are vertical.

Tetragramm gravatar imageTetragramm ( 2016-03-29 06:52:23 -0600 )edit

Thank you very much

benz gravatar imagebenz ( 2016-03-31 20:56:03 -0600 )edit

Thank you very much, Tetragramm, now I can remove lines, and use findCoutours to remove specks. Finally, I set the ROI by the location of vertical line.

benz gravatar imagebenz ( 2016-03-31 20:59:02 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-23 21:41:03 -0600

Seen: 612 times

Last updated: Mar 23 '16