Files
Sim-Tello-KI-fun/example_exercises/5_take_a_picture.py
Andrew Johnson 26b19a909f First Version (#1)
Co-authored-by: Anujith Muraleedharan <140189296+AnujithM@users.noreply.github.com>
2025-03-22 16:06:45 +01:00

31 lines
685 B
Python
Executable File

import os
import cv2
import time
import numpy as np
from tello_sim.tello_sim_client import TelloSimClient
# Initialize and connect
tello = TelloSimClient()
tello.connect()
tello.streamon()
# Takeoff
tello.takeoff()
time.sleep(5) # Let drone stabilize after takeoff
# Get frame object
frame_read = tello.get_frame_read()
tello.streamoff()
# Prepare directory to save
script_dir = os.path.dirname(__file__)
artifact_folder_path = os.path.join(script_dir, "../../artifacts/images")
os.makedirs(artifact_folder_path, exist_ok=True)
# Save the frame
save_path = os.path.join(artifact_folder_path, "picture.png")
cv2.imwrite(save_path, np.array(frame_read.frame))
# Land
tello.land()