Enhancing UAV Safety: Accurate Distance Measurement with YOLOV8-based Measuring Application

This article introduces a lightweight and efficient model for measuring applications, aimed at enhancing the current UAV monitoring system. The primary objective of this project is to develop a measuring application capable of determining and displaying the distance between the camera on the UAV and the facial model. The YOLOV8 framework is employed as a detection model to identify and interpret objects within the region of interest. Additionally, the algorithm incorporates the concept of focal length in lenses to calculate the distance between the facial expressions of a human face and the camera. To assess the algorithm’s accuracy, facial models were placed at various distances from the camera during testing. The predicted distance values obtained through the algorithm were then compared to the actual measured distances using a measuring tape. The results demonstrated a maximum tolerance of ±0.9 cm, indicating the algorithm’s reliable performance in predicting distance measurements.


Introduction
Initially, drones were primarily utilized in military tasks, but today they serve a wide range of applications, including military operations, search and rescue missions, environmental monitoring, agriculture, and delivery services [1].They have also gained popularity among hobbyists and photographers, becoming readily available for purchase by the public [2].However, the increased use of drones as flying camera toys has led to a surge in drone accidents due to the lack of strict regulations and rules for drone enthusiasts [3].To address this issue and reduce accidents, computer vision can be integrated into drones.Computer vision is a cutting-edge field of study that focuses on enabling computers and machines to interpret and comprehend the visual world [4][5].It involves developing algorithms and systems that can analyze images and videos to recognize objects, understand their meaning, and extract valuable information [6].However, the current UAV monitoring systems may lack in adapting functions of computer vision which made it unable to accurately detect and classify objects or features in complex visual environments, such as those with low lighting, high contrast, or cluttered backgrounds [7][8].Moreover, the current UAV monitoring systems rely on human operators to interpret the images and identify any issues [9].This process can consume a significant amount of time and prone to errors, as the human operators may not always be able to accurately interpret the images or identify subtle issues.Furthermore, the current drone monitoring system may not be able to tell the distance between object and the drone [10].In this project, we propose an object detection, self-interpreting, and measuring application to enhance the UAV monitoring system.The aim is to improve the capabilities of the drone by integrating computer vision and enabling it to autonomously detect, interpret, and measure objects in various visual environments.

Distance Measurement of Facial Mode
To evaluate the measurement application's accuracy, an experimental setup was established within a room.A stationary webcam was positioned, while a human assumed various poses as a moving object.The distances between the camera and the human were set at 45cm, 75cm, 105cm, and 135cm, each measured precisely with a measuring tape.Subsequently, the algorithm was integrated, enabling realtime distance prediction in video.The predicted values generated by the algorithm were then juxtaposed against the measured values.Progressing to the equation's middle segment, "tan theta" represents the tangent of the angle of incidence.This term establishes a connection between the angle at which light strikes the lens, the object's height, and its distance from the lens.Essentially, it elucidates the interplay between incident angle, object characteristics, and image outcome.
On the equation's right side, "h/d" denotes the ratio between the object's height and its distance from the lens.This ratio facilitates understanding the interrelationship between object height and its lens-related distance, both shaping the final image presentation.Now, when the object shifts from position P1 to P2, variations occur in both the incident ray angle and the object's distance from the lens.Simultaneously, the object's height remains constant.These alterations lead to elevated angle and distance values, ultimately rendering the object taller in the resultant image.Figure 3 illustrates a visual depiction of these principles.
Equation 2 presents a similar structure, with "b/f" on the left denoting the object's height-to-focal length ratio.This ratio offers insights into the lens's magnification prowess.The middle segment, "tantheta," establishes a connection between the incident angle, image height, and the object-lens distance.It relates this angle to both the height of the resulting image and the distance between the object and the lens.On the right, "h/(d-m)" signifies the ratio between image height and the difference between object and image distances.The primary purpose of this equation revolves around determining object's displacement in the object plane.Equation ( 3) results from dividing Equation (1) by Equation (2), and through simplification, yields Equation (4).
To find the new distance, simply move  to the left-hand side of the equation and Equation ( 5) will be obtained.

Measuring Application Within Different Distances
The purpose of the measuring application is to notify drone operators about the proximity of their drones to obstacles.When flying a drone, if the drone is far from an object, the object appears smaller in the image, and the distance value is greater.Conversely, when the drone gets closer to the object, the object appears larger in the image, and the distance value becomes smaller.Figure 4 and figure 5 depict the graphs of predicted distances and measured distances at distances of 45cm, 75cm, 105cm, and 135cm from the camera, respectively.For each measured distance, the predicted distance value was collected 7 times.This multiple data collection is necessary as the predicted distance value changes each second the camera captures.With the human pose positioned at various distances from the camera, it is observed that at least one predicted distance value closely aligns with the measured distance value (as illustrated in figures 6 to figures 7).

Conclusion
The experiment utilizing the YOLOV8 framework for the measuring application was conducted successfully, and the results were gathered.The hypothesis states that when the drone is farther from an object, the object appears smaller in the image plane, and the distance value is greater, while when the drone is closer to the object, the object appears larger in the image plane, and the distance value is smaller, was tested for accuracy.The algorithm's performance was evaluated through 7 attempts at distances of 45cm, 75cm, 105cm, and 135cm, with the predicted distance values being compared to the measured values obtained using a measuring tape.In the experiment, the algorithm demonstrated remarkable accuracy by detecting the same distance as the measured distance, with a maximum tolerance of ±0.9cm.Thus, confirming the validity of the hypothesis that as the object moves closer to the camera, the value of the distance becomes smaller.

Figure 1 .
Figure 1.Distance displayed in 45cm of predicted distance between the facial model and the camera.

Figure 1
Figure1illustrates the predicted distance determination based on the principles of optic lenses, particularly convex lenses.When a parallel beam of light traverses a convex lens, it converges, altering the direction of the rays.This phenomenon causes them to merge and form an image on the lens's opposing side.The orientation of the real image depends on the object's positioning relative to the lens and can be either inverted or upright.A focal point exists within a convex lens, where parallel light rays unite post-lens passage.This focal point lies opposite to the lens's side housing the object, with the distance between it and the lens being referred to as the lens's focal length.Figure2visually elucidates the aforementioned concepts.!" =  # = $ %

Figure 2 .
Figure 2. Illustration of convergence of object plane into image plane.

Figure 3 .
Figure 3. Illustration of object moves from P1 to P2.

Figure 4 .Figure 6 .Figure 7 .
Figure 4 and figure 5 present data from experiments conducted in a laboratory using a stationary webcam, with humans positioned in various locations to simulate moving objects.The figures compare the data obtained from a tape measure with the predicted distance values generated by the YOLOV8 framework algorithm.(a) Human pose at 45 cm distance and (b) Human pose at 75 cm distance away from the camera on the UAV.(a) (b) Figure 5. (a) Human pose at 105 cm distance and (b) Human pose at 135 cm distance away from the camera on the UAV.(a) Human pose at 45 cm distance and (b) Human pose at 75 cm distance away from the camera on the UAV.(a) Human pose at 105 cm distance and (b) Human pose at 135 cm distance away from the camera on the UAV.