# Code to control webcam based on u
# Code to control webcam based on u
recognition.
# Calculate distance
duration = end_time - start_time
distance = (duration * 34300) / 2 # Speed of sound in cm/s
return distance
# Initial Variables
cap = None
light_on = False
webcam_active = False
distance_threshold = 30 # Distance threshold to trigger the camera (in cm)
# Main Loop
while True:
# Ultrasonic Sensor Reading
distance = get_distance()
print("Distance:", distance, "cm")
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(image, hand_landmarks,
mp_hands.HAND_CONNECTIONS)