Necesito controlar el mouse de mi windows con python, pero que detecte mi mano con la…
- User
Necesito controlar el mouse de mi windows con python, pero que detecte mi mano con la camara, y que se mueva a la dirección de la que muevo mi mano a la camara.
- Assistant
Puedes utilizar la biblioteca OpenCV para procesar los datos de video de la cámara y detectar la posición de la mano en la imagen. Luego, puedes utilizar la biblioteca PyAutoGUI para controlar el mouse en Windows.
Aquí está un ejemplo básico que utiliza OpenCV para detectar la mano en una imagen y PyAutoGUI para mover el mouse:
import cv2 import numpy as np import pyautogui
Load Haar cascade file for hand detection
hand_cascade = cv2.CascadeClassifier('hand.xml')
Start webcam
cap = cv2.VideoCapture(0)
Run infinite loop to process video frames
while True: # Read a frame from the webcam ret, frame = cap.read()
# Convert the frame to grayscale gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # Detect hands in the frame hands = hand_cascade.detectMultiScale(gray, 1.3, 5) # Draw a rectangle around the hand for (x, y, w, h) in hands: cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 0, 255), 2) # Calculate the center of the hand hand_center = (x + w//2, y + h//2) # Move the mouse to the hand center pyautogui.moveTo(hand_center[0], hand_center[1]) # Display the processed frame cv2.imshow('Hand Detection', frame) # Break the loop if 'q' key is pressed if cv2.waitKey(1) & 0xFF == ord('q'): break
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.