
Создать .exe файл простой программы
Есть рабочий код на python, есть видео с описанием кода. Нужно создать исполняемый файл для запуска. Библиотеки: opencv-python, mediapipe, pyautogui.
Исполняемый файл назвать "VirtualMouse.py"
Cod
import cv2
import mediapipe as mp
import pyautogui
from mediapipe.python.solutions import drawing_utils
cap = cv2.VideoCapture(0)
hand_detector = mp.solutions.hands.Hands()
drawing_detector = mp.solutions.drawing_utils
screen_width, screen_height = pyautogui.size()
index_y = 0
try:
while True:
ret, frame = cap.read()
if not ret:
break # Break the loop if there's an issue with reading the frame
cv2.imshow('Virtual Mouse', frame)
key = cv2.waitKey(1)
if key == ord('q'): # Press 'q' to quit
break
frame_height, frame_width, _ = frame.shape
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
output = hand_detector.process(rgb_frame)
hands = output.multi_hand_landmarks
if hands:
for hand in hands:
drawing_utils.draw_landmarks(frame, hand)
landmarks = hand.landmark
for id, landmark in enumerate(landmarks):
x = int(landmark.x * frame_width)
y = int(landmark.y * frame_height)
if id == 9:
cv2.circle(frame, (x, y), radius=20, color=(0, 255, 255))
index_x = screen_width / frame_width * x
index_y = screen_height / frame_height * y
pyautogui.moveTo(index_x, index_y)
finally:
cv2.destroyAllWindows()
cap.release()
Заявки фрилансеров
