how can I get information from every pixel from a CVImageBufferRef type?(OSX)

3.2k Views Asked by At

I'm trying to extract pixel data from individual frames of a QT Movie.

I think I need to use CV, because QTKit and NSImage would be too slow...

I need to compare each pixel of the image in the buffer (CVImageBufferRef) containing the current frame of the webcam (iSight). So I need speed.

Sorry for my bad english language, I'm Italian.

1

There are 1 best solutions below

0
On

See the code in the question how to convert a CVImageBufferRef to UIImage, which is a bigger question but covers the same ground. Here's the base code you'd need (from the OP of that question):

CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); 
/*Lock the image buffer*/
CVPixelBufferLockBaseAddress(imageBuffer,0); 
/*Get information about the image*/
uint8_t *baseAddress = (uint8_t *)CVPixelBufferGetBaseAddress(imageBuffer); 
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer); 
size_t width = CVPixelBufferGetWidth(imageBuffer); 
size_t height = CVPixelBufferGetHeight(imageBuffer); 

/*We unlock the  image buffer*/
CVPixelBufferUnlockBaseAddress(imageBuffer,0);

Be sure to read the accepted answer for a fuller explanation of the data format.