直接上源码:
void testApp::ofSkinDetector(unsigned char* Pointer, ofImage& image, int CAMERA_WIDTH, int CAMERA_HEIGHT) { int len = CAMERA_WIDTH * CAMERA_HEIGHT * 3; unsigned char* SkinP= new unsigned char[len]; for (int Y = 0; Y < CAMERA_HEIGHT; Y++) { for (int X = 0; X < CAMERA_WIDTH; X++) { unsigned char Red = Pointer[CAMERA_WIDTH * Y * 3 + X * 3]; unsigned char Green = Pointer[CAMERA_WIDTH * Y * 3 + X * 3 + 1]; unsigned char Blue = Pointer[CAMERA_WIDTH * Y * 3 + X * 3 + 2]; unsigned char Max = 0, Min = 0; if (Red > 95 && Green > 40 && Blue > 20 && Red > Blue && Red > Green && abs(Red - Green) > 15) { if (Blue >= Green) { Max = Blue; Min = Green; } else { Max = Green; Min = Blue; } if (Red > Max) Max = Red; else if (Red < Min) Min = Red; if (Max - Min > 15) { SkinP[CAMERA_WIDTH * Y * 3 + X * 3] = 255; SkinP[CAMERA_WIDTH * Y * 3 + X * 3 + 1] = 255; SkinP[CAMERA_WIDTH * Y * 3 + X * 3 + 2] = 255; } } } } image.setFromPixels(SkinP, CAMERA_WIDTH, CAMERA_HEIGHT, OF_IMAGE_COLOR); delete SkinP; SkinP = NULL; }
感谢这位博主的博文: 参考博客链接,以上代码也是基于该博文进行的修改。