1

based on this article skin could be approximatly detected using hsv color space and taking hue range between 6 and 38.

i tried to use some combination of cvThreshold, in particular i thought this could be the right way:

cvThreshold(planeH, planeH, 38, UCHAR_MAX, CV_THRESH_TRUNC);
cvThreshold(planeH, planeH, 6, UCHAR_MAX, CV_THRESH_BINARY_INV);

but it does not work. some help?

nkint
  • 11,513
  • 31
  • 103
  • 174
  • could you please post some more code - since you should have some dilate and erode calls as well. – Gambrinus Mar 04 '12 at 22:11
  • i'm interested only in understand if cvThreshold is applaid correctly to get the specified range – nkint Mar 04 '12 at 22:18

2 Answers2

4

I believe the function you are really after is the cvInRange function. This function allows you to specify multiple intervals simultaneously.

For example,

CvMat* skinMask = cvCreateMat(...);
cvInRange(hsvImage, CvScalar(6, loS, loV), CvScalar(38, hiS, hiV), skinMask);

Where loS, loV, hiS, hiV are the lower and upper bounds of the S and V channels respectively.

Here is another one of my answers using inRange. If you can use the C++ interface, I would recommend that over the C interface as it has more features and is the actively maintained side of OpenCV going forward.

Community
  • 1
  • 1
mevatron
  • 13,911
  • 4
  • 55
  • 72
1

I'm not sure whether you can safely use the same image (planeH) as input and output of the function. You might get border effects. Better use a temporary image

Also, if you look here : http://www710.univ-lyon1.fr/~bouakaz/OpenCV-0.9.5/docs/ref/OpenCVRef_ImageProcessing.htm#decl_cvThreshold you'll see that the output of cvthreshold is a binary image (either value or 0) if you're not using CV_THRESH_TOZERO. So your code is biased, as after the operation planeH should contain only two different values

What you should do is use CV_THRESH_TOZERO, or perform each operation on two different images, and then perform on OR operation on both results (the result being a binary image with 1 for pixels between 6 and 38).

jlengrand
  • 12,152
  • 14
  • 57
  • 87
  • Then have a llok at the documentation man http://opencv.willowgarage.com/documentation/python/core_operations_on_arrays.html?highlight=or#Or. Should be your bedbook :). – jlengrand Mar 05 '12 at 17:17