GPUImage icon indicating copy to clipboard operation
GPUImage copied to clipboard

Camera zooming

Open peterhwong opened this issue 14 years ago • 5 comments

Hey Brad, I'm trying to implement zooming just like the Camera app with pinching in and out. After looking at Apple sample code, I see they use setVideoScaleAndCropFactor to do this. However the GPUImageFramework doesn't have a AVCaptureVideoPreviewLayer. Looking further into past issues, you mentioned the CropFilter. Is this what I should use instead? And it gives the same results as the Camera app?

Thanks! Peter

peterhwong avatar Sep 05 '12 19:09 peterhwong

Yes, the crop filter should achieve pretty much the same sort of "digital zooming" that you get with the built-in camera. That just ends up being interpolation.

If you want to get really fancy, you could try using a GPUImageLanczosResamplingFilter with -forceProcessingAtSize: to upsample the image first, then crop out the section you want. Lanczos resampling yields a much cleaner up- or downsampled image.

BradLarson avatar Sep 05 '12 20:09 BradLarson

Awesome. Thanks a lot Brad!

peterhwong avatar Sep 05 '12 21:09 peterhwong

Hi Brad, I'm having some issues with the crop filter. I'm experiencing a crash due to low memory when using this filter. After some investigating I've found that the crop filter does not enforce the size I specified in forceProcessingAtSize. I am using forceProcessingAtSize to reduce the memory needed when applying a large filterGroup. I see in GPUImageCropFilter's setInputSize, the code to overrideInputSize is commented out. So I'm not sure how the size from forceProcessingAtSize should behave with the cropRegion. Plus it seems the fbosize doesn't always get recreated in the case of overrideInputSize(even in GPUImageFilter). Is that right? When and why is the size ever set to CGSizeZero?

Thanks Peter

On Sep 5, 2012, at 1:04 PM, Brad Larson wrote:

Yes, the crop filter should achieve pretty much the same sort of "digital zooming" that you get with the built-in camera. That just ends up being interpolation.

If you want to get really fancy, you could try using a GPUImageLanczosResamplingFilter with -forceProcessingAtSize: to upsample the image first, then crop out the section you want. Lanczos resampling yields a much cleaner up- or downsampled image.

— Reply to this email directly or view it on GitHub.

peterhwong avatar Sep 07 '12 18:09 peterhwong

This is a known bug with that filter. See issue #362. I'm trying to fix it.

BradLarson avatar Sep 07 '12 18:09 BradLarson

@BradLarson instead of zooming, how does one get the crop filter to behave more like a mask, preserving the original size of the cropped region? related to #679

stevegraham avatar Dec 03 '12 06:12 stevegraham