gpt4 book ai didi

iphone - 有人有 iOS 上 vImage 处理的示例代码吗?

转载 作者:行者123 更新时间:2023-12-02 01:21:06 25 4
gpt4 key购买 nike

我已经阅读了我能找到的所有文档,但无法让简单的 vImage 调用起作用。我只需要一个真实的例子。文档非常稀疏。

最佳答案

如果您正在实时处理视频,并且您的输入是在像素缓冲区中处理的,则以下是如何将该缓冲区复制到 vImage 中,此时您可以调用您喜欢的任何命令:

- (CVPixelBufferRef)copyRenderedPixelBuffer:(CVPixelBufferRef)pixelBuffer
{
CVPixelBufferLockBaseAddress( pixelBuffer, 0 );

// vImage processing
vImage_Error err;
vImage_Buffer buffer;
buffer.data = (unsigned char *)CVPixelBufferGetBaseAddress( pixelBuffer );
buffer.rowBytes = CVPixelBufferGetBytesPerRow( pixelBuffer );
buffer.width = CVPixelBufferGetWidth( pixelBuffer );
buffer.height = CVPixelBufferGetHeight( pixelBuffer );
vImageCVImageFormatRef vformat = vImageCVImageFormat_CreateWithCVPixelBuffer( pixelBuffer );
vImage_CGImageFormat cgformat = {
.bitsPerComponent = 8,
.bitsPerPixel = 32,
.bitmapInfo = kCGBitmapByteOrderDefault,
.colorSpace = NULL, //sRGB
};
const CGFloat bgColor[3] = {0.0, 0.0, 0.0};
vImageBuffer_InitWithCVPixelBuffer(&buffer, &cgformat, pixelBuffer, vformat, bgColor, kvImageNoAllocate);

vImage_Buffer outbuffer;
void *tempBuffer;
tempBuffer = malloc(CVPixelBufferGetBytesPerRow( pixelBuffer ) * CVPixelBufferGetHeight( pixelBuffer ));
outbuffer.data = tempBuffer;
outbuffer.rowBytes = CVPixelBufferGetBytesPerRow( pixelBuffer );
outbuffer.width = CVPixelBufferGetWidth( pixelBuffer );
outbuffer.height = CVPixelBufferGetHeight( pixelBuffer );

err = vImageEqualization_ARGB8888(&buffer, &outbuffer, kvImageNoFlags);

if(err != -1)
err = vImageContrastStretch_ARGB8888(&buffer, &outbuffer, kvImageNoFlags);

if(err != -1)
err = vImageBuffer_CopyToCVPixelBuffer(&outbuffer, &cgformat, pixelBuffer, vformat, bgColor, kvImageNoFlags);

if(err != -1)
free(tempBuffer);

CVPixelBufferUnlockBaseAddress( pixelBuffer, 0 );

return (CVPixelBufferRef)CFRetain( pixelBuffer );
}

关于iphone - 有人有 iOS 上 vImage 处理的示例代码吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4402152/

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