# Importing Librariesimportcv2importmediapipeasmpfrommathimporthypotimportscreen_brightness_controlassbcimportnumpyasnp# Initializing the ModelmpHands=mp.solutions.handshands=mpHands.Hands(static_image_mode=False,model_complexity=1,min_detection_confidence=0.75,min_tracking_confidence=0.75,max_num_hands=2)Draw=mp.solutions.drawing_utils# Start capturing video from webcamcap=cv2.VideoCapture(0)whileTrue:# Read video frame by frame_,frame=cap.read()# Flip imageframe=cv2.flip(frame,1)# Convert BGR image to RGB imageframeRGB=cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)# Process the RGB imageProcess=hands.process(frameRGB)landmarkList=[]# if hands are present in image(frame)ifProcess.multi_hand_landmarks:# detect handmarksforhandlminProcess.multi_hand_landmarks:for_id,landmarksinenumerate(handlm.landmark):# store height and width of imageheight,width,color_channels=frame.shape# calculate and append x, y coordinates# of handmarks from image(frame) to lmListx,y=int(landmarks.x*width),int(landmarks.y*height)landmarkList.append([_id,x,y])# draw LandmarksDraw.draw_landmarks(frame,handlm,mpHands.HAND_CONNECTIONS)# If landmarks list is not emptyiflandmarkList!=[]:# store x,y coordinates of (tip of) thumbx_1,y_1=landmarkList[4][1],landmarkList[4][2]# store x,y coordinates of (tip of) index fingerx_2,y_2=landmarkList[8][1],landmarkList[8][2]# draw circle on thumb and index finger tipcv2.circle(frame,(x_1,y_1),7,(0,255,0),cv2.FILLED)cv2.circle(frame,(x_2,y_2),7,(0,255,0),cv2.FILLED)# draw line from tip of thumb to tip of index fingercv2.line(frame,(x_1,y_1),(x_2,y_2),(0,255,0),3)# calculate square root of the sum of# squares of the specified arguments.L=hypot(x_2-x_1,y_2-y_1)# 1-D linear interpolant to a function# with given discrete data points# (Hand range 15 - 220, Brightness# range 0 - 100), evaluated at length.b_level=np.interp(L,[15,220],[0,100])# set brightnesssbc.set_brightness(int(b_level))# Display Video and when 'q' is entered, destroy# the windowcv2.imshow('Image',frame)ifcv2.waitKey(1)&0xff==ord('q'):break