gpt4 book ai didi

ios - 带有核心图像过滤器的 EAGLContext

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:46:55 24 4
gpt4 key购买 nike

我想将图像实时添加到摄像机视频源中,但只需要显示它们,不需要保存。如果我使用标准的 Core Image 程序,它工作正常,但我需要更多的帧速率。但是,如果我取消注释此代码并在接下来进行注释,则不会。 OpenGLView 只是一个带有方法的 UIView 子类

+(Class)layerClass {
return [CAEAGLLayer class];
}

//Working code
EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
NSDictionary *options = @{ kCIContextWorkingColorSpace : [NSNull null] };
CIContext *context = [CIContext contextWithEAGLContext:myEAGLContext options:options];
UIImage* foto = [UIImage imageNamed:@"foto2.jpg"];
UIImage* foto2 = [UIImage imageNamed:@"foto_no_ok.png"];
CIImage *backgroundImage = [[CIImage alloc]initWithImage:foto];
CIImage *foregroundImage = [[CIImage alloc]initWithImage:foto2];
CIFilter *myFilter = [CIFilter filterWithName:@"CISourceOverCompositing" keysAndValues: kCIInputImageKey, foregroundImage, kCIInputBackgroundImageKey, backgroundImage, nil];
CIImage* resultingImage = [myFilter outputImage];

/* Not working code, GPU processing
self.view = [[OpenGLView alloc]initWithFrame:self.view.frame];
[self.view setOpaque:YES];
[self.view setFrame:CGRectMake(0, 0, 500, 500)];
[context drawImage:resultingImage inRect:self.view.bounds fromRect:self.view.bounds];
*/

//Working code, CPU processing
CGRect extent = [resultingImage extent];
CGImageRef cgImage = [context createCGImage:resultingImage fromRect:extent];
UIImage* myImage = [[UIImage alloc]initWithCGImage:cgImage];
self.myImageView.image = myImage;
CFRelease(cgImage);

缺少什么?我做错了什么?非常感谢。

最佳答案

好吧,我终于明白了。记住不要将此代码放在 viewDidLoad: 中。图像需要一些工作,但那是另一个话题。

EAGLContext *myEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
NSDictionary *options = @{ kCIContextWorkingColorSpace : [NSNull null] };
self.context = [CIContext contextWithEAGLContext:myEAGLContext options:options];
[EAGLContext setCurrentContext:myEAGLContext];
self.visorOpenGLView.context = myEAGLContext;

UIImage* foto = [UIImage imageNamed:@"onepic.jpg"];
UIImage* foto2 = [UIImage imageNamed:@"anotherpic.png"];
CIImage *backgroundImage = [[CIImage alloc]initWithImage:foto];
CIImage *foregroundImage = [[CIImage alloc]initWithImage:foto2];
CIFilter *myFilter = [CIFilter filterWithName:@"CISourceOverCompositing" keysAndValues: kCIInputImageKey, foregroundImage, kCIInputBackgroundImageKey, backgroundImage, nil];
self.resultingImage = [myFilter outputImage];
UIImage* result = [UIImage imageWithCIImage:self.resultingImage];
self.resultingImageView.image = result;

CGRect ext = [foregroundImage extent];
[self.visorOpenGLView bindDrawable];
[self.context drawImage:self.resultingImage inRect:self.visorOpenGLView.frame fromRect:ext];
[self.visorOpenGLView display];

关于ios - 带有核心图像过滤器的 EAGLContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21083984/

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