まだまだ情報は少ないようですが、今年の11月から調査を開始して2週間以内に機能を自作ライブラリーに組み込みました。
参考資料
https://developer.apple.com/videos/play/wwdc2019/225/
OSS内に組み込んだ機能
実際のカメラでは高画質です。 pic.twitter.com/t8vnCBI6y5
— DaisukeNagata (@dbank0208) November 5, 2019
これは調査の段階で確認した機能
人間版のアバターも作れます。
— DaisukeNagata (@dbank0208) November 14, 2019
ファイル化すると背景だけ、とばして、画像をviewかすれば人物像のみ拡大縮小も可能です。
今は動画系の新技術をインプットしてます。 pic.twitter.com/1g1QdSC3I7
どのように実現しているのか?
自作ライブラリー
機能を単体で作成したサンプル
機能クラス
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()
以上、貴重なお時間お読み下さいまして、誠にありがとうございます。
8 Responses
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.
Thank you comment
Why people still make use of to read news papers when in this technological globe the whole
thing is presented on web?
The speed of progress is free.
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?
Hacker has no problem.
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/
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