How to enable Tello drones to scan barcodes via Python?

Dynamsoft Barcode Reader SDK is a multi-functional barcode reading control that can embed the barcode reading function into web or desktop applications with just a few lines of code. This can save months of development time and cost. It can support a variety of image file formats and DIB formats obtained from cameras or scanners. Using Dynamsoft Barcode Reader SDK, you can create powerful and practical barcode scanner software to meet your business needs.

Click to download the latest version of Dynamsoft Barcode Reader

In the warehouse management system, Drone can be used to automatically scan barcodes for inventory counting. In order to learn drone driving and try to scan barcodes in the air, I purchased Ryze Tello, which is a micro drone powered by DJI. In this article, I will share how to use Dynamsoft Barcode Reader to detect and decode barcodes in Tello UAV video streams in real time.

Insert picture description here

Port Tello Video Sample from Python 2.7 to Python 3.7

The sample code dji-sdk/Tello-Python is a good crash course for Tello drone control. However, the maintenance of the repository seems to have stopped, and the code only works with Python 2.7.

Since Python 2 is no longer supported and I am using Python 3.7, I have to change the Python code and rebuild the related h264 decoding library to be compatible with Python 3.

Steps to run Tello Video Sample on Windows

Get the source code from DJI's GitHub repository.
git clone https://github.com/dji-sdk/Tello-Python.git
to import the project into your coding tool. Search globally and replace Python 3.7 with the following code snippet:

#2.7
import Tkinter
#3.7
import tkinter
#2.7
print “”
#3.7
print()
#2.7
packet_data = “”
#3.7
packet_data = bytes()
To build the h264 decoding library, first, install ffmpeg through vcpkg:
vcpkg.exe install ffmpeg: After x64-windows
, get the source code of h264decoder and build the Python module:

git clone https://github.com/DaWelter/h264decoder.git
cd h264decoder
python setup.py build_ext --cmake-args="-DCMAKE_TOOLCHAIN_FILE=[path to vcpkg]/scripts/buildsystems/vcpkg.cmake"

Why use Dynamsoft Python barcode SDK

Barcode scanning is a CPU-intensive operation, so running it in a Python thread will suffer from the performance bottleneck of the GIL. In order to avoid performance problems, Dynamsoft Python Barcode SDK provides a set of video decoding API based on C/C++ native thread implementation:
start_video_mode()
append_video_frame()
stop_video_mode()

Tello drone with barcode scanning

Install the Barcode SDK for Dynamsoft Python. This is for Python 3.6, 3.7 and 3.8:
pip install dbr to
apply for a free trial license to unlock all features.

Create a barcode reader object in tello.py:
from dbr import *
self.reader = BarcodeReader()
self.reader.init_license('LICENSE-KEY')
initialize the parameters and start the video mode:
parameters = self.reader.init_frame_decoding_parameters()
self.frameWidth = 640 # max: 960
self.frameHeight = 480 # max: 720
self.results = None
parameters.image_pixel_format = EnumImagePixelFormat.IPF_RGB_888
parameters.max_queue_length = 2
parameters.max_result_queue_length = 2
parameters.width = self.frameWidth
parameters.height = self.frameHeight
parameters.stride = self.frameWidth * 3
parameters.auto_filter = 1
self.reader.start_video_mode(parameters, self.on_barcode_result)
The camera resolution of the Tello drone is 720P. We can save the decoding result through the callback function for later UI rendering:
def on_barcode_result(self, data):
self.results = data
Next, go to the _receive_video_thread() function to append the received frame to the barcode decoding queue in:
for Frame in self._h264_decode (packet_data):
self.frame cv2.resize = (Frame, (self.frameWidth, self.frameHeight))
the try:
RET = self.reader.append_video_frame (self.frame)
the except:
Pass
Note : Unless you want to speed up the decoding speed, you do not need to adjust the frame size (large images are better for recognition accuracy).

Finally, we add stop_video_mode() to the destructor method:
def del (self):
self.reader.stop_video_mode()
With a few lines of Python code, I realized the barcode scanning of the Tello drone. Let's try the Tello UAV GUI application: How does the
python main.py
environment affect the UAV's vision system

When I tested the video stream of the drone in the office, I found that the image was not clear.

Insert picture description here

There is no mention of commands for adjusting focus in the Tello SDK user guide.

In addition, even though I have calibrated the IMU (Inertial Measurement Unit), it is difficult for the Tello drone to stay still when hovering in a low-light environment.

Source code
https://github.com/yushulx/tello-drone

Guess you like

Origin blog.csdn.net/RoffeyYang/article/details/113739450