2
- (void)processPixelBuffer: (CVImageBufferRef)pixelBuffer 
{
    CVPixelBufferLockBaseAddress( pixelBuffer, 0 );

    int bufferWidth = CVPixelBufferGetWidth(pixelBuffer);
    int bufferHeight = CVPixelBufferGetHeight(pixelBuffer);
    unsigned char *pixel = (unsigned char *)CVPixelBufferGetBaseAddress(pixelBuffer);

    for( int row = 0; row < bufferHeight; row++ ) {     
        for( int column = 0; column < bufferWidth; column++ ) {
            pixel[1] = 0; //  it sets the green element of each pixel to zero, which gives the entire frame a purple tint.
            pixel += 4;
        }
    }

    CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );
}

我的问题是我怎样才能操纵像素如此黑暗所有明亮的颜色变成黄色和所有黑暗的颜色变成蓝色

太感谢了

4

1 回答 1

1

亮度可以表示为 Y = 0.2126 R + 0.7152 G + 0.0722 B

 float threshold = 122; // for example
 float luma = 0.2126*pixel[0]+0.7152*pixel[1]+0.0722*pixel[2];
 if(luma>threshold){
   pixel[0]=255;
   pixel[1]=255;
   pixel[2]=0;
 }else{
   pixel[0]=0;
   pixel[1]=0;
   pixel[2]=255;
 }       
于 2013-08-14T18:43:12.333 回答