From Image Detection to Safe Control Commands · Study
English translation
Execution conditions
The basic activities use NumPy and Matplotlib. Use OpenCV when connecting to the previous unit.
Topics covered
Use simulated inputs to examine how sign errors and oscillation arise when horizontal and vertical image errors are converted into movement commands.
Overall workflow
Detected center → image error → validity/limits → command/stop
Image errors and physical commands differ
The difference between object center and image center is measured in pixels. Converting it to actual velocity requires camera orientation, aircraft coordinates, and scale. First validate signs and error handling using bounded corrective commands in image space.
Missing and delayed observations
In detection results, None means the object was not found, while coordinates (0,0) refer to the image's upper-left pixel. Distinguish these cases and set velocity commands to 0 when detection fails.
Even if filtering reduces center coordinate fluctuations, also examine the delay between the object starting to move and the coordinates following it.
Boundaries when connecting your aircraft
First check image detection and command calculations using saved images. In MATLAB, replace only the frame acquisition using camera and snapshot; in Python, replace only streamon and get_frame_read.
When connecting your Tello, retain the same stop rules for failed detections and stale frames.
Worked example
The center of a 160×120 image is (80,60), and the observed center is (110,50). x points right and y points down.
import numpy as np
import matplotlib.pyplot as plt
def command(center):
if center is None:return np.zeros(2)
error=np.asarray(center)-[80,60]
return np.clip(np.where(np.abs(error)<=10,0,.02*error),-.5,.5)
print(command((110,50)),command(None))
plt.scatter([80,110],[60,50]);plt.arrow(80,60,30,-10,head_width=3);plt.xlim(0,160);plt.ylim(120,0);plt.gca().set_aspect('equal')
[0.5 0. ] [0. 0.]
Official documentation and data
Reference example
View more examples