VisionでHand Pose Detection 手のトラッキング
5151 ワード
iOS14から手のポイントを認識できるようになりました。
上のお絵かきはAppleのサンプルプロジェクトです。
この記事では、画像から手のポイントを取る手順を紹介します。
手順
リクエスト実行までは、いつものVisionと同じです。
1.Visionをインポート。
import Vision
2.リクエストを作成。
var handPoseRequest = VNDetectHumanHandPoseRequest()
handPoseRequest.maximumHandCount = 1 // 検出するての数
3.ImageRequestHandlerで実行。
AVFoundationのCaptureOutputメソッドなどでフレームのPixelBufferを当て込みます。
let handler = VNImageRequestHandler(cvPixelBuffer:pixelBuffer, orientation: .up, options: [:])
do {
try handler.perform([handPoseRequest!])
guard let observation = handPoseRequest?.results?.first as? VNHumanHandPoseObservation else { return }
// maximumHandCountで設定した手の数だけObservationを取得できます。
} catch let error {
print(error)
}
4.指の各ポイントへのアクセス
例えば、人差し指の先のポイントへのアクセスは以下。
let indexFingerTip = try observation.recognizedPoints(.all)[.indexTip]
print(indexFingerTip)
Optional([0.984453; 0.562278])
ポイントは与えた画像の向きなどによって原点が変化するので、X軸Y軸を確認しましょう。
取得できるポイント一覧
5本の指それぞれの先の、第一関節、第二関節、付け根と、手首の21ポイントが取得できます。
指 | 先 | 第一関節 | 第二関節 | 付け根 |
---|---|---|---|---|
親指 | .thumbTIP | .thumbIP | .thumbMP | .thumbCMC |
人差し指 | .indexTip | .indexDIP | .indexPIP | .indexMCP |
中指 | .middleTip | .middleDIP | .middlePIP | .middleMCP |
薬指 | .ringTip | .ringDIP | .ringPIP | .ringMCP |
小指 | .littleTip | .littleDIP | .littlePIP | .littleMCP |
手首は.wrist
🐣
フリーランスエンジニアです。
お仕事のご相談こちらまで
[email protected]
Core MLを使ったアプリを作っています。
機械学習関連の情報を発信しています。
Author And Source
この問題について(VisionでHand Pose Detection 手のトラッキング), 我々は、より多くの情報をここで見つけました https://qiita.com/john-rocky/items/29c2cf791051c7205302著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .