Posted on Wed 13 July 2016

A brief introduction on object recognition techniques in CV

Object recognition is one of the hot topics in computer vision. Particularly, of much significance, it has various applications in robotics, identification, interpretation and such image oriented tasks.

One can ramify between Object recognition into 4 major subsets such as :

1. Template based approach : We take the object and match the object with distribution pattern of intensities. It’s quite exhaustive is not invariant to geometric transformations inside search image Eg: Template Matching . However, this isint much sturdy.

2. Geometric approach : Recognize the object on basis of edges, corners, angles. Then we create a one 2 one match and then make a transformation that handles rotation, scaling, etx.
Eg: Matching w.r.t positioning of objects. Classifying patterns

3. Graph based approach : we match similar types of structures. Encode the relationship between structures rather than the geometry of the figure.

4. Bag of Visual Words : I will cover Bag of Words in a seperate post Bag of Words.

I’ll be going through a couple of common techniques. Firstly I’ll introduce template matching and in the follow, using probabilistic recognition , then moving on to Machine learning applications such as using BOW models coupled with SVM , or feature extrapolation and recognition using neural nets.

Template based aproach Well, there are a few contentions i;d like to make when we use this approach. Shape based approach is not the key or the best method for recognition. But , in industry, all methods have their perks. Say we have an industry converyor belt that is suppossed to carry only boxes or T- Joints or anything so simply extrapolable and uniform that it is feasible to use shape matching rather than going for complex approaches like using nets, or using SVM along with bag of words. Then I’d say, template matching or shape based matching is the best bet in terms of accuracy as well as speed.

Lets dive a little deeper in the aforementioned topic. I’ll be using template matching as an example to explain how Shape based matching works. Consider two images. The template image (T) and the actual image (I). We say that we want to find the location / occurence of template inside the actual image.

In simple words I can say, return True, iff $$T \subseteq I$$. But life aint so simple. In reality, every pixel needs to be iterated over and checked. It can be said that the a template is belonging to a particular image iff, all pixels match exactly. i.e. the sum of ( Absolute Difference between every pixel must be zero).

$$SAD(x, y) = \sum_{i=0}^{T_{\text{rows}}}\sum_{j=0}^{T_{\text{cols}}} {\text{Diff}(x+i, y+j,i,j)}$$

Here’s how the above formula works.

$$SAD$$ : sum of absolute differences. $$SAD (x, y)$$ : the SAD of a particular pixel location in the actual Image $$I$$

Each pixel in $$I$$ can be represented using $$(x, y)$$. It has an intensity, or color value expresed as $$Intensity(I(x,y))$$.

Now, a pixel in template image $$T(p,q)$$ will have intensity as $$Intensity(T(p,q))$$.

A search window is created that is of the size of template image. The window is then slid over the actual Image I and every time SAD is computed. For checking single occurence of template the iterations can be stopped once SAD is $$0$$, or else it can be continued until the end of $$I$$ is reached.

We’ll be implementing the algorithm using opencv , python

Take a look at $$line 14$$, it states cv2.TM_SQDIFF parameter in matchTemplate(). Opencv’s rendition for SAD can be delineated as :

$$R(x, y) = \sum_{i, j}\ {(\text{T}(i,j) - \text{I}(x+i, y+j))^2}$$

And here is the output ! We will search a pair of glares from this paraphenalia  Okay, so template matching can be established using the opencv api. Its’ quite simple to implement in plain ol c++ as well. Not a biggie. We’ll use the helper functions for image reading , accessing pixel value, etc. but the rest can be quite easily implemented using a bunch of for loops

 
 You can find my remaining code on Github remaining posts on other approaches coming soon … if (!document.getElementById('mathjaxscript_pelican_#%@#@#')) { var align = "center", indent = "0em", linebreak = "false"; if (false) { align = (screen.width < 768) ? "left" : align; indent = (screen.width < 768) ? "0em" : indent; linebreak = (screen.width < 768) ? 'true' : linebreak; } var mathjaxscript = document.createElement('script'); mathjaxscript.id = 'mathjaxscript_pelican_#%@#@#'; mathjaxscript.type = 'text/javascript'; mathjaxscript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js?config=TeX-AMS-MML_HTMLorMML'; mathjaxscript[(window.opera ? "innerHTML" : "text")] = "MathJax.Hub.Config({" + " config: ['MMLorHTML.js']," + " TeX: { extensions: ['AMSmath.js','AMSsymbols.js','noErrors.js','noUndefined.js'], equationNumbers: { autoNumber: 'AMS' } }," + " jax: ['input/TeX','input/MathML','output/HTML-CSS']," + " extensions: ['tex2jax.js','mml2jax.js','MathMenu.js','MathZoom.js']," + " displayAlign: '"+ align +"'," + " displayIndent: '"+ indent +"'," + " showMathMenu: true," + " messageStyle: 'normal'," + " tex2jax: { " + " inlineMath: [ ['\\\$$','\\\$$'] ], " + " displayMath: [ ['$$','$$'] ]," + " processEscapes: true," + " preview: 'TeX'," + " }, " + " 'HTML-CSS': { " + " styles: { '.MathJax_Display, .MathJax .mo, .MathJax .mi, .MathJax .mn': {color: 'inherit ! important'} }," + " linebreaks: { automatic: "+ linebreak +", width: '90% container' }," + " }, " + "}); " + "if ('default' !== 'default') {" + "MathJax.Hub.Register.StartupHook('HTML-CSS Jax Ready',function () {" + "var VARIANT = MathJax.OutputJax['HTML-CSS'].FONTDATA.VARIANT;" + "VARIANT['normal'].fonts.unshift('MathJax_default');" + "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" + "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" + "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" + "});" + "MathJax.Hub.Register.StartupHook('SVG Jax Ready',function () {" + "var VARIANT = MathJax.OutputJax.SVG.FONTDATA.VARIANT;" + "VARIANT['normal'].fonts.unshift('MathJax_default');" + "VARIANT['bold'].fonts.unshift('MathJax_default-bold');" + "VARIANT['italic'].fonts.unshift('MathJax_default-italic');" + "VARIANT['-tex-mathit'].fonts.unshift('MathJax_default-italic');" + "});" + "}"; (document.body || document.getElementsByTagName('head')).appendChild(mathjaxscript); } 
 
 Filed under Object Recognition,CV | Tagged: ObjectRecognition CV | Permalink /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */ var disqus_shortname = "bitsmakemecrazy"; // required: replace example with your forum shortname var disqus_identifier = "simple-object-recognition-techniques"; var disqus_url = "https://kushalvyas.github.io/Obj_CV.html"; var disqus_title = "Simple Object Recognition techniques"; /* * * DON'T EDIT BELOW THIS LINE * * */ (function() { var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true; dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js'; (document.getElementsByTagName('head') || document.getElementsByTagName('body')).appendChild(dsq); })(); Please enable JavaScript to view the comments powered by Disqus. comments powered by Disqus 
 
 function load_sideID(){ var curr_url= document.URL; if(curr_url.indexOf('projects')>0){ console.log("on project page"); }else{ console.log("not on project page"); var side= \$("#SIDEID"); var data = "<h3>TOP ARTICLES</3>"; data += "<ul>"; data += '<li><a href="https://kushalvyas.github.io/calib.html">Camera Calibration</a></li>'; data += '<li><a href="https://kushalvyas.github.io/stitching.html">Image Stitching</a></li>'; data += '<li><a href="https://kushalvyas.github.io/BOV.html#BOV">Bag of Visual Words</a></li>'; data += '<li><a href="https://kushalvyas.github.io/sl_3d.html">Structured Light 3D Reconstruction</a></li>'; data += '<li><a href="https://kushalvyas.github.io/caffe_cnn.html">Caffe + ConvNets</a></li>'; data += "</ul>"; data +="<h3>Coming Soon</3>"; data+="<ul>"; data += '</ul>'; side.append(data); } } load_sideID(); window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date; ga('create', 'UA-75632170-1', 'auto'); ga('send', 'pageview'); 
 
 
 Stuff and credits Proudly powered by Pelican, which takes great advantage of Python. Theme is a modified Pelican Bricks This site also makes use of Zurb Foundation Framework and is typeset using the blocky -- but quite good-looking indeed -- Exo 2 fonts, which comes in a lot of weight and styles. Enjoy! Tags stitching(1) mosaicking(1) AI(1) utils(1) Py(1) wikipedia(1) Machine Vision(1) technical(1) dev(1) images(1) 3D(1) Camera Calibration(1) CV(4) ObjectRecognition(4) Categories 3D Reconstruction, 3D, stereo, CV (1) AI (1) Computer Vision, Javascript, JS, CV (1) CV (3) CV, IP (1) CV, Machine Vision, Camera (1) graph_py (1) networks (1) Object Recognition, Classification, CV (2) Object Recognition,CV (1) technical, dev (1) utils (1)