問(wèn)題描述
我需要給臉部的皮膚上色...我如何找到膚色?
I need to color the skin of the face... How do i find the skin color?
現(xiàn)在我通過(guò) RGB 像素值獲取膚色...仍然我面臨的問(wèn)題是我正在匹配顏色坐標(biāo)以匹配特定顏色范圍的皮膚......但臉部的某些區(qū)域仍然不在我的顏色范圍內(nèi),那么它不是那個(gè)區(qū)域的顏色..
now i get the skin color by RGB pixel value ... Still i am facing the problem i was matching the color coordinates to match the skin by certain color range... but still some area of the face not fall in my range of colors then it is not color that area..
除了面部區(qū)域可能落在那個(gè)區(qū)域之外,那個(gè)區(qū)域也有顏色......
other than the face area may fall that region, that area also colored...
關(guān)于我的問(wèn)題的任何想法...
Any idea about my issue...
提前謝謝....
我的代碼:
-(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);
}
問(wèn)候,
間諜網(wǎng)
推薦答案
您可以創(chuàng)建兩個(gè)圖像,一個(gè)是原始圖像,另一個(gè)是單獨(dú)修改的圖像像素,然后修復(fù)...并通過(guò)首先添加原始圖像并將修改后的像素單獨(dú)添加到原始圖像來(lái)覆蓋圖像....
you can create the two images one is the original image and other one is the modified image pixels alone and fix that... and and overlay the images by adding the original image first and the modified pixel alone over the original....
for (int index=0; index<length; index+=4)
{
if (data2[index]==data1[index])
{
data1[index]=data2[index];
data1[index+1]=data2[index+1];//aRed+value;//aRed;//13;
data1[index+2]=data2[index+2];//aGreen;//aGreen;//43;
data1[index+3]=data2[index+3];
}
這篇關(guān)于如何從ios 5中的源圖像中檢測(cè)面部的膚色?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!