Green Screen in Swift & PixelKit

In this tutorial you can use a live camera feed or just a video file, either works.

Setup your project with PixelKit in this tutorial.

First add the camera:

let content = CameraPIX()

or your video:

let content = VideoPIX()
content.load(fileNamed: "superman", withExtension: "mov")

Then we need a background image:

let image = ImagePIX()
image.image = UIImage(named: "city")

Remember to add your photo to the Assets in Xcode.

Now let’s key the green screen away:

let key = ChromaKeyPIX()
key.input = content
key.keyColor = .green

Then finally we blend the content and the image together:

let blend = BlendPIX()
blend.blendingMode = .over
blend.inputA = image
blend.inputB = key

To view the final result:

let final: PIX = blend
final.view.frame = view.bounds

That’s it, now you can chroma key!

Lämna en kommentar

E-postadressen publiceras inte. Obligatoriska fält är märkta *