Finger print detection by Krishnam Goyal

Today, one of our customer Krishnam Goyal Worked on and shared a nice OpenCV based code to detect hand (fingers) using simple camera module and python code.

This is not a tutorial but just a shared post to congratulate Krishnam for nice work and to encourage to create more such projects.

Its the photo of Krishnam doing the experiment and code

Python Code

import cv2 as cv
import mediapipe as mp

import time
cap = cv.VideoCapture(0)
class handDetector():
    def __init__(self, mode = False,maxHands = 2, detectionCon = 0.5, trackcon = 0.5):
        self.mode = mode
        self.maxHands = maxHands
        self.detectionCon = detectionCon
        self.trackcon = trackcon
        self.mpHands =
        self.hands = self.mpHands.Hands(self.mode,self.maxHands,self.detectionCon,self.trackcon)
        self.mpDarw =

    def findHands(self,img,draw = True):
        imgRgb = cv.cvtColor(img, cv.COLOR_BGR2RGB)
        self.results = self.hands.process(imgRgb)

        if self.results.multi_hand_landmarks:
            for handLms in self.results.multi_hand_landmarks:
                if draw:
                    self.mpDarw.draw_landmarks(img, handLms, self.mpHands.HAND_CONNECTIONS)
        return img
    def findposition(self,img,handNo = 0, draw=True):
                lmlist = []
                myHand = self.results.multi_hand_landmarks[handNo]
                if self.results.multi_hand_landmarks:
                    for id, lm in enumerate(myHand.landmark):

                        # print(id,lm)
                        h, w, c = img.shape
                        cx, cy = int(lm.x * w), int(lm.y * h)
                        lmlist.append(id, c, cy)
                        # print(id, cx, cy)
                        # if id == 4:
                            #, (cx, cy), 25, (255, 0, 255), cv.FILLED)'
                return lmlist

def main():
    Pt = 0
    cT = 0
    #cap = cv.imread(0)
    cap = cv.VideoCapture(0)
    detector = handDetector()
    while True:
        success, img =
        img = detector.findHands(img)
        cT = time.time()
        fps = 1/(cT-Pt)
        Pt = cT

        cv.putText(img,str(int(fps)),(18, 78), cv.FONT_HERSHEY_COMPLEX,3,(255,0,255))
    # if fps >= 20:
    #     cv.putText(img, str(int(20)), (180, 78), cv.FONT_HERSHEY_COMPLEX, 3, (255, 0, 255))
        cv.imshow("Video", img)
if (__name__ == "__main__"):

The modules needed to run this code

Feel free to experiment with this code.

Leave a Reply

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

Tutorials and Posts you may be interested in...

How to use bluetooth with 8051

This Project is Suitable for Everyone Including student and Professional Bluetooth-based relay control using an 8051-based microcontroller involves using Bluetooth communication to remotely control the switching of a relay. Here’s

Read More »

How to use Raspberry Pi Pico W with Optocoupler

Optocouplers, also known as opto-isolators, are electronic components that provide electrical isolation between two circuits by using light to transfer signals. Optocouplers are commonly used to protect sensitive electronic devices

Read More »