Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Detect numbers and calculate it in box

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.