Gets the RGB value of avcapturesession Samplebuffer one pixel
typedef unsignedChar byte; typedefstructrgbpixel{bytered, green, blue;} Rgbpixel;- (void) Captureoutput: (Avcaptureoutput *) captureoutput Didoutputsamplebuffer: (cmsamplebufferref) Samplebuffer fromconnection: (AVCaptureConnection *) connection {cvimagebufferref Imagebuffer=Cmsamplebuffergetimagebuffer (Samplebuffer); Cvpixelbufferlockbaseaddress (Imagebuffer,0); size_t Bytesperrow=Cvpixelbuffergetbytesperrow (Imagebuffer); size_t width=cvpixelbuffergetwidth (Imagebuffer); size_t Height=cvpixelbuffergetheight (Imagebuffer); uint8_t*src_buff = (uint8_t*) cvpixelbuffergetbaseaddress (Imagebuffer); Cvpixelbufferunlockbaseaddress (Imagebuffer,0); Rgbpixel*pixeldata = (Rgbpixel *) Src_buff; intLen = Bytesperrow *height; for(intI=0; i<len; i+=4) {Rgbpixel pixel= pixeldata[i/4]; intA =0; intR =pixel.red; intg =Pixel.green; intb =Pixel.blue; NSLog (@"First values = r:%d g:%d b:%d", R, G, b); A= src_buff[i+3]; R= src_buff[i+2]; G= src_buff[i+1]; b=Src_buff[i]; NSLog (@"Second values = r:%d g:%d b:%d", R, G, b); }}
If it's Bgra,
struct rgbpixel{ byte blue, green, red;} Rgbpixel;
Reference: http://iphonedevsdk.com/forum/iphone-sdk-development/
Gets the RGB value of avcapturesession Samplebuffer one pixel