0

我有两个 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 进行比较?谢谢

4

1 回答 1

1

我从来没有真正做过你正在做的事情,但是有没有理由你不能一次性比较缓冲区,比如说,memcmp

- (BOOL) isBuffer:(unsigned char*)pixelA equalToBuffer:(unsigned char*)pixelB
{
    size_t bufferSize = bufferWidth * bufferHeight * BYTES_PER_PIXEL;

    return memcmp( pixelA, pixelB, bufferSize ) == 0;
}
于 2012-11-11T03:30:14.030 回答