gpt4 book ai didi

iphone - 如何从 ios 中的源图像更改脸部的肤色?

转载 作者:技术小花猫 更新时间:2023-10-29 10:18:13 25 4
gpt4 key购买 nike

我的代码:不同深浅人脸的RGB值如何管理,如何应用?这段代码会随着头发改变脸的颜色,但我想要1.除了头发,只有脸要上色。

    -(void)changeSkinColorValue:(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(firstImageV.image.size.height * firstImageV.image.size.width * 10);

CFMutableDataRef m_DataRef = CFDataCreateMutableCopy(0, 0,CGDataProviderCopyData(CGImageGetDataProvider(firstImageV.image.CGImage)));
UInt8 *rawData = (UInt8 *) CFDataGetMutableBytePtr(m_DataRef);
int length = CFDataGetLength(m_DataRef);
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = bytesPerPixel * firstImageV.image.size.width;
NSUInteger bitsPerComponent = 8;

CGContextRef context1 = CGBitmapContextCreate(rawData, firstImageV.image.size.width, firstImageV.image.size.height, bitsPerComponent, bytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);

CGContextDrawImage(context1, CGRectMake(0, 0, firstImageV.image.size.width, firstImageV.image.size.height), imageRef);

NSLog(@"%d::%d",width,height);


// for(int ii = 0 ; ii < 250 ; ii+=4)
//{

for(int ii = 0 ; ii < length ; ii+=4)
{
//NSLog(@"Raw data %s",rawData);

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<260) ) || ((G>40)&&(G<210))||((B>20) && (B<170)))

//new code......

if( ( (R>0)&&(R<260) ) || ((G>0)&&(G<210))||((B>0) && (B<170)))

{
rawData[ii+1]=R;//13;
rawData[ii+2]=G;//43;
rawData[ii+3]=value;//63
}
}


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];
[secondImageV setImage:rawImage];
CGContextRelease(context1);
CGContextRelease(ctx);
free(rawData);
}

最佳答案

尝试使用 Brad Larson 的 GPUImage 框架:

https://github.com/BradLarson/GPUImage

这是处理图像的非常强大的框架。

阅读这个问题:

GPUImage create a custom Filter that change selected colors

希望对您有所帮助!

关于iphone - 如何从 ios 中的源图像更改脸部的肤色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16236934/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com