1

检查 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 );
4

0 回答 0