【问题标题】:how to do manipulation on CVImageBufferRef video frame如何对 CVImageBufferRef 视频帧进行操作
【发布时间】:2013-08-16 01:08:55
【问题描述】:
- (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 );
}

我的问题是如何操作像素,使所有亮色变为黄色,所有暗色变为蓝色

非常感谢你

【问题讨论】:

    标签: iphone ios image-processing


    【解决方案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;
     }       
    

    【讨论】:

      猜你喜欢
      • 2020-06-04
      • 2013-11-04
      • 1970-01-01
      • 2011-05-10
      • 1970-01-01
      • 1970-01-01
      • 2023-04-07
      • 2018-08-25
      • 1970-01-01
      相关资源
      最近更新 更多