Мне нужно окрасить кожу лица ... Как мне найти цвет кожи?Как определить цвет кожи лица из исходного изображения в ios 5?
теперь я получить цвет кожи, RGB значение пикселя ... Тем не менее я столкнулся с проблемой я был соответствующий цвет координаты, чтобы соответствовать коже по определенной цветовой гамме ... но все-таки какой-то области лица не падать в моем диапазоне цветов, то это не цвет, что область ..
кроме области лица может упасть, что область, эта область также цветные ...
Любая идея о моей проблеме ...
Заранее спасибо ....
Мой код:
-(void)colorImageBySliderValue:(float)value WithImage:(UIImage*)needToModified
{
CGContextRef ctx;
CGImageRef imageRef = needToModified.CGImage;
NSUInteger width = CGImageGetWidth(imageRef);
NSUInteger height = CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
unsigned char *rawData = malloc(self.sourceImage.image.size.height * self.sourceImage.image.size.width * 10);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * self.sourceImage.image.size.width;
NSUInteger bitsPerComponent = 8;
CGContextRef context1 = CGBitmapContextCreate(rawData, self.sourceImage.image.size.width, self.sourceImage.image.size.height,
bitsPerComponent, bytesPerRow, colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextDrawImage(context1, CGRectMake(0, 0, self.sourceImage.image.size.width, self.sourceImage.image.size.height), imageRef);
NSLog(@"%d::%d",width,height);
for(int ii = 0 ; ii < 768 * 1024 ; ii+=4)
{
int R = rawData[ii];
int G = rawData[ii+1];
int B = rawData[ii+2];
// NSLog(@"%d %d %d", R, G, B);
if(((R>60)&&(R<237)) || ((G>10)&&(G<120))||((B>4) && (B<120)))
// if(((R>100)&&(R<186)) || ((G>56)&&(G<130))||((B>30) && (B<120)))
// if(((R>188)&&(R<228)) || ((G>123)&&(G<163))||((B>85) && (B<125)))
// if(((R>95)&&(R<220)) || ((G>40)&&(G<210))||((B>20) && (B<170)))
{
rawData[ii+1]=R;//13;
rawData[ii+2]=G;//43;
rawData[ii+3]=value;//63
// NSLog(@"entered");
}
}
ctx = CGBitmapContextCreate(rawData,
CGImageGetWidth(imageRef),
CGImageGetHeight(imageRef),
8,
CGImageGetBytesPerRow(imageRef),
CGImageGetColorSpace(imageRef),
kCGImageAlphaPremultipliedLast);
imageRef = CGBitmapContextCreateImage(ctx);
UIImage* rawImage = [UIImage imageWithCGImage:imageRef];
UIImageView *ty=[[UIImageView alloc]initWithFrame:CGRectMake(100, 200, 400, 400)];
ty.image=rawImage;
[self.view addSubview:ty];
CGContextRelease(context1);
CGContextRelease(ctx);
free(rawData);
}
С уважением,
Spynet