Azure Cloud Services for Tello Drones: How to Send Images to Azure Blob Storage
Introduction
Tello is a programmable mini drone, which is perfect and popular for beginners. Users can easily control it by programming languages such as Scratch, Python, and Swift. Microsoft Azure provides a variety of cloud computing services including artificial intelligence, machine learning, IoT, storage, security, networking, media, integration and so on. Azure Blob storage is Microsoft's object storage solution for the cloud. Blob storage is optimized for storing massive amounts of unstructured data, for example, images, documents, video and audio files.
In this article, we will walk you through the steps required to capture and send image from Tello to Azure Blob Storage with Azure Storage Blobs client library for Python.
Prerequisites
- Tello Drone.
- Azure Storage Blobs client library for Python
- IDE: PyCharm Community
- Azure subscription
Network Access for PC
Since Tello is connected to the PC by Wi-Fi, it is straightforward to know that our PC should equipped with two network interface cards, one is for connecting with Tello, and the other one is for connecting with Internet.
Fig. 1 Network Access
Azure Blob Storage
Azure Blob Storage is Microsoft's object storage solution for the cloud. Blob Storage is optimized for storing massive amounts of unstructured data. It is designed for:
- Serving images or documents directly to a browser.
- Storing files for distributed access.
- Streaming video and audio.
- Writing to log files.
- Storing data for backup and restore, disaster recovery, and archiving.
- Storing data for analysis by an on-premises or Azure-hosted service.
In this project, we make use of Azure Blob Storage to store the image captured by the Tello.
Create an Azure Storage Account
We can create an Azure Storage Account using the Azure Portal. Please refer to the “Create a storage account” section on this page: Create a storage account. Then, in order to send the files to Azure Storage, we should get the connection string. The “View account access keys” section is available on this page Manage storage account access keys to help you with this. This connection string will be used by Python code to communicate with the Azure Storage.
Install Python Packages
In this project, we will install “djitellopy”, “azure-storage-blob” and “Pygame” packages to accelerate the development. Please refer to the “Install Python Azure IoT SDK and Tello Python SDK” section of the article “Azure Cloud Services for Tello Drones: How to send telemetry to Azure IoTHub” to complete this step.
Create and Debug Python Code on Your PC
Copy and paste the following code to your PyCharm project.
from djitellopy import tello
import KeyPressModule as kp
import time
import cv2
from azure.storage.blob import ContentSettings, BlobClient
kp.init()
me = tello.Tello()
me.connect()
print(me.get_battery())
me.streamon()
global img
conn_str = "your connection string"
container_name = "raspberrypic"
blob_name = "capture"
def getKeyboardInput():
lr, fb, ud, yv = 0, 0, 0, 0
speed = 50
if kp.getKey("LEFT"):
lr = -speed
elif kp.getKey("RIGHT"):
lr = speed
if kp.getKey("UP"):
fb = speed
elif kp.getKey("DOWN"):
fb = -speed
if kp.getKey("w"):
ud = speed
elif kp.getKey("s"):
ud = -speed
if kp.getKey("a"):
yv = speed
elif kp.getKey("d"):
yv = -speed
if kp.getKey("q"): me.land()
if kp.getKey("e"): me.takeoff()
if kp.getKey("z"):
global img
cv2.imwrite(f'Resources/Images/capture.jpg', img)
time.sleep(0.3)
# upload the image to Azure Blob Storage, Overwrite if it already exists!
blob = BlobClient.from_connection_string(conn_str, container_name, blob_name)
image_content_setting = ContentSettings(content_type='image/jpeg')
with open(f'Resources/Images/capture.jpg', "rb") as data:
try:
blob.upload_blob(data, overwrite=True, content_settings=image_content_setting)
print("Blob storage uploading completed")
except ValueError:
print("Blob storage uploading error")
return [lr, fb, ud, yv]
def main():
print("Capture and send Tello image to Azure Blob Storage")
while True:
vals = getKeyboardInput()
me.send_rc_control(vals[0], vals[1], vals[2], vals[3])
global img
img = me.get_frame_read().frame
img = cv2.resize(img, (1280, 720))
cv2.putText(img, str(me.get_current_state()), (10, 60), cv2.FONT_HERSHEY_PLAIN, 0.9, (255, 0, 255), 1)
cv2.imshow("image", img)
cv2.waitKey(50)
if __name__ == "__main__":
main()
In this Python application, we define a function getKeyboardInput to receive the keyboard input of the user, which return the control parameters to the loop in main function. It is quite the same as we designed in this article “Azure Cloud Services for Tello Drones: How to Control Tello by Azure C2D Messages”.
To achieve the image transmitting, we first store the image in the folder “Resources/Images/” of the project when we input “z” from keyboard. Then, a BlobClient is created to send the image to the Azure Storage by its upload_blob method.
Please do substitute the connection string with yours that created before. Then, power on the Tello, connect your PC with Tello by Wi-Fi. You will notice that the LED on the Tello will flash quickly with yellow color. Press Run or Debug button to start the process. You will see the information in output window as shown in Fig. 2.
Fig. 2 Realtime Debug Information
After a few seconds, the real time image that streamed from the Tello, as well as the Pygame window will be shown on the screen, as presented in Fig. 3.
Fig. 3 Real time image and Pygame window
Then, we can click the mouse on the Pygame window to focus user input on it. After that, we can use “w, s, a, d, e, q, up arrow, down arrow, left arrow, right arrow” to control the movement of the Tello drone. The device status of the Tello will be written on the top center of the image. Importantly, the “z” is used to store and send the image to the Azure Storage Blob.
Once the image is transmitted to the Azure Blob storage, we can see the log information on the debug window. Then, we can make use of Azure Storage Explorer to check the image as shown in Fig. 4.
Fig. 4 Review Image with Azure Storage Explorer
Summary
In this tutorial, we have presented the steps and Python codes on how to send image streamed from Tello drone to Azure Blob Storage.
Resources
- MS Docs for Azure Blob storage.
- MS Docs for Create a storage account.
- MS Docs for Manage storage account access keys.