Giter Club home page Giter Club logo

judgepazair / hand-gesture-recognition-using-mediapipe Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kazuhito00/hand-gesture-recognition-using-mediapipe

0.0 0.0 0.0 1.13 MB

MediaPipe(Python版)を用いて手の姿勢推定を行い、検出したキーポイントを用いて、簡易なMLPでハンドサインとフィンガージェスチャーを認識するサンプルプログラムです。(Estimate hand pose using MediaPipe(Python version). This is a sample program that recognizes hand signs and finger gestures with a simple MLP using the detected key points.)

License: Apache License 2.0

Python 10.17% Jupyter Notebook 89.83%

hand-gesture-recognition-using-mediapipe's Introduction

[Japanese/English]


hand-gesture-recognition-using-mediapipe

MediaPipe(Python版)を用いて手の姿勢推定を行い、検出したキーポイントを用いて、
簡易なMLPでハンドサインとフィンガージェスチャーを認識するサンプルプログラムです。 mqlrf-s6x16

本リポジトリは以下の内容を含みます。

  • サンプルプログラム
  • ハンドサイン認識モデル(TFLite)
  • フィンガージェスチャー認識モデル(TFLite)
  • ハンドサイン認識用学習データ、および、学習用ノートブック
  • フィンガージェスチャー認識用学習データ、および、学習用ノートブック

Requirements

  • mediapipe 0.8.1
  • OpenCV 3.4.2 or Later
  • Tensorflow 2.3.0 or Later
    tf-nightly 2.5.0.dev or later (LSTMモデルのTFLiteを作成する場合のみ)
  • scikit-learn 0.23.2 or Later (学習時に混同行列を表示したい場合のみ)
  • matplotlib 3.3.2 or Later (学習時に混同行列を表示したい場合のみ)

Demo

Webカメラを使ったデモの実行方法は以下です。

python app.py

デモ実行時には、以下のオプションが指定可能です。

  • --device
    カメラデバイス番号の指定 (デフォルト:0)
  • --width
    カメラキャプチャ時の横幅 (デフォルト:960)
  • --height
    カメラキャプチャ時の縦幅 (デフォルト:540)
  • --use_static_image_mode
    MediaPipeの推論にstatic_image_modeを利用するか否か (デフォルト:未指定)
  • --min_detection_confidence
    検出信頼値の閾値 (デフォルト:0.5)
  • --min_tracking_confidence
    トラッキング信頼値の閾値 (デフォルト:0.5)

Directory

│  app.py
│  keypoint_classification.ipynb
│  point_history_classification.ipynb
│  
├─model
│  ├─keypoint_classifier
│  │  │  keypoint.csv
│  │  │  keypoint_classifier.hdf5
│  │  │  keypoint_classifier.py
│  │  │  keypoint_classifier.tflite
│  │  └─ keypoint_classifier_label.csv
│  │          
│  └─point_history_classifier
│      │  point_history.csv
│      │  point_history_classifier.hdf5
│      │  point_history_classifier.py
│      │  point_history_classifier.tflite
│      └─ point_history_classifier_label.csv
│          
└─utils
    └─cvfpscalc.py

app.py

推論用のサンプルプログラムです。
また、ハンドサイン認識用の学習データ(キーポイント)、
フィンガージェスチャー認識用の学習データ(人差指の座標履歴)を収集することもできます。

keypoint_classification.ipynb

ハンドサイン認識用のモデル訓練用スクリプトです。

point_history_classification.ipynb

フィンガージェスチャー認識用のモデル訓練用スクリプトです。

model/keypoint_classifier

ハンドサイン認識に関わるファイルを格納するディレクトリです。
以下のファイルが格納されます。

  • 学習用データ(keypoint.csv)
  • 学習済モデル(keypoint_classifier.tflite)
  • ラベルデータ(keypoint_classifier_label.csv)
  • 推論用クラス(keypoint_classifier.py)

model/point_history_classifier

フィンガージェスチャー認識に関わるファイルを格納するディレクトリです。
以下のファイルが格納されます。

  • 学習用データ(point_history.csv)
  • 学習済モデル(point_history_classifier.tflite)
  • ラベルデータ(point_history_classifier_label.csv)
  • 推論用クラス(point_history_classifier.py)

utils/cvfpscalc.py

FPS計測用のモジュールです。

Training

ハンドサイン認識、フィンガージェスチャー認識は、
学習データの追加、変更、モデルの再トレーニングが出来ます。

ハンドサイン認識トレーニング方法

1.学習データ収集

「k」を押すと、キーポイントの保存するモードになります(「MODE:Logging Key Point」と表示される)


「0」~「9」を押すと「model/keypoint_classifier/keypoint.csv」に以下のようにキーポイントが追記されます。
1列目:押下した数字(クラスIDとして使用)、2列目以降:キーポイント座標


キーポイント座標は以下の前処理を④まで実施したものを保存します。


初期状態では、パー(クラスID:0)、グー(クラスID:1)、指差し(クラスID:2)の3種類の学習データが入っています。
必要に応じて3以降を追加したり、csvの既存データを削除して、学習データを用意してください。
  

2.モデル訓練

keypoint_classification.ipynb」をJupyter Notebookで開いて上から順に実行してください。
学習データのクラス数を変更する場合は「NUM_CLASSES = 3」の値を変更し、
「model/keypoint_classifier/keypoint_classifier_label.csv」のラベルを適宜修正してください。

X.モデル構造

keypoint_classification.ipynb」で用意しているモデルのイメージは以下です。

フィンガージェスチャー認識トレーニング方法

1.学習データ収集

「h」を押すと、指先座標の履歴を保存するモードになります(「MODE:Logging Point History」と表示される)


「0」~「9」を押すと「model/point_history_classifier/point_history.csv」に以下のようにキーポイントが追記されます。
1列目:押下した数字(クラスIDとして使用)、2列目以降:座標履歴


キーポイント座標は以下の前処理を④まで実施したものを保存します。


初期状態では、静止(クラスID:0)、時計回り(クラスID:1)、反時計回り(クラスID:2)、移動(クラスID:4)の
4種類の学習データが入っています。
必要に応じて5以降を追加したり、csvの既存データを削除して、学習データを用意してください。
   

2.モデル訓練

point_history_classification.ipynb」をJupyter Notebookで開いて上から順に実行してください。
学習データのクラス数を変更する場合は「NUM_CLASSES = 4」の値を変更し、
「model/point_history_classifier/point_history_classifier_label.csv」のラベルを適宜修正してください。

X.モデル構造

point_history_classification.ipynb」で用意しているモデルのイメージは以下です。
「LSTM」を用いたモデルは以下です。
使用する際には「use_lstm = False」を「True」に変更してください(要tf-nightly(2020/12/16時点))

Application example

以下に応用事例を紹介します。

Reference

Author

高橋かずひと(https://twitter.com/KzhtTkhs)

License

hand-gesture-recognition-using-mediapipe is under Apache v2 license.

hand-gesture-recognition-using-mediapipe's People

Contributors

kazuhito00 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.