Thursday, 5 September 2013

openCV2, Qt and Histogram back projection--00

This post will talk about how to implement histogram back projection with openCV2.First of all,
the algorithm was proposed by Michael J. Swainiand Dana H. Ballard in their paper.
Besides, I gain many helps from abid rahman, the author of the blog OpenCV Python Tutorials,
he helps me understand what is the algorithm doing about, the core of the codes in this post are translated by the codes of his tutorial--Histograms - 4 : Backprojection.His blog is very good, If you are interesting about computer vision, please give it a visit.

I prefer to re-implement the algorithms I don't quite understand for two reasons.

This is a good method to study how do the algorithms work

Many algorithms are anti-intuitive of humans, if I don't write them down, when I forget how do they work in the future, I need to spend more times to refresh what do they do.

Re-implement the algorithm can help me learn how to use the algorithm, like when should I use them, their bottleneck, use conditions and so on.

In this tutorial, I would not talk about how to combine openCV2 and Qt5 together but leave it to the next post.

This post will focus on the algorithm only(no GUI).The images use in this post could download from target, region of intereset.
Source codes could download from github.

Custom histogram back projection

The principle of histogram back projection is measure the probability between the color histogram of the target and the region of interest(ROI, the object you want to know where is it in the target).
The blog OpenCV Python Tutorials use two dimensions histogram(hue, saturation) to measure the ratio, I will compare about the result between one dimension histogram(hue) and two dimensions histogram(hue, saturation) in this post.Full source codes are uploading to github, this post would talk about the concepts only.

About the model(region of interest--ROI), we should make sure the selected ROI as big as possible, because this could increase the quality of the probability map.

Step 2--get histograms

Now we need to get the histograms of the model_ and input_.Why hsv but not bgr?
Because hsv could separate the color from intensities, the intensity of b, g, r may be the same,
but hue could separate which one is red, green or blue.