开发者

Is there a way to measure skin tone of an object from an iphone app

开发者 https://www.devze.com 2022-12-30 11:56 出处:网络
Im tr开发者_高级运维ying to find a way to programme/buy an app to use the iphone to detect someones skin tone against an objective scale using RGB froma phot they take of themselves. Anyone got any po

Im tr开发者_高级运维ying to find a way to programme/buy an app to use the iphone to detect someones skin tone against an objective scale using RGB froma phot they take of themselves. Anyone got any pointers?


I think the objections to this are correct - its going to be pretty hard work to calibrate it. However, any solution is going to rely on being able to get the colour of a specific pixel in an image (in this case a 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;

}

This code is from a colourPicker class which carries the following (c)

// Created by markj on 3/6/09. // Copyright 2009 Mark Johnson. All rights reserved.

The full article is here http://www.markj.net/iphone-uiimage-pixel-color/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号