Hello Tello Pilot!
Join our DJI Tello community & remove this banner.
Sign up

Taking Pictures with Tello Drone using Python 3

SunshineBunny

New member
Joined
Feb 10, 2020
Messages
2
Reaction score
0
Hi! I'm a middle grade student and I'm currently working on a project that involves making a program in Python 3 that lets the user control a Tello drone with arrow keys and letters on a computer. When the "s" key is clicked, the drone will take a picture. So far, I was able to get a live video feed from the drone with the easytello library, but I still need help finding a way for the drone to take a picture and save it to a certain directory in my computer. Thank you and I would really appreciate the help!
 

f41ardu

Well-known member
Joined
Jan 3, 2019
Messages
68
Reaction score
26
Location
Back in Stuttgart ;->
Pretty Easy:

Run this as seperate python script. One to controll tello and this one to take pictures. send streamon to tello and you see the video. Move the mouse pointer into the video window and press 's' to take a picure. The rest is up to you.

Python:
#
# --- (c) 02/2020 f41ardu
#
# Tello cam using opencv proof of concept
#
#

# import opencv 4.2.0
import cv2

telloVideo = cv2.VideoCapture("udp://@0.0.0.0:11111")


# wait for frame
ret = False
# scale down
scale = 3

while(True):
    # Capture frame-by-framestreamon
    ret, frame = telloVideo.read()
    if(ret):
    # Our operations on the frame come here
        height , width , layers =  frame.shape
        new_h=int(height/scale)
        new_w=int(width/scale)
        resize = cv2.resize(frame, (new_w, new_h)) # <- resize for improved performance
        # Display the resulting frame
        cv2.imshow('Tello',resize)
        
    if cv2.waitKey(1) & 0xFF == ord('s'):
        cv2.imwrite("test.jpg",resize) # writes image test.bmp to disk
        print("Take Picture")
    
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
telloVideo.release()
cv2.destroyAllWindows()
 
  • Like
Reactions: SunshineBunny

SunshineBunny

New member
Joined
Feb 10, 2020
Messages
2
Reaction score
0
Pretty Easy:

Run this as seperate python script. One to controll tello and this one to take pictures. send streamon to tello and you see the video. Move the mouse pointer into the video window and press 's' to take a picure. The rest is up to you.

Python:
#
# --- (c) 02/2020 f41ardu
#
# Tello cam using opencv proof of concept
#
#

# import opencv 4.2.0
import cv2

telloVideo = cv2.VideoCapture("udp://@0.0.0.0:11111")


# wait for frame
ret = False
# scale down
scale = 3

while(True):
    # Capture frame-by-framestreamon
    ret, frame = telloVideo.read()
    if(ret):
    # Our operations on the frame come here
        height , width , layers =  frame.shape
        new_h=int(height/scale)
        new_w=int(width/scale)
        resize = cv2.resize(frame, (new_w, new_h)) # <- resize for improved performance
        # Display the resulting frame
        cv2.imshow('Tello',resize)
       
    if cv2.waitKey(1) & 0xFF == ord('s'):
        cv2.imwrite("test.jpg",resize) # writes image test.bmp to disk
        print("Take Picture")
   
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

# When everything done, release the capture
telloVideo.release()
cv2.destroyAllWindows()
It works! Thank you so much for the help! :)
 

martinpi2

Member
Joined
Feb 21, 2020
Messages
12
Reaction score
3
Thanks a lot this is a good start.
I was looking for a solution to this question so I found this thread.

However, there's two more things:
  1. The resolution (if "scaled down" by a factor of 1) is only 720 px, but Tello cab take still pictures with much better resolution

  2. I would like to handle the photo in the main script. Like fly to a predefined location and take a photo. Or, later, do things like object recognition and react to the results like following an object.
There is definitely a way to do it, not necessarily in Python and not necessarily via the SDK. ATelloPilot (an Android app) can do it.
 

martinpi2

Member
Joined
Feb 21, 2020
Messages
12
Reaction score
3
Now I had some time to look at it more closely.

It is pretty cool and basically it fulfills everything I wrote under item 2.
It should be possible to run it in one script, e.g. copying your code into tello3.py.
And I have access to "frame" so I could do interesting things with opencv.
I don't have any experience with opencv, but it looks very promising.

Scaling down for performance was not necessary, I can change the scale factor to 1.
I also tried to scale it down for the video window and store the original frame in test.jpg. Worked.

It works as a proof of concept, but I met a few difficulties.

First, there are many error messages. It is not so disturbing when they are in a separate window (which is a temporary and makeshift solution).
The same kind of error messages occur when I call ffmpeg to display the video. At one time I forgot to send "streamon" and got these error messages

Code:
d:\daten\robotics\tello>python3 takePhoto.py
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:856)
warning: udp://@0.0.0.0:11111 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:857)
So opencv works with ffmpeg. Interesting.

In the combined script, I seem to have some timing issues, or I am not doing things in the right order. The video window opens but it hangs and has to be killed (Windows taskmanager).

Back to the two-scripts-variety:
It works fine when Tello is parked on the ground. In flight it shows the video in the window, but when I try to take a photo things get ugly. Tello stops to respond to commands and fortunately it does an emergency landing. The photo is not stored.

Conclusion:
Hot stuff, but some investigating has to be done.
 

martinpi2

Member
Joined
Feb 21, 2020
Messages
12
Reaction score
3
Tried again, the two-script-version, this time on the Raspberry Pi 4.
It worked! A lot better than on the PC under Windows. :)
It worked even in flight! I was able to take an aerial photo.

Before that, I had kind of a hard time to get cv2 working.
Error message - google - install something - error message - google - install something - and so on.
Without understanding what is going on.

2020-02-25-200644_1280x1024_scrot.png

Here you see a screenshot with the usual error messages (the red ones)
and the video preview from takePhoto.py, scaled down by a factor of 3.
The image quality is poor, but this is due to the light. At daylight the picture is better, and Tello flies better.
 
Last edited:

f41ardu

Well-known member
Joined
Jan 3, 2019
Messages
68
Reaction score
26
Location
Back in Stuttgart ;->
I also recognized this issues. Sometimes errors shows up while decoding and running this on my Raspberry 3+. Cause there is a large delay in the video stream, due to the limited performance of the Raspberry 3+. So I give up any further development on my Raspberry.

A much better approach is using pygame. Idea come cause I have an old RealFlight USB based Remote Controller. Using a laptop and the video stream performance is ok.

It is still in an experimental state and I have not much time to work on. My repository is still private on git, just get in touch with me and I invite you for joined development.

I also think about to implement the low level protocol which I already tried using Processing. But also give up last year due to the limited video performance using Processing on my Raspberry.

And it is not possible to change the video resolution using the simple SDK.

Thanks a lot this is a good start.
I was looking for a solution to this question so I found this thread.

However, there's two more things:
  1. The resolution (if "scaled down" by a factor of 1) is only 720 px, but Tello cab take still pictures with much better resolution

  2. I would like to handle the photo in the main script. Like fly to a predefined location and take a photo. Or, later, do things like object recognition and react to the results like following an object.
There is definitely a way to do it, not necessarily in Python and not necessarily via the SDK. ATelloPilot (an Android app) can do it.
 

New Threads

Members online

Forum statistics

Threads
4,188
Messages
31,784
Members
10,724
Latest member
Ajkari