GPUImage色度键过滤器 [英] GPUImage Chroma Key filter

查看:283
本文介绍了GPUImage色度键过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用GPUImage框架的chromakey过滤器。我按照Filtershowcase示例,但显然我错过了一些东西,因为它只显示视频,但没有绿屏幕键效果。这是我的视频摄像头/过滤器的初始化:

I am trying to use the GPUImage framework's chromakey filter. I followed the Filtershowcase example, but obviously I am missed something becuase it only shows the video, but no green screen keying out effect. Here's my initialization of video camera/filter:

camera = [[GPUImageStillCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480
                                             cameraPosition:AVCaptureDevicePositionBack];
camera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft;
camera.horizontallyMirrorFrontFacingCamera = NO;
camera.horizontallyMirrorRearFacingCamera = NO;


chromaKeyFilter = [[GPUImageChromaKeyFilter alloc] init];
chromaKeyFilter.thresholdSensitivity = sliderThres.value;

UIImage *inputImage = [UIImage imageNamed:@"WID-small.jpg"];


GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage
                                                    smoothlyScaleOutput:YES];


[camera addTarget:chromaKeyFilter];
[sourcePicture addTarget:chromaKeyFilter];
[sourcePicture processImage];

[chromaKeyFilter addTarget:viewCamera];


[camera startCameraCapture];

所以camera和sourcePicture都进入过滤器,比viewCamera过滤。但现在,我只看到平原的视频,没有chromakey效果。 (我有一个滑块来改变阈值)。

So camera and sourcePicture both feed into the filter, filter than goes into viewCamera. But right now, I only see the plain video, no chromakey effect. (I have a slider that alters the threshold).

UPDATED 与GPUImageChromaKeyBlendFilter

UPDATED with GPUImageChromaKeyBlendFilter

camera = [[GPUImageVideoCamera alloc] initWithSessionPreset:AVCaptureSessionPreset640x480 cameraPosition:AVCaptureDevicePositionBack];
camera.outputImageOrientation = UIInterfaceOrientationLandscapeLeft;
chromaKeyFilter = [[GPUImageChromaKeyBlendFilter alloc] init];


UIImage *inputImage;
inputImage = [UIImage imageNamed:@"WID-small.jpg"];
GPUImagePicture *sourcePicture = [[GPUImagePicture alloc] initWithImage:inputImage smoothlyScaleOutput:YES];


[camera addTarget:chromaKeyFilter];
[sourcePicture processImage];
[sourcePicture addTarget:chromaKeyFilter];
[chromaKeyFilter addTarget:viewCamera];

[camera startCameraCapture];

使用此过滤器,只需将其替换为黑色,而不是实际图像。

With this filter, it simply replaced it with black, not the actual image.

推荐答案

经过几天的尝试后发现这个宝石.... 。显然,你假设要挂在(强ref)到GPUImagePicture。我的印象是,内部的过滤器链将有一个强的引用,但事实并非如此。保持它作为实例var解决了这个问题。

Found this gem after a couple of days of trying..... Apparently you are suppose to hang on (strong ref) to GPUImagePicture. I was under the impression that the filter chain internally would have a strong reference, but that's not the case. Keeping it as instance var solved the problem.

这篇关于GPUImage色度键过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆