2

I've created a simple green screen with GPUImage library and the following code:

import UIKit
import GPUImage


class CaptureViewController: UIViewController {

  var videoCamera:GPUImageVideoCamera?
  var filter:GPUImageChromaKeyFilter?

@IBOutlet weak var cameraView: GPUImageView!

override func viewDidLoad() {
    super.viewDidLoad()
    cameraView.backgroundColor = UIColor.clearColor()
    videoCamera = GPUImageVideoCamera(sessionPreset: AVCaptureSessionPreset640x480, cameraPosition: .Back)
    videoCamera!.outputImageOrientation = .Portrait;
    filter = GPUImageChromaKeyFilter()
    filter?.setColorToReplaceRed(0.0, green: 1.0, blue: 0.0)
    filter?.thresholdSensitivity = 0.4
    videoCamera?.addTarget(filter)
    filter?.addTarget(cameraView)
    videoCamera?.startCameraCapture()
}

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
}
}

Now I want to change the color from green to where ever the user taps on the video.

Q: How can I get the pixel data from the tapped location?

Léo Natan
  • 56,823
  • 9
  • 150
  • 195
Shlomi Schwartz
  • 8,693
  • 29
  • 109
  • 186

1 Answers1

2

Is your question how do you get the touch point in the view (override touchesEnded and look at touch.locationInView) or how do you read back the pixel values at or around that point?

The answer to the latter is that he GPUImage project has an example called RawDataTest that shows you how to read the RGBA values for arbitrary pixels in a view from the GPU.

https://github.com/BradLarson/GPUImage/tree/master/examples/iOS/RawDataTest/RawDataTest

Josh Homann
  • 15,933
  • 3
  • 30
  • 33