在基本的GPUImage2相机设置中从未调用过imageAvailableCallback [英] imageAvailableCallback never called in basic GPUImage2 camera setup
问题描述
我已按照GPUImage2的github上的基本设置说明进行操作,过滤实时视频和从视频中捕获图像只是为了设置基本的相机。当用户点击按钮时,我尝试使用以下代码专门从过滤器捕获图像:
I have followed the basic setup instructions on GPUImage2's github for filtering live video and capturing an image from video just so I can setup a basic camera. When the user taps a button, I try to capture the image from the filter using this code specifically:
let pictureOutput = PictureOutput()
pictureOutput.encodedImageFormat = .JPEG
pictureOutput.imageAvailableCallback = {image in
// Do something with the image
self.previewImageView.image = image
}
self.filter! --> pictureOutput
无论出于何种原因,都不会调用imageAvailableCallback,并且无法从摄像机获取图像。
For whatever reason, the imageAvailableCallback is never called and I am unable to get the image from the camera.
推荐答案
->
调用 addTarget
和 addTarget
附加到目标( TargetContainer
),后者附加弱引用。因此,您应该确保目标在回调中可用。例如,只需将pictureOutput变量放在类的顶部。
The -->
calls addTarget
and addTarget
appends to targets (TargetContainer
) which appends a weak reference. So you should make sure the target will be available on callback. For example just place the pictureOutput variable at the top of your class.
这篇关于在基本的GPUImage2相机设置中从未调用过imageAvailableCallback的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!