Harbola DataScience

Answer, Read and Post Coding related Questions!

Realtime Hand Detection using Python Open-cv Project

This is one of the best Python open-cv project for beginners who wanna try their hands on something that is kinda advanced.

It is a basic Artificial Intelligence project in which our system automatically try to detect your hand marks with the help of your web cam and show points drawn to your computer screen on realtime without any delay.

Using image processing library open-cv you can easily build this project if you follow this step step guide.

We will also see the use of Mediapipe, cross-platform, customizable ML solutions for live and streaming media.

Using this we can do many image related detection task like

image from mediapipe site

Prerequisite for this projects : you need to have knowledge of python and open-cv library functions. And we will cover all the other things.


import cv2 #open-cv library
import mediapipe as mp
import time


We have imported mediapipe as mp. Mediapipe has a method solutions which contain many Machine learning trained models which are ready to use. Here we are using holistic model which have attributes min_detection_confidence and min_tracking_confidence.

Confidence scores are a critical component of face detection and comparison systems. These systems make predictions of whether a face exists in an image or matches a face in another image, with a corresponding level of confidence in the prediction.

next we will intialise drawing utils for drawing landmarks on screen


VideoCapture is a opencv method used to connect or capture camera. And if you want to connect to default camera you will need to pass 0 inside it.

video is when we play multiple images in a row. So we are using while loop in image and processing those images.

we are here using capture, which we created earlier and using read() method, we are storing the image in ‘frame’. and on 26th line using resize() method we are changing its size so to get a better view. Once we have resized our image that we have captured using our web cam. Now we can convert the resized image into rgb (red, green, blue) using cvtColor() method.

Which we also discussed in the previous project of How can we DETECT PALM LINES using Python

Machine Learning Part

Now its turn to use holistic_model on our image process() method. And after that again convert image into BGR.

DRAWING landmarks (points and lines) on hand using draw_landmarks() method. and passing image as a parameter to perform task.

Calculating fps using python

# Calculating the FPS
currentTime = time.time()
fps = 1 / (currentTime-previousTime)
previousTime = currentTime

here we are using time module to get current Time and substracting it from previous time which we initialised earlier. To calculate frame per second (fps) we are dividing currentTime-previousTime 1 (for 1second as it is frame per ‘second’)

Errors that occur while creating a open cv project – Errors while Creating open cv – Python Project


Hope you get how easy or difficuilt was this to build a simple AI project – Realtime Hand Detection using Python Open-cv Project

So these were some open-cv and mediapipe methods that you required to know for every open cv project. Difficuilty was moderate to hard. I say you must try it once and play around it. If you find it hard to implement and don’t understand the working of this, contact me using my gmail and I will definitely try to solve your query or doubt.

If you want to share your projects or want to learn these concepts contact me @ chitranshuharbola@gmail.com and comment down below.

Chitranshu Harbola

Self taught programmer, Web Developer and an aspiring Machine learning engineer cum Data Science student

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Back to top