Python HandDetection
Python with OpenCV - MediaPip Framework Hand Detection
Explore the docs »
Contact Me
About The Project
It is a Computer vision package that makes it easy to operate image processing and AI functions. It mainly uses OpenCV and Mediapipe libraries.
Usage areas
- Military Industry (submarine sonic wave scans), underwater imaging.
- Security, criminal laboratories.
- Medicine.
- Clarification of structures such as tumors, vessels, Tomography, Ultrasound.
- Robotics, traffic, astronomy, radar, newspaper and photography industry applications
- Vb..
Here we just do hand identification with a computer camera based on the basics.
Built With
Libraries and programming language I use.
Getting Started
The materials you need to do this.
Installation
· Install PIP packages
! pip install opencv
! pip install mediapip
! pip install numpy
Usage
Basic Code Example
import cvzone
import cv2
cap = cv2.VideoCapture(0)
cap.set(3, 1280)
cap.set(4, 720)
detector = cvzone.HandDetector(detectionCon=0.5, maxHands=1)
while True:
# Get image frame
success, img = cap.read()
# Find the hand and its landmarks
img = detector.findHands(img)
lmList, bbox = detector.findPosition(img)
# Display
cv2.imshow("Image", img)
cv2.waitKey(1)
Finding How many finger are up
if lmList:
fingers = detector.fingersUp()
totalFingers = fingers.count(1)
cv2.putText(img, f'Fingers:{totalFingers}', (bbox[0] + 200, bbox[1] - 30),
cv2.FONT_HERSHEY_PLAIN, 2, (0, 255, 0), 2)
My Hand Detection
import mediapipe as mp
import cv2
import numpy as np
mp_drawing = mp.solutions.drawing_utils
mp_hands = mp.solutions.hands
cap = cv2.VideoCapture(0)
with mp_hands.Hands(min_detection_confidence=0.8, min_tracking_confidence=0.5) as hands:
while cap.isOpened():
ret, frame = cap.read()
image = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
image = cv2.flip(image, 1)
image.flags.writeable = False
results = hands.process(image)
image.flags.writeable = True
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
#print(results)
if results.multi_hand_landmarks:
for num, hand in enumerate(results.multi_hand_landmarks):
mp_drawing.draw_landmarks(image, hand, mp_hands.HAND_CONNECTIONS,
mp_drawing.DrawingSpec(color=(217, 133, 0), thickness=2, circle_radius=4),
mp_drawing.DrawingSpec(color=(105, 0, 101), thickness=2, circle_radius=2),)
cv2.imshow('HandTracking', image)
if cv2.waitKey(10) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
mp_drawing.DrawingSpec()
Contact
Twitter - @filokipatisi
E-Mail - GMAIL
Linkedin - oguzzmuslu