I have two CVImageBufferRef buffers that correspond to two images grabbed in sequence by AVCaptureSession. I would like to compare both to see if all the pixels are the same. In order to loop thru all pixels of the frame buffer and compare them, I have this:
unsigned char *pixelA = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBufferA);
unsigned char *pixelB = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBufferB);
- (BOOL) isBuffer:(unsigned char *)pixelA equalToBuffer:(unsigned char *)pixelB {
for( int row = 0; row < bufferHeight; row++ ) {
for( int column = 0; column < bufferWidth; column++ ) {
if ((pixelA[0] != pixelB[0]) ||
(pixelA[1] != pixelB[1]) ||
(pixelA[2] != pixelB[2]) ){
return NO;
// means at some point pixelA is not equal to pixelB, so
// pixelBufferA is not equal to pixelBufferB
}
pixelA += BYTES_PER_PIXEL;
pixelB += BYTES_PER_PIXEL;
}
}
// if the method reached here, pixelBufferA is equal to pixelBufferB, so
return YES; // are equal
}
Obviously it is crashing in the comparison. How do I compare all values in pixelA with pixelB ? thanks
I’ve never actually done what you’re doing, but is there a reason you can’t just compare the buffers in one go, say, with
memcmp?