本文介绍了OpenCV中的肤色检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Opencv中进行肤色检测.

I trying to do skin color detection in Opencv.

1)首先,我将图像从RGB转换为HSV

1) First i converted the image into HSV from RGB

cvCvtColor(frame, hsv, CV_BGR2HSV);

2)比起我在HSV图像中应用肤色阈值

2) Than i had applied skin color threshold in the HSV image

cvInRangeS(hsv, hsv_min, hsv_max, mask); // hsv_min & hsv_max are the value for skin detection

3)因此,它会生成仅具有肤色但在Black& amp;中的糊状食物.白色图像,所以我将该图像转换为RGB

3) So it generates the mash which has only skin color but in Black & white image, so i converted that image in to RGB

 cvCvtColor(mask, temp, CV_GRAY2RGB);

4)所以现在我只希望皮肤颜色为RGB值.

4) so now i want the skin color in only RGB value.

for(c = 0; c <  frame -> height; c++) {
            uchar* ptr = (uchar*) ((frame->imageData) + (c * frame->widthStep));
            uchar* ptr2 = (uchar*) ((temp->imageData) + (c * temp->widthStep));
            for(d = 0; d < frame -> width; d++) {
                if(ptr2[3*d+0] != 255 && ptr2[3*d+1] != 255 && ptr2[3*d+2] != 255 && ptr2[3*d+3] != 255 ){
                    ptr[3 * d + 0] = 0;
                    ptr[3 * d + 1] = 0;
                    ptr[3 * d + 2] = 0;
                    ptr[3 * d + 3] = 0;
                }
            }
        }

现在我没有得到我真正想要的仅具有RGB肤色的图像.

now i am not getting the image that i want actually that has only skin color in RGB.

任何解决方案,

谢谢

第一张原始图片黑色和2号皮肤检测到的第二张图像白色的第三输出(不实际)

1st Original Image2nd Skin Detected Image in Black & White3rd Output (Not Actual)

推荐答案

您已经很接近了.

给定,您已经有一个3通道遮罩:

given, you have a 3 channel mask already:

Mat mask, temp;
cv::cvtColor(mask, temp, CV_GRAY2RGB);

您需要做的就是将其与原始图像结合起来,以遮盖所有非肤色:

all you need to do is combine it with your original image to mask out all non-skin color:

(而且,不要在那儿写[容易出错的]循环,最好依靠内置功能!)

(and no, don't write [error prone] loops there, better rely on the builtin functionality !)

Mat draw = frame & temp; // short for bitwise_and()

imshow("skin",draw);
waitKey();

这篇关于OpenCV中的肤色检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 17:11
查看更多