import threading
from djitellopy import Tello
import cv2
from time import sleep

drone = Tello()
drone.connect()
drone.streamon()
    
def stream():
    ESC = 27
    while True:
        frame = drone.get_frame_read().frame
        bgr_frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        cv2.imshow('Drone Frame', bgr_frame)
        if cv2.waitKey(1) == ESC:
            drone.streamoff()
            cv2.destroyAllWindows()
            break
        
def drone_control():
    drone.takeoff()
    sleep(2)
    drone.move_left(100)
    sleep(2)
    drone.rotate_counter_clockwise(90)
    sleep(2)
    drone.move_forward(100)
    sleep(2)
    
a = threading.Thread(target = stream)
b = threading.Thread(target = drone_control)

a.start()
b.start()