Camera focal length control method, system, device and medium based on target imaging

By acquiring flight altitude and attitude information from the UAV system, performing focal length traversal and target detection, calculating offset distance and imaging size parameters, and performing corrections and attitude compensation, the problem of inaccurate focal length control in UAV camera systems under dynamic environments is solved, and image quality is improved.

CN121619498BActive Publication Date: 2026-05-08BEIJING ZHONGDIAN LIANDA INFORMATION TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING ZHONGDIAN LIANDA INFORMATION TECH CO LTD
Filing Date
2026-01-14
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing drone camera systems struggle to fully capture target imaging characteristics in dynamic environments, leading to inaccurate focus control and impacting image quality.

Method used

By acquiring the current flight altitude and attitude information of the UAV, the focal length traversal range and step interval are determined, image acquisition and target detection are performed, the offset distance and imaging size parameters of the target area are calculated, corrections and attitude compensation are performed, and focal lengths that meet the size and sharpness requirements are selected.

Benefits of technology

It improves the accuracy of camera focal length control, enabling it to more accurately reflect target imaging characteristics and enhance image quality in dynamic flight environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121619498B_ABST
    Figure CN121619498B_ABST
Patent Text Reader

Abstract

A camera focal length control method, system, device and medium based on target imaging, relates to the technical field of data processing. The method comprises: obtaining a desired imaging parameter and a current height of a UAV, determining a focal length traversal range and a step interval according to the desired imaging parameter and the current height of the UAV, and controlling the camera to collect an image sequence in the range. Target detection is performed on each frame of image, the imaging size and center offset of the target region are calculated, and offset correction is performed to obtain the imaging parameter under each focal length. By calculating the deviation of the imaging parameter and the desired parameter, the target focal length meeting the threshold value is selected. Then, the clarity of the region corresponding to the target focal length is calculated, and the final clarity value is obtained according to the attitude angle and flight speed information of the UAV. The focal length corresponding to the maximum clarity is selected as the optimal focal length, and the camera is controlled to complete the focusing. The technical scheme provided by the application can improve the accuracy of camera focal length control.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data processing technology, specifically to a camera focal length control method, system, device, and medium based on target imaging. Background Technology

[0002] With the widespread application of drone technology in fields such as industrial inspection, emergency rescue, and surveying, increasingly higher demands are being placed on the imaging quality of camera systems. When performing various tasks, drones need to capture high-quality images of specific targets and ensure that the size and sharpness of the targets in the images meet the requirements of practical applications. This poses a significant challenge to the camera's focal length control capabilities.

[0003] Currently, drone camera systems mainly use autofocus technology to adjust the focal length. They evaluate image quality by acquiring image data in real time and analyzing image features, and dynamically adjust the focal length based on the evaluation results to generate target images that meet shooting requirements.

[0004] However, in practical applications, existing focal length control methods usually analyze and evaluate the local features of a single image frame independently. This approach ignores the impact of UAV attitude changes during flight on the imaging effect, making it difficult to fully reflect the imaging characteristics of the target in a dynamic environment. This results in unstable image quality and reduces the accuracy of camera focal length control. Summary of the Invention

[0005] This application provides a camera focal length control method, system, device, and medium based on target imaging, which can improve the accuracy of camera focal length control.

[0006] In a first aspect, this application provides a camera focal length control method based on target imaging, comprising:

[0007] Obtain the desired imaging parameters and the current flight altitude of the UAV;

[0008] Based on the current flight altitude, determine the focal length traversal range and focal length step interval, control the camera lens of the UAV to traverse and acquire images within the focal length traversal range at the focal length step interval, and determine the image acquisition sequence.

[0009] Target detection is performed on each frame of the image acquisition sequence to determine the target region, the imaging width and imaging height of the target region are acquired, and the offset distance between the geometric center of the target region and the image center is calculated;

[0010] Based on the offset distance, the imaging width and imaging height are corrected to obtain imaging size parameters at multiple focal lengths;

[0011] Calculate the size deviation between the imaging size parameters and the target desired imaging parameters at each focal length, and filter out the target focal lengths whose size deviation values ​​are less than a preset threshold;

[0012] The image sharpness of the tracking area corresponding to the target focal length is calculated to determine the first image sharpness;

[0013] The attitude angle information and flight speed information of the UAV are obtained, and attitude compensation is performed on the first image sharpness based on the attitude angle information and the flight speed information to obtain the second image sharpness;

[0014] The target focal length corresponding to the maximum image clarity is taken as the focal length of the camera to be adjusted, and the camera lens of the UAV is controlled to be adjusted to the focal length of the camera to be adjusted.

[0015] By adopting the above technical solution, firstly, the focal length traversal range and step interval are determined based on the current flight altitude of the UAV, and the camera is controlled to traverse and acquire images within this range, thus comprehensively obtaining the target imaging features at different focal lengths. Secondly, by performing target detection and determining the target region for each frame of the acquired sequence, the offset distance between the geometric center of the target region and the image center is calculated, and the imaging size parameters are corrected based on this offset distance, which can eliminate the influence of target position offset on imaging size evaluation. Then, by calculating the size deviation value between the corrected imaging size parameters and the desired imaging parameters at each focal length, and screening out the target focal lengths that meet the preset threshold requirements, candidate focal lengths that meet the size requirements can be preliminarily determined. Finally, based on the UAV attitude angle information and flight speed information, image sharpness calculation and attitude compensation are performed on the tracking area corresponding to the target focal length, thus comprehensively considering the influence of attitude changes on imaging quality during the dynamic flight of the UAV, so that the final selected focal length to be adjusted can more accurately reflect the imaging characteristics of the target in the actual flight environment, effectively improving the accuracy of camera focal length control.

[0016] Optionally, the minimum and maximum focal length values ​​of the drone's camera lens are obtained; a preset altitude-focal length mapping table is queried based on the current flight altitude to determine the recommended focal length center value corresponding to the current flight altitude; a preset focal length range is extended in the directions of the minimum and maximum focal length values ​​based on the recommended focal length center value to obtain the focal length traversal range; and the focal length step interval is determined based on the ratio of the span of the focal length traversal range to the preset number of traversal frames.

[0017] Optionally, the bounding box coordinates of the target region are extracted, including the coordinates of the upper left corner and the lower right corner; the geometric center coordinates of the target region are calculated based on the bounding box coordinates, where the geometric center coordinates are the midpoint coordinates of the upper left corner and the lower right corner; the image center coordinates of the current image in the image acquisition sequence are obtained; the coordinate differences between the geometric center coordinates and the image center coordinates in the horizontal and vertical directions are calculated; and the offset distance is calculated using the Euclidean distance formula based on the coordinate differences in the horizontal and vertical directions.

[0018] Optionally, the imaging width and imaging height are iterated according to a preset focal length scale to obtain multiple sub-imaging widths and sub-imaging heights corresponding to each focal length. For each focal length, it is determined whether the target region is located in the center region of the image based on the offset distance. If the target region is located in the center region of the image, the sub-imaging width and sub-imaging height corresponding to the focal length are used as the imaging size parameters under the focal length. If the target region is not located in the center region of the image, a perspective distortion correction coefficient is calculated based on the offset distance and the distortion parameters of the camera lens. Based on the perspective distortion correction coefficient, a compensation calculation is performed on the sub-imaging width and sub-imaging height corresponding to the focal length to obtain the imaging size parameters under the focal length.

[0019] Optionally, the radial distortion coefficient and tangential distortion coefficient of the camera lens are obtained; the radial offset and tangential offset of the target region in the image are calculated based on the offset distance; a first dimensional error introduced by radial distortion is calculated based on the radial distortion coefficient and the radial offset; a second dimensional error introduced by tangential distortion is calculated based on the tangential distortion coefficient and the tangential offset; the first dimensional error and the second dimensional error are vector-synthesized to obtain a distortion error value; and a perspective distortion correction coefficient is determined based on the ratio of the distortion error value to the reference dimensional value of the camera lens.

[0020] Optionally, the target region in the image corresponding to the target focal length is extracted as the tracking region; the tracking region is grayscaled to obtain a grayscale image; the Sobel operator is used to perform edge detection on the grayscale image, and the gradient magnitude of each pixel in the tracking region is calculated; the number of pixels in the tracking region with gradient magnitudes greater than a preset gradient threshold is counted to obtain the number of effective edge pixels; the average gradient magnitude of all pixels in the tracking region is calculated to obtain the average gradient intensity; the ratio of the number of effective edge pixels to the total number of pixels in the tracking region is used as the edge density coefficient; the average gradient intensity and the edge density coefficient are weighted and summed to obtain the first image sharpness.

[0021] Optionally, the pitch and roll angles are extracted from the attitude angle information; the attitude deviation is calculated based on the pitch and roll angles, where the attitude deviation is the square root of the sum of the squares of the pitch and roll angles; an attitude compensation coefficient is determined based on the attitude deviation, where the attitude compensation coefficient is positively correlated with the attitude deviation; the horizontal and vertical flight speeds are obtained from the flight speed information; the displacement of the UAV during the image exposure time is calculated based on the horizontal and vertical flight speeds; a motion blur compensation coefficient is determined based on the displacement, where the motion blur compensation coefficient is positively correlated with the displacement; and the first image sharpness is multiplied by the attitude compensation coefficient and the motion blur compensation coefficient to obtain the second image sharpness.

[0022] A second aspect of this application provides a camera focal length control system based on target imaging, the system comprising:

[0023] The data acquisition module is used to acquire the desired imaging parameters and the current flight altitude of the UAV;

[0024] The offset distance determination module is used to determine the focal length traversal range and focal length step interval based on the current flight altitude, control the camera lens of the UAV to traverse and acquire images within the focal length traversal range at the focal length step interval, determine the image acquisition sequence, perform target detection on each frame of the image acquisition sequence, determine the target region, acquire the imaging width and imaging height of the target region, and calculate the offset distance between the geometric center of the target region and the image center.

[0025] An image sharpness determination module is used to correct the imaging width and imaging height based on the offset distance to obtain imaging size parameters at multiple focal lengths; calculate the size deviation value between the imaging size parameters at each focal length and the target desired imaging parameters, and filter out target focal lengths whose size deviation value is less than a preset threshold; perform image sharpness calculation on the tracking area corresponding to the target focal length to determine the first image sharpness;

[0026] The focal length adjustment module is used to acquire the attitude angle information and flight speed information of the UAV, and to perform attitude compensation on the first image sharpness according to the attitude angle information and flight speed information to obtain the second image sharpness; the target focal length corresponding to the maximum second image sharpness is used as the camera focal length to be adjusted, and the camera lens of the UAV is controlled to adjust to the camera focal length to be adjusted.

[0027] A third aspect of this application provides an electronic device including a memory, a processor, and a program stored in the memory and executable on the processor, the program being loaded and executed by the processor to implement a camera focal length control method based on target imaging.

[0028] A fourth aspect of this application provides a computer-readable storage medium storing a computer program that, when executed by a processor, causes the processor to implement a camera focal length control method based on target imaging.

[0029] In summary, one or more technical solutions provided in this application have at least the following technical effects or advantages:

[0030] By adopting the above technical solution, firstly, the focal length traversal range and step interval are determined based on the current flight altitude of the UAV, and the camera is controlled to traverse and acquire images within this range, thus comprehensively obtaining the target imaging features at different focal lengths. Secondly, by performing target detection and determining the target region for each frame of the acquired sequence, the offset distance between the geometric center of the target region and the image center is calculated, and the imaging size parameters are corrected based on this offset distance, which can eliminate the influence of target position offset on imaging size evaluation. Then, by calculating the size deviation value between the corrected imaging size parameters and the desired imaging parameters at each focal length, and screening out the target focal lengths that meet the preset threshold requirements, candidate focal lengths that meet the size requirements can be preliminarily determined. Finally, based on the UAV attitude angle information and flight speed information, image sharpness calculation and attitude compensation are performed on the tracking area corresponding to the target focal length, thus comprehensively considering the influence of attitude changes on imaging quality during the dynamic flight of the UAV, so that the final selected focal length to be adjusted can more accurately reflect the imaging characteristics of the target in the actual flight environment, effectively improving the accuracy of camera focal length control. Attached Figure Description

[0031] Figure 1 This is a schematic flowchart of a camera focal length control method based on target imaging provided in an embodiment of this application;

[0032] Figure 2 This is another schematic flowchart of a camera focal length control method based on target imaging provided in an embodiment of this application;

[0033] Figure 3 This is a schematic diagram of a camera focal length control system based on target imaging provided in an embodiment of this application;

[0034] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0035] To enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments.

[0036] In the description of the embodiments of this application, the words "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design that is described as "for example" or "for instance" in the embodiments of this application should not be construed as being more preferred or advantageous than other embodiments or design options. Rather, the use of the words "for example" or "for instance" is intended to present the relevant concepts in a specific manner.

[0037] In the description of the embodiments of this application, the term "multiple" means two or more. For example, multiple systems means two or more systems, and multiple screen terminals means two or more screen terminals. Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the indicated technical features. Thus, a feature defined with "first" or "second" may explicitly or implicitly include one or more of that feature. The terms "comprising," "including," "having," and variations thereof all mean "including but not limited to," unless otherwise specifically emphasized.

[0038] This application provides a camera focal length control method based on target imaging. In one embodiment, please refer to... Figure 1 , Figure 1 This is a flowchart illustrating a camera focal length control method based on target imaging provided in this application. This method can be implemented using a computer program, which can be integrated into an application or run as a standalone utility application. The method can also be implemented using a microcontroller or run on a target imaging-based camera focal length control system based on the von Neumann architecture. Specifically, the method may include the following steps:

[0039] Step 101: Obtain the desired imaging parameters and the current flight altitude of the UAV.

[0040] Desired imaging parameters refer to the specific requirements for the imaging effect of the target in the image, mainly including quantitative indicators such as the expected size of the target in the image (e.g., the proportion of the target area in the entire image, the pixel width and height of the target area), and the expected resolution (e.g., the number of pixels per meter). The current flight altitude of the UAV refers to the vertical distance of the UAV relative to the ground, which can be obtained through an onboard altimeter, GPS, or other altimetering equipment, and is usually measured in meters. These parameters constitute the basic input data for camera focal length control.

[0041] Specifically, the target's desired imaging parameters are first set through the task planning module. This includes setting the desired pixel size of the target in the image, such as requiring the target area to be 800 pixels wide and 600 pixels high; or setting the area ratio of the target area to the entire image area, such as requiring the target area to occupy 30% of the total image area; or setting the ground sampling distance (GSD), such as requiring 20 pixels per meter. Simultaneously, real-time flight altitude data of the UAV is collected through onboard equipment. This can be achieved using a barometric altimeter to obtain relative barometric altitude, an ultrasonic or laser rangefinder to obtain relative ground altitude, or differential GPS to obtain absolute altitude. When multiple altitude data sources exist, a data fusion algorithm is used to obtain a more accurate altitude value. For example, when a UAV is performing an industrial chimney inspection task, the task requires the target chimney to be at least 1000 pixels wide in the image. In this case, the target width in the desired imaging parameters is set to 1000 pixels, and the current flight altitude of the UAV above the ground is obtained as 120 meters via RTK-GPS. These collected parameters will be used for subsequent focal length range determination and imaging effect evaluation.

[0042] Step 102: Determine the focal length traversal range and focal length step interval based on the current flight altitude, control the UAV's camera lens to traverse and acquire images within the focal length traversal range at focal length step intervals, and determine the image acquisition sequence.

[0043] The focal length traversal range refers to the search interval of a camera lens when adjusting its focal length, determined by the minimum and maximum focal length values, measured in millimeters. The focal length step interval refers to the difference between two adjacent focal length values ​​during the traversal, used to control the accuracy and sampling density of the focal length adjustment. The image acquisition sequence refers to a set of consecutive image frames acquired during the focal length traversal, with each frame corresponding to a specific focal length value. The camera lens refers to the variable focal length optical system mounted on the drone, which can change the focal length by adjusting the relative positions of the lens groups.

[0044] Specifically, firstly, based on the current flight altitude, a preset altitude-focal length mapping table is consulted to obtain the recommended focal length center value. For example, at a flight altitude of 100 meters, the table shows a recommended focal length center value of 35 mm. Next, using this center value as a reference, a preset range is expanded to both sides to determine the focal length traversal range, such as expanding downwards by 10 mm and upwards by 15 mm, resulting in a traversal range of 25-50 mm. Then, the focal length step interval is calculated based on the preset traversal frame number. The specific calculation method is: Focal length step interval = (maximum focal length value - minimum focal length value) / (preset traversal frame number - 1). Taking a preset traversal frame number of 6 as an example, the focal length step interval is (50-25) / (6-1) = 5 mm. Afterwards, the camera lens is controlled to sequentially adjust to focal length values ​​of 25, 30, 35, 40, 45, and 50 mm, acquiring one frame at each focal length position. Constant exposure parameters are used during the acquisition process to ensure the consistency of the image sequence. The final result is a sequence of 6 images, each corresponding to a specific focal length value, used for subsequent target detection and imaging performance evaluation. The entire acquisition process is automated through the camera control interface, ensuring the accuracy and efficiency of the sampling process.

[0045] In one possible implementation, the focal length traversal range and focal length step interval are determined based on the current flight altitude, specifically including steps 1021-1023, as follows:

[0046] Step 1021: Obtain the minimum and maximum focal length values ​​of the drone's camera lens; based on the current flight altitude, query the preset altitude-focal length mapping table to determine the recommended focal length center value corresponding to the current flight altitude.

[0047] The minimum and maximum focal length values ​​of a camera lens refer to the boundaries of the focal length range achievable by the lens's physical structure, measured in millimeters. These parameters are typically provided by the lens manufacturer in the product specifications. An altitude-focal length map is a pre-established data lookup table that records suitable focal length values ​​for different flight altitudes. Each entry in the table includes the flight altitude and the corresponding recommended focal length center value. The recommended focal length center value refers to the baseline focal length value most suitable for target imaging at a specific flight altitude.

[0048] Specifically, the minimum and maximum focal length values ​​of the lens are extracted by reading the product parameter configuration file of the camera lens. Taking a certain model of zoom lens as an example, its minimum focal length is 24mm and its maximum focal length is 70mm. These two parameters determine the physical boundary of subsequent focal length adjustment. Then, the recommended focal length center value is determined: First, an altitude-focal length mapping table is constructed, which records a series of discrete flight altitude points and their corresponding optimal focal length values. For example, 50 meters corresponds to a 35mm focal length, 100 meters corresponds to a 50mm focal length, and 150 meters corresponds to a 65mm focal length. After obtaining the current flight altitude, the corresponding recommended focal length center value is calculated from the mapping table using a linear interpolation method. The specific calculation method is as follows: find two adjacent table record points of the current flight altitude, and use the linear interpolation formula: Recommended focal length center value = focal length 1 + (focal length 2 - focal length 1) × (current altitude - altitude 1) / (altitude 2 - altitude 1). For example, when the flight altitude is 75 meters, adjacent recording points at 50 meters and 100 meters are found. Through interpolation, a recommended focal length center value of 42.5 millimeters is calculated. This recommended focal length center value will serve as the reference point for subsequently determining the focal length traversal range.

[0049] Step 1022: Based on the recommended focal length center value, expand the preset focal length range in the directions of minimum focal length value and maximum focal length value respectively to obtain the focal length traversal range.

[0050] The recommended focal length center value refers to the optimal focal length reference value obtained by looking up a table at the current flight altitude, in millimeters. The preset focal length range refers to the distance extended on both sides of the focal length center value, used to determine the size of the actual search interval, in millimeters. The focal length traversal range refers to the finally determined focal length search interval, consisting of a lower limit and an upper limit. This range must simultaneously meet the requirements of not exceeding the lens's physical limitations and containing a sufficiently large search space. The extension direction refers to extending the range from the focal length center value towards the direction of the minimum focal length value (lower limit direction) and the direction of the maximum focal length value (upper limit direction).

[0051] Specifically, first, a basic extension range value is set, which is determined based on the target imaging requirements and flight altitude, for example, set to ±15 mm. Using the recommended focal length center value as a reference point, the range is extended in two directions. The specific calculation method is: Lower temporary limit value = Recommended focal length center value - Basic extension range value; Upper temporary limit value = Recommended focal length center value + Basic extension range value. Then, boundary checks and adjustments are performed: If the lower temporary limit value is less than the lens's minimum focal length value, the lower limit value is set to the minimum focal length value; if the upper temporary limit value is greater than the lens's maximum focal length value, the upper limit value is set to the maximum focal length value. For example: A drone is equipped with a zoom lens with a focal length range of 24-70 mm, the current recommended focal length center value is 35 mm, and the basic extension range value is 15 mm. The calculated temporary lower limit is 20 mm (35-15=20). Since this is less than the lens's minimum focal length of 24 mm, the lower limit is adjusted to 24 mm. The temporary upper limit is 50 mm (35+15=50). This value does not exceed the maximum focal length of 70 mm, so it remains unchanged. The final determined focal length traversal range is [24, 50] mm. This range ensures sufficient search space while avoiding exceeding the lens's physical limitations.

[0052] Step 1023: Determine the focal length step interval based on the ratio of the span of the focal length traversal range to the preset number of traversal frames.

[0053] The focal length traversal range refers to the width of the focal length search interval, calculated by subtracting the minimum focal length value from the maximum focal length value, in millimeters. The preset traversal frame count refers to the number of images to be acquired during focal length traversal; this value directly affects the sampling density and computational cost. The focal length step interval refers to the interval between two adjacent focal length adjustments, used to determine the accuracy of the focal length adjustment, in millimeters. The ratio operation is the quotient obtained by dividing the focal length range span by the preset traversal frame count minus 1.

[0054] Specifically, first, the span of the focal length traversal range is calculated using the formula: Span = Upper limit of focal length traversal range - Lower limit of focal length traversal range. Then, a preset traversal frame count is set based on the actual application scenario; this value needs to balance sampling accuracy and processing efficiency. Next, a division operation is performed using the formula: Focal length step interval = Focal length range span / (Preset traversal frame count - 1). The reason for subtracting 1 here is that n sampling points divide the range into n-1 intervals. For example, in a certain task, the focal length traversal range is [24, 50] mm, the span is 26 mm (50-24=26), and the preset traversal frame count is 6 frames. Therefore, the focal length step interval = 26 / (6-1) = 5.2 mm. To ensure the accuracy of focal length adjustment, the calculated step interval value is rounded down, ultimately determining the focal length step interval to be 5 mm. In this way, during the actual traversal, the camera lens will be adjusted to positions of 24, 29, 34, 39, 44, and 49 mm in sequence to acquire images, which ensures both the uniformity of sampling and meets the requirements of computational efficiency.

[0055] Step 103: Perform target detection on each frame of the image acquisition sequence, determine the target region, acquire the imaging width and imaging height of the target region, and calculate the offset distance between the geometric center of the target region and the image center.

[0056] Object detection refers to the process of locating and identifying specific targets in an image using computer vision algorithms, outputting the target's location and category information. The target region refers to the area occupied by the target in the image, usually represented by a rectangular bounding box. Imaging width and imaging height refer to the width and height values ​​of the target region's bounding box in pixel coordinates. The geometric center refers to the coordinates of the center point of the target region's bounding box. The image center refers to the coordinates of the center point of the entire image, typically half the image width and height. The offset distance is the Euclidean distance from the target's geometric center to the image center.

[0057] Specifically, the target detection algorithm is first executed on each frame of the image acquisition sequence. A deep learning-based target detection network (such as YOLOv5 or Faster R-CNN) is used. The network input is the original image, and the output is the bounding box coordinates of the target, including the top-left corner (x1, y1) and the bottom-right corner (x2, y2). The imaging parameters of the target region are calculated using the bounding box coordinates: imaging width = x2 - x1, imaging height = y2 - y1. Simultaneously, the geometric center coordinates of the target region are calculated: center x-coordinate = (x1 + x2) / 2, center y-coordinate = (y1 + y2) / 2. The image center coordinates are then obtained: image center x-coordinate = image width / 2, image center y-coordinate = image height / 2. Finally, the offset distance is calculated: the offset in the x-direction dx = |target center x-coordinate - image center x-coordinate|, the offset in the y-direction dy = |target center y-coordinate - image center y-coordinate|, and the total offset distance = sqrt(dx² + dy²). For example, if an image has a resolution of 1920×1080 pixels, and the detected target bounding box coordinates are (500, 300, 900, 600), then the image width is 400 pixels, the image height is 300 pixels, the target geometric center coordinates are (700, 450), and the image center coordinates are (960, 540). The calculated offset in the x-direction is 260 pixels, the offset in the y-direction is 90 pixels, and the total offset distance is 275 pixels. These parameters will be used for subsequent image size correction.

[0058] In one possible implementation, the offset distance between the geometric center of the target region and the image center is calculated, specifically including steps 1031-1033, as follows:

[0059] Step 1031: Extract the bounding box coordinates of the target region, including the coordinates of the top left corner and the bottom right corner; calculate the geometric center coordinates of the target region based on the bounding box coordinates, which are the midpoint coordinates of the top left corner and the bottom right corner.

[0060] Bounding box coordinates refer to the pixel coordinates of the four vertices of the rectangle used to represent the location of the target region. The top-left corner coordinates are represented as (x1, y1), which is the top-left point of the bounding box in the image coordinate system; the bottom-right corner coordinates are represented as (x2, y2), which is the bottom-right point of the bounding box in the image coordinate system. The geometric center coordinates refer to the position of the center point of the bounding box in the image coordinate system, represented as (cx, cy). The midpoint coordinates are the position of the geometric center point calculated using the top-left and bottom-right corner coordinates.

[0061] Specifically, the bounding box coordinates are first obtained through an object detection algorithm. The raw data output by the object detection algorithm usually contains multiple sets of coordinate values, and the coordinates of the top left corner (x1, y1) and the bottom right corner (x2, y2) need to be extracted. The coordinate extraction is performed by array indexing or accessing structure members. For example, bbox[0] and bbox[1] correspond to x1 and y1 respectively, and bbox[2] and bbox[3] correspond to x2 and y2 respectively. Then, the geometric center coordinates are calculated. The calculation formula is: center point x coordinate cx=(x1+x2) / 2, center point y coordinate cy=(y1+y2) / 2. For example, the target detection algorithm outputs the bounding box coordinates of a target as follows: top left corner (400, 300), bottom right corner (800, 600). Substituting these coordinates into the calculation formula, we get: cx = (400 + 800) / 2 = 600, cy = (300 + 600) / 2 = 450. Therefore, the geometric center coordinates of the target region are (600, 450). In actual programming implementation, integer arithmetic is used to avoid floating-point errors and ensure the accuracy of the coordinate values. The calculated geometric center coordinates will be used for subsequent position offset analysis. These coordinate values ​​are all integer values ​​in the pixel coordinate system, and their range is limited to the image resolution.

[0062] Step 1032: Obtain the coordinates of the image center of the current image in the image acquisition sequence; calculate the coordinate difference between the geometric center coordinates and the image center coordinates in the horizontal and vertical directions.

[0063] Image center coordinates refer to the position of the center point of the image in the pixel coordinate system, represented as (ix, iy), where ix equals the image width divided by 2, and iy equals the image height divided by 2. The horizontal coordinate difference refers to the difference between the x-coordinate of the target's geometric center and the x-coordinate of the image center, representing the target's horizontal offset. The vertical coordinate difference refers to the difference between the y-coordinate of the target's geometric center and the y-coordinate of the image center, representing the target's vertical offset. The current image refers to the frame being processed in the image acquisition sequence.

[0064] Specifically, first, obtain the resolution parameters of the current image, including the image width and image height. The method for calculating the image center coordinates is: image center x-coordinate ix = width / 2, image center y-coordinate iy = height / 2. For example, for an image with a resolution of 1920×1080, its center coordinates are (960, 540). Then, calculate the offset of the target's geometric center relative to the image center using the following formulas: horizontal coordinate difference dx = geometric center x-coordinate cx - image center x-coordinate ix, vertical coordinate difference dy = geometric center y-coordinate cy - image center y-coordinate iy. The sign of the coordinate difference indicates the direction of offset: a positive horizontal difference indicates the target is to the right of the image center, and a negative difference indicates it is to the left; a positive vertical difference indicates the target is below the image center, and a negative difference indicates it is above. Specific example: Given an image with a resolution of 1920×1080 and a target's geometric center coordinates of (1200, 700), the image center coordinates are (960, 540). The calculated horizontal coordinate difference dx = 1200 - 960 = 240 pixels, indicating the target center is 240 pixels to the right of the image center. The vertical coordinate difference dy = 700 - 540 = 160 pixels, indicating the target center is 160 pixels below the image center. These differences will be used to assess the target's positional offset within the image.

[0065] Step 1033: Calculate the offset distance using the Euclidean distance formula based on the coordinate difference in the horizontal direction and the coordinate difference in the vertical direction.

[0066] The horizontal coordinate difference, denoted as dx, is the distance between the target center and the image center along the x-axis. The vertical coordinate difference, denoted as dy, is the distance between the target center and the image center along the y-axis. Offset distance refers to the straight-line distance from the geometric center of the target to the image center, indicating the degree to which the target deviates from the image center, and is measured in pixels.

[0067] Specifically, first, obtain the horizontal coordinate difference dx and the vertical coordinate difference dy calculated in the previous step. Then, calculate the total offset distance using the Euclidean distance formula: offset distance d = sqrt(dx² + dy²), where sqrt represents the square root operation. In practice, first calculate the squares of dx and dy, add the two squares to get the sum of squares, and finally take the square root of the sum of squares to obtain the final offset distance. For example, in a certain detection, the horizontal coordinate difference dx = 240 pixels and the vertical coordinate difference dy = 160 pixels. The offset distance calculation process is: dx² = 240² = 57600, dy² = 160² = 25600, sum of squares = 57600 + 25600 = 83200, and the final offset distance d = sqrt(83200) = 288.44 pixels. For ease of subsequent processing, the calculation result is usually rounded to 288 pixels. In actual programming, mathematical library functions (such as the sqrt function in C++ or the math.sqrt function in Python) are used to calculate the square root to ensure accuracy. This offset distance value will be used to assess the degree of displacement of the target in the image, thereby guiding subsequent focus adjustment.

[0068] Step 104: Correct the imaging width and imaging height based on the offset distance to obtain imaging size parameters at multiple focal lengths.

[0069] Offset distance refers to the straight-line distance from the geometric center of the target to the center of the image, measured in pixels. Imaging width and imaging height refer to the width and height values ​​of the original bounding box obtained from target detection, measured in pixels. Imaging size parameters refer to the corrected target size data at different focal lengths, including the corrected width and height values.

[0070] Specifically, a perspective transformation correction model is first established. According to the camera imaging principle, the apparent size of the target changes as its distance from the image center increases. The formula for calculating the correction coefficient is: Correction coefficient k = 1 + (Offset distance / Image diagonal length) × Correction weight. Where the image diagonal length = sqrt(Image width² + Image height²), and the correction weight is typically set to 0.15. Then, the image size at each focal length is corrected: Corrected image width = Original image width × Correction coefficient, Corrected image height = Original image height × Correction coefficient. For example, in a 1920×1080 resolution image with an offset distance of 288 pixels and an image diagonal length of 2202 pixels, the calculated correction coefficient k = 1 + (288 / 2202) × 0.15 = 1.0196. If the original image width is 400 pixels and the original image height is 300 pixels, then the corrected image width is 408 pixels (400×1.0196) and the corrected image height is 306 pixels (300×1.0196). The same correction calculation is performed for each focal length position in the image sequence, ultimately resulting in a set of corrected image size parameters, each containing the corrected width and height values. These corrected size parameters more accurately reflect the actual size of the target, providing a basis for subsequent optimal focal length selection.

[0071] Step 105: Calculate the size deviation between the imaging size parameters and the target desired imaging parameters at each focal length, and select the target focal lengths whose size deviation values ​​are less than a preset threshold.

[0072] Imaging size parameters refer to the corrected target size data obtained at various focal length positions, including the corrected width and height values, in pixels. Target desired imaging parameters refer to the mission-preset ideal target size requirements, including the desired width and height, in pixels. Size deviation value refers to the degree of difference between the actual imaging size and the desired size, calculated by the difference in corresponding dimensions. Preset threshold refers to the maximum allowable size deviation range, used to filter focal length values ​​that meet the imaging requirements. Target focal length refers to the candidate focal length values ​​that meet the size deviation requirements.

[0073] Specifically, the dimensional deviation value at each focal length position is first calculated. For a single focal length position, the width deviation and height deviation are calculated separately: Width deviation = |corrected image width - desired image width| / desired image width, Height deviation = |corrected image height - desired image height| / desired image height. The larger value of the width deviation and height deviation is taken as the overall dimensional deviation value for that focal length position. For example, in a certain task, the desired imaging parameters are a width of 1000 pixels and a height of 800 pixels. The corrected image size obtained at a focal length of 35 mm is a width of 950 pixels and a height of 770 pixels. Then the width deviation is 5% (|950-1000| / 1000), and the height deviation is 3.75% (|770-800| / 800). The overall dimensional deviation value for this focal length position is 5%. The deviation calculation is repeated for all focal length positions to obtain a complete sequence of deviation values. Then, a filtering threshold is set, such as a maximum allowed deviation of 10%, and all focal length values ​​with a dimensional deviation value less than 10% are extracted as a candidate focal length set. In this example, if a certain traversal captures six focal length positions (30, 35, 40, 45, 50, 55 mm), and the calculated size deviation values ​​are 12%, 5%, 3%, 7%, 11%, and 15%, respectively, with a preset threshold of 10%, then the selected candidate focal length set is {35, 40, 45} mm. These candidate focal lengths all meet the target imaging size requirements and will be used to determine the optimal focal length in the subsequent process.

[0074] Step 106: Calculate the image sharpness of the tracking area corresponding to the target focal length and determine the first image sharpness.

[0075] The tracking region refers to the image area encompassed by the bounding box of the target in the image, containing complete visual information about the target. Image sharpness refers to the sharpness of image details, typically quantified by calculating image gradients, edge strength, or frequency domain features. First image sharpness refers to the sharpness evaluation value calculated using a specific algorithm, used to measure the imaging quality of the target region. Image gradient refers to the rate of change of image pixel values ​​in space, obtained through differential operations in the horizontal and vertical directions. Edge strength refers to the degree of abrupt change in pixel values ​​at the edges of objects in an image.

[0076] Specifically, the tracking area at each target focal length position is first preprocessed, including grayscale conversion and Gaussian smoothing to eliminate noise. Then, several sharpness evaluation metrics are calculated: The first is a gradient-based method, using the Sobel operator to calculate the horizontal gradient Gx and vertical gradient Gy, with the gradient magnitude G = sqrt(Gx² + Gy²). The average gradient magnitude of all pixels within the region is used as the sharpness evaluation value. The second is a Laplacian operator-based method, calculating the variance of the second derivative of the image; a larger variance indicates a sharper image. The third is an energy function-based method, evaluating sharpness by calculating the energy of the high-frequency components of the image. For example, for a tracking area of ​​200×150 pixels, the Sobel operator yields an average gradient magnitude of 45, a Laplacian operator variance of 680, and an energy function value of 0.75. These three metrics are then weighted and fused: the final sharpness score = 0.4 × normalized gradient value + 0.3 × normalized Laplacian value + 0.3 × normalized energy value. The same sharpness calculation process is repeated for all target focal length positions to obtain a set of sharpness evaluation values. These sharpness values ​​reflect the quality level of target imaging at different focal lengths and will be used for the final optimal focal length selection. In practice, functions provided by image processing libraries such as OpenCV are used for gradient calculation and filtering operations to ensure computational efficiency and accuracy.

[0077] In one possible implementation, image sharpness calculation is performed on the tracking area corresponding to the target focal length to determine a first image sharpness, specifically including steps 1061-1063, as follows:

[0078] Step 1061: Extract the target region from the image corresponding to the target focal length as the tracking region; perform grayscale processing on the tracking region to obtain a grayscale image.

[0079] The target focal length corresponding image refers to the original image frame acquired at a specific focal length. The target region refers to the image area contained within the target bounding box obtained by the target detection algorithm, represented by the coordinates of its top-left and bottom-right corners. The tracking region refers to the target region image patch cropped from the original image. A grayscale image refers to an image where each pixel contains only brightness information, with pixel values ​​typically ranging from 0 to 255.

[0080] Specifically, the target region is first extracted from the original image based on the bounding box coordinates obtained from object detection. The extraction process uses image cropping. Let the bounding box coordinates of the target region be (x1, y1, x2, y2), then the width of the cropped region is width = x2 - x1, and the height is height = y2 - y1. The ROI (Region of Interest) function of image processing libraries such as OpenCV is used to crop the image, obtaining a sub-image of the target region. Then, the extracted target region is converted to grayscale, and the grayscale value is calculated using a weighted average method: Gray = 0.299 × R + 0.587 × G + 0.114 × B, where R, G, and B represent the red, green, and blue channel values ​​of the pixel, respectively. For example, in a 1920 × 1080 color image, the target bounding box coordinates are (500, 300, 900, 600). First, this region is extracted to obtain a sub-image of size 400 × 300. For a pixel in a sub-image with RGB values ​​of (180, 160, 140), its grayscale value is calculated as: Gray = 0.299 × 180 + 0.587 × 160 + 0.114 × 140 = 163. The same grayscale conversion operation is performed on all pixels within the region, resulting in a 400 × 300 grayscale image. Grayscale conversion reduces data dimensionality while preserving the main structural information of the image, providing a unified data format for subsequent sharpness calculations. In practice, the OpenCV `cvtColor` function can be directly called to perform the RGB to grayscale conversion, with the conversion mode set to `COLOR_BGR2GRAY` to ensure processing efficiency and accuracy.

[0081] Step 1062: Use the Sobel operator to perform edge detection on the grayscale image and calculate the gradient magnitude of each pixel within the tracking area.

[0082] The Sobel operator is an image processing operator used for edge detection, consisting of two 3×3 convolution kernels in the horizontal and vertical directions. Edge detection refers to identifying regions in an image where pixel values ​​change significantly by calculating the image gradient. The gradient magnitude is the combined value of the horizontal and vertical gradients at a point in the image, reflecting the degree of drastic change in pixel value at that point. A pixel is the smallest unit in a digital image; in a grayscale image, each pixel contains a grayscale value between 0 and 255.

[0083] Specifically, we first construct the horizontal convolution kernel Gx and the vertical convolution kernel Gy of the Sobel operator. The horizontal Sobel operator is: [-1, 0, 1; -2, 0, 2; -1, 0, 1], and the vertical Sobel operator is: [-1, -2, -1; 0, 0, 0; 1, 2, 1]. For each pixel in the grayscale image, we perform convolution operations using the Sobel operators in both directions. Taking a 3×3 neighborhood centered at a pixel (i, j) as an example, its grayscale matrix is: [[120, 125, 130], [122, 126, 129], [125, 128, 132]]. Convolving this matrix with the horizontal Sobel operator yields: Gx = (-1×120 + 1×130 + -2×122 + 2×129 + -1×125 + 1×132) = 23. Convolving this matrix with the vertical Sobel operator yields: Gy = (-1×120 + -2×125 + -1×130 + 1×125 + 2×128 + 1×132) = 18. Then, the gradient magnitude at this point is calculated: G = sqrt(Gx² + Gy²) = sqrt(23² + 18²) = 29.21. The same calculation process is repeated for all pixels within the tracking region to obtain the complete gradient magnitude matrix. Specifically, OpenCV's Sobel function is used to calculate the gradient images in the x and y directions, respectively. The function parameters include: input image, output image depth (usually CV_64F to ensure calculation accuracy), x-direction derivative order, y-direction derivative order, and kernel size (set to 3). Then, the magnitude function is used to calculate the magnitude of the gradients in both directions. The resulting gradient magnitude matrix reflects the edge strength at each location in the image, providing fundamental data for subsequent sharpness assessment.

[0084] Step 1063: Count the number of pixels in the tracking area whose gradient magnitude is greater than the preset gradient threshold to obtain the number of effective edge pixels.

[0085] Gradient magnitude refers to the gradient strength at each pixel in an image, calculated using the Sobel operator to obtain the composite gradient value. The preset gradient threshold is a boundary value used to distinguish between valid edge points and non-edge points; it is usually set to a fixed value based on image characteristics. The number of valid edge pixels refers to the total number of pixels whose gradient magnitude exceeds the preset threshold, reflecting the number of significant edge features in the image. Pixels within the tracking region refer to the set of all pixels in the target region image block.

[0086] Specifically, first, a preset gradient threshold is set. The threshold is chosen based on the overall gradient distribution characteristics of the image, typically 1.5 to 2 times the average gradient of the image. For example, if the average gradient value of the tracking region is 20, the preset gradient threshold can be set to 35. Then, the gradient magnitude of each pixel within the tracking region is iterated and compared with the preset threshold. A counter is set to an initial value of 0, and when the gradient magnitude of a pixel is greater than the preset threshold, the counter is incremented by 1. For example, in a 400×300 tracking region with a preset gradient threshold of 35, after iterating through all 120,000 pixels in the region, it is found that 15,000 pixels have a gradient magnitude greater than 35, so the number of effective edge pixels is 15,000. In practice, the OpenCV compare function can be used for batch threshold comparison. The function parameters include: gradient magnitude matrix, threshold matrix (all elements are set to the preset threshold), and comparison operation type (set to CMP_GT for greater than comparison). The comparison result is a binary mask matrix, and then the countNonZero function is used to count the number of non-zero elements in the mask matrix, which is the number of effective edge pixels. This quantity reflects the richness of edge features in the image and is one of the important indicators for evaluating image sharpness. The complete calculation process ensures the accuracy and efficiency of edge statistics.

[0087] Step 1064: Calculate the average gradient magnitude of all pixels in the tracking area to obtain the average gradient intensity; use the ratio of the number of effective edge pixels to the total number of pixels in the tracking area as the edge density coefficient; and perform a weighted summation of the average gradient intensity and the edge density coefficient to obtain the first image sharpness.

[0088] The average gradient intensity is the arithmetic mean of the gradient magnitudes of all pixels within the tracking region, reflecting the overall edge strength level. The edge density coefficient is the proportion of effective edge pixels in the total number of pixels, ranging from 0 to 1, reflecting the distribution density of edge features. The total number of pixels refers to the total number of pixels in the tracking region, equal to the product of the region's width and height. The primary image sharpness is a comprehensive evaluation value obtained by weighting the average gradient intensity and edge density coefficient, used to quantify the sharpness of the image.

[0089] Specifically, first, the average gradient intensity is calculated by summing the gradient magnitudes of all pixels within the tracking region and then dividing by the total number of pixels. The mean of the gradient magnitude matrix can be directly calculated using OpenCV's `mean` function. For example, for a tracking region of 400×300 pixels, the sum of the gradient magnitudes is 3,600,000, so the average gradient intensity is 3,600,000 / 120,000 = 30. Next, the edge density coefficient is calculated by dividing the number of effective edge pixels obtained in the previous step by the total number of pixels. Taking 15,000 effective edge pixels as an example, the edge density coefficient is 15,000 / 120,000 = 0.125. Finally, a weighted combination is performed. Setting the weight coefficient w1 for the average gradient intensity to 0.6 and the weight coefficient w2 for the edge density coefficient to 0.4, the formula for calculating the first image sharpness is: Sharpness = w1 × Normalized Average Gradient Intensity + w2 × Edge Density Coefficient. Normalization is used to balance the magnitude difference between the two indicators. Normalization typically involves dividing the average gradient intensity by a preset baseline value (e.g., 100). Substituting the values ​​into the calculation: Sharpness = 0.6 × (30 / 100) + 0.4 × 0.125 = 0.23. The same calculation process is repeated for each target focal length position to obtain a set of sharpness evaluation values. This comprehensive sharpness index considers both the absolute level of edge intensity and the spatial distribution characteristics of edge features, providing a more comprehensive assessment of image sharpness. The selection of weighting coefficients is based on experimental verification and can be fine-tuned according to specific application scenarios.

[0090] Step 107: Obtain the attitude angle information and flight speed information of the UAV, and perform attitude compensation on the first image sharpness based on the attitude angle information and flight speed information to obtain the second image sharpness.

[0091] Attitude angle information refers to the pitch and roll angles of the UAV, reflecting the aircraft's attitude state in space. Flight speed information includes horizontal and vertical speeds, describing the UAV's motion state in space. Attitude compensation is the process of correcting the image sharpness evaluation value based on the UAV's motion state. Second image sharpness refers to the corrected sharpness value after attitude compensation. First image sharpness refers to the original sharpness evaluation value calculated solely based on image features.

[0092] Specifically, first, the attitude parameters of the UAV are obtained, including pitch angle θ and roll angle φ; simultaneously, flight speed parameters are obtained, including horizontal speed vh and vertical speed vv, in meters per second. Then, an attitude compensation model is constructed. The calculation of the compensation coefficients is divided into two parts: attitude angle compensation coefficient and velocity compensation coefficient. The formula for calculating the attitude angle compensation coefficient ka is: ka = cos(θ) × cos(φ), which considers the influence of pitch and roll angles on image quality. The formula for calculating the velocity compensation coefficient kv is: kv = 1 / (1 + α × sqrt(vh² + vv²)), where α is the velocity influence factor, typically taken as 0.05. The final compensation coefficient k = ka × kv. For example, if at a certain moment the drone's pitch angle is 15 degrees, roll angle is 10 degrees, horizontal speed is 5 m / s, and vertical speed is 2 m / s, then the attitude angle compensation coefficient ka = cos(15°) × cos(10°) = 0.94, the speed compensation coefficient kv = 1 / (1 + 0.05 × sqrt(5² + 2²)) = 0.78, and the final compensation coefficient k = 0.94 × 0.78 = 0.73. The formula for calculating the second image sharpness is: Second image sharpness = First image sharpness × k. If the first image sharpness is 0.23, then the second image sharpness = 0.23 × 0.73 = 0.168. This compensation mechanism considers the impact of the drone's motion state on image quality, making the sharpness assessment more accurate. Attitude angle data is acquired through an IMU sensor, and speed data is acquired through a GPS or optical flow sensor, ensuring the real-time nature and accuracy of the data.

[0093] In one possible implementation, the rate of curvature change between adjacent sampling points is calculated based on three-dimensional coordinate data, specifically including steps 1071-1073, as follows:

[0094] Step 1071: Extract the pitch and roll angles from the attitude angle information; calculate the attitude deviation based on the pitch and roll angles, where the attitude deviation is the square root of the sum of the squares of the pitch and roll angles.

[0095] Attitude angle information includes the aircraft's pitch and roll angles. Pitch angle refers to the angle at which the aircraft's nose tilts up or down; a positive value indicates upward pitch, and a negative value indicates downward pitch, measured in degrees. Roll angle refers to the angle of rotation of the aircraft around its longitudinal axis; a positive value indicates right roll, and a negative value indicates left roll, measured in degrees. Attitude deviation refers to the degree of deviation of the aircraft's current attitude from its level flight state, calculated by combining the pitch and roll angles, measured in degrees. Square root operation refers to calculating the square root of a numerical value.

[0096] Specifically, firstly, complete attitude angle data is obtained from the flight control system, extracting the pitch angle θ and roll angle φ. Attitude angle data is typically measured in real-time by the onboard IMU (Inertial Measurement Unit), with a sampling frequency of no less than 50Hz to ensure data timeliness. Then, the extracted angle values ​​are preprocessed, converting them to radians: θrad = θ × π / 180, φrad = φ × π / 180. Next, the attitude deviation is calculated using the Euclidean distance formula: deviation = sqrt(θ² + φ²). For example, if the UAV's pitch angle θ is 15 degrees and the roll angle φ is 10 degrees at a certain moment, the calculation is: attitude deviation = sqrt(15² + 10²) = sqrt(325) = 18.03 degrees. This deviation value reflects the degree of deviation of the aircraft from its ideal horizontal attitude. To improve calculation efficiency, mathematical library functions can be used for direct calculation: in C++, the std::hypot function is used, and in Python, the math.hypot function is used. The deviation calculation results will be used to determine the subsequent attitude compensation coefficients. In practice, attention must be paid to the sign of the angle values ​​and numerical stability must be ensured during the calculation process. When the pitch or roll angle exceeds a preset safety threshold (e.g., ±45 degrees), an attitude anomaly warning should be triggered. This deviation calculation method based on Euclidean distance effectively integrates attitude deviations in two directions into a single scalar index.

[0097] Step 1072: Determine the attitude compensation coefficient based on the attitude deviation. The attitude compensation coefficient is positively correlated with the attitude deviation.

[0098] The attitude compensation coefficient is a weighting factor used to correct image sharpness. Its value ranges from 0 to 1, reflecting the degree to which attitude changes affect image quality.

[0099] Specifically, first, a baseline deviation threshold α (e.g., 30 degrees) and a maximum compensation coefficient β (e.g., 0.8) are set. Then, a piecewise linear mapping function is constructed to map the attitude deviation to the compensation coefficient. The calculation formula for the mapping function is: when the attitude deviation is less than or equal to the baseline threshold α, the attitude compensation coefficient k = β × (attitude deviation / α); when the attitude deviation is greater than the baseline threshold α, the attitude compensation coefficient k = β. This piecewise function design ensures smooth changes in the compensation coefficient and upper limit constraints. For example: if the baseline deviation threshold α = 30 degrees and the maximum compensation coefficient β = 0.8, and the attitude deviation is measured to be 18.03 degrees at a certain moment, then the calculation process for the attitude compensation coefficient is: k = 0.8 × (18.03 / 30) = 0.48. This means that a 48% attenuation compensation is needed for image sharpness under the current attitude. When the attitude deviation is 35 degrees, exceeding the baseline threshold of 30 degrees, the maximum compensation coefficient is directly taken: k = 0.8. In practical implementation, a conditional statement is used to handle the piecewise function: if (deviation <= α) then β × deviation / α elsek = β. To improve computational efficiency, the baseline threshold α and the maximum compensation coefficient β are set as constants. The calculation results of the compensation coefficient need to be validated to ensure that the value is between 0 and 1. This compensation mechanism based on piecewise linear mapping reflects the influence of attitude changes on image quality and ensures the numerical stability of the compensation process. The entire calculation process is simple and efficient, suitable for real-time processing systems.

[0100] Step 1073: Obtain the horizontal and vertical flight speeds from the flight speed information; calculate the displacement of the UAV during the image exposure time based on the horizontal and vertical flight speeds.

[0101] Horizontal flight speed refers to the speed of a drone in the horizontal plane, measured in meters per second. Vertical flight speed refers to the speed of a drone in the vertical direction, measured in meters per second. Image exposure time refers to the duration for which the camera sensor receives light, measured in seconds. Displacement refers to the spatial distance moved by the drone during the exposure time, measured in meters. Flight speed information refers to real-time speed data measured by GPS, optical flow, or other sensors.

[0102] Specifically, the flight speed data is first acquired, including horizontal speed (vh) and vertical speed (vv). This speed data is typically provided by a GPS module with a sampling frequency of 10Hz. Simultaneously, the camera's exposure time (te) is acquired. The exposure time is determined by the camera's parameter settings, typically ranging from 1 / 1000 to 1 / 60 of a second. Then, the composite speed is calculated using the speed composition formula: v = sqrt(vh² + vv²). Finally, the displacement during the exposure is calculated using the formula: displacement s = v × te. For example, if at a certain moment the drone's horizontal flight speed (vh) is 5 m / s, its vertical flight speed (vv) is 2 m / s, and the camera exposure time (te) is 1 / 100 of a second, then the calculation process is: composite speed v = sqrt(5² + 2²) = 5.385 m / s, and displacement during the exposure s = 5.385 × (1 / 100) = 0.054 m. In practical implementation, it is necessary to pay attention to the real-time performance and validity verification of the speed data. When the velocity data update interval exceeds a preset threshold (e.g., 200 milliseconds), a velocity estimation algorithm needs to be activated for data compensation. Displacement calculations use floating-point arithmetic to ensure accuracy, and the results are rounded to three decimal places. This displacement reflects the potential blurring caused by the drone's movement during image acquisition and will be used for subsequent motion compensation coefficient calculations. The complete implementation process includes three main steps: data acquisition, velocity synthesis, and displacement calculation. Each step requires numerical validity checks.

[0103] Step 1074: Determine the motion blur compensation coefficient based on the displacement amount. The motion blur compensation coefficient is positively correlated with the displacement amount. Multiply the first image sharpness with the attitude compensation coefficient and the motion blur compensation coefficient to obtain the second image sharpness.

[0104] Displacement refers to the spatial distance moved by the drone during the image exposure time, measured in meters. Motion blur compensation coefficient is a weighting factor used to correct image blur caused by motion, ranging from 0 to 1. First image sharpness refers to the original sharpness evaluation value calculated based on image features. Second image sharpness refers to the corrected sharpness value after attitude and motion compensation.

[0105] Specifically, the motion blur compensation coefficient is first determined based on the displacement. A baseline displacement threshold δ (e.g., 0.1 meters) and a maximum compensation coefficient γ (e.g., 0.7) are set. The compensation coefficient is calculated using a piecewise function: when the displacement s is less than or equal to the baseline threshold δ, the motion blur compensation coefficient km = γ × (s / δ); when the displacement s is greater than the baseline threshold δ, the motion blur compensation coefficient km = γ. For example: with a baseline displacement threshold δ = 0.1 meters and a maximum compensation coefficient γ = 0.7, and a measured displacement s = 0.054 meters at a certain moment, the motion blur compensation coefficient is calculated as: km = 0.7 × (0.054 / 0.1) = 0.378. This indicates that the current motion state requires a 37.8% attenuation compensation for image sharpness. Then, the final sharpness correction calculation is performed, multiplying the first image sharpness by the two compensation coefficients. The calculation formula is: Second image sharpness = First image sharpness × Attitude compensation coefficient × Motion blur compensation coefficient. Substituting specific values: Assuming the first image sharpness is 0.23, the attitude compensation coefficient is 0.48, and the motion blur compensation coefficient is 0.378, then the second image sharpness = 0.23 × 0.48 × 0.378 = 0.0417. In implementation, an if-else statement is used to handle the piecewise calculation of the motion blur compensation coefficient: if (s <= δ) then nkm = γ × s / δ elsekm = γ. The calculation results of the compensation coefficient need to undergo boundary checks to ensure that the values ​​are within the valid range. The final product operation uses floating-point calculation to ensure accuracy, and the result is retained to four decimal places. This compensation mechanism comprehensively considers the impact of both attitude change and motion blur on image quality, making sharpness assessment more accurate and reliable.

[0106] Step 108: Take the target focal length corresponding to the maximum image clarity as the focal length of the camera to be adjusted, and control the camera lens of the drone to adjust to the focal length of the camera to be adjusted.

[0107] The second image sharpness refers to the corrected sharpness evaluation value after attitude and motion compensation, ranging from 0 to 1. The target focal length refers to discrete sampling points within the focal length traversal range, measured in millimeters. The camera focal length to be adjusted refers to the optimal focal length value determined through sharpness evaluation, which will be used for the actual adjustment of the camera lens. The camera lens refers to the variable focal length optical system mounted on the UAV, capable of focal length adjustment via motor drive.

[0108] Specifically, firstly, a focal length-resolution mapping table is constructed, with each entry containing a focal length value and its corresponding second image resolution. The resolution data for all target focal length positions is traversed, and a bubble sort or quicksort algorithm is used to find the maximum resolution value and its corresponding focal length. For example, in one iteration, six focal length positions (30, 35, 40, 45, 50, 55 mm) were collected, with corresponding second image resolutions of 0.0321, 0.0417, 0.0485, 0.0392, 0.0308, and 0.0275, respectively. By sorting, the maximum resolution of 0.0485 is found, corresponding to a focal length of 40 mm, which is then determined as the focal length to be adjusted. Next, lens adjustment control is executed. The specific steps are: firstly, the current lens focal length position is read, and the difference Δf between this position and the desired focal length is calculated. The adjustment mode is selected based on the difference in focal length: when |Δf|>10 mm, a fast adjustment mode is used, with the motor speed set to 200 steps / second; when 5 mm < |Δf|≤10 mm, a medium-speed adjustment mode is used, with the motor speed set to 100 steps / second; when |Δf|≤5 mm, a fine adjustment mode is used, with the motor speed set to 50 steps / second. The feedback from the lens position encoder is monitored in real time during adjustment, and adjustment stops when the target position is reached. Specifically, adjustment commands are sent to the lens controller via serial port or I2C interface. The command format is: [command word][target position][adjustment speed]. For example, if the current focal length is 30 mm, the focal length to be adjusted is 40 mm, and the difference is 10 mm, the medium-speed adjustment mode is selected, and the command sent is: 0x010x280x64 (hexadecimal). The entire adjustment process includes two main stages: optimal focal length determination and lens control. Each stage requires parameter validity verification and anomaly handling.

[0109] In the above embodiments, a basic lens parameter adaptive adjustment framework was implemented through target area localization and imaging size calculation. To further improve the imaging quality of a large field of view and reduce the impact of perspective distortion on target observation, this application also provides a camera focal length control method based on target imaging. This method intelligently adjusts the size parameters by analyzing the coupling relationship between target position offset and lens distortion characteristics, enabling the system to more accurately handle imaging requirements under different focal length and field of view position combinations. The following section combines... Figure 2 Another camera focal length control method based on target imaging in the embodiments of this application is described below:

[0110] Please see Figure 2 This is another flowchart illustrating a camera focal length control method based on target imaging in an embodiment of this application.

[0111] Step 201: Traverse the imaging width and imaging height according to the preset focal length scale to obtain sub-imaging width and sub-imaging height corresponding to multiple focal lengths.

[0112] The preset focal length scale refers to the discrete sampling interval set within the focal length adjustment range, measured in millimeters. Imaging width and imaging height refer to the image size of the target area, measured in pixels. Sub-imaging width and sub-imaging height refer to the image size corresponding to different focal lengths, measured in pixels. Focal length refers to the distance from the optical center of the lens to the image plane in an optical system, measured in millimeters.

[0113] Specifically, first, the focal length traversal range and sampling interval are determined. For example, if the focal length range is 30-60 mm and the sampling interval is 5 mm, then the focal length sampling sequence is formed as: [30, 35, 40, 45, 50, 55, 60]. Then, based on the camera imaging principle, the sub-image size corresponding to each focal length position is calculated. The calculation formula adopts the principle of proportional scaling: for focal length f, the sub-image width w = W × (f0 / f), and the sub-image height h = H × (f0 / f), where W and H are the image width and height, respectively, and f0 is the reference focal length. For example, suppose the size of the second imaging area is 1920 × 1080 pixels, and the reference focal length f0 is 30 mm. Calculate the corresponding sub-image size for each value in the focal length sequence. When f = 35 mm, the sub-image width w = 1920 × (30 / 35) = 1646 pixels, and the sub-image height h = 1080 × (30 / 35) = 926 pixels; when f = 40 mm, w = 1920 × (30 / 40) = 1440 pixels, and h = 1080 × (30 / 40) = 810 pixels. Following this method, the dimensions for all focal length positions are calculated, resulting in the sub-image size sequence: [(1920, 1080), (1646, 926), (1440, 810), (1280, 720), (1152, 648), (1047, 589), (960, 540)]. In practice, a loop structure is used to traverse the focal length sequence, storing the calculation result in an array or list each time. During the calculation process, numerical rounding is performed to ensure that the sub-image size is an integer pixel value. Simultaneously, parameter boundary checks are performed: the sub-image size should not be smaller than a preset minimum value (e.g., 640×360 pixels). The time complexity of the entire calculation process is O(n), where n is the number of focal length sampling points. The calculation results will be used for subsequent image scaling and feature extraction.

[0114] Step 202: For each focal length, determine whether the target area is located in the center region of the image based on the offset distance; if the target area is located in the center region of the image, use the sub-imaging width and sub-imaging height corresponding to the focal length as the imaging size parameters under the focal length; if the target area is not located in the center region of the image, calculate the perspective distortion correction coefficient based on the offset distance and the distortion parameters of the camera lens.

[0115] Offset distance refers to the distance from the center point of the target region to the geometric center of the image, measured in pixels. The image center region refers to a specific area with the geometric center of the image as the reference point. Sub-imaging width and sub-imaging height refer to the image size of the target region at a specific focal length. Imaging size parameters refer to the size of the target region used for subsequent image processing. Distortion parameters are a set of coefficients describing the radial and tangential distortion characteristics of the camera lens. Perspective distortion correction coefficients are correction factors used to compensate for distortion effects in image edge regions. The target region refers to the image region where sharpness evaluation is required.

[0116] Specifically, first, the Euclidean distance d = sqrt((x-x0)² + (y-y0)²) between the center point coordinates (x, y) of the target region and the geometric center (x0, y0) of the image is calculated. This distance is the offset distance. A center region judgment threshold R is set (usually 1 / 4 of the image diagonal length). When the offset distance d is less than the threshold R, the target region is determined to be located within the center region, and the sub-imaging size calculated in step 201 is directly used as the imaging size parameter. For example: The image size is 1920×1080 pixels, the center point coordinates are (960, 540), and the target area center point coordinates are (1060, 640). The offset distance d is calculated as sqrt((1060-960)²+(640-540)²=141.4 pixels. If the threshold R=400 pixels, then 141.4<400, and the target area is located within the center area. When the offset distance d is greater than or equal to the threshold R, perspective distortion correction coefficients need to be calculated. The calculation of the correction coefficients is based on the distortion parameters obtained from camera calibration, including radial distortion coefficients k1, k2, k3 and tangential distortion coefficients p1, p2. First, the pixel coordinates are normalized: x'=(x-x0) / f, y'=(y-y0) / f, where f is the focal length. Then, the distortion coefficients are calculated as: r=sqrt(x'²+y'²), and the distortion factor λ=1+k1r²+k2r. 4 +k3r 6 The perspective distortion correction factor is k = 1 / λ. For example: Suppose the normalized coordinates of a point are x' = 0.3, y' = 0.2, and the radial distortion factors are k1 = -0.2, k2 = 0.1, k3 = 0. Then r = sqrt(0.3² + 0.2²) = 0.361, λ = 1 + (-0.2 × 0.361² + 0.1 × 0.361) / λ. 4 The value is 0.973, and the correction coefficient k = 1 / 0.973 = 1.028. The correction coefficient needs to be calculated separately for each of the four vertices of the target region, and the average value is taken as the final correction coefficient. In practice, a matrix operation library (such as OpenCV's Mat class) is used for batch calculation to improve efficiency. The calculation results will be used for subsequent image size correction.

[0117] In one possible implementation, the perspective distortion correction coefficient is calculated based on the offset distance and the distortion parameters of the camera lens, specifically including steps 2021-2023, as follows:

[0118] Step 2021: Obtain the radial and tangential distortion coefficients of the camera lens; calculate the radial and tangential offsets of the target region in the image based on the offset distance.

[0119] Radial distortion coefficients refer to the set of parameters k1, k2, and k3 describing the radial distortion characteristics of a lens, used to characterize the degree of image deformation along the radial direction. Tangential distortion coefficients refer to the set of parameters p1 and p2 describing the tangential distortion characteristics of a lens, used to characterize the degree of image deformation along the tangential direction. Offset distance refers to the straight-line distance from the center of the target region to the geometric center of the image, measured in pixels. Radial offset refers to the positional deviation of the target region in the radial direction of the image. Tangential offset refers to the positional deviation of the target region in the direction perpendicular to the radial direction.

[0120] Specifically, first, obtain the distortion coefficients from the camera calibration results. Radial distortion coefficients typically include three parameters: k1, k2, and k3, for example, k1 = -0.2, k2 = 0.1, and k3 = 0.01. Tangential distortion coefficients include two parameters: p1 and p2, for example, p1 = 0.003 and p2 = -0.002. Then, calculate the coordinate deviation of the target region center point (x, y) relative to the image center point (x0, y0): Δx = x - x0, Δy = y - y0. Normalize the pixel coordinates: x' = Δx / f, y' = Δy / f, where f is the focal length. Calculate the normalized coordinate modulus r = sqrt(x'² + y'²), which represents the normalized radial distance. The formula for calculating the radial offset is: dr = r × (k1r² + k2r²) 4 +k3r 6 The tangential offset is calculated using two components: dx = 2p1x'y' + p2(r² + 2x'²), dy = p1(r² + 2y'²) + 2p2x'y'. For example: the target area center point coordinates are (1060, 640), the image center point coordinates are (960, 540), and the focal length is 40 mm. First, calculate the coordinate deviation: Δx = 100 pixels, Δy = 100 pixels. Normalize the coordinates: x' = 100 / 40 = 2.5, y' = 100 / 40 = 2.5. Calculate the normalized radial distance: r = sqrt(2.5² + 2.5²) = 3.54. Substitute into the radial distortion formula: dr = 3.54 × (-0.2 × 3.54² + 0.1 × 3.54) 4 +0.01×3.54 6=-2.86. Substituting into the tangential distortion formula: dx=2×0.003×2.5×2.5+(-0.002)×(3.54²+2×2.5²)=0.0375, dy=0.003×(3.54²+2×2.5²)+2×(-0.002)×2.5×2.5=0.0425. Finally, convert the normalized offsets back to pixel coordinates: radial offset Dr=dr×f=-2.86×40=-114.4 pixels, tangential offset Dx=dx×f=1.5 pixels, Dy=dy×f=1.7 pixels. These offsets will be used for subsequent distortion compensation calculations. In the specific implementation, a matrix operation library is used for batch calculation to improve computational efficiency.

[0121] Step 2022: Calculate the first dimensional error introduced by radial distortion based on the radial distortion coefficient and radial offset; calculate the second dimensional error introduced by tangential distortion based on the tangential distortion coefficient and tangential offset.

[0122] Radial distortion coefficients refer to parameters k1, k2, and k3 that describe the radial distortion characteristics of a lens. Radial offset refers to the positional deviation of the target area in the radial direction, measured in pixels. First dimensional error refers to the change in image size caused by radial distortion, measured in pixels. Tangential distortion coefficients refer to parameters p1 and p2 that describe the tangential distortion characteristics of a lens. Tangential offset includes two components, horizontal and vertical, Dx and Dy, measured in pixels. Second dimensional error refers to the change in image size caused by tangential distortion, measured in pixels.

[0123] Specifically, the first dimensional error introduced by radial distortion is calculated. A polynomial model is used to describe the radial distortion effect: δr = r × (k1r² + k2r) 4 +k3r 6 The formula for calculating the first dimensional error is: E1 = |Dr| × (1 + |δr|), where Dr is the radial offset. For example: Given radial distortion coefficients k1 = -0.2, k2 = 0.1, k3 = 0.01, normalized radial distance r = 3.54, and radial offset Dr = -114.4 pixels. Substituting these values, we get: δr = 3.54 × (-0.2 × 3.54² + 0.1 × 3.54) / (1 + |δr|). 4 +0.01×3.54 6Given that the tangential distortion coefficient is -2.86, the first dimensional error E1 = |-114.4| × (1 + |-2.86|) = 441.4 pixels. Then, the second dimensional error introduced by tangential distortion is calculated. Tangential distortion produces displacements in the horizontal and vertical directions: dx = 2p1x'y' + p2(r² + 2x'²), dy = p1(r² + 2y'²) + 2p2x'y'. The second dimensional error is calculated using Euclidean distance: E2 = sqrt(Dx² + Dy²) × (1 + sqrt(dx² + dy²)), where Dx and Dy are the tangential offsets. Substituting the values: tangential distortion coefficients p1 = 0.003, p2 = -0.002, normalized coordinates x' = y' = 2.5, tangential offsets Dx = 1.5 pixels, Dy = 1.7 pixels. The calculations yield: dx = 2 × 0.003 × 2.5 × 2.5 + (-0.002) × (3.54² + 2 × 2.5²) = 0.0375, dy = 0.003 × (3.54² + 2 × 2.5²) + 2 × (-0.002) × 2.5 × 2.5 = 0.0425. Therefore, the second dimensional error E2 = sqrt(1.5² + 1.7²) × (1 + sqrt(0.0375² + 0.0425²)) = 2.27 × 1.057 = 2.4 pixels. In practice, a vector operation library is used for batch calculations to improve computational efficiency. The calculation results are rounded to one decimal place. The two dimensional errors will be used for subsequent calculations of perspective distortion correction coefficients.

[0124] Step 2023: Perform vector synthesis of the first dimensional error and the second dimensional error to obtain the distortion error value; determine the perspective distortion correction coefficient based on the ratio of the distortion error value to the reference dimensional value of the camera lens.

[0125] The first dimensional error refers to the change in image size caused by radial distortion, measured in pixels. The second dimensional error refers to the change in image size caused by tangential distortion, also measured in pixels. The distortion error value refers to the overall dimensional deviation combining radial and tangential distortion effects, measured in pixels. The reference dimensional value refers to the image size of the camera lens at its standard working distance, measured in pixels. The perspective distortion correction factor is a dimensionless correction factor used to compensate for distortion effects.

[0126] Specifically, error vector synthesis is first performed, using the Euclidean norm to calculate the overall error: E = sqrt(E1² + E2²), where E1 is the first size error and E2 is the second size error. For example, given a first size error E1 = 441.4 pixels and a second size error E2 = 2.4 pixels, the distortion error is calculated as: E = sqrt(441.4² + 2.4²) = 441.4 pixels. Since the second size error is relatively small, the synthesis result is mainly determined by the radial distortion error. Then, the ratio of the distortion error to the reference size is calculated. The reference size is usually the diagonal length of the image. For a 1920×1080 resolution image, the reference size L = sqrt(1920² + 1080²) = 2203 pixels. The error ratio α = E / L = 441.4 / 2203 = 0.20. Finally, the correction coefficient is determined based on the error ratio using a nonlinear mapping function: k = 1 + β × tan(π × α / 2), where β is the correction gain coefficient, typically taken as 1.2. Substituting into the calculation: k = 1 + 1.2 × tan(π × 0.20 / 2) = 1.384. In practice, to prevent excessive error from causing instability in the correction coefficient, an upper limit (e.g., 1.5) and a lower limit (e.g., 1.0) are set for the correction coefficient. When the calculation result exceeds the range, boundary values ​​are used. Double-precision floating-point numbers are used in the calculation of the correction coefficient, and the final result is retained to three decimal places. The entire calculation process includes three steps: error synthesis, ratio calculation, and coefficient mapping. Each step requires numerical validity verification. Mathematical library functions (e.g., std::hypot, std::tan) can be used to improve computational efficiency and accuracy. The perspective distortion correction coefficient will be used for subsequent image size compensation.

[0127] Step 203: Based on the perspective distortion correction coefficient, calculate the compensation for the sub-image width and sub-image height corresponding to the focal length to obtain the image size parameters at the focal length.

[0128] Perspective distortion correction factor is a correction factor used to compensate for lens distortion effects, typically with a value greater than 1. Sub-image width and sub-image height refer to the original image size at a specific focal length, measured in pixels. Compensation calculation refers to the mathematical operation process of correcting the original size using the correction factor. Image size parameters refer to the final image size after distortion compensation, including the corrected width and height values, measured in pixels. Focal length refers to the distance from the optical center of the lens to the image plane in an optical system, measured in millimeters.

[0129] Specifically, the sub-image size at each focal length position is first compensated. The compensation calculation uses a linear correction model: corrected width w' = w × k, corrected height h' = h × k, where w and h are the original sub-image width and height, and k is the perspective distortion correction coefficient. For example, if the sub-image size at a certain focal length position is 1440 × 810 pixels, and the perspective distortion correction coefficient k = 1.028, then the corrected image size parameters are calculated as follows: corrected width w' = 1440 × 1.028 = 1480 pixels, corrected height h' = 810 × 1.028 = 833 pixels. The calculation results are then rounded down to the nearest pixel. When multiple distortion correction coefficients exist (such as the correction coefficients for the four vertices of the target area), a weighted average strategy is used: the weight coefficient is inversely proportional to the distance from the vertex to the center of the area. The specific implementation is as follows: First, calculate the distances d1, d2, d3, and d4 from the four vertices to the center. Then, calculate the weights ω_i = (1 / d_i) / Σ(1 / d_j), and finally, the correction coefficient k = Σ(k_i × ω_i). For example, if the correction coefficients for the four vertices are 1.028, 1.032, 1.025, and 1.030, and the corresponding normalized weights are 0.26, 0.24, 0.28, and 0.22, then the comprehensive correction coefficient k = 1.028 × 0.26 + 1.032 × 0.24 + 1.025 × 0.28 + 1.030 × 0.22 = 1.0285. This comprehensive correction coefficient is used for size compensation calculation. The results of the compensation calculation need to be validated: the corrected size should not exceed the camera's maximum resolution and should not be less than the preset minimum size threshold. The entire calculation process uses floating-point arithmetic to ensure accuracy, and the final result is converted to integer pixel values. The corrected imaging size parameters will be used for subsequent image scaling and feature extraction operations.

[0130] Reference Figure 3 This application provides a camera focal length control system based on target imaging. The system includes: a data acquisition module, an offset distance determination module, an image sharpness determination module, and a focal length adjustment module, wherein:

[0131] The data acquisition module is used to acquire the desired imaging parameters and the current flight altitude of the UAV;

[0132] The offset distance determination module is used to determine the focal length traversal range and focal length step interval based on the current flight altitude, control the UAV's camera lens to traverse and acquire images within the focal length traversal range at focal length step intervals, and determine the image acquisition sequence; perform target detection on each frame of the image acquisition sequence, determine the target area, acquire the imaging width and imaging height of the target area, and calculate the offset distance between the geometric center of the target area and the image center.

[0133] The image sharpness determination module is used to correct the imaging width and imaging height based on the offset distance to obtain imaging size parameters at multiple focal lengths; calculate the size deviation between the imaging size parameters at each focal length and the target desired imaging parameters, and filter out the target focal lengths with size deviation values ​​less than a preset threshold; calculate the image sharpness of the tracking area corresponding to the target focal length to determine the first image sharpness;

[0134] The focal length adjustment module is used to acquire the attitude angle information and flight speed information of the UAV, and to perform attitude compensation on the first image sharpness based on the attitude angle information and flight speed information to obtain the second image sharpness; the target focal length corresponding to the maximum second image sharpness is used as the camera focal length to be adjusted, and the UAV's camera lens is controlled to adjust to the camera focal length to be adjusted.

[0135] Based on the above embodiments, the offset distance determination module is also used to obtain the minimum focal length value and the maximum focal length value of the UAV's camera lens; query a preset altitude-focal length mapping table according to the current flight altitude to determine the recommended focal length center value corresponding to the current flight altitude; expand the preset focal length range in the direction of the minimum focal length value and the maximum focal length value respectively based on the recommended focal length center value to obtain the focal length traversal range; and determine the focal length step interval according to the ratio of the span of the focal length traversal range to the preset traversal frame number.

[0136] Based on the above embodiments, the offset distance determination module is also used to extract the bounding box coordinates of the target area, the bounding box coordinates including the coordinates of the upper left corner and the lower right corner; calculate the geometric center coordinates of the target area based on the bounding box coordinates, the geometric center coordinates being the midpoint coordinates of the upper left corner and the lower right corner; obtain the image center coordinates of the current image in the image acquisition sequence; calculate the coordinate differences between the geometric center coordinates and the image center coordinates in the horizontal and vertical directions; and calculate the offset distance using the Euclidean distance formula based on the coordinate differences in the horizontal and vertical directions.

[0137] Based on the above embodiments, the image sharpness determination module is further configured to traverse the imaging width and imaging height according to a preset focal length scale to obtain multiple sub-imaging widths and sub-imaging heights corresponding to each focal length. For each focal length, it determines whether the target area is located in the center region of the image based on the offset distance. If the target area is located in the center region of the image, the sub-imaging width and sub-imaging height corresponding to the focal length are used as the imaging size parameters under the focal length. If the target area is not located in the center region of the image, the perspective distortion correction coefficient is calculated based on the offset distance and the distortion parameters of the camera lens. Based on the perspective distortion correction coefficient, the sub-imaging width and sub-imaging height corresponding to the focal length are compensated to obtain the imaging size parameters under the focal length.

[0138] Based on the above embodiments, the image sharpness determination module is further configured to obtain the radial distortion coefficient and tangential distortion coefficient of the camera lens; calculate the radial offset and tangential offset of the target region in the image based on the offset distance; calculate the first dimensional error introduced by radial distortion based on the radial distortion coefficient and radial offset; calculate the second dimensional error introduced by tangential distortion based on the tangential distortion coefficient and tangential offset; perform vector synthesis of the first dimensional error and the second dimensional error to obtain the distortion error value; and determine the perspective distortion correction coefficient based on the ratio of the distortion error value to the reference dimensional value of the camera lens.

[0139] Based on the above embodiments, the image sharpness determination module is further used to extract the target region in the image corresponding to the target focal length as the tracking region; perform grayscale processing on the tracking region to obtain a grayscale image; use the Sobel operator to perform edge detection on the grayscale image and calculate the gradient magnitude of each pixel in the tracking region; count the number of pixels in the tracking region whose gradient magnitude is greater than a preset gradient threshold to obtain the number of effective edge pixels; calculate the average gradient magnitude of all pixels in the tracking region to obtain the average gradient intensity; use the ratio of the number of effective edge pixels to the total number of pixels in the tracking region as the edge density coefficient; and perform a weighted summation of the average gradient intensity and the edge density coefficient to obtain the first image sharpness.

[0140] Based on the above embodiments, the focus adjustment module is also used to extract the pitch angle and roll angle from the attitude angle information; calculate the attitude deviation based on the pitch angle and roll angle, where the attitude deviation is the square root of the sum of the squares of the pitch angle and the roll angle; determine the attitude compensation coefficient based on the attitude deviation, where the attitude compensation coefficient is positively correlated with the attitude deviation; acquire the horizontal flight speed and vertical flight speed from the flight speed information; calculate the displacement of the UAV within the image exposure time based on the horizontal and vertical flight speeds; determine the motion blur compensation coefficient based on the displacement, where the motion blur compensation coefficient is positively correlated with the displacement; and multiply the first image sharpness by the attitude compensation coefficient and the motion blur compensation coefficient to obtain the second image sharpness.

[0141] It should be noted that the above embodiments of the apparatus are only illustrated by the division of the above functional modules. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.

[0142] This application also discloses an electronic device. (See reference...) Figure 4 , Figure 4This is a schematic diagram of the structure of an electronic device disclosed in an embodiment of this application. The electronic device 400 may include: at least one processor 401, at least one network interface 404, a user interface 403, a memory 405, and at least one communication bus 402.

[0143] The communication bus 402 is used to enable communication between these components.

[0144] The user interface 403 may include a display interface and a camera interface. Optionally, the user interface 403 may also include a standard wired interface and a wireless interface.

[0145] The network interface 404 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface).

[0146] The processor 401 may include one or more processing cores. The processor 401 connects to various parts of the server using various interfaces and lines, and performs various server functions and processes data by running or executing instructions, programs, code sets, or instruction sets stored in memory 405, and by calling data stored in memory 405. Optionally, the processor 401 may be implemented using at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 401 may integrate one or a combination of several of the following: Central Processing Unit (CPU), Graphics Processing Unit (GPU), and modem. The CPU primarily handles the operating system, user interface graphics, and applications; the GPU is responsible for rendering and drawing the content required for display; and the modem handles wireless communication. It is understood that the modem may also not be integrated into the processor 401 and may be implemented as a separate chip.

[0147] The memory 405 may include random access memory (RAM) or read-only memory. Optionally, the memory 405 may include a non-transitory computer-readable storage medium. The memory 405 may be used to store instructions, programs, code, code sets, or instruction sets. The memory 405 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as touch function, sound playback function, image playback function, etc.), instructions for implementing the above-described method embodiments, etc.; the data storage area may store data involved in the above-described method embodiments, etc. Optionally, the memory 405 may also be at least one storage device located remotely from the aforementioned processor 401. (Refer to...) Figure 4 The memory 405, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an application program for a camera focal length control method based on target imaging.

[0148] exist Figure 4 In the illustrated electronic device 400, the user interface 403 is mainly used to provide an input interface for the user and acquire user input data; while the processor 401 can be used to call an application program stored in the memory 405 for a camera focal length control method based on target imaging. When executed by one or more processors 401, the electronic device 400 performs one or more methods as described in the above embodiments. It should be noted that, for the foregoing method embodiments, for the sake of simplicity, they are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, because according to this application, some steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also understand that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to this application.

[0149] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions in other embodiments.

[0150] In the various embodiments provided in this application, it should be understood that the disclosed apparatus can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some service interface; the indirect coupling or communication connection between apparatuses or units may be electrical or other forms.

[0151] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0152] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0153] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage device (CMD). Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned memory includes various media capable of storing program code, such as USB flash drives, portable hard drives, magnetic disks, or optical disks.

[0154] The above are merely exemplary embodiments of this disclosure and should not be construed as limiting the scope of this disclosure. Any equivalent changes and modifications made in accordance with the teachings of this disclosure shall still fall within the scope of this disclosure. Other embodiments of this disclosure will be readily apparent to those skilled in the art upon consideration of the specification and practical disclosure.

[0155] This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The specification and embodiments are to be considered exemplary only.

Claims

1. A camera focal length control method based on target imaging, characterized in that, include: Obtain the desired imaging parameters and the current flight altitude of the UAV; Based on the current flight altitude, determine the focal length traversal range and focal length step interval, control the camera lens of the UAV to traverse and acquire images within the focal length traversal range at the focal length step interval, and determine the image acquisition sequence. Target detection is performed on each frame of the image acquisition sequence to determine the target region, the imaging width and imaging height of the target region are acquired, and the offset distance between the geometric center of the target region and the image center is calculated; Based on the offset distance, the imaging width and imaging height are corrected to obtain imaging size parameters at multiple focal lengths; Calculate the size deviation between the imaging size parameters and the target desired imaging parameters at each focal length, and filter out the target focal lengths whose size deviation values ​​are less than a preset threshold; The image sharpness of the tracking area corresponding to the target focal length is calculated to determine the first image sharpness; The attitude angle information and flight speed information of the UAV are obtained, and attitude compensation is performed on the first image sharpness based on the attitude angle information and the flight speed information to obtain the second image sharpness; The target focal length corresponding to the maximum image clarity is taken as the focal length of the camera to be adjusted, and the camera lens of the UAV is controlled to be adjusted to the focal length of the camera to be adjusted.

2. The method according to claim 1, characterized in that, The step of determining the focal length traversal range and focal length step interval based on the current flight altitude includes: Obtain the minimum and maximum focal length values ​​of the camera lens of the drone; Based on the current flight altitude, a preset altitude-focal length mapping table is queried to determine the recommended focal length center value corresponding to the current flight altitude; Based on the recommended focal length center value, the preset focal length range is extended in the directions of the minimum focal length value and the maximum focal length value respectively to obtain the focal length traversal range; The focal length step interval is determined based on the ratio of the span of the focal length traversal range to the preset number of traversal frames.

3. The method according to claim 1, characterized in that, The calculation of the offset distance between the geometric center of the target region and the image center includes: Extract the bounding box coordinates of the target region, the bounding box coordinates including the coordinates of the top left corner and the bottom right corner; The geometric center coordinates of the target region are calculated based on the bounding box coordinates, where the geometric center coordinates are the midpoint coordinates of the upper left corner and the lower right corner. Obtain the image center coordinates of the current image in the image acquisition sequence; Calculate the coordinate differences between the geometric center coordinates and the image center coordinates in the horizontal and vertical directions; The offset distance is calculated using the Euclidean distance formula based on the coordinate difference in the horizontal direction and the coordinate difference in the vertical direction.

4. The method according to claim 1, characterized in that, The process of correcting the imaging width and imaging height based on the offset distance yields imaging size parameters at multiple focal lengths, including: By iterating through the imaging width and imaging height according to a preset focal length scale, multiple sub-imaging widths and sub-imaging heights corresponding to different focal lengths are obtained. For each focal length, determine whether the target region is located in the center region of the image based on the offset distance; If the target area is located within the center area of ​​the image, then the sub-imaging width and sub-imaging height corresponding to the focal length are used as the imaging size parameters under the focal length; If the target area is not located within the center area of ​​the image, then the perspective distortion correction coefficient is calculated based on the offset distance and the distortion parameters of the camera lens; Based on the perspective distortion correction coefficient, the sub-image width and sub-image height corresponding to the focal length are compensated and calculated to obtain the image size parameters at the focal length.

5. The method according to claim 4, characterized in that, The calculation of the perspective distortion correction coefficient based on the offset distance and the distortion parameters of the camera lens includes: Obtain the radial distortion coefficient and tangential distortion coefficient of the camera lens; Calculate the radial and tangential offsets of the target region in the image based on the offset distance; Based on the radial distortion coefficient and the radial offset, the first dimensional error introduced by the radial distortion is calculated; Based on the tangential distortion coefficient and the tangential offset, the second dimensional error introduced by the tangential distortion is calculated; The distortion error value is obtained by vector synthesis of the first dimensional error and the second dimensional error; The perspective distortion correction coefficient is determined based on the ratio of the distortion error value to the reference size value of the camera lens.

6. The method according to claim 1, characterized in that, The step of calculating the image sharpness of the tracking area corresponding to the target focal length and determining the first image sharpness includes: Extract the target region from the image corresponding to the target focal length as the tracking region; The tracking area is converted to grayscale to obtain a grayscale image; The Sobel operator is used to perform edge detection on the grayscale image, and the gradient magnitude of each pixel within the tracking region is calculated. The number of pixels with gradient magnitude greater than a preset gradient threshold within the tracking area is counted to obtain the number of effective edge pixels; Calculate the average gradient magnitude of all pixels within the tracking region to obtain the average gradient intensity; The ratio of the number of effective edge pixels to the total number of pixels in the tracking region is used as the edge density coefficient; The first image sharpness is obtained by weighted summation of the average gradient intensity and the edge density coefficient.

7. The method according to claim 1, characterized in that, The step of performing attitude compensation on the first image sharpness based on the attitude angle information and the flight speed information to obtain the second image sharpness includes: Extract the pitch and roll angles from the attitude angle information; The attitude deviation is calculated based on the pitch angle and the roll angle, whereby the attitude deviation is the square root of the sum of the squares of the pitch angle and the roll angle. An attitude compensation coefficient is determined based on the attitude deviation, and the attitude compensation coefficient is positively correlated with the attitude deviation. Obtain the horizontal and vertical flight speeds from the flight speed information; Calculate the displacement of the UAV during the image exposure time based on the horizontal flight speed and the vertical flight speed; The motion fuzziness compensation coefficient is determined based on the displacement amount, and the motion fuzziness compensation coefficient is positively correlated with the displacement amount; The second image sharpness is obtained by multiplying the first image sharpness with the attitude compensation coefficient and the motion blur compensation coefficient.

8. A camera focal length control system based on target imaging, characterized in that, The system includes: The data acquisition module is used to acquire the desired imaging parameters and the current flight altitude of the UAV; The offset distance determination module is used to determine the focal length traversal range and focal length step interval based on the current flight altitude, control the camera lens of the UAV to traverse and acquire images within the focal length traversal range at the focal length step interval, determine the image acquisition sequence, perform target detection on each frame of the image acquisition sequence, determine the target region, acquire the imaging width and imaging height of the target region, and calculate the offset distance between the geometric center of the target region and the image center. An image sharpness determination module is used to correct the imaging width and imaging height based on the offset distance to obtain imaging size parameters at multiple focal lengths; calculate the size deviation value between the imaging size parameters at each focal length and the target desired imaging parameters, and filter out target focal lengths whose size deviation value is less than a preset threshold; perform image sharpness calculation on the tracking area corresponding to the target focal length to determine the first image sharpness; The focal length adjustment module is used to acquire the attitude angle information and flight speed information of the UAV, and to perform attitude compensation on the first image sharpness according to the attitude angle information and flight speed information to obtain the second image sharpness; the target focal length corresponding to the maximum second image sharpness is used as the camera focal length to be adjusted, and the camera lens of the UAV is controlled to adjust to the camera focal length to be adjusted.

9. An electronic device, characterized in that, The device includes a processor, a memory, a user interface, and a network interface. The memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory to cause the electronic device to perform the camera focal length control method based on target imaging as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores instructions that, when executed, perform the camera focal length control method based on target imaging as described in any one of claims 1-7.

Citation Information

Patent Citations

  • Digital image correction method for continuous variable-focal-length optical imaging system

    CN104835159A

  • Aerial remote sensing narrow-view-field camera shooting control method

    CN113252008A