まだまだ情報は少ないようですが、今年の11月から調査を開始して2週間以内に機能を自作ライブラリーに組み込みました。

参考資料

https://developer.apple.com/videos/play/wwdc2019/225/

OSS内に組み込んだ機能

これは調査の段階で確認した機能

どのように実現しているのか?

自作ライブラリー

           MaskingLayer         

機能を単体で作成したサンプル

MaskMatte

機能クラス

https://github.com/daisukenagata/MaskMatte/blob/master/MaskMatte/MaskFilterBuiltinsMatte.swift

ポイントのメソッド

//MARK: AVCapturePhotoCaptureDelegate
extension MaskFilterBuiltinsMatte: AVCapturePhotoCaptureDelegate{
    
    func photoOutput(_ output: AVCapturePhotoOutput, didFinishProcessingPhoto photo: AVCapturePhoto, error: Error?) {
        var uiImage: UIImage?
        if let imageData = photo.fileDataRepresentation() {

            uiImage = UIImage(data: imageData)

            for semanticSegmentationTypes in output.enabledSemanticSegmentationMatteTypes {
                if semanticSegmentationTypes == .hair {
                    semanticSegmentationType = semanticSegmentationTypes
                    maskFilterBuiltins(callBack(image:), photo: photo, ssmType: semanticSegmentationType!, image: uiImage ?? UIImage())
                }
            }
        }
    }
    func callBack(image: UIImage?) { call(image) }
}

上記のメソッドを呼び出しているコード

photoOutput?.capturePhoto(with: settings, delegate: self)

settingsはAVCapturePhotoSettingsという、カメラの詳細を決めるプロパティです。

メソッド内で様々に設定しています。https://developer.apple.com/documentation/avfoundation/avcapturephotosettings AVCapturePhotoSettingsリファレンス内に、実装しているコードの詳細説明が記載されています。

髪を合成しているメソッド

private func maskFilterBuiltinsChanges~~~

private func matteSetting~~~

CoreImageの複合トリックでMake

CIFilter.gammaAdjustとCIFilter.colorMatrixでググってみて下さい。

gammaとは非線形濃度変換。コントラストの調整です。

colorMatrixはRGBの部分の値を調整します。

value2,3,4でスライダーから取得した値を設定して髪の加工を可変しています。

2つのCoreImage機能を合わせることで、画像のような本物のような髪の色を実現しました。

メモリー使用量のコントロール

260MBから60MBほどにコントロール出来ます。 なのでインターナルに宣言する場合はoptinalにするとnilに出来、コントロール出来ます。

func cameraReset()

以上、貴重なお時間お読み下さいまして、誠にありがとうございます。

Tags:

8 Responses

  1. Excellent pieces. Keep posting such kind of information on your page.
    Im really impressed by your blog.
    Hi there, You have performed a fantastic job. I will certainly digg it and in my opinion recommend to my friends.
    I’m confident they’ll be benefited from this site.

  2. Hello! I just wanted to ask if you ever have any issues with hackers?

    My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due
    to no backup. Do you have any solutions to stop hackers?

  3. I am sure this article has touched all the internet users, its really really fastidious piece of writing on building up new weblog.
    I will immediately snatch your rss as I can’t to find
    your e-mail subscription hyperlink or e-newsletter
    service. Do you have any? Please allow me recognize in order that I could subscribe.
    Thanks. I couldn’t resist commenting. Exceptionally well written! http://Plumbing.com/

  4. I just couldn’t depart your website before suggesting that I extremely loved the usual
    information a person provide in your visitors?
    Is gonna be again steadily in order to check out new posts

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

このサイトについて

プログラミング記事、関連記事、ブログを公開しております。

Tool