Skip to main content

This package will allow users to detect objects, such as hands and fingers, in a very simple way.

Project description

PyDetection

"pydetection" is a python library that allows users to find and locate various objects such as hands and fingers. It contains many functions that simplify the tedious works and worries to detect real life objects.

How does it work?

  • To detect objects, it uses a library called "mediapipe".
    Note: Mediapipe requires a python version below or equal to 3.7!
  • It also uses the "opencv-python" library to process and display images.

Mediapipe: pip install mediapipe
Opencv: pip install opencv-python

Installation and setup

  • INSTALLATION: Open your terminal and type: pip install pydetection
  • SETUP: Open up a python file and type: import pydetection

PyDetection - Code examples

Find hands in an image

import pydetection as hand # The pydection module
import cv2 # Used for displaying images (Comes installed with pydetection

detector = hand.HandRecogniser() 
image_dir = "./images/hands_image.jpg" # Our image

# The variable "image": This contains the image with the hands outlined (Image can be shown with the cv2 module)
# The variable "hand_landmark_position": This contains the coordinates for each joint in each hand in the image (Can be used with the "Hand()" class
image, hand_landmark_position = detector.findHands(image_dir, draw=True) # If draw is false, the returned image will not have the hands outlined

cv2.imshow(image) # Use the cv2 module to display the image
cv2.waitKey(5000) # Wait for 5 seconds (5000 milli seconds) so that we can see the image.

Get the name of each joint in the hand

import pydetection as hand # The pydetection module

detector = hand.HandRecogniser() 
image_dir = "./images/hands_image.jpg" # The image

image, hand_landmark_position = detector.findHands(image_dir, draw=False) # We set draw to False because we don't need the image and it uses a lot of CPU.

# The "Hand()" class only excepts the coordinates of one hand
handObject = hand.Hand([hand_landmark_position[0]]) # The first hand

# Let's say that we need the coordinates of the thumb tip
id = handObject.thumb_tip["id"] # Every landmark (joint) has a specific ID
x = handObject.thumb_tip["x axis"] # The x axis of the coordinate
y = handObject.thumb_tip["y axis"] # The y axis of the coordinate

Detect hand in real time webcam footage

import pydetection as hand # The pydetection module
import cv2 # We will use this for reading and displaying webcam frames

detector = hand.HandRecogniser()
webcam = cv2.VideoCapture(0) # Change the number for a different camera. 0 is the default one.

while True:
    _, frame = webcam.read() # Gets a frane of the current webcam feed
  
    processed_image, hand_landmark_position = detector.findHands(frame, draw=True)
    
    cv2.imshow(processed_image) # Show the image with the hands outlined
    
    # Add a delay of 1 milli second and check for the keystroke "q"
    key = cv2.waitKey(1)
    if key == ord("q"):
      break

Check if the thumb is closed

import pydetection as hand # The pydetection module

detector = hand.HandRecogniser(max_num_hands=1) # Detect only 1 hand
image_dir = "./images/hand_image.jpg" # The image

# Fingers available: ["thumb", "index", "middle", "ring", "thumb"]
# Parameter "hand_orientation": You need to provide the function with whether the hand you want is a right or left hand.
# Parameter "hand_num": If you have multiple hands in this image, you need to specify which hand you are targetting
thumb_state = detector.getFingerState(image_dir, "thumb", hand_orientation="right", hand_num=1)

print(thumb_state) # It will print "True" if the hand is opened, and "False" if not

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydetection-0.0.4.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydetection-0.0.4-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file pydetection-0.0.4.tar.gz.

File metadata

  • Download URL: pydetection-0.0.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.0

File hashes

Hashes for pydetection-0.0.4.tar.gz
Algorithm Hash digest
SHA256 7ff339f417a85cfe4c9dde3565d8410a530f12ed3ae5721ff254df5e876585cd
MD5 e5c747681f69d92cb0e5232274d9c3ee
BLAKE2b-256 2875ffd75829a80fa9ea9a4a9a614103918ff13f6c1d5b9859144f31d7abf818

See more details on using hashes here.

File details

Details for the file pydetection-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: pydetection-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.0

File hashes

Hashes for pydetection-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 81a913e6dabd0bbd88ea1f6feb6720f705ef004018d3146c0ef8f03a63947fc3
MD5 a3fb41e5c379b3632e1d40dd463de1a8
BLAKE2b-256 6f8690644b4c6d0350d1af57d368413d27270f82867f181ed291b75237dd9801

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page