检查CVPixelBufferRef的最有效方法是什么?有白色像素?

时间:2017-07-07 05:49:29

标签: ios objective-c cvpixelbuffer

检查CVPixelBufferRef的最有效方法是什么?有白色像素?

下面是我正在使用的代码,但是当照片明显有白色像素时,它不会返回白色像素。

const int kBytesPerPixel = 4;
        CVPixelBufferLockBaseAddress( pixelBuffer, 0 );
        int bufferWidth = (int)CVPixelBufferGetWidth( pixelBuffer );
        int bufferHeight = (int)CVPixelBufferGetHeight( pixelBuffer );
        size_t bytesPerRow = CVPixelBufferGetBytesPerRow( pixelBuffer );
        uint8_t *baseAddress = CVPixelBufferGetBaseAddress( pixelBuffer );


        int count = 0;
        BOOL hasWhitePixels = NO;
        for ( int row = 0; row < bufferHeight; row++ ){
            uint8_t *pixel = baseAddress + row * bytesPerRow;
            for ( int column = 0; column < bufferWidth; column++ ){
                if (pixel[0] == 255 && pixel[1] == 255 && pixel[2] == 255) {
                    count++;
                    hasWhitePixels = YES;
                    NSLog(@"HAS WHITE PIXELS");
                    break;
                }
                pixel += kBytesPerPixel;

            }
        }

        CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );

0 个答案:

没有答案