├── .gitignore ├── LICENSE ├── Media-Demo └── demo.gif ├── PoseVideos └── 2.mp4 ├── README.md ├── Source ├── PoseModule.py └── main.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Abbas Ataei 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Media-Demo/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImAyrix/Pose-Detection/08fe5ea8d28a3e9c42b37d97d4877745c86f05f9/Media-Demo/demo.gif -------------------------------------------------------------------------------- /PoseVideos/2.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImAyrix/Pose-Detection/08fe5ea8d28a3e9c42b37d97d4877745c86f05f9/PoseVideos/2.mp4 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Pose-Detection 2 | 3 | 🤔 Overview Human pose estimation from video plays a critical role in various applications such as quantifying physical exercises, sign language recognition, and full-body gesture control. For example, it can form the basis for yoga, dance, and fitness applications. It can also enable the overlay of digital content and information on top of the physical world in augmented reality. MediaPipe Pose is a ML solution for high-fidelity body pose tracking, inferring 33 3D landmarks and background segmentation mask on the whole body from RGB video frames utilizing our BlazePose research that also powers the ML Kit Pose Detection API. Current state-of-the-art approaches rely primarily on powerful desktop environments for inference, whereas our method achieves real-time performance on most modern mobile phones, desktops/laptops, in python and even on the web. 4 | 5 | # 📀 Demo 6 | ![GIF](Media-Demo/demo.gif) 7 | 8 | # ⌨️ Code 9 | Firstly I have created a Module "PoseModule.py", this file contains the code which detects our pose, in this file I have created functions for specific tasks in a "class poseDetector()". Short description of functions are - 10 | 11 | findPose() - This function detect Pose and show landmarks of your hand and it return image in RGB. 12 | getPosition() - This function finds the position of particular landmark of your Pose and it returns a list containing id_of_that_landmark, x_position_of_that_landmark, y_position_of_that_landmark. 13 | 14 | # 👀 About Me 15 | Full name : Abbas Ataei 16 | 17 | Learning : Python 18 | 19 | Gmail : AbbasAtaei.py@gmail.com 20 | 21 | Telegram : https://t.me/Abbasataei_py 22 | 23 | More : https://bioly.io/AbbasAtaei 24 | -------------------------------------------------------------------------------- /Source/PoseModule.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import time 3 | import mediapipe as mp 4 | 5 | 6 | class poseDetector(): 7 | 8 | def __init__(self, static_image_mode = False, 9 | model_complexity = 1, 10 | smooth_landmarks = True, 11 | enable_segmentation = False, 12 | smooth_segmentation = True, 13 | min_detection_confidence = 0.5, 14 | min_tracking_confidence = 0.5): 15 | 16 | self.static_image_mode = static_image_mode 17 | self.model_complexity = model_complexity 18 | self.smooth_landmarks = smooth_landmarks 19 | self.enable_segmentation = enable_segmentation 20 | self.smooth_segmentation = smooth_segmentation 21 | self.min_detection_confidence = min_detection_confidence 22 | self.min_tracking_confidence = min_tracking_confidence 23 | 24 | self.mpDraw = mp.solutions.drawing_utils 25 | self.mpPose = mp.solutions.pose 26 | self.pose = self.mpPose.Pose(self.static_image_mode, self.model_complexity, self.smooth_landmarks, 27 | self.enable_segmentation, self.smooth_segmentation, self.min_detection_confidence, 28 | self.min_tracking_confidence) 29 | 30 | def findPose(self, img, draw=True): 31 | imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) 32 | self.results = self.pose.process(imgRGB) 33 | if self.results.pose_landmarks: 34 | if draw: 35 | self.mpDraw.draw_landmarks(img, self.results.pose_landmarks, self.mpPose.POSE_CONNECTIONS) 36 | return img 37 | 38 | def getPosition(self, img, draw=True): 39 | lmList = [] 40 | if self.results.pose_landmarks: 41 | for id, lm in enumerate(self.results.pose_landmarks.landmark): 42 | h, w, c = img.shape 43 | cx, cy = int(lm.x * w), int(lm.y * h) 44 | lmList.append([id, cx, cy]) 45 | if draw: 46 | cv2.circle(img, (cx, cy), 3, (255, 0, 255), cv2.FILLED) 47 | return lmList 48 | 49 | 50 | def main(): 51 | cap = cv2.VideoCapture("../PoseVideos/2.mp4") 52 | pTime = 0 53 | detector = poseDetector() 54 | while True: 55 | success, img = cap.read() 56 | img = cv2.resize(img, (960, 540)) 57 | img = detector.findPose(img) 58 | lmList = detector.getPosition(img) 59 | 60 | cTime = time.time() 61 | fps = 1 / (cTime - pTime) 62 | pTime = cTime 63 | 64 | cv2.putText(img, str(int(fps)), (30, 30), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0), 3) 65 | cv2.imshow("Image", img) 66 | cv2.waitKey(1) 67 | 68 | 69 | if __name__ == "__main__": 70 | main() 71 | -------------------------------------------------------------------------------- /Source/main.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import time 3 | import PoseModule 4 | import mediapipe as mp 5 | import numpy as np 6 | 7 | cap = cv2.VideoCapture("../PoseVideos/2.mp4") 8 | pTime = 0 9 | detector = PoseModule.poseDetector() 10 | while True: 11 | success, img = cap.read() 12 | img = cv2.resize(img, (960, 540)) 13 | img = detector.findPose(img) 14 | lmList = detector.getPosition(img) 15 | 16 | length = lmList[19][2] 17 | per = np.interp(int(length), [157, 285], [100, 0]) 18 | poseBar = np.interp(length, [157, 285], [150, 400]) 19 | 20 | cv2.putText(img, f"{int(per)} %", (40, 450), cv2.FONT_HERSHEY_COMPLEX, 1, (240, 103, 106), 3) 21 | cv2.rectangle(img, (50, int(poseBar)), (85, 400), (0, 182, 255), cv2.FILLED) 22 | cv2.rectangle(img, (50, 150), (85, 400), (240, 103, 106), 3) 23 | 24 | cTime = time.time() 25 | fps = 1 / (cTime - pTime) 26 | pTime = cTime 27 | 28 | cv2.putText(img, f"FPS: {int(fps)}", (425, 40), cv2.FONT_HERSHEY_COMPLEX, 1, (240, 103, 106), 3) 29 | cv2.imshow("Image", img) 30 | cv2.waitKey(1) 31 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ImAyrix/Pose-Detection/08fe5ea8d28a3e9c42b37d97d4877745c86f05f9/requirements.txt --------------------------------------------------------------------------------