# mediapipe-python-sample
**Repository Path**: juneral/mediapipe-python-sample
## Basic Information
- **Project Name**: mediapipe-python-sample
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2021-06-29
- **Last Updated**: 2021-10-21
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# mediapipe-python-sample
[MediaPipe](https://github.com/google/mediapipe)のPythonパッケージのサンプルです。
2021/06/04時点でPython実装のある以下7機能について用意しています。
* [Hands](https://google.github.io/mediapipe/solutions/hands)

* [Pose](https://google.github.io/mediapipe/solutions/pose)

* [Face Mesh](https://google.github.io/mediapipe/solutions/face_mesh)

* [Holistic](https://google.github.io/mediapipe/solutions/holistic)

* [Face Detection](https://google.github.io/mediapipe/solutions/face_detection)

* [Objectron](https://google.github.io/mediapipe/solutions/objectron)

* [Selfie Segmentation](https://google.github.io/mediapipe/solutions/selfie_segmentation)

# Requirement
* mediapipe 0.8.5 or later
* OpenCV 3.4.2 or later
mediapipeはpipでインストールできます。
```bash
pip install mediapipe
```
# Demo
デモの実行方法は以下です。
#### Face Mesh
```bash
python sample_facemesh.py
```
* --device
カメラデバイス番号の指定
デフォルト:0
* --width
カメラキャプチャ時の横幅
デフォルト:960
* --height
カメラキャプチャ時の縦幅
デフォルト:540
* --max_num_hands
最大手検出数
デフォルト:1
* --min_detection_confidence
検出信頼値の閾値
デフォルト:0.5
* --min_tracking_confidence
トラッキング信頼値の閾値
デフォルト:0.5
* --use_brect
外接矩形を描画するか否か
デフォルト:指定なし
#### Hands
```bash
python sample_hand.py
```
* --device
カメラデバイス番号の指定
デフォルト:0
* --width
カメラキャプチャ時の横幅
デフォルト:960
* --height
カメラキャプチャ時の縦幅
デフォルト:540
* --max_num_faces
最大顔検出数
デフォルト:1
* --min_detection_confidence
検出信頼値の閾値
デフォルト:0.7
* --min_tracking_confidence
トラッキング信頼値の閾値
デフォルト:0.5
* --use_brect
外接矩形を描画するか否か
デフォルト:指定なし
#### Pose
```bash
python sample_pose.py
```
* --device
カメラデバイス番号の指定
デフォルト:0
* --width
カメラキャプチャ時の横幅
デフォルト:960
* --height
カメラキャプチャ時の縦幅
デフォルト:540
* --model_complexity
モデルの複雑度(0:Lite 1:Full 2:Heavy)
※性能差は[Pose Estimation Quality](https://google.github.io/mediapipe/solutions/pose#pose-estimation-quality)を参照ください
デフォルト:1
* --min_detection_confidence
検出信頼値の閾値
デフォルト:0.5
* --min_tracking_confidence
トラッキング信頼値の閾値
デフォルト:0.5
* --use_brect
外接矩形を描画するか否か
デフォルト:指定なし
#### Holistic
```bash
python sample_holistic.py
```
* --device
カメラデバイス番号の指定
デフォルト:0
* --width
カメラキャプチャ時の横幅
デフォルト:960
* --height
カメラキャプチャ時の縦幅
デフォルト:540
* --model_complexity
モデルの複雑度(0:Lite 1:Full 2:Heavy)
※性能差は[Pose Estimation Quality](https://google.github.io/mediapipe/solutions/pose#pose-estimation-quality)を参照ください
デフォルト:1
* --min_detection_confidence
検出信頼値の閾値
デフォルト:0.5
* --min_tracking_confidence
トラッキング信頼値の閾値
デフォルト:0.5
* --use_brect
外接矩形を描画するか否か
デフォルト:指定なし
#### Face Detection
```bash
python sample_facedetection.py
```
* --device
カメラデバイス番号の指定
デフォルト:0
* --width
カメラキャプチャ時の横幅
デフォルト:960
* --height
カメラキャプチャ時の縦幅
デフォルト:540
* --min_detection_confidence
検出信頼値の閾値
デフォルト:0.5
#### Objectron
```bash
python sample_objectron.py
```
* --device
カメラデバイス番号の指定
デフォルト:0
* --width
カメラキャプチャ時の横幅
デフォルト:960
* --height
カメラキャプチャ時の縦幅
デフォルト:540
* --static_image_mode
静止画像モード ※トラッキング無し
デフォルト:指定なし
* --min_detection_confidence
検出信頼値の閾値
デフォルト:0.5
* --min_tracking_confidence
トラッキング信頼値の閾値
デフォルト:0.99
* --model_name
検出対象(20201/03/03時点:'Shoe', 'Chair', 'Cup', 'Camera'の4種類)
デフォルト:Cup
#### Selfie Segmentation
```bash
python sample_selfie_segmentation
```
* --device
カメラデバイス番号の指定
デフォルト:0
* --width
カメラキャプチャ時の横幅
デフォルト:960
* --height
カメラキャプチャ時の縦幅
デフォルト:540
* --model_selection
モデル種類指定
0:Generalモデル(256x256x1 出力)
1:Landscapeモデル(144x256x1 出力)
デフォルト:0
* --score_th
スコア閾値(閾値以上:人間、閾値未満:背景)
デフォルト:0.1
* --bg_path
背景画像格納パス ※未指定時はグリーンバック
デフォルト:None
# For Raspberry Pi
以下のRaspberry Pi向けビルドを利用することで、Raspberry Pi上で本サンプルを試すことが出来ます。
* [Raspberry Piで手軽にMediaPipeを楽しむ方法](https://zenn.dev/karaage0703/articles/63fed2a261096d)
* [PINTO0309/mediapipe-bin](https://github.com/PINTO0309/mediapipe-bin)
# ToDo
- [x] ~~[Holistic](https://google.github.io/mediapipe/solutions/holistic)のサンプル追加 (mediapipe 0.8.1)~~
- [x] ~~Poseのz座標表示を追加 (mediapipe 0.8.3)~~
- [x] ~~[Face Detection](https://google.github.io/mediapipe/solutions/face_detection)のサンプル追加 (mediapipe 0.8.3)~~
- [x] ~~[Objectron](https://google.github.io/mediapipe/solutions/objectron)のサンプル追加 (mediapipe 0.8.3)~~
# Reference
* [MediaPipe](https://github.com/google/mediapipe)
# Author
高橋かずひと(https://twitter.com/KzhtTkhs)
# License
mediapipe-python-sample is under [Apache-2.0 License](LICENSE).
また、女性の画像、および背景画像は[フリー素材ぱくたそ](https://www.pakutaso.com)様の写真を利用しています。