我有兩個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?感謝
你有沒有想過在摺疊之前得到了多少? –
第一個循環............ – SpaceDog
您是否驗證過您收到的地址甚至有效?使用調試器來顯示它們是什麼以及它們指向什麼? –