Metadata-Version: 2.1
Name: pipetrt
Version: 0.1.2
Summary: TensorRT accelerated hand tracking library
Author-email: Norifumi Kondo <norifumi.kondo.it@gmail.com>
License: Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for reasonable and customary use in describing the
              origin of the Work and reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may choose to offer,
              and charge a fee for, acceptance of support, warranty, indemnity,
              or other liability obligations and/or rights consistent with this
              License. However, in accepting such obligations, You may act only
              on Your own behalf and on Your sole responsibility, not on behalf
              of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed page" as the copyright notice for easier
              identification within third-party archives.
        
           Copyright 2026 Norifumi Konndo
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
        
Project-URL: Homepage, https://github.com/Konoa-1025/PipeTRT
Project-URL: Repository, https://github.com/Konoa-1025/PipeTRT
Project-URL: Issues, https://github.com/Konoa-1025/PipeTRT/issues
Keywords: TensorRT,CUDA,hand-tracking,hand-landmark,computer-vision
Requires-Python: <3.12,>=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: opencv-python
Requires-Dist: tensorrt
Requires-Dist: cuda-python
Requires-Dist: onnx
Requires-Dist: nvidia-modelopt[onnx]
Requires-Dist: pywin32; platform_system == "Windows"

<p align="center">
  <img src="./assets/pipetrt_header.png" alt="PipeTRT" width="100%">
</p>

<p align="center">
  MediaPipe-inspired TensorRT hand landmark library for NVIDIA GPUs
</p>

<p align="center">
  <a href="https://pypi.org/project/pipetrt/">
    <img src="https://img.shields.io/pypi/v/pipetrt">
  </a>
  <img src="https://img.shields.io/pypi/pyversions/pipetrt">
  <a href="./LICENSE">
    <img src="https://img.shields.io/github/license/Konoa-1025/PipeTRT">
  </a>
</p>

MediaPipeのハンドトラッキング構成を参考に開発した、NVIDIA GPU向けTensorRT手骨格検出ライブラリです。

このプロジェクトは、MediaPipeのようなシンプルな使い方で、TensorRTによる高速な手の検出・21点ランドマーク推論を利用できるようにすることを目的としています。

PipeTRTは、自分自身の開発だけではなく、将来同じようにJetsonやNVIDIA GPUを用いたエッジAI開発を行う学生や開発者が、手軽に利用できるライブラリを目指しています。


## デモンストレーション映像

![PipeTRT v0.1.0 Demo](./assets/pipetrt0.1.0_demo_full.gif)


## リリース 0.1.2

PipeTRT v0.1.2では、TensorRTのバージョン差によるEngine生成処理の互換性を改善しました。

TensorRTのメジャーバージョンを判定し、使用しているTensorRTに応じてEngine生成処理を切り替えます。

これにより、従来のWindows + NVIDIA GeForce RTX環境に加えて、NVIDIA Jetson Xavier NX上のTensorRT 8.5環境でも動作を確認しました。

現在はPython 3.8以上、3.12未満の環境を対象としています。

カメラ映像や画像から手を検出し、21点のHand Landmarkを取得できます。

内部では以下の処理を行います。

1. Palm Detection
2. ROI生成・変換
3. Hand Landmark推論
4. ROI Tracking
5. 21点ランドマークの出力

Palm DetectionとHand Landmarkの推論にはNVIDIA TensorRTを使用しています。

> [!NOTE]
> v0.1.xは初期リリースです。
> APIや内部仕様は今後変更される可能性があります。


## v0.1.2の主な変更点

- TensorRTのメジャーバージョン判定を追加
- TensorRT 8系でのEngine生成に対応
- TensorRT 8系で`EXPLICIT_BATCH`を使用する処理を追加
- TensorRTのバージョンに応じたFP16 Engine生成処理を追加
- NVIDIA Jetson Xavier NXでの動作確認
- TensorRT 8.5.2.2での動作確認
- Python 3.8環境での動作確認


## 機能

v0.1.2では以下の機能を利用できます。

- TensorRTによるPalm Detection
- 手領域（ROI）の生成
- 回転を考慮したROI変換
- TensorRTによるHand Landmark推論
- 21点のHand Landmark取得
- Landmarkを利用したROI Tracking
- Palm DetectionとTrackingの自動切り替え
- MediaPipe風の`HandLandmarker` API
- 静止画・リアルタイムカメラ映像への対応
- 各処理の推論時間・処理時間の取得
- Python 3.8以上への対応
- TensorRTのバージョン差を考慮したEngine生成


## 動作確認環境

現在、以下の環境で動作確認しています。

### Windows

- Windows
- Python 3.8 / 3.11
- NVIDIA GeForce RTX 3070
- NVIDIA CUDA
- NVIDIA TensorRT

### NVIDIA Jetson

以下の環境で動作を確認しています。

- NVIDIA Jetson Xavier NX 8GB
- JetPack 5.1.2
- Python 3.8.10
- CUDA 11.4
- TensorRT 8.5.2.2

> [!NOTE]
> 現在Jetson環境については、Jetson Xavier NX + JetPack 5.1.2で動作確認を行っています。
> すべてのJetsonシリーズおよびJetPackバージョンでの動作を保証するものではありません。

### 対応Pythonバージョン

```text
Python >= 3.8, < 3.12
```

現在、Python 3.8およびPython 3.11で動作確認を行っています。


## インストール

PipeTRTはPyPIからインストールできます。

```bash
pip install pipetrt
```

対応Pythonバージョンは以下です。

```text
Python >= 3.8, < 3.12
```

> [!NOTE]
> PipeTRTはNVIDIA GPUおよびTensorRTを使用します。
> CUDA・TensorRTなどの対応状況は、使用する環境によって異なる場合があります。


### GitHubからインストール

GitHub上のソースコードからインストールする場合は、リポジトリをCloneします。

```bash
git clone https://github.com/Konoa-1025/PipeTRT.git
cd PipeTRT
pip install .
```


### 開発用インストール

PipeTRT自体の開発やコードの変更を行う場合は、Editable Installを利用できます。

```bash
git clone https://github.com/Konoa-1025/PipeTRT.git
cd PipeTRT
pip install -e .
```


## 使い方

### 基本

```python
import pipetrt

hands = pipetrt.HandLandmarker()

result = hands.detect(frame)

print(result.hand_landmarks)

hands.close()
```

`detect()`にOpenCVの画像（NumPy配列）を渡すことで、手のランドマークを取得できます。


### OpenCVでリアルタイム検出

```python
import cv2
import pipetrt


hands = pipetrt.HandLandmarker()

cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()

    if not ret:
        break

    result = hands.detect(frame)

    if result.hand_landmarks is not None:
        for landmark in result.hand_landmarks:
            x = int(landmark[0])
            y = int(landmark[1])

            cv2.circle(
                frame,
                (x, y),
                4,
                (0, 255, 0),
                -1
            )

    cv2.imshow("PipeTRT", frame)

    if cv2.waitKey(1) & 0xFF == ord("q"):
        break

cap.release()
hands.close()
cv2.destroyAllWindows()
```


## 取得できるデータ

`HandLandmarker.detect()`は`HandLandmarkerResult`を返します。

現在、以下のデータを取得できます。

- `hand_landmarks`
- `palm_result`
- `roi`
- `roi_image`
- `timings`

### hand_landmarks

21点のHand Landmarkを取得できます。

```python
result.hand_landmarks
```

### timings

各処理にかかった時間を取得できます。

```python
print(result.timings)
```

Palm Detection、ROI変換、Hand Landmark推論などの処理時間を確認できます。


## 処理の流れ

```text
Input Frame
     |
     v
Palm Detection
     |
     v
ROI Generation
     |
     v
Hand Landmark
     |
     v
ROI Tracking
     |
     v
21 Hand Landmarks
```


## 注意

- 本プロジェクトはMediaPipeにインスパイアされていますが、Google公式のMediaPipeプロジェクトとは独立した非公式プロジェクトです。
- TensorRTを利用していますが、NVIDIA公式のプロジェクトではありません。
- GitHub上などで公開されている情報・データを調査し、利用条件を確認した上で開発しています。使用・参考にしたものについては`reference.md`に記載しています。
- このライブラリでは画像処理をローカル環境内で実行します。PipeTRT自体が画像を第三者へ送信したり、外部サーバーへ保存したりする機能はありません。
- 使用しているデータ等について権利者から案内・通告があった場合、プログラムの修正や該当リリースの公開停止を行う場合があります。
- Pythonのバージョンが対応範囲内であっても、CUDA・TensorRT・NVIDIA GPUなどの環境によって動作状況が異なる場合があります。
- Jetsonについては現在Jetson Xavier NX + JetPack 5.1.2環境で動作確認を行っており、その他のJetsonシリーズ・JetPackバージョンについては検証中です。
- このプロジェクトでは学習を目的としてAIを開発補助に使用しています。生成された内容をそのまま公開するのではなく、内容の確認・理解・独自の実装やリファクタリングを行った上でリリースしています。そのため、開発版とリリース版には時間差が生じる場合があります。最新の開発状況については`dev`ブランチを確認してください。


## License

Apache License 2.0
