OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Wed, 01 Feb 2017 14:21:48 -0600Back Projection and Shadows/Lightinghttp://answers.opencv.org/question/124627/back-projection-and-shadowslighting/Hi everyone,
I am currently back projecting in order to find my hands in a video feed however the current solution is too lighting dependent. I am currently converting to HSV and sampling an ROI ( I cover the camera with my hand at this point). Then I use this histogram to backproject as shown. If I pose my fingers down to create a shadow on my hand this loses accuracy, and as you can see the background has a lot of false positives. Can anyone give me some advice on how to improve this?
Thanks.
<pre><code>//0,1 means use H and S channels in backproj
int channels[] {0, 1};
//Bins are the number of bars in the histogram that a value can fall into
int histSize[] = { h_bins, s_bins };
float hue_range[] = {0, 180};
float sat_range[] = {0, 255};
const float* ranges[] = { hue_range, sat_range };
if (sampleHand){
//Uncomment to blur
/*cv::Size *mySize = new cv::Size(15,15);
GaussianBlur(hsv, hsv, *mySize, 5, 5);*/
Mat roi;
getRectSubPix(hsv, *new cv::Size(50,50), *new cv::Point(hsv.cols/2, hsv.rows/2), roi);
calcHist(&roi, 1, channels, Mat(), skinShadeHist, 2, histSize, ranges, true, false);
normalize(skinShadeHist, skinShadeHist, 0, 255, NORM_MINMAX, -1, Mat());
samplesExist = true; sampleHand = false;
} else if (samplesExist){
MatND backproj;
//Calculate the 'confidence' of a pixel being skin
calcBackProject(&hsv, 1, channels, skinShadeHist, backproj, ranges, 1, true);
return backproj;
}
</code></pre>
![Current output](/upfiles/14859808753974519.jpg) ginisterWed, 01 Feb 2017 14:21:48 -0600http://answers.opencv.org/question/124627/What mathematically is back projection?http://answers.opencv.org/question/59021/what-mathematically-is-back-projection/I'm able to use openCV backprojection and I'm also able to implement it myself. However, I don't really understand why it works.
On the obvious side it is just building up a histogram of a target image, creating a probability distribution with it and then applying that pdf to a new image. I believe this is done in the hope that the new back projected image will only show the target information with high probability in the backprojected image.
However, in the docs page ([http://docs.opencv.org/doc/tutorials/imgproc/histograms/back_projection/back_projection.html]) it says:
"In terms of statistics, the values stored in BackProjection represent the probability that a pixel in Test Image belongs to a skin area, based on the model histogram that we use."
I'm really struggling to interpret this and in particular the "represent the probability". There must be some formula that specifies it like:
prob("Pixel is from test image" | "New image pixel") = ?????
I just can't get my head around it though. Does anybody have any links or a good explanation of what the terms in the equation are?
Many thanksricor29Thu, 02 Apr 2015 13:42:04 -0500http://answers.opencv.org/question/59021/