Depth APIで簡易クロマキー合成 #geek_garage_ios/depth_api_ios11_20170627

249b3122eee454c0a818bfe7851418e4?s=47 fromkk
June 27, 2017

Depth APIで簡易クロマキー合成 #geek_garage_ios/depth_api_ios11_20170627

GEEK GARAGE iOS vol3で発表したiOS 11から利用出来るDepth APIについて

249b3122eee454c0a818bfe7851418e4?s=128

fromkk

June 27, 2017
Tweet

Transcript

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

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

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

  4. ΫϩϚΩʔ߹੒ — ฐࣾͷݕ౼தࢪࡦͷதʹΫϩϚ Ωʔ߹੒͕ඞཁͳ෺͕͋ͬͨ — ࣸਅͷಛఆ৭ͷ෦෼ΛಁԽͯ͠എ ܠը૾ͱ߹੒(άϦʔϯόοΫ) — Ϣʔβʔ͕Ξοϓϩʔυ͢Δࣸਅ ͷഎܠ͕Ұ৭͚ͩͳΜͯ΄΅օແ

    ը૾ૉࡐ:εϚʔτϑΥϯͰࠓ໷ͷҿ ΈձΛ༧໿ʢάϦʔϯόοΫʣ 4
  5. ͦΜͳத 5

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

  7. Sessions — 507 Capturing Depth in iPhone Photography — 508

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

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

  10. ͕ 10

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

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

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

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

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

    — etc... 15
  16. More info about HEIF — 503 Introducing HEIF and HEVC

    — 513 High Efficiency Image File Format 16
  17. 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
  18. ͪͳΈʹ 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
  19. { "{FileContents}" = { ImageCount = 1; Images = (

    { AuxiliaryData = ( { AuxiliaryDataType = kCGImageAuxiliaryDataTypeDisparity; Height = 768; Width = 576; } ); } ); }; } ͱ͍ͬͨ৘ใ͕औಘग़དྷΔ 19
  20. ը૾߹੒ͯ͠ΈΔ 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
  21. ը૾ௐ੔ 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
  22. Sample https://github.com/fromkk/DepthAPISampleForiOS11 22

  23. ϋϚͬͨࣄ — ͦ΋ͦ΋CIImageɺCIFilterશવ஌Βͳ͔ͬͨ — kCIImageAuxiliaryDepth Ͱ΋ը૾͕औಘग़དྷΔ͸ͣͳͷ ʹग़དྷͳ͔ͬͨ — ճస͍ͯ͠Δը૾ʹରԠग़དྷͳ͔ͬͨʢৄ͍͠ਓ͍ͨΒڭ ͑ͯԼ͍͞!ʣ

    — ͦ΋ͦ΋਺ֶతͳ஌͕ࣝແ͍ͷͰηογϣϯͷҙຯ͕͋· Γཧղग़དྷͳ͔ͬͨʢসʣ 23
  24. Recap — ݸਓతʹ͸Ұ୴Disparityͷը૾͕औಘग़དྷͯ࠷௿ݶͷ߹ ੒͕ग़དྷͨͷͰຬ଍! — ݱ࣌఺ͰରԠ৚͕݅গͳ͔͘ͳΓχονͳػೳͳͷͰ࢖͍ ಓ͕೉͍͠" — iOS 11Ҏ߱ͰࡱӨͨࣸ͠ਅ͔͠Disparityը૾͕औಘग़དྷ

    ͳͯ͘൵͠Έ# 24
  25. ͝ਗ਼ௌ͋Γ͕ͱ͏͍͟͝·ͨ͠! 25