Hand Tracking with opencv and mediapipe on python
Simple hand tracking using opencv and mediapipe.
I start from the code of opencvhandracking library that actually do not work on my python 3.6 and 3.8. I copy their classes and I use it into a very simple script.
Requirements
You need to have python and pip and install the following libraries
pip install mediapipe opencv-python
Code
The code can be downloaded here
Now connect a webcam and exec it with:
python3 main.py
As in the figure you will see the output of your webcam and the hand tracking draw. Press ‘q’ to quit.
Conclusions
This code is very simple and use only 51 lines of codes, but when the library will work well with pip it can be replaced with 10 as follow
import cv2
from opencvtracking import HandGesturecap = cv2.VideoCapture(0)
handtrckingdetector = HandGesture()while True:
success, img = cap.read()
img = handtrckingdetector.drawHand(img)
# landmarkList = handtrckingdetector.handPosition(img)
cv2.imshow("Image", img)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
This can be very useful for to much applications, for example to create interactive museum objects.