this question is regarding opencv with c++ in VS2008 express.
I'm doing very simple thing. Trying to get skin values from camera image.
As you can see in the screenshot camera image looks fairly good. I'm converting it to HSV & separating Hue channel from that to later threshold the skin value. But Hue channel seems too much noisy & grainy. Also HSV image window shows degradation of information. Why is that happening? & how to solve that. If we cant can we remove noise by some kind of smoothing? Code is as below :
#include <opencv2/opencv.hpp>
int main(){
cv::VideoCapture cap(0); // open the default camera
cv::Mat hsv, bgr, skin;//make image & skin container
cap >> bgr;
//cvNamedWindow("Image");
//cvNamedWindow("Skin");
//cvNamedWindow("Hue");
cv::cvtColor(bgr, hsv, CV_BGR2HSV);
std::vector<cv::Mat> channels;
cv::split(hsv, channels);
cv::Mat hue;
hue = channels[0];
cv::imshow("Image", bgr);cvMoveWindow("Image",0,0);
cv::imshow("HSV", hsv);cvMoveWindow("HSV",660,0);
cv::imshow("Hue", hue);cvMoveWindow("Hue",0,460);
cvWaitKey(0);//wait for key press
return 0;
}
Hue channel seems too much noisy & grainy. Why is that happening?
In the real-world colors we see, the portion of information that is represented by "hue" varies. The color red is completely described by hue. Black has no hue information at all.
However, when a color is represented in HSV as you have done, the hue is always one-third of the color information.
So as colors approach any shade of gray, the hue component will be artificially inflated. That's the graininess you're seeing. The closer to gray, the more hue must be amplified, including error in captured hue.
Also HSV image window shows degradation of information. Why is that happening?
There will be rounding errors in the conversion, but it's probably not as much as you think. Try converting your HSV image back to BGR to see how much degradation actually happened.
& how to solve that.
Realistically, you have two options.
Use a higher-quality camera, or don't use HSV format.
If you look at the formulae in the OpenCV documentation for the function cvtColor
with parameter CV_BGR2HSV
you will have
Now, when you have a shade of gray, i.e. when R is equal to B and R is equal to G, the fraction in the H formula is always undefined since it is zero divided by zero. It seems to me that the documentation does not describe what happens in that case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With