CoreImageHelpers
CoreImageHelpers copied to clipboard
Syntactic sugar for displaying CIImage using OpenGL and grabbing CIImages from iOS cameras
CoreImageHelpers
Syntactic sugar for displaying CIImage using OpenGL and grabbing CIImages from iOS cameras
Introduction
CoreImageHelpers contains two classes to wrap up all the boilerplate code required for:
ImageViewfor displayingCIImageinstances with OpenGL and skipping the extraUIImagestepCameraCaptureHelperfor grabbing a series ofCIImageinstances from either the front or back camera.
Implementation
The project contains a demonstration that applies a Crystallize filter to the camera feed and displays full screen. The code is super simple:
class ViewController: UIViewController, CameraCaptureHelperDelegate
{
let imageView = ImageView()
let cameraCaptureHelper = CameraCaptureHelper(cameraPosition: .Front)
let crystallize = CIFilter(name: "CICrystallize",
withInputParameters: [kCIInputRadiusKey: 30])!
override func viewDidLoad()
{
super.viewDidLoad()
view.addSubview(imageView)
cameraCaptureHelper.delegate = self
}
override func viewDidLayoutSubviews()
{
imageView.frame = view.bounds.insetBy(dx: 50, dy: 50)
}
func newCameraImage(cameraCaptureHelper: CameraCaptureHelper, image: CIImage)
{
crystallize.setValue(image, forKey: kCIInputImageKey)
imageView.image = crystallize.outputImage
}
}
Installation
Simply copy one or both of ImageView and CameraCaptureHelper
Further Information
This project is a companion to my upcoming book, Core Image for Swift, follow me on Twitter where I am @FlexMonkey to keep up to date with developments!