从GPUImageVideoCamera获取像素颜色

时间:2016-01-19 15:19:39

标签: ios swift gpuimage chromakey

我用GPUImage库和以下代码创建了一个简单的绿色屏幕:

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)
}
}

现在我想将颜色从绿色更改为用户点按视频的位置。

:如何从分接位置获取像素数据?

1 个答案:

答案 0 :(得分:2)

您的问题是如何在视图中获得触摸点(覆盖touchesEnded并查看touch.locationInView),或者如何读回该点或其周围的像素值?

后者的答案是他的GPUImage项目有一个名为RawDataTest的例子,它向您展示如何从GPU中读取视图中任意像素的RGBA值。

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