我有两个 CVImageBufferRef 缓冲区,它们对应于 AVCaptureSession 依次抓取的两个图像。我想比较两者以查看所有像素是否相同。为了遍历帧缓冲区的所有像素并比较它们,我有这个:
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
}
显然,它在比较中崩溃了。如何将 pixelA 中的所有值与 pixelB 进行比较?谢谢