Portrait-without-Depth-ios
try! Swift 2019 demo app that converts Depth-less 2D images into Portrait mode.
How to build
- Download
opencv2.frameworkfrom here v3.4.5, then put it into this folder. - Open
Portrait.xcworkspacewith Xcode 10.x and build it
About this app
In iOS’s Portrait mode, you can take beautiful photos that keep your subject sharp while blurring the background.
This so-called bokeh effect can be done by using Depth.
In contrast, this app attempts to make Depth-less 2D images into Portrait mode by following steps.
1. Segmentation ✂️
This app uses “GrabCut” to perform segmentation of the subject and the background.
GrabCut with Rect

GrabCut with Mask

2. Color leak prevention ?
As it’s not beautiful if the subject color leaks into the background, this app tries to delete the subject from the background by using “Inpainting”.
Blur & Inpainting

3. Depth-of-Field ?
“Depth-of-Field” is the range where the photo is in focus.
I implemented an adjusting function to blur an area.
Adjust

Result✨
before ← → after

Please give it a try !
Requirement
Xcode 10.x
iOS 12.0+