Activate Portrait Effects using depth data

I started with this code :session 507 WWDC 2017
and I use this tutorial : ray tutorial

In iOS camera Roll I can activate “Portrait effect” during the editing of the image taken from my app.
Now I want to know how can I save directly the picture with this effect already activated?

I think my code is right because I can save the depth metadata.

I activate the bool in session configuration

self.photoOutput.depthDataDeliveryEnabled = YES;

and in capture output session I update the settings:

photoSettings.depthDataDeliveryEnabled = self.photoOutput.isDepthDataDeliveryEnabled;

and this is in my delegate :

  • (void)captureOutput:(AVCapturePhotoOutput *)captureOutput didFinishProcessingPhoto:(AVCapturePhoto *)photo error:(nullable NSError *)error
    {
    if ( error != nil ) {
    NSLog( @“Error capturing photo: %@”, error );
    return;
    }

    self.photoData = [photo fileDataRepresentation];

}

but I do not understand why in system camera roll I don’t have the " portrait badge", but It only appears during the editing :

So how can I save my photo with the portrait effect activated?

Thanks a lot

@toojuice Can you please help with this when you get a chance? Thank you - much appreciated! :]

Hi @fulof

You need to use the depth data to filter the original image manually. I don’t think there are any APIs that automatically bring up the Apple portrait mode filters. They are available in the Photos app for any images saved with depth data, but not available to your app.

You can recreate their effects using CIFilters as I discussed in the tutorial you pointed to. Then you could save the image after filtering.

This topic was automatically closed after 166 days. New replies are no longer allowed.