This sample code uses Portrait Effects Matte added from iOS 12 as a mask image to extract only people.
This app requires a portrait photo. So you need an iPhone that supports dual camera (e.g. iPhone 8 Plus) or a True Depth camera (e.g. IPhone X). After shooting a human in portrait mode, please try this app.
#1 Open PortraitEffectsMatteSample.xcodeproj, Build, Run.
#2 Select “Select portrait photo” button
#3 Select a portrait photo taken in advance .
#4 The masked photo is displayed at the top of the screen.The selected photo is displayed at the lower left of the screen, and Portrait Effects Matte is displayed at the lower right of the screen.
#5 You can change the background to transparent, white, or black in the UISegmentedControl below the masked image.
#6 Press the Save button at the top left of the screen to save the masked photo in "Photos".
#7 Press the upper right share button to display the share screen.