BradLarson / GPUImage

An open source iOS framework for GPU-based image and video processing
http://www.sunsetlakesoftware.com/2012/02/12/introducing-gpuimage-framework
BSD 3-Clause "New" or "Revised" License
20.24k stars 4.61k forks source link

ChromaKeyBlendFilter stretching #2613

Closed allenkiehl closed 5 years ago

allenkiehl commented 5 years ago

I am using the GPUImageChromaKeyBlendFilter and getting undesired output. I either have my camera input correct, or my background image thats blending not both. I have a view size of 930, 620, and my background image is 1200x800 which scales to 930x620 while maintaining aspect ratio.

filter = GPUImageChromaKeyBlendFilter() filter?.setColorToReplaceRed(0.0, green: 1.0, blue: 0.0) filter?.thresholdSensitivity = CGFloat(effectSlider) filter?.thresholdSensitivity = 0.40 filter?.smoothing = 0.14

If I use the below the backround image shows correctly, however, the preview of the image is stretched, if I remove preview image is correct, but background is skewed. filter?.forceProcessing(at: overlayImage.frame.size) (the overlay is again 1200x800/930x620)

I am using kGPUImageFillModePreserveAspectRatioAndFill, any help would be appreciated.

allenkiehl commented 5 years ago

I am using the method below to filter

greenscreenCamera = GPUImageStillCamera(sessionPreset: AVCaptureSession.Preset.photo, cameraPosition: .back)

filter = GPUImageChromaKeyBlendFilter() filter?.setColorToReplaceRed(0.0, green: 1.0, blue: 0.0) filter?.thresholdSensitivity = CGFloat(effectSlider) filter?.thresholdSensitivity = 0.40 filter?.smoothing = 0.14 gpuImage.fillMode = kGPUImageFillModePreserveAspectRatioAndFill

greenscreenCamera?.addTarget(filter) backgroundPicture!.addTarget(filter) filter?.addTarget(gpuImage) backgroundPicture!.processImage() greenscreenCamera?.startCapture()

@BradLarson any ideas?