Question

I'm using AVFoundationFramework to show preview from camera. I do it like that:

self.previewLayer = [AVCaptureVideoPreviewLayer layerWithSession:session];
self.previewLayer.frame = cameraPreview.bounds;
self.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
[self.previewLayer.connection setVideoOrientation:AVCaptureVideoOrientationPortrait];

[cameraPreview.layer addSublayer:previewLayer];

cameraPreview is simple UIView. It works like a charm but I need to have blur on this preview. Is there any build-in feature on AVFoundationFramework? If not how can I do such blur?

Was it helpful?

Solution

Should use GPUImage - https://github.com/BradLarson/GPUImage - for this. Runs on GPU so it is fast enough I think. You'll need convert UIImages from CMSampleBuffers that AVCaptureSession spits out. This - https://github.com/eppz/eppz.capture/blob/master/eppz!capture/EPPZCaptureBufferParser.m#L81 - may help.

// Create filter.
self.blurFilter = [GPUImageiOSBlurFilter new];

// Apply filter.
UIImage *blurredSnapshotImage = [self.blurFilter imageByFilteringImage:snapshotImage];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top