狠狠撸

狠狠撸Share a Scribd company logo
Depth in Depth
Shuichi Tsutsumi @shu223
iOSDC 2018
? Fyusion Inc. @ H-1B
? Senior Principal Software Engineer
? →
? @
? 8 IoT
Metal ARKit NFC etc...
? GitHub: shu223
? : Qiita Note
? :
Depth in Depth #iOSDC
Depth in Depth
Depth in Depth #iOSDC
1
RGB
Depth in Depth #iOSDC
?
:
?
Depth in Depth #iOSDC
: 3D
? 3D
?
:
30
※
Depth in Depth #iOSDC
? iOS API
?
?
?
?
?
?
?
?
?
?
Disparity
iPhone 7/8 Plus, X
Depth in Depth #iOSDC
Focal Length
Disparity
Depth Disparity
Depth Disparity
? Depth(z) = Disparity(d)
Time of Flight (ToF)
? Depth
?
TrueDepth
iPhone X
? Proximity sensor ToF
? Dot projector ( ) 3
? Infrated camera ( )
→
?
?
?
?
AVDepthData
?
?
? @available(iOS 11.0, *)
AVDepthData
var depthDataMap: CVPixelBuffer { get }
?
? CVPixelBuffer Core Image
Metal
iOS
? 1:
? 2:
? 3: ARKit
1:
? ImageIO
? URL
Photos
URL CGImageSource
let source = CGImageSourceCreateWithURL(url as CFURL, nil)
CGImageSource Dictionary
let info = CGImageSourceCopyAuxiliaryDataInfoAtIndex(
source, 0,
kCGImageAuxiliaryDataTypeDisparity //
) as? [String : AnyObject]
// info CFDataRef
// CGImageMetadataRef
Dictionary AVDepthData
let depthData =
try! AVDepthData(fromDictionaryRepresentation: info)
2:
? AVFoundation
?
AVCaptureDevice
.builtInDualCamera, .builtInTrueDepthCamera
let device = AVCaptureDevice.DiscoverySession(
deviceTypes: [.builtInDualCamera],
mediaType: .video,
position: .back).devices.first
var supportedDepthDataFormats: [AVCaptureDevice.Format]
? AVCaptureDevice.Format
? AVCaptureDevice
activeDepthDataFormat
AVCaptureDepthDataOutput
let depthOutput = AVCaptureDepthDataOutput()
captureSession.addOutput(depthOutput)
depthOutput.setDelegate(
self, callbackQueue: dataOutputQueue)
? AVCaptureVideoDataOutput
AVCaptureAudio
AVCaptureDepthDataOutputDelegate didOutput
AVDepthData
func depthDataOutput(
_ output: AVCaptureDepthDataOutput,
didOutput depthData: AVDepthData,
timestamp: CMTime,
connection: AVCaptureConnection)
3:
ARKit
ARFrame capturedDepthData
var capturedDepthData: AVDepthData? { get }
?
? 1:
? 2:
? 3: ARKit
?
?
?
?
Depth in Depth #iOSDC
Depth in Depth #iOSDC
? chroma
CIBlendWithMask
Parameters
inputImage
inputBackgroundImage
inputMaskImage
?
? CIFilter Metal
OK!?
?
? CIFilter CIBlendWithMask
? Metal MTKView
Depth in Depth #iOSDC
Depth in Depth #iOSDC
Depth in Depth #iOSDC
Depth in Depth #iOSDC
Depth in Depth #iOSDC
?
Depth in Depth #iOSDC
?
2
? AVCaptureMetadataOutput
? +offset
cutOff
?
? cutOff
? cutOff
Depth in Depth #iOSDC
Depth in Depth #iOSDC
?
? "Holes"
?
? Holes RGB
isFilteringEnabled
? AVCaptureDepthDataOutput
?
? "Holes" RGB
Depth in Depth #iOSDC
Depth in Depth #iOSDC
Depth in Depth #iOSDC
Depth in Depth #iOSDC
?
?
Portrait Matte
Portrait Matte
?
? iOS 12
Portrait Matte
Depth in Depth #iOSDC
? CGImageSource
? PortraitEffectsMatte
? AVDapthData AVPortraitEffectsMatte
guard let info = CGImageSourceCopyAuxiliaryDataInfoAtIndex(
self, 0,
kCGImageAuxiliaryDataTypePortraitEffectsMatte
) as? [String : AnyObject] else { return }
let matte =
AVPortraitEffectsMatte(fromDictionaryRepresentation: info)
Depth in Depth #iOSDC
Depth in Depth #iOSDC
Portrait Matte
?
?
? iOS 12
?
?
?
?
? / / ARKit
? Dual / TrueDepth /
? /
? iOS 12 / 11 /
? / /
Depth in Depth #iOSDC
Depth in Depth #iOSDC
Photoshop
?
? Portrait Matte
? Portrait Matte
?
? Portrait Matte
? Disprity
?
?
ARKit
? OK
? NG
? ARFaceTrackingConfiguration
?
ARWorldTracking capturedDepth nil
?
?
?
?
? Twitter: https://twitter.com/shu223
? GitHub: https://github.com/shu223
? : http://shu223.hatenablog.com/
Depth in Depth #iOSDC
Depth in Depth #iOSDC
AVCaptureDataOutputSynchronizer
//
synchronizer = AVCaptureDataOutputSynchronizer(
dataOutputs: [videoOutput, depthOutput])
AVCaptureDataOutputSynchronizerDelegate
didOutput
AVCaptureSynchronizedDataCollection
? → AVCaptureSynchronizedDepthData
? → AVDepthData
// AVCaptureSynchronizedDepthData
if let syncedDepthData =
synchronizedDataCollection.synchronizedData(for: depthOutput)
as? AVCaptureSynchronizedDepthData,
!syncedDepthData.depthDataWasDropped
{
// AVDepthData
let depthData = syncedDepthData.depthData
...
}
Metal 3D
Depth in Depth #iOSDC
?
? z
?
? RGB

More Related Content

Depth in Depth #iOSDC