Package: pydetection
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 mediapipeOpencv:pip install opencv-pythonInstallation and setupINSTALLATION: Open your terminal and type:pip install pydetectionSETUP: Open up a python file and type:import pydetectionPyDetection - Code examplesFind hands in an imageimportpydetectionashand# The pydection moduleimportcv2# Used for displaying images (Comes installed with pydetectiondetector=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()" classimage,hand_landmark_position=detector.findHands(image_dir,draw=True)# If draw is false, the returned image will not have the hands outlinedcv2.imshow(image)# Use the cv2 module to display the imagecv2.waitKey(5000)# Wait for 5 seconds (5000 milli seconds) so that we can see the image.Get the name of each joint in the handimportpydetectionashand# The pydetection moduledetector=hand.HandRecogniser()image_dir="./images/hands_image.jpg"# The imageimage,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 handhandObject=hand.Hand([hand_landmark_position[0]])# The first hand# Let's say that we need the coordinates of the thumb tipid=handObject.thumb_tip["id"]# Every landmark (joint) has a specific IDx=handObject.thumb_tip["x axis"]# The x axis of the coordinatey=handObject.thumb_tip["y axis"]# The y axis of the coordinateDetect hand in real time webcam footageimportpydetectionashand# The pydetection moduleimportcv2# We will use this for reading and displaying webcam framesdetector=hand.HandRecogniser()webcam=cv2.VideoCapture(0)# Change the number for a different camera. 0 is the default one.whileTrue:_,frame=webcam.read()# Gets a frane of the current webcam feedprocessed_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)ifkey==ord("q"):breakCheck if the thumb is closedimportpydetectionashand# The pydetection moduledetector=hand.HandRecogniser(max_num_hands=1)# Detect only 1 handimage_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 targettingthumb_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