<jupyter_start><jupyter_text>HandGestureDetection using OpenCV This code template is for Hand Gesture detection in a video using OpenCV Library.  Required Packages<jupyter_code>!pip install opencv-python
!pip install mediapipe
import cv2
import mediapipe as mp
import time<jupyter_output><empty_output><jupyter_text>Hand DetectionFor detecting hands in the image, we use the detectMultiScale() function.It detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles which can be then plotted around the hands.Tuning Parameters:**image** - Matrix of the type CV_8U containing an image where objects are detected.**objects** - Vector of rectangles where each rectangle contains the detected object, the rectangles may be partially outside the original image.**scaleFactor** - Parameter specifying how much the image size is reduced at each image scale.**minNeighbors** - Parameter specifying how many neighbors each candidate rectangle should have to retain it.<jupyter_code>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 = mp.solutions.hands
        self.hands = self.mpHands.Hands(self.mode, self.maxHands, self.detectionCon, self.trackCon)
        self.mpDraw = mp.solutions.drawing_utils
        
    def findHands(self,img, draw = True):
        imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        self.results = self.hands.process(imgRGB)
        # print(results.multi_hand_landmarks)

        if self.results.multi_hand_landmarks:
            for handLms in self.results.multi_hand_landmarks:
                if draw:
                    self.mpDraw.draw_landmarks(img, handLms, self.mpHands.HAND_CONNECTIONS)
        return img

    def findPosition(self, img, handNo = 0, draw = True):

        lmlist = []
        if self.results.multi_hand_landmarks:
            myHand = self.results.multi_hand_landmarks[handNo]
            for id, lm in enumerate(myHand.landmark):
                h, w, c = img.shape
                cx, cy = int(lm.x * w), int(lm.y * h)
                lmlist.append([id, cx, cy])
                if draw:
                    cv2.circle(img, (cx, cy), 3, (255, 0, 255), cv2.FILLED)
        return lmlist<jupyter_output><empty_output><jupyter_text>To run the handDetector(), save this file with .py extension and allow your webcam to take a video. The co-ordinates will be outputted at the terminal.<jupyter_code>pTime = 0
cTime = 0
cap = cv2.VideoCapture(0)
detector = handDetector()

while True:
  success, img = cap.read()
  img = detector.findHands(img)
  lmlist = detector.findPosition(img)
  if len(lmlist) != 0:
    print(lmlist[4])

  cTime = time.time()
  fps = 1 / (cTime - pTime)
  pTime = cTime

  cv2.putText(img, str(int(fps)), (10, 70), cv2.FONT_HERSHEY_PLAIN, 3, (255, 0, 255), 3)

  cv2.imshow("Image", img)
  cv2.waitKey(1)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0927734375, 'fraction_numerical': 0.014973958333333334, 'mean_word_length': 3.2095890410958905, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '6176', 'license': 'Apache-2.0', 'n_tokens_mistral': 1005, 'n_tokens_neox': 945, 'n_words': 287, 'path': 'Audio Visual/Problems/HandGestureDetection_OpenCV_Video.ipynb', 'repo_name': 'pavi-ninjaac/ai-seed', 'size': '3072'}