gpt4 book ai didi

iphone - 如何对 CVImageBufferRef 视频帧进行操作

转载 作者:行者123 更新时间:2023-11-29 13:07:39 26 4
gpt4 key购买 nike

- (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 );
}

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

非常感谢

最佳答案

亮度可以表示为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;
}

关于iphone - 如何对 CVImageBufferRef 视频帧进行操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18225672/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com