How to train SVM for "Euro" coin recognition with OpenCV 3?
<p>My xmas holiday project this year was to build a little Android app, which should be able to detect arbitrary Euro coins in a picture, recognize their value and sum the values up. </p>

<p>My <strong>assumptions/requirements</strong> for the picture for a good recognition are</p>

<ul>
<li>uniform background</li>
<li>picture should be roughly the size of a DinA4 paper</li>
<li>coins may not overlap, but may touch each other</li>
<li>number-side of the coins must be up/visible</li>
</ul>

<p>My initial thought was, that for the coin value-recognition later it would be best to first detect the actual coins/their regions in the picture. Any recognition then would run on only these regions of the picture, where actual coins are found.</p>

<p><strong>So the first step was to find circles.</strong> This i have accomplished using this OpenCV 3 pipeline, as suggested in several books and SO postings:</p>

<ol>
<li>convert to gray</li>
<li>CannyEdge detection</li>
<li>Gauss blurring</li>
<li>HoughCircle detection</li>
<li>filtering out inner/redundant circles</li>
</ol>

<p>The detection works rather successfully IMHO, here a picture of the result:
<a href="http://i.stack.imgur.com/LqdQS.jpg" rel="nofollow">Coins detected with HoughCircles with blue border</a></p>

<p><strong>Up to the recognition now for every found coin!</strong></p>

<p>I searched for solutions to this problem and came up with</p>

<ul>
<li>template matching</li>
<li>feature detection</li>
<li>machine learning</li>
</ul>

<p>The <strong>template matching</strong> seems very inappropriate for this problem, as the coins can be arbitrary rotated with respect to a template coin (and the template matching algorithm is not rotation-invariant! so i would have to rotate the coins!). 
Also pixels of the template coin will never exactly match those of the region of the formerly detected coin. So any algorithm computing the similarity will produce only poor results, i think.</p>

<p>Then i looked into <strong>feature detection</strong>. This seemed more appropriate to me. I detected the features of a template-coin and the candidate-coin picture and drew the matches (combination of ORB and BRUTEFORCE_HAMMING). Unfortunately the features of the template-coin were also detected in the wrong candidate coins. 
See the following picture, where the template or "feature" coin is on the left, a 20 Cents coin. To the right there are the candidate coin, where the left-most coin is a 20 Cents coin. I actually expected this coin to have the most matches, unfortunately not. So again, this seems not to be a viable way to recognize the value of coins.
<a href="http://i.stack.imgur.com/Btofs.jpg" rel="nofollow">Feature-matches drawn between a template coin and candidate coins</a></p>

<p>So <strong>machine learning</strong> is the third possible solution. From university i still now about neural networks, how they work, etc. Unfortunately my practical knowledge is rather poor AND i don't know Support Vector Machines (SVM) at all, which is the machine learning supported by OpenCV.</p>

<p>So my question is actually not source-code related, but more how to setup the learning process.</p>

<ol>
<li>Should i learn on the plain coin-images or should i first extract features and learn on the features? (i think: features)</li>
<li>How much positives and negatives per coin should be given?</li>
<li>Would i have to learn also on rotated coins or would this rotation be handled "automagically" by the SVM? So would the SVM recognize rotated coins, even if i only trained it on non-rotated coins?</li>
<li>One of my picture-requirements above ("DinA4") limits the size of the coin to a certain size, e.g. 1/12 of the picture-height. Should i learn on coins of roughly the same size or different sizes? I think, that different sizes would result in different features, which would not help the learning process, what do you think?</li>
</ol>

<p>Of course, if you have a different possible solution, this is also welcome!
Any help is appreciated! :-)</p>

<p>Bye &amp; Thanks!</p>