0

我试图找到一种方法来编程/购买一个应用程序,以使用 iphone 来检测某人的肤色,使用他们自己拍摄的照片中的 RGB。有人有任何指示吗?

4

1 回答 1

0

我认为对此的反对意见是正确的——校准它将是一项相当艰巨的工作。但是,任何解决方案都将依赖于能够获取图像中特定像素的颜色(在本例中为 UIImageView ...)

- (UIColor*) getPixelColorAtLocation:(CGPoint)point {

UIColor* color = nil;
CGImageRef inImage = self.image.CGImage;
// Create off screen bitmap context to draw the image into. Format ARGB is 4 bytes for each pixel: Alpa, Red, Green, Blue
CGContextRef cgctx = [self createARGBBitmapContextFromImage:inImage];
if (cgctx == NULL) { return nil; /* error */ }

size_t w = CGImageGetWidth(inImage);
size_t h = CGImageGetHeight(inImage);
CGRect rect = {{0,0},{w,h}}; 

// Draw the image to the bitmap context. Once we draw, the memory 
// allocated for the context for rendering will then contain the 
// raw image data in the specified color space.
CGContextDrawImage(cgctx, rect, inImage); 

// Now we can get a pointer to the image data associated with the bitmap
// context.
unsigned char* data = CGBitmapContextGetData (cgctx);
if (data != NULL) {
    //offset locates the pixel in the data from x,y. 
    //4 for 4 bytes of data per pixel, w is width of one row of data.
    int offset = 4*((w*round(point.y))+round(point.x));
    int alpha =  data[offset]; 
    int red = data[offset+1]; 
    int green = data[offset+2]; 
    int blue = data[offset+3]; 
    NSLog(@"offset: %i colors: RGB A %i %i %i  %i",offset,red,green,blue,alpha);
    color = [UIColor colorWithRed:(red/255.0f) green:(green/255.0f) blue:(blue/255.0f) alpha:(alpha/255.0f)];
}

// When finished, release the context
CGContextRelease(cgctx); 
// Free image data memory for the context
if (data) { free(data); }

return color;

}

此代码来自 colourPicker 类,它带有以下 (c)

// 由 markj 于 2009 年 3 月 6 日创建。// 版权所有 2009 马克·约翰逊。版权所有。

全文在这里 http://www.markj.net/iphone-uiimage-pixel-color/

于 2010-05-18T12:52:07.713 回答