Slide 1

Slide 1 text

Depth APIͰ؆қΫϩϚΩʔ߹੒ GEEK GARAGE iOS vol3 2017/06/27 1

Slide 2

Slide 2 text

Profile Kazuya Ueoka Timers inc.ͷiOSΤϯδχΞ Twitter: @fromkk Github: fromkk Qiita: fromkk 2

Slide 3

Slide 3 text

WWDC 2017ʹߦͬͯདྷ·ͨ͠✈ ϒϩά͍͔ͭ͘ॻ͍ͨͷͰΑ͔ͬͨΒ؍ͯͶ! http://techblog.timers-inc.com/archive/category/ wwdc2017 3

Slide 4

Slide 4 text

ΫϩϚΩʔ߹੒ — ฐࣾͷݕ౼தࢪࡦͷதʹΫϩϚ Ωʔ߹੒͕ඞཁͳ෺͕͋ͬͨ — ࣸਅͷಛఆ৭ͷ෦෼ΛಁԽͯ͠എ ܠը૾ͱ߹੒(άϦʔϯόοΫ) — Ϣʔβʔ͕Ξοϓϩʔυ͢Δࣸਅ ͷഎܠ͕Ұ৭͚ͩͳΜͯ΄΅օແ ը૾ૉࡐ:εϚʔτϑΥϯͰࠓ໷ͷҿ ΈձΛ༧໿ʢάϦʔϯόοΫʣ 4

Slide 5

Slide 5 text

ͦΜͳத 5

Slide 6

Slide 6 text

WWDC 2017ͰDepth Api͕ެ։͞Ε·ͨ͠! 6

Slide 7

Slide 7 text

Sessions — 507 Capturing Depth in iPhone Photography — 508 Image Editing with Depth 7

Slide 8

Slide 8 text

Depthͱ͸ — iPhone 7 PlusͷϙʔτϨʔτϞʔυͰࡱӨͨࣸ͠ਅ͔Β Ͱऔಘग़དྷΔ෺ମͷڑ཭ — ϙʔτϨʔτࡱӨͰ͸ԕ͘ʹ͍͘ʹ࿈Εͯڧ͍΅͔͠Τ ϑΣΫτΛೖΕ͍ͯΔ( CIDepthBlurEffect ) 8

Slide 9

Slide 9 text

Disparityͱ͸ — ೔ຊޠͰ͸֨ࠩ — ਂ౓Λը૾Ͱදݱͨ͠෺ͱউखʹղऍ 9

Slide 10

Slide 10 text

͕ 10

Slide 11

Slide 11 text

ରԠ୺຤ iPhone 7 Plus iOS 11Ҏ্ ͷΈ! 11

Slide 12

Slide 12 text

࢖͍͔ͨͬͨͷͰ ϝΠϯ࢖༻͍ͯ͠ΔiPhone 7 PlusʹiOS 11 betaΛΠϯε τʔϧ͠·ͨ͠! 12

Slide 13

Slide 13 text

ݪཧ — 2ͭͷΧϝϥͰࡱӨͨ͠ಛఆͷ2 ఺ͷڑ཭͕͍ۙํ͕खલɾ཭Εͯ Δํ͕Ԟ — σΟʔϓϥʔχϯάͷٕज़Λར༻ ͍ͯ͠ΔΒ͍͠ʢಛ௃఺ͷந ग़ʁʣ 13

Slide 14

Slide 14 text

੍ݶࣄ߲ — iOS 11ͰࡱӨͨ͠ը૾͔Β͔͠Disparity͕औಘग़དྷͳ͍ — HEIFϑΥʔϚοτͷΈରԠ 14

Slide 15

Slide 15 text

HEIF — iOS 11͔ΒରԠͨ͠৽͍͠ը૾ϑΥʔϚοτ — ͍ܰʂ — Alphaνϟϯωϧ/Depth/ΞχϝʔγϣϯରԠ — λΠϧಡΈࠐΈରԠ — etc... 15

Slide 16

Slide 16 text

More info about HEIF — 503 Introducing HEIF and HEVC — 513 High Efficiency Image File Format 16

Slide 17

Slide 17 text

Disparityը૾ͷऔಘ — طʹࡱӨͨࣸ͠ਅ͔Βऔಘ — PhotoKitΛར༻ let asset: PHAsset = ... asset.requestContentEditingInput(with: nil) { (input, info) in guard let imageURL: URL = input?.fullSizeImageURL else { return } if let disparityImage: CIImage = CIImage(contentsOf: imageURL, options: [kCIImageAuxiliaryDisparity: true]) { self.disparityImageView.image = UIImage(ciImage: disparityImage) } } 17

Slide 18

Slide 18 text

ͪͳΈʹ self.asset.requestContentEditingInput(with: nil) { (input, info) in guard let imageURL: URL = input?.fullSizeImageURL else { return } guard let source = CGImageSourceCreateWithURL(imageURL as CFURL, nil) else { return } guard let sourceProperties = CGImageSourceCopyProperties(source, nil) else { return } print(sourceProperties) } ͱ͢Ε͹ 18

Slide 19

Slide 19 text

{ "{FileContents}" = { ImageCount = 1; Images = ( { AuxiliaryData = ( { AuxiliaryDataType = kCGImageAuxiliaryDataTypeDisparity; Height = 768; Width = 576; } ); } ); }; } ͱ͍ͬͨ৘ใ͕औಘग़དྷΔ 19

Slide 20

Slide 20 text

ը૾߹੒ͯ͠ΈΔ let ciImage: CIImage = CIImage(image: image) let wallImage: UIImage = #imageLiteral(resourceName: "wall") guard let wallCIImage: CIImage = CIImage(image: wallImage) else { return } let maskedImage: CIImage = ciImage.applyingFilter("CIBlendWithMask", withInputParameters: [ kCIInputBackgroundImageKey: wallCIImage, kCIInputMaskImageKey: disparityImage.applyingFilter("CIColorClamp", withInputParameters: nil), ]) self.disparityImageView.image = UIImage(ciImage: maskedImage) 20

Slide 21

Slide 21 text

ը૾ௐ੔ CIColorMatrix Λར༻ͯ͠άϨʔͷೱ͞Λௐ੔ let maskImage = disparityImage.applyingFilter("CIColorMatrix", withInputParameters: [ "inputRVector" : CIVector(x: value, y: 0, z: 0, w: 0), "inputGVector" : CIVector(x: 0, y: value, z: 0, w: 0), "inputBVector" : CIVector(x: 0, y: 0, z: value, w: 0), "inputBiasVector" : CIVector(x: bias, y: bias, z: bias, w: 0)]) 21

Slide 22

Slide 22 text

Sample https://github.com/fromkk/DepthAPISampleForiOS11 22

Slide 23

Slide 23 text

ϋϚͬͨࣄ — ͦ΋ͦ΋CIImageɺCIFilterશવ஌Βͳ͔ͬͨ — kCIImageAuxiliaryDepth Ͱ΋ը૾͕औಘग़དྷΔ͸ͣͳͷ ʹग़དྷͳ͔ͬͨ — ճస͍ͯ͠Δը૾ʹରԠग़དྷͳ͔ͬͨʢৄ͍͠ਓ͍ͨΒڭ ͑ͯԼ͍͞!ʣ — ͦ΋ͦ΋਺ֶతͳ஌͕ࣝແ͍ͷͰηογϣϯͷҙຯ͕͋· Γཧղग़དྷͳ͔ͬͨʢসʣ 23

Slide 24

Slide 24 text

Recap — ݸਓతʹ͸Ұ୴Disparityͷը૾͕औಘग़དྷͯ࠷௿ݶͷ߹ ੒͕ग़དྷͨͷͰຬ଍! — ݱ࣌఺ͰରԠ৚͕݅গͳ͔͘ͳΓχονͳػೳͳͷͰ࢖͍ ಓ͕೉͍͠" — iOS 11Ҏ߱ͰࡱӨͨࣸ͠ਅ͔͠Disparityը૾͕औಘग़དྷ ͳͯ͘൵͠Έ# 24

Slide 25

Slide 25 text

͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠! 25