Syntactic sugar for displaying CIImage using OpenGL and grabbing CIImages from iOS cameras
CoreImageHelpers
contains two classes to wrap up all the boilerplate code required for:
ImageView
for displayingCIImage
instances with OpenGL and skipping the extraUIImage
stepCameraCaptureHelper
for grabbing a series ofCIImage
instances from either the front or back camera.
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
}
}
Simply copy one or both of ImageView
and CameraCaptureHelper
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!