Skip to content

Instantly share code, notes, and snippets.

@irudnyts
Created December 9, 2023 19:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save irudnyts/16d007db4fd042cd3e5dc8cf1e1b909f to your computer and use it in GitHub Desktop.
Save irudnyts/16d007db4fd042cd3e5dc8cf1e1b909f to your computer and use it in GitHub Desktop.
import cv2
import pygame
import numpy as np
from djitellopy import Tello
# --------------
# mediapipe
import mediapipe as mp
from mediapipe.tasks import python
from mediapipe.tasks.python import vision
model_path = 'gesture_recognizer.task'
base_options = python.BaseOptions(model_asset_path='gesture_recognizer.task')
options = vision.GestureRecognizerOptions(base_options=base_options)
recognizer = vision.GestureRecognizer.create_from_options(options)
mp_drawing = mp.solutions.drawing_utils
mp_drawing_styles = mp.solutions.drawing_styles
mp_hands = mp.solutions.hands
# --------------
width = 960
height = 720
pygame.init()
screen = pygame.display.set_mode((width, height))
is_running = True
drone = Tello()
drone.connect()
drone.streamon()
frame_read = drone.get_frame_read()
with mp_hands.Hands(
model_complexity=0,
min_detection_confidence=0.5,
min_tracking_confidence=0.5) as hands:
while is_running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
drone.streamoff()
is_running = False
frame = frame_read.frame
mp_image = mp.Image(image_format=mp.ImageFormat.SRGB, data=frame)
recognition_result = recognizer.recognize(mp_image)
print(recognition_result.gestures)
results = hands.process(frame)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(
frame,
hand_landmarks,
mp_hands.HAND_CONNECTIONS,
mp_drawing_styles.get_default_hand_landmarks_style(),
mp_drawing_styles.get_default_hand_connections_style())
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = np.rot90(frame)
frame = np.flipud(frame)
frame = pygame.surfarray.make_surface(frame)
screen.blit(frame, (0, 0))
pygame.display.flip()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment