2010-05-18 111 views
0

我試圖找到一種方式來編程/購買應用程序使用iPhone檢測某人的膚色對客觀規模使用RGB froma照片他們採取他們自己。任何人有任何指針?有沒有辦法從iPhone應用程序測量對象的膚色

+0

這可能不是那麼容易,因爲音調依賴於光了很多,結果是不可靠的最好的。 – dbemerlin 2010-05-18 11:57:49

+0

@dbemerlin說的平方。每個人都必須在他們臉上貼一張標準校準卡。你在做什麼?自動化種族分析? < - 笑話。 – 2010-05-18 12:16:20

+0

這個問題提出類似的問題:http://stackoverflow.com/questions/2720336/how-to-get-skin-tone-color-pixel-in-iphone,雖然不是很清楚。 – 2010-05-18 20:37:44

回答

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在3/6/09創建。 //版權所有2009 Mark Johnson。版權所有。

完整的文章是在這裏 http://www.markj.net/iphone-uiimage-pixel-color/

相關問題