Saturday, 13 August 2016

opencv - What algorithms or approaches apart from Haar cascades could be used for custom objects detection?



I need to do computer visions tasks in order to detect watter bottles or soda cans. I will obtain 'frontal' images of bottles, soda cans or any other random objects (one by one) and my algorithm should determine whether it's a bottle, a can or any of them.



Some details about object detecting scenario:




  • As mentioned, I will test one single object per image/video frame.

  • Not all watter bottles are the same. There could be color in plastic, lid or label variation. Maybe some could not get label or lid.

  • Same about variation goes for soda cans. No wrinkled soda cans are gonna be tested though.


  • There could be small size variation between objects.

  • I could have a green (or any custom color) background.

  • I will do any needed filters on image.

  • This will be run on a Raspberry Pi.



Just in case, an example of each:



enter image description here enter image description here




I've tested a couple times OpenCV face detection algorithms and I know it works pretty good but I'd need to obtain an special Haar Cascades features XML file for detecting each custom object on this approach.



So, the distinct alternatives I have in mind are:





I'd like to get a simple algorithm and I think creating a custom Haar classifier could be even not needed. What would you suggest?



Update




I strongly considered the shape/aspect ratio approach.



However I guess I'm facing some issues as bottles come in distinct sizes or even shapes each. But this made me think or set following considerations:




  • I'm applying a threshold with THRESH_BINARY method. (Thanks to the answers).

  • I will use a white background on detection.

  • Soda cans are all same size.

  • So, a bounding box for soda cans with high accuracy might distinguish a can.




What I've achieved:



Threshold really helped me, I could notice that on white background tests I would obtain for cans:



enter image description here enter image description here enter image description here enter image description here enter image description here



And this is what it's obtained for bottles:



enter image description here enter image description here enter image description here enter image description here




So, darker areas left dominancy is noticeable. There are some cases in cans where this might turn into false negatives. And for bottles, light and angle may lead to not consistent results but I really really think this could be a shorter approach.



So, I'm quite confused now how I should evaluate that darkness dominancy, I've read that findContours leads to it but I'm quite lost on how to seize such function. For example, in case of soda cans, it may find several contours, so I get lost on what to evaluate.



Note: I'm open to test any other algorithms or libraries distinct to Open CV.


Answer



I see few basic ideas here:





  1. Check object (to be precise - object boundind rect) width/height ratio. For can it's approimetely 2-2.5, for bottle i think it will be >3. It's very simple idea to it should be easy to test it quickly and i think it should has quite good accuracy. For some values, like 2.75 (assumimg that values that i gave are correct, which most likely isn't true) you can use some different algorithm.

  2. Check whether you object contains glass/transparence regions - if yes, than definitely it's a bottle. Here you can read more about it.

  3. Use grabcut algorithm to get object mask/more precise shape and check whether this shape width at the top is similar to width at the bottom - if yes than it's a can, no - bottle (bottles has screw cap at the top).


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...