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
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:
- grayscale
- mean filter (boxFilter)
- binarization (adaptive threshold)
- remove noise in connected components, kernel less then 10 (I don't know how to do it)
- dilate (with structure Mat (-4, 4, -12, 12) )
- remove noise in connected components, (remove the little things)
- 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); 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
My questions list as follows,
- what is the good approach ? I'm care about the performance, the total calculate time should less then 300ms
- 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.
- how to remove noises ?
- should I use equalizeHist to equalize the source because different illumination condition ?
Thank you in advance, I'm very appreciated for your advices.