質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Leap Motion

Leap Motionは、Leap Motionによって開発、販売している、手のジェスチャーでパソコンを操作できるデバイスです。

Q&A

解決済

1回答

2439閲覧

Leap Motion:指の関節のデータの取得

huton

総合スコア30

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Leap Motion

Leap Motionは、Leap Motionによって開発、販売している、手のジェスチャーでパソコンを操作できるデバイスです。

0グッド

0クリップ

投稿2020/12/11 06:49

編集2020/12/12 14:09

質問内容

現在次のサイト:python+keras+LeapMotionで手の形の判別をしてみた。を参考に「Leap Motionを用いて数種類の手の形状のデータセットを作成し、それをCNNによって学習させ、OpenCVのカメラ画像に映った手の形状が何を表すかを判別する」といったことをやりたいと思っています。
上記したサイトを参考にCNNによって学習まではできたのですが、そのあとが出来ません。なのでOpenCVのプログラムに合わせてwhile文で指の関節のデータの取得を行いたいと考えています。どのようにすれば指の関節のデータの取得ができるでしょうか?
ソースコード

leapmotion_pd.py:上記したサイト内にあるデータセット作成に用いたソースコード
このプログラムうちのの以下のデータに取得を行いたいと思っています。

if self.finger_names[finger.type] == 'Thumb': if self.bone_names[bone.type] == 'Metacarpal': Thumb_fin_meta_direction_x.append(bone.direction.x) Thumb_fin_meta_direction_y.append(bone.direction.y) Thumb_fin_meta_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Proximal': Thumb_fin_prox_direction_x.append(bone.direction.x) Thumb_fin_prox_direction_y.append(bone.direction.y) Thumb_fin_prox_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Intermediate': Thumb_fin_inter_direction_x.append(bone.direction.x) Thumb_fin_inter_direction_y.append(bone.direction.y) Thumb_fin_inter_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Distal': Thumb_fin_dist_direction_x.append(bone.direction.x) Thumb_fin_dist_direction_y.append(bone.direction.y) Thumb_fin_dist_direction_z.append(bone.direction.z) if self.finger_names[finger.type] == 'Index': if self.bone_names[bone.type] == 'Metacarpal': Index_fin_meta_direction_x.append(bone.direction.x) Index_fin_meta_direction_y.append(bone.direction.y) Index_fin_meta_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Proximal': Index_fin_prox_direction_x.append(bone.direction.x) Index_fin_prox_direction_y.append(bone.direction.y) Index_fin_prox_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Intermediate': Index_fin_inter_direction_x.append(bone.direction.x) Index_fin_inter_direction_y.append(bone.direction.y) Index_fin_inter_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Distal': Index_fin_dist_direction_x.append(bone.direction.x) Index_fin_dist_direction_y.append(bone.direction.y) Index_fin_dist_direction_z.append(bone.direction.z) if self.finger_names[finger.type] == 'Middle': if self.bone_names[bone.type] == 'Metacarpal': Middle_fin_meta_direction_x.append(bone.direction.x) Middle_fin_meta_direction_y.append(bone.direction.y) Middle_fin_meta_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Proximal': Middle_fin_prox_direction_x.append(bone.direction.x) Middle_fin_prox_direction_y.append(bone.direction.y) Middle_fin_prox_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Intermediate': Middle_fin_inter_direction_x.append(bone.direction.x) Middle_fin_inter_direction_y.append(bone.direction.y) Middle_fin_inter_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Distal': Middle_fin_dist_direction_x.append(bone.direction.x) Middle_fin_dist_direction_y.append(bone.direction.y) Middle_fin_dist_direction_z.append(bone.direction.z) if self.finger_names[finger.type] == 'Ring': if self.bone_names[bone.type] == 'Metacarpal': Ring_fin_meta_direction_x.append(bone.direction.x) Ring_fin_meta_direction_y.append(bone.direction.y) Ring_fin_meta_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Proximal': Ring_fin_prox_direction_x.append(bone.direction.x) Ring_fin_prox_direction_y.append(bone.direction.y) Ring_fin_prox_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Intermediate': Ring_fin_inter_direction_x.append(bone.direction.x) Ring_fin_inter_direction_y.append(bone.direction.y) Ring_fin_inter_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Distal': Ring_fin_dist_direction_x.append(bone.direction.x) Ring_fin_dist_direction_y.append(bone.direction.y) Ring_fin_dist_direction_z.append(bone.direction.z) if self.finger_names[finger.type] == 'Pinky': if self.bone_names[bone.type] == 'Metacarpal': Pinky_fin_meta_direction_x.append(bone.direction.x) Pinky_fin_meta_direction_y.append(bone.direction.y) Pinky_fin_meta_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Proximal': Pinky_fin_prox_direction_x.append(bone.direction.x) Pinky_fin_prox_direction_y.append(bone.direction.y) Pinky_fin_prox_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Intermediate': Pinky_fin_inter_direction_x.append(bone.direction.x) Pinky_fin_inter_direction_y.append(bone.direction.y) Pinky_fin_inter_direction_z.append(bone.direction.z) if self.bone_names[bone.type] == 'Distal': Pinky_fin_dist_direction_x.append(bone.direction.x) Pinky_fin_dist_direction_y.append(bone.direction.y) Pinky_fin_dist_direction_z.append(bone.direction.z) -----------------------------------省略----------------------------------------------   arm_direction_x.append(arm.direction.x) arm_direction_y.append(arm.direction.y) arm_direction_z.append(arm.direction.z)

OpenCVのプログラム

import cv2 import Leap, sys, time controller = Leap.Controller() now=0 # 動画表示 cap = cv2.VideoCapture(0) # 無限ループ while(cap.isOpened()): ret, frame = cap.read() #LeapMotionの挙動 f = controller.frame() #LeapMotionに手をかざしてないとき if f.hands.is_empty:   #LeapMotionに手をかざしたとき if not f.hands.is_empty: cv2.imshow("frame",frame) # カメラ画像を表示 # qキーが押されたら途中終了 if cv2.waitKey(1) & 0xFF == ord('q'): break cap.release() # カメラを解放 cv2.destroyAllWindows() # ウィンドウを消す

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

import Leap, sys, time controller = Leap.Controller() class frameframe(): finger_names = ['Thumb', 'Index', 'Middle', 'Ring', 'Pinky'] bone_names = ['Metacarpal', 'Proximal', 'Intermediate', 'Distal'] def onframe(self): f = controller.frame() for hand in f.hands: arm = hand.arm direction = hand.direction for finger in hand.fingers: for b in range(0, 4): bone = finger.bone(b) if self.finger_names[finger.type] == 'Thumb': if self.bone_names[bone.type] == 'Metacarpal': self.Thumb_meta_x=bone.direction.x self.Thumb_meta_y=bone.direction.y self.Thumb_meta_z=bone.direction.z if self.bone_names[bone.type] == 'Proximal': self.Thumb_prox_x=bone.direction.x self.Thumb_prox_y=bone.direction.y self.Thumb_prox_z=bone.direction.z if self.bone_names[bone.type] == 'Intermediate': self.Thumb_inter_x=bone.direction.x self.Thumb_inter_y=bone.direction.y self.Thumb_inter_z=bone.direction.z if self.bone_names[bone.type] == 'Distal': self.Thumb_dist_x=bone.direction.x self.Thumb_dist_y=bone.direction.y self.Thumb_dist_z=bone.direction.z -----------------------------------省略---------------------------------------------- if self.finger_names[finger.type] == 'Pinky': if self.bone_names[bone.type] == 'Metacarpal': self.Pinky_meta_x=bone.direction.x self.Pinky_meta_y=bone.direction.y self.Pinky_meta_z=bone.direction.z if self.bone_names[bone.type] == 'Proximal': self.Pinky_prox_x=bone.direction.x self.Pinky_prox_y=bone.direction.y self.Pinky_prox_z=bone.direction.z if self.bone_names[bone.type] == 'Intermediate': self.Pinky_inter_x=bone.direction.x self.Pinky_inter_y=bone.direction.y self.Pinky_inter_z=bone.direction.z if self.bone_names[bone.type] == 'Distal': self.Pinky_dist_x=bone.direction.x self.Pinky_dist_y=bone.direction.y self.Pinky_dist_z=bone.direction.z while True: f = controller.frame() test=frameframe() if f.hands.is_empty: print("not hand") if not f.hands.is_empty: test.onframe() print("Index x:%s"% (test.Index_meta_x)) print("Index y:%s"% (test.Index_meta_y)) print("Index z:%s"% (test.Index_meta_z))

こんな感じで出来ました。

投稿2020/12/12 14:13

huton

総合スコア30

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問