Self-learning-based focusing method, system, electronic device and medium for deviation between tof and distance from real focus position of lens

CN122802790APending Publication Date: 2026-09-22HANGZHOU XINGXI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611275705.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-21
Publication Date
2026-09-22

AI Technical Summary

Technical Problem

[0003]本申请提供一种基于自学习的TOF与镜头真实准焦位置距离之间偏差量的对焦方法、系统、电子设备及介质,用于解决现有TOF辅助对焦在线学习方法因物距均匀建模、缺乏分层限幅与可信度防护、缺乏陈旧数据动态淘汰、以及补偿不可信时学习成果整体作废,导致坏样本污染对焦曲线、跟不上温漂/场景迁移、以及弱信息被浪费等问题

Benefits of technology

[0016]1)采用按距离的自适应非均匀分桶(近密远疏)并以分桶平均替代曲线拟合,近距保留分辨率、远距抑制噪声,相较现有技术的均匀建模,在远距噪声大、近距要求高的真实场景下偏差估计更稳定、计算量更低,适合嵌入式在线实时运行。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122802790A_ABST
    Figure CN122802790A_ABST
Patent Text Reader

Abstract

The application provides a focusing method and system based on a deviation amount between a TOF and a real focusing position distance of a lens, an electronic device and a medium. The method comprises: collecting focusing data samples; the focusing data samples comprise a binary group of a TOF measured object distance after successful focusing and a real focusing position distance of a lens; the focusing data samples are stored in a ring buffer area after being filtered for effectiveness based on a sampling end limit; the filtered focusing data samples are generated into a deviation mapping relationship table according to an adaptive non-uniform bucketing rule; when a focusing request is received, a current TOF measured object distance corresponding deviation amount is determined based on the deviation mapping relationship table; the current TOF measured object distance corresponding deviation amount is determined based on the deviation mapping relationship table and is output after being limited at an output end, and is superimposed on the current TOF measured object distance to obtain a TOF corrected object distance to drive a camera lens. The present scheme solves the problems of existing methods, such as bad sample pollution of a focusing curve, failure to follow temperature drift / scene migration, and waste of weak information.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application belongs to the field of camera autofocus technology, and relates to a focusing method, system, electronic device and medium based on the deviation between the self-learning TOF and the actual focus position distance of the lens. Background Technology

[0002] Currently, mainstream focusing solutions generally employ a combination of "TOF (Time of Flight) coarse focusing + CAF (Continuous Auto Focus) fine focusing." First, TOF measures the distance and uses a pre-calibrated focusing curve to determine the lens motor control value for coarse focusing. Then, CAF, using a contrast-based algorithm, repeatedly drives the motor and calculates image sharpness (FV) to gradually converge to the sharpest position. However, TOF focusing itself is affected by calibration errors, focusing curve fitting errors, motor control errors, lens consistency errors, lens assembly consistency errors, and temperature drift, resulting in systematic deviations. Therefore, a second CAF fine focusing is required each time, leading to long focusing times and repeated "sharp-blurred" switching of the image during the CAF process. Summary of the Invention

[0003] This application provides a focusing method, system, electronic device, and medium based on the deviation between the Time-of-Flight (TOF) sensor and the lens's actual focus position distance, which solves the problems of existing TOF-assisted focusing online learning methods, such as uniform object distance modeling, lack of layered limiting and reliability protection, lack of dynamic elimination of outdated data, and overall invalidation of learning results when compensation is unreliable, resulting in bad samples contaminating the focus curve, failing to keep up with temperature drift / scene migration, and wasting weak information.

[0004] In a first aspect, this application provides a focusing method based on the deviation between the Time-of-Flight (TOF) sensor and the actual focusing position of the lens, comprising: acquiring focusing data samples; wherein the focusing data samples include a pair of objects measured by the TOF sensor after successful focusing and the actual focusing position of the lens; performing validity filtering on the focusing data samples based on sampling end limiting, and storing the filtered focusing data samples in a circular buffer; generating a deviation mapping table between the TOF-measured object distance and the deviation amount according to an adaptive non-uniform binning rule for the filtered focusing data samples; when a focusing request is received, determining the deviation amount corresponding to the current TOF-measured object distance based on the deviation mapping table, performing output end limiting on the deviation amount, and superimposing the output end-limited deviation amount onto the current TOF-measured object distance to obtain the TOF corrected object distance, thereby driving the camera lens.

[0005] In this application, when filtering the collected focus data samples for validity, the samples are screened based on the sampling end limiting to prevent bad samples from participating in the modeling. For valid samples within the annular buffer, an adaptive non-uniform binning rule (i.e., the bin width increases with the TOF-measured object distance rather than changing uniformly) is used to generate a deviation mapping table between the TOF-measured object distance and the deviation amount. This non-uniform binning rule matches the modeling resolution with the distance distribution of the TOF-measured object distance error, preserving resolution at close range and suppressing noise at long range. Therefore, the deviation estimation is more stable and the computational load is lower, making it suitable for embedded online real-time operation. The deviation mapping table stores the deviation amount between the TOF-measured object distance and the distance to the lens's actual focus position, rather than the absolute motor value in the prior art. Since the numerical range of the deviation amount is much smaller than the absolute motor value (i.e., absolute position) and the distribution is more concentrated, it is easier to set the limiting boundary based on the object distance percentage. It also decouples the "lens basic focus curve" and the "TOF system deviation" parts, making the learning target more stable and easier to implement safety protection. Upon receiving a focus request, the deviation corresponding to the current TOF-measured object distance is determined based on the deviation mapping table. This deviation is then output-limited, and the output-limited deviation is superimposed on the current TOF-measured object distance to obtain the corrected TOF object distance, which drives the camera lens. Sampling-end limiting is responsible for eliminating extreme outliers to prevent bad pixels from entering valid data samples, while output-end limiting is responsible for providing a final safety clamp to deviation values ​​from any source.

[0006] In one implementation of the first aspect, the focusing method further includes: based on whether the deviation of each node in the deviation mapping table exceeds the reasonable error band, counting the number of nodes with positive and negative deviation directions; when the total number of valid nodes and the proportion of the direction with the largest proportion meet the preset confidence conditions, determining that the overall bias of the camera lens is reliable; when deviation compensation is unavailable and the overall bias is reliable, determining the starting direction of continuous autofocus search based on the overall bias.

[0007] In one implementation of the first aspect, the step of filtering the focus data samples based on sampling end limiting and storing the filtered focus data samples in a circular buffer includes: calculating the original deviation between the object distance measured by TOF and the actual focus position of the lens after each successful focus; calculating the allowable deviation range corresponding to the object distance measured by TOF according to a preset limiting configuration, and determining a sampling threshold based on the allowable deviation range; if the absolute value of the original deviation is greater than the sampling threshold, the focus data sample is discarded; otherwise, the focus data sample is stored in the circular buffer.

[0008] In one implementation of the first aspect, generating a deviation mapping table between the TOF-measured object distance and the deviation amount by means of an adaptive non-uniform binning rule for the filtered focus data samples includes: whenever a preset number of focus data samples are added to the annular buffer, calculating the width of each bin for all TOF-measured object distances in the annular buffer; wherein the bin width changes non-uniformly with the increase of the TOF-measured object distance; calculating the bin key based on each TOF-measured object distance and its corresponding bin width, and merging all focus data samples according to the bin key; when the number of samples in a bin is greater than or equal to a preset number, generating a valid node, and the set of all nodes serves as the deviation mapping table between the TOF-measured object distance and the deviation amount.

[0009] In one implementation of the first aspect, the focusing method further includes: whenever a preset number of focusing data samples are added to the circular buffer, all existing nodes in the current deviation mapping table are traversed, and the discard count of each node is incremented by 1; if a new focusing data sample after validity filtering is stored in a bucket, the discard count of the node corresponding to that bucket is reset to 0; after rebuilding the deviation mapping table, if the discard count of a node reaches the upper limit, the node is deleted.

[0010] In one implementation of the first aspect, the step of determining the deviation amount corresponding to the current TOF measured object distance based on the deviation mapping table when a focus request is received, performing output-end limiting on the deviation amount, and superimposing the output-end limited deviation amount onto the current TOF measured object distance to obtain the TOF corrected object distance for driving the camera lens includes: when a focus request is received, if the number of valid nodes in the deviation mapping table is less than the minimum number of nodes, then the current TOF measured object distance is used as the TOF corrected object distance; if the number of valid nodes in the deviation mapping table is greater than or equal to the minimum number of nodes, the theoretical barrel key is calculated based on the current TOF measured object distance; if the deviation amount is less than the minimum number of nodes, then the deviation amount is used as the TOF corrected object distance. If the node corresponding to the bucket key is matched in the difference mapping table, the deviation corresponding to that node is selected; otherwise, the distance difference between the two adjacent nodes closest to the current TOF measured object distance and the current TOF measured object distance is calculated, and the reliability of the two adjacent nodes is determined based on whether the distance difference exceeds the maximum allowable reliable distance limit; if both sides are not reliable, the deviation is 0; if only one side is reliable, the deviation of the node on that side is adopted; if both sides are reliable, the deviation is obtained by weighted fusion according to the inverse weight of the object distance domain; the deviation is output-limited according to the calculated current allowable deviation amplitude limit, and then quantized and rounded to obtain the TOF corrected object distance.

[0011] In one implementation of the first aspect, the step of limiting the output amplitude of the deviation amount based on the calculated upper limit of the current allowable deviation amplitude and quantizing and rounding it to obtain the TOF corrected object distance includes: calculating the allowable deviation amplitude corresponding to the current TOF measured object distance according to a preset limiting configuration; performing bidirectional clamping on the deviation amount based on the allowable deviation amplitude to control the deviation amount within the range of the allowable deviation amplitude, and quantizing and rounding the bidirectionally clamped deviation amount according to a preset granularity.

[0012] Secondly, this application also provides a focusing system based on the deviation between the Time-of-Flight (TOF) sensor and the lens's true focusing position distance, comprising: a sample acquisition module for acquiring focusing data samples; wherein the focusing data samples include a tuple of the object distance measured by the TOF sensor after successful focusing and the distance between the object distance and the lens's true focusing position distance; a sample filtering module for filtering the focusing data samples based on sampling end limiting and storing the filtered focusing data samples in a circular buffer; a sample binning modeling processing module for generating a deviation mapping relationship table between the TOF-measured object distance and the deviation amount according to an adaptive non-uniform binning rule; and a focusing control module for determining the deviation amount corresponding to the current TOF-measured object distance based on the deviation mapping relationship table when a focusing request is received, performing output end limiting on the deviation amount, and superimposing the output end-limited deviation amount onto the current TOF-measured object distance to obtain a corrected TOF object distance to drive the camera lens.

[0013] Thirdly, this application also provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the program to implement the above-mentioned focusing method based on the deviation between the self-learning TOF and the actual focusing position distance of the lens.

[0014] Fourthly, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by an electronic device, implements the above-described focusing method based on the deviation between the self-learning TOF and the lens's true focus position distance.

[0015] As described above, the focusing method, system, and medium based on the deviation between the self-learning TOF and the actual focusing position distance of the lens, as described in this application, have the following beneficial effects:

[0016] 1) Adaptive non-uniform binning based on distance (dense near distance and sparse far distance) and replacement of curve fitting with bin average are used. Near distance retains resolution and far distance suppresses noise. Compared with the uniform modeling of existing technologies, the bias estimation is more stable and the computation is lower in real-world scenarios with high noise at a distance and high requirements at a distance, making it suitable for embedded online real-time operation.

[0017] 2) Two levels of amplitude limiting are set at the sampling end and the output end, and the credibility of adjacent nodes is judged during interpolation. If the node is not credible, it returns 0. Compared with the existing technology which only has coarse-grained error tolerance, this scheme can actively give up compensation when there are bad samples or sparse data, which significantly improves the focusing robustness.

[0018] 3) By adopting continuous incremental learning during operation and introducing a discard count and refresh reset mechanism, compared with the existing schemes that rely on offline pre-calibration and fixed offsets during power-on self-test, as well as the existing static / full self-learning calibration schemes, this scheme does not require factory or recalibration. The mapping table can smoothly migrate with temperature drift / scene changes, automatically remove old points, and does not degrade in long-term operation.

[0019] 4) The “overall bias of the camera lens” is used as the output product with an independent confidence threshold. Compared with the existing technology, the learning results are completely invalid when the compensation value is unreliable. This solution can guide the CAF starting orientation even if numerical compensation is disabled, thereby reducing blind search and shortening the focusing time.

[0020] 5) The above-mentioned deviation compensation and directional guidance work together to make the camera lens closer to the true focus position after TOF coarse focusing, and the CAF convergence stroke is shorter, thereby shortening the overall focusing time and reducing the visual impact of repeated "sharp-blurred" images during the CAF process.

[0021] 6) By adopting automatic online learning and table-driven limit configuration on the production line / site, compared with the solution that relies on the factory calibration table, it achieves low cost, good compatibility, dynamic parameter adjustment, and good scalability and adjustability. Attached Figure Description

[0022] Figure 1 The diagram shows a flowchart illustrating the focusing method based on self-learning TOF and the distance between the actual focusing position and the lens, as described in an embodiment of this application.

[0023] Figure 2 The diagram shows the process of adaptive non-uniform bucketing modeling in the focusing method based on the deviation between the self-learning TOF and the actual focusing position distance of the lens, as described in the embodiments of this application.

[0024] Figure 3 The diagram shows the flow chart of direction signal determination and CAF starting direction decision in the focusing method based on self-learning TOF and the distance between the actual focusing position of the lens as described in the embodiments of this application.

[0025] Figure 4 The diagram shows a module structure of a focusing system based on self-learning TOF and the distance between the actual focus position of the lens, as described in an embodiment of this application. Detailed Implementation

[0026] The following specific examples illustrate the implementation of this application. Those skilled in the art can easily understand other advantages and effects of this application from the content disclosed in this specification. This application can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of this application. It should be noted that, unless otherwise specified, the following embodiments and features in the embodiments can be combined with each other.

[0027] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of this application. Therefore, the drawings only show the components related to this application and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0028] The technical solutions in the embodiments of this application will be described in detail below with reference to the accompanying drawings.

[0029] like Figure 1 The diagram shown is a flowchart illustrating the focusing method based on the deviation between the self-learning TOF and the actual focusing position distance of the lens, as described in an embodiment of this application.

[0030] refer to Figure 1 The focusing method includes the following steps:

[0031] Step S101: Collect focus data samples; wherein the focus data samples include a pair of objects measured by TOF after successful focusing and the distance between the actual focus position of the lens.

[0032] Step S102: Perform validity filtering on the focus data samples based on the sampling end limiting, and store the focus data samples after validity filtering into the circular buffer.

[0033] Step S103: Generate a deviation mapping table between the object distance measured by TOF and the deviation amount by using the filtered focus data samples according to the adaptive non-uniform binning rule.

[0034] Step S104: When a focus request is received, the deviation amount corresponding to the current TOF measured object distance is determined based on the deviation mapping table, and the output end is limited for the deviation amount. The output end limited deviation amount is then superimposed on the current TOF measured object distance to obtain the TOF corrected object distance, so as to drive the camera lens.

[0035] The focusing method described in this embodiment is suitable for use in a continuous autofocus (CAF) camera, and the camera utilizes TOF ranging to assist CAF focusing.

[0036] In this embodiment, in step S101, the focus data sample can record the object distance measured by TOF and the corresponding actual lens focus position distance after each successful CAF focusing in the form of a tuple. For example, the tuple of a sample data in this focus data sample is {tof = TOF measured object distance, lens = actual lens focus position distance after CAF convergence}. Furthermore, the sample data information can also record the time information (i.e., timestamp) of a successful CAF focusing and the confidence of that sample data. In the camera, the collected focus data sample can be input to the lens calibrator through the focus management module.

[0037] As described in step S102, the focus data samples are filtered for validity based on the sampling end limiting, and the focus data samples after validity filtering are stored in the circular buffer.

[0038] In one embodiment, this step specifically includes:

[0039] Step S1021: Calculate the original deviation between the object distance measured by TOF and the actual focus position of the lens after each successful focus.

[0040] Step S1022: Calculate the allowable deviation amplitude corresponding to the object distance measured by the TOF according to the preset amplitude limiting configuration, and determine the sampling threshold based on the allowable deviation amplitude.

[0041] Step S1023: If the absolute value of the original deviation is greater than the sampling threshold, the focus data sample is discarded; otherwise, the focus data sample is stored in the circular buffer.

[0042] Those skilled in the art will understand that the input focus data samples may contain anomalies due to various reasons. For example, the movement of the subject may cause the CAF to converge to a non-target subject; ambient light interference or TOF multipath effects may cause range jumps; the CAF algorithm may converge to a local extremum instead of the globally sharpest point due to insufficient contrast; and there may be instantaneous system noise or data transmission errors. If such bad samples are directly used in modeling, the contamination bias mapping table will be applied, causing subsequent focus to continuously deviate from the correct position.

[0043] Specifically, before the focus data samples enter the circular buffer, the isSampleValid() function performs sampling-end limiting. For each successful CAF focus, the raw bias bias = lens - tof is calculated in the tuple {tof, lens}. Then, the limiting configuration table mBiasLimits is set. For example, the limiting configuration table is as follows:

[0044] TOF distance interval Percentage of allowable deviation ≤1000 mm (≤1 m) 10% 1000 ~ 2000 mm 20% 2000 ~ 3000 mm 20% 3000 ~ 4000 mm 20% > 4000 mm 20%

[0045] Based on the object distance measured by the Time-of-Flight (TOF) sensor, consult the aforementioned limit configuration table to determine the allowable deviation range corresponding to that TOF-measured object distance: limit = max(tof, 1000) × maxPercent (allowable deviation percentage). Here, max(tof, 1000) ensures that the baseline is not less than 1000mm at close range (<1m), avoiding excessively tight limit settings. For example, if the TOF-measured object distance is 1500mm, then the allowable deviation percentage is 20%, corresponding to an allowable deviation range of 300mm.

[0046] Based on the allowable deviation range, a sampling threshold is set as follows: allowable deviation range limit × 2 (i.e., twice the allowable deviation range) as the threshold for judging bad pixels. If the original deviation amount |bias| calculated above is greater than the sampling threshold, the focus data sample is judged as an abnormal bad pixel and is directly discarded without entering the circular buffer area; and if TOF < 300mm, it is also directly rejected (because close-range TOF is easily affected by obstruction and the object distance is too close to exceed the lens's close-up capability).

[0047] In this embodiment, the sampling threshold is set to twice the allowable deviation range, rather than directly using the allowable deviation range. This is to retain a certain degree of large deviation samples within a reasonable range. These samples may correspond to real individual differences in lenses or sudden environmental changes (such as temperature jumps). They are allowed to enter the system, but must be constrained by subsequent output limiting. In practical applications, the numerical relationship between the sampling threshold and the allowable deviation range is not limited.

[0048] As described in step S103, the filtered focus data samples are used to generate a deviation mapping table between the object distance measured by TOF and the deviation amount according to the adaptive non-uniform binning rule.

[0049] In one embodiment, this step specifically includes:

[0050] Step S1031: Whenever a preset number of focus data samples are added to the annular buffer, the width of the corresponding bucket is calculated for all the TOF-measured object distances in the annular buffer; wherein the bucket width changes with the increase of the TOF-measured object distance rather than uniformly.

[0051] Step S1032: Calculate the barrel key based on the object distance measured by each TOF and its corresponding barrel width, and merge all focus data samples according to the barrel key.

[0052] Step S1033: When the number of samples in the bucket is greater than or equal to the preset number, a valid node is generated, and the set of all nodes is used as a deviation mapping table between the object distance measured by TOF and the deviation amount.

[0053] Those skilled in the art will understand that in a TOF-assisted CAF focusing system, mapping modeling faces two contradictory core challenges: 1) TOF ranging noise exhibits strong distance nonlinearity: at close range (<1m), the signal-to-noise ratio is high and ranging jitter is small; at long range (>3m), due to echo signal attenuation and ambient light interference, ranging noise increases exponentially. 2) The mapping relationship between lens motor control values ​​and object distance is nonlinear: for most fixed-focus or zoom lenses, the effect of object distance changes on lens displacement tends to saturate at long distances; the same amount of lens displacement causes a huge change in object distance at close range, but only a small change in object distance at long distances.

[0054] To address the aforementioned issues, this embodiment employs "adaptive non-uniform bucket modeling," which utilizes a non-uniform segmented quantization mechanism that matches the physical characteristics and optical projection laws of Time of Flight (TOF).

[0055] First, bucketed modeling does not update in real time with each received focus data sample. Instead, it employs a batch-triggered reconstruction strategy to balance real-time performance and computational efficiency. Specifically, the system maintains a circular buffer with a maximum capacity (e.g., 100 samples) to store valid focus data samples {tof, lens} that have been sampled and limited at the sampling end. Whenever the circular buffer accumulates 3 new valid samples (or other preset numbers can be configured), a full reconstruction using rebuildModel() is triggered. During each reconstruction, the existing node mapping table (NodeMap) is retained, and the corresponding nodes are refreshed or added based on the bucket key of all currently valid focus data samples in the circular buffer. This embodiment uses incremental updates with nodes retained across rounds instead of clearing and rebuilding, enabling the discard counting and eviction mechanism described later to take effect. The trigger interval of 3 focus data samples ensures that the model can respond quickly to environmental changes with iterations at the second level, while avoiding frequent reconstructions that consume CPU resources.

[0056] Then, in rebuildModel(), the object distance measured by TOF for each focus data sample in the annular buffer is calculated using the following piecewise function: getBucketSize(tof).

[0057] TOF distance interval Bucket width Design basis ≤ 1000mm (≤1m) 100mm The shallow depth of field at close range requires extremely high focusing accuracy; TOF has a good signal-to-noise ratio and allows for fine-grained modeling to capture subtle deviations. 1000mm ~ 3000mm (1m ~ 3m) 200mm The mid-range design balances accuracy and stability, with moderate TOF noise and appropriately widened buckets to smooth out individual sample jitter. > 3000mm (>3m) 500mm Long-range TOF sensors have high noise levels and their focusing curves tend to saturate, making fine-grained binning meaningless and easily biased by noise; coarse binning can effectively suppress noise and improve the robustness of bias estimation.

[0058] Bucket key calculation formula: bucketKey = floor(tof / bucketSize) × bucketSize. That is, each bucket uses its starting distance as the key value (for example, if tof = 1250mm falls within the 1m~3m range, and the bucket width is 200mm, then bucketKey = floor(1250 / 200)×200 = 1200mm, representing the range [1200mm, 1400mm)).

[0059] Then, all focus data samples are merged according to the bucket key. Specifically, all valid focus data samples in the circular buffer are traversed and merged into buckets according to the calculated bucketKey. A minimum sample number threshold is set (as a preset quantity). For example, a valid node is generated only when the number of samples in the bucket is ≥2. Buckets with only a single sample are considered unreliable and are directly discarded in this round of reconstruction without generating a node.

[0060] All node sets (NodeMap) are constructed into a node lookup table with bucketKey as the bucket key and bias as the value, serving as a deviation mapping table between the object distance measured by TOF and the aforementioned deviation. The calculation of each node attribute includes:

[0061] 1) node.bias = the arithmetic mean of the bias (lens - tof) of all focus data samples in this bucket.

[0062] 2) node.weight = total number of samples in the bucket (used as a reference for subsequent credibility and as a threshold for subsequent direction determination).

[0063] 3) node.tof = the bucketKey of the bucket (i.e., the bucket reference distance).

[0064] Furthermore, during each rebuildModel() process, in addition to generating new nodes, an obsolete counting and eviction mechanism is also executed. In one embodiment, this includes the following steps:

[0065] Whenever a preset number of focus data samples are added to the annular buffer, all existing nodes in the current deviation mapping table are traversed, and the discard count of each node is incremented by 1.

[0066] If a new, filtered, and focused data sample is stored in a bucket, the discard count of the node corresponding to that bucket is reset to 0.

[0067] After reconstructing the deviation mapping table, if the discard count of a certain node reaches the upper limit, then the node is deleted.

[0068] Specifically, at the start of reconstruction (i.e., every 3 new valid samples), the deprecateCnt count of all existing nodes is incremented by 1. Nodes refreshed by new samples in the current round (i.e., samples have fallen into that bucket) have their deprecateCnt reset to zero. Nodes that have not been refreshed by any new samples for 50 consecutive rounds (upper limit mDeprecateLimit) are deleted from the NodeMap. In other words, if the distance region represented by a node has never been refreshed by any new samples within a period of 50 × 3 = 150 consecutive new valid samples, it is considered that the deviation pattern of that region no longer exists or has undergone a fundamental change, and its historical information is no longer reliable, thus it is discarded. This deprecation count elimination mechanism ensures that the deviation mapping table timely reflects the distribution of recent valid samples, while historically outdated nodes are automatically discarded, allowing the model to follow temperature drift and scene migration.

[0069] like Figure 2 The diagram shown is a flowchart illustrating the adaptive non-uniform bucketing modeling process in the focusing method based on the deviation between the self-learning TOF and the actual focusing position distance of the lens, as described in an embodiment of this application.

[0070] refer to Figure 2 It includes the following steps:

[0071] S201: Triggers rebuildModel() (triggered once for every 3 new samples).

[0072] S202: deprecateCnt += 1 for all existing nodes (deprecation count increments automatically).

[0073] S203: Traverse each valid sample within the circular buffer and calculate the bucket to which it belongs based on toof: Get the bucket width getBucketSize(tof): toof≤1000mm, use 100mm; toof≤3000mm, use 200mm; toof>3000mm, use 500mm; Bucket key =(tof / bucket width)*bucket width, and merge samples according to the bucket key.

[0074] S204: Determine if the number of samples in this bucket is ≥2;

[0075] S205: If so, then node.bias = average of the biases of all samples in the bucket; node.weight = number of samples in the bucket; S207: clear deprecateCnt for nodes refreshed by new samples in this round.

[0076] S206: If not, this node will not be generated in this round;

[0077] S208: Determine if deprecateCnt is ≥50 (has not been refreshed for 50 consecutive rounds?).

[0078] S209: If so, delete the old node.

[0079] S210: Update NodeMap;

[0080] S211: Determine if the number of nodes is ≥3?

[0081] S212: If so, then isReady() = True;

[0082] S213: If not, then isReady() = false.

[0083] As described in step S104, when a focus request is received, the deviation amount corresponding to the current TOF measured object distance is determined based on the deviation mapping table, and the output end is limited for the deviation amount. The output end limited deviation amount is then superimposed on the current TOF measured object distance to obtain the TOF corrected object distance, so as to drive the camera lens.

[0084] As mentioned above, this embodiment is applied to a continuous autofocus (CAF) camera. Its core is an online self-learning deviation corrector (i.e., the deviation between the TOF and the lens). During camera operation, it continuously learns "the distance between the object distance measured by the TOF and the actual focus position of the lens at various distances of the camera lens", and when a focus request is received, it adds the learned deviation to the object distance measured by the TOF before driving the camera lens.

[0085] This embodiment employs "dual limiting at both the sampling end and the output end + interpolation credibility determination that returns to zero if the result is unreliable". In the aforementioned step S102, the sampling end limiting is used to filter the effectiveness of the focus data sample. Then, in this step S104, the output end limiting is used, and the credibility determination of adjacent nodes is embedded in the interpolation process. When the determination result is unreliable, zero deviation is returned directly (i.e., no compensation).

[0086] In one embodiment, this step specifically includes:

[0087] Step S1041: When a focus request is received, if the number of valid nodes in the deviation mapping table is less than the minimum number of nodes, the object distance measured by the current TOF is used as the corrected object distance for the TOF.

[0088] Specifically, when the focus management module initiates a focus request, it carries the TOF distance currently acquired by the TOF sensor. It calls `isReady()` to determine if the deviation corrector has basic modeling reliability, based on whether the total number of valid nodes in the NodeMap is ≥ 3 (i.e., the minimum number of nodes). If not ready (i.e., valid node count < 3), based on the principle of stability over accuracy, the system considers the current data too sparse, and any interpolation or compensation may be misleading. The system directly returns the original TOF distance, meaning the corrected distance equals the original TOF distance. The camera lens is driven by the uncorrected TOF coarse focus value, and fine focusing relies entirely on subsequent CAF (Computer-Aided Focusing).

[0089] Step S1042: If the number of valid nodes in the deviation mapping table is greater than or equal to the minimum number of nodes, calculate the theoretical barrel bond based on the object distance measured by the current TOF.

[0090] Step S1043: If the node corresponding to the bucket key is matched in the deviation mapping table, the deviation amount corresponding to the node is selected; otherwise, the distance difference between the two adjacent nodes closest to the current TOF measured object distance and the current TOF measured object distance is calculated respectively, and the reliability of the two adjacent nodes is determined according to whether the distance difference exceeds the maximum allowable reliable distance limit.

[0091] Specifically, if the total number of valid nodes in the NodeMap is ≥ 3, the theoretical bucket key is calculated based on the object distance measured by the current TOF (the specific implementation is described in step S103 above). If the node corresponding to the key value is accurately hit in the NodeMap, the bias of the node is directly taken (no interpolation is required).

[0092] If no exact match is found in the NodeMap, the nearest neighboring node to the current TOF-measured object distance is searched on both the left and right sides. Then, the distance difference d between the adjacent nodes on both sides and the TOF-measured object distance is calculated, and the reliability of the adjacent nodes on both sides is determined based on whether the distance difference exceeds the maximum allowable reliable distance limit. The maximum reliable distance limit can be calculated and determined by the following formula: d_max = min(3 × the width of the node's bucket, 500mm). The basis for reliability quantification is: if a node is too far from the target (more than 3 times its own bucket width or the absolute distance exceeds 500mm), then the "local deviation environment" represented by the node is considered to be far from the current target, and forcibly dragging the interpolation will introduce a large error risk.

[0093] Step S1044: If neither side is trustworthy, the deviation is 0; if only one side is trustworthy, the deviation of that side node is adopted; if both sides are trustworthy, the deviation is obtained by weighted fusion according to the inverse weight of the object distance domain.

[0094] Specifically, the results of determining whether adjacent nodes are trustworthy fall into the following three categories:

[0095] 1) If neither side is reliable, the current area is determined to be in a data sparse blind zone, and the bias value is returned as 0, that is, compensation for the object distance measured by the TOF is abandoned.

[0096] 2) If only one side is trusted: The deviation of the trusted node on that side can be adopted, but the deviation will then be subject to strong limiting by the output limiting. In practical applications, the deviation of that side can also be ignored (i.e., not blindly extended).

[0097] 3) If both sides are reliable, then a weighted fusion is performed based on the inverse weight of the object distance domain, using the formula w = 1 / (d + 1) (nodes closer to the target have larger weights). The final bias is calculated as: bias = (bias_left × w_left + bias_right × w_right) / (w_left + w_right). Therefore, in this step, the three scenarios yield a raw interpolation bias (or 0) that is not limited at the output end.

[0098] Step S1045: Limit the output amplitude of the deviation amount according to the calculated upper limit of the current allowable deviation amplitude, and perform quantization and rounding to obtain the TOF corrected object distance.

[0099] This step specifically includes: calculating the allowable deviation range corresponding to the current TOF measured object distance according to the preset limiting configuration; performing bidirectional clamping on the deviation amount based on the allowable deviation range to control the deviation amount within the range of the allowable deviation range, and rounding the deviation amount after bidirectional clamping according to the preset granularity.

[0100] Regardless of whether the bias obtained in step S1044 is derived from a precise hit, weighted interpolation, or zeroing, before it is finally superimposed on the object distance measured by TOF, the bias needs to be output-limited according to the calculated upper limit of the current allowable bias amplitude, and quantized and rounded according to a preset granularity to obtain the corrected TOF object distance.

[0101] Specifically, the maximum allowable deviation is calculated as follows: limit = max(tof, 1000) × maxPercent. Here, max(tof, 1000) ensures that the baseline for close-range (<1m) objects is not less than 1000mm, preventing the limit from becoming too tight and thus failing to drive. maxPercent (allowable deviation percentage) can be obtained by referring to the limit configuration table above. For example, if the TOF measured object distance ≤ 1000mm, maxPercent is 10%; if the TOF measured object distance > 1000mm, maxPercent is 20%.

[0102] Output clamping employs a two-way clamping mechanism: bias = clamp(bias, ±max(tof, 1000) * maxPercent). Output clamping ensures that even if the interpolation logic calculates a large deviation due to some extreme condition, it will force the deviation back to the physically permissible safe range for the current object distance (±10% for near distances, ±20% for far distances). Furthermore, the deviation (bias) after output clamping can be quantized and rounded to a preset granularity, aligned to an integer multiple of 10mm (i.e., rounded down or to the nearest multiple of 10mm).

[0103] The calculated "corrected object distance = TOF measured object distance + bias after output limiting and alignment" is transmitted to the camera lens's motor control module to drive the camera lens to move to that position. Subsequently, the camera can switch to the CAF fine focusing stage. Because this position is extremely close to the true focus point, the CAF convergence travel is extremely short, significantly reducing the total focusing time.

[0104] Furthermore, this embodiment also includes the following steps:

[0105] Based on whether the deviation of each node in the deviation mapping table exceeds the reasonable error band, the number of nodes with positive and negative deviation directions is counted; when the total number of valid nodes and the proportion of the direction with the largest proportion meet the preset confidence conditions, the overall bias of the camera lens is determined to be reliable; when the deviation compensation is unavailable and the overall bias is reliable, the starting direction of continuous autofocus search is determined according to the overall bias.

[0106] Specifically, even if the aforementioned specific deviation amount (bias) is unreliable due to data sparsity or exceeding limits, the positive / negative direction of the deviation (i.e., which side the lens is generally biased towards) is still a valuable piece of weak information. Therefore, in this embodiment, this weak information is extracted from the numerical compensation and given an independent reliability threshold, making it an independent decision-making basis for guiding the starting direction of CAF.

[0107] In practical applications, the reliability condition `directionReliable()` is defined as follows: The positive / negative bias direction is statistically analyzed based on whether the bias of each node exceeds a reasonable error band (e.g., 5%, minimum 50mm). A reliable direction is determined when the number of nodes is ≥ 3 and the maximum proportion of the most frequent direction is ≥ 80% (e.g., more positive directions than negative directions, and the positive direction accounts for more than or equal to 80% of all positive and negative directions) or when the number of nodes is ≥ 5 and the maximum proportion of the most frequent direction is ≥ 60%. When the correction and compensation bias is disabled, but the direction is reliable, the focus management module uses the direction given by `getLensBiasDirection(tof)` to determine the starting orientation of the camera's CAF search (i.e., which direction the lens axis should move first). Even if the specific bias compensation value is not trusted, this weak information about the lens orientation is still effectively utilized, preventing the CAF from starting blindly. Figure 3 The diagram shows the flow chart of direction signal determination and CAF starting direction decision in the focusing method based on self-learning TOF and the distance between the actual focusing position of the lens as described in the embodiments of this application.

[0108] refer to Figure 3 It includes the following steps:

[0109] S301: Traverse each node of the NodeMap.

[0110] S302: Does |node.bias| exceed the reasonable error band?

[0111] S303: If so, count by sign (count by positive bias / negative bias).

[0112] S304: If not, then it is considered that there is no obvious bias.

[0113] S305: Statistics completed.

[0114] S306: directionReliable(): Whether the following conditions are met: number of nodes ≥ 3 and the maximum proportion of directions ≥ 80%, or number of nodes ≥ 5 and the maximum proportion of directions ≥ 60%.

[0115] S307: If satisfied, getLensBiasDirection(tof) outputs the overall lens bias (positive / negative).

[0116] S308: If not satisfied, the direction is unreliable, and CAF starts the search normally.

[0117] S309: Determine if correction compensation is disabled but the direction is reliable.

[0118] S310: If so, use this direction to determine the starting orientation of the CAF search.

[0119] S311: If not, focus is dominated by mapToLens numerical compensation.

[0120] Furthermore, this embodiment may also include an online self-monitoring mechanism: after each CAF convergence, the focus management module compares the percentage deviation between the CAF convergence position and the corrected object distance predicted based on the deviation mapping table; when the deviation corrector is ready, the prediction is valid (i.e., the interpolation gives a non-zero deviation amount) and the percentage deviation exceeds a preset threshold (e.g., 10%), it is marked as a SUSPECT state to monitor online learning quality and anomalies, facilitating on-site diagnosis and subsequent strategy iteration.

[0121] Those skilled in the art will understand that systems typically save the deviation mapping table obtained through online self-learning to non-volatile memory, which can be directly loaded when the camera is powered on again, achieving a warm start and immediate use. However, in real-world camera applications, issues may arise such as environmental drift (old data may not keep up with temperature drift and scene changes), mismatch between write and read limits causing old data to interfere with current focus, version compatibility, and data format changes. Therefore, this embodiment provides a phased strategy for cold start relearning. Specifically, in the system, shouldSkipHistory() always returns true: nodes are persistently saved as usual, but historical data is not read back after the camera restarts, and relearning is performed each time. During loading, if the lens serial number in the file does not match the current one, loading is also refused. This is a clear trade-off between the temporary inaccuracy during the cold start period and avoiding all the troubles of environmental drift and version compatibility, and it reserves an extension bit for opening up historical weighted reuse after the algorithm stabilizes.

[0122] It should be noted that the specific parameters and strategies in this embodiment can be implemented in various alternative ways: the binning threshold and bin width can be replaced with other segments that match the lens depth-of-field characteristics; non-uniform binning can be replaced with uniform binning according to the diopter domain (i.e., the reciprocal of the object distance); averaging within a bin can be replaced with median, weighted average, or weighted least squares local fitting; the capacity of the annular buffer and the interval between triggering reconstruction and saving samples can be adjusted; sample merging can be replaced with an exponential moving average with a forgetting factor, or sample confidence can be introduced as a weighting factor; the percentage of allowable deviation, the magnification factor of the sampling threshold relative to the allowable deviation, the granularity of quantization, the upper limit of the maximum reliable distance, etc. in the limiting configuration table can all be adjusted according to the lens model or distance. The segment calibration and the confidence determination of adjacent nodes can be replaced by a determination based on the threshold of the number of node samples or the consistency of the deviation of adjacent nodes; the reciprocal weighted interpolation can be replaced by linear interpolation, Gaussian weighted interpolation or spline interpolation, and the interpolation domain can be switched between the object distance domain and the diopter domain; the strategy of not loading historical data after restart can be replaced by weighted reuse of historical data by temperature or time window, or reuse can only be performed when the write limit and read limit are consistent; the node number threshold, direction ratio and reasonable error band of the direction determination can be adjusted as needed, and the direction signal can also be used for other focusing decisions besides the CAF starting orientation; the persistent storage path and format of the deviation mapping relationship table, the saving trigger conditions, and the isolated storage by lens serial number on multi-lens devices can also be replaced and implemented.

[0123] The scope of protection for the focusing method based on the deviation between the self-learning TOF and the lens's true focus position described in this application is not limited to the order of steps listed in this embodiment. Any solution implemented by adding, subtracting, or replacing steps in the prior art based on the principles of this application is included within the scope of protection of this application.

[0124] Based on the above method embodiments, this application also provides a focusing system based on the deviation between the self-learning TOF and the actual focusing position distance of the lens.

[0125] like Figure 4 The diagram shown is a schematic diagram of the module structure of the focusing system based on self-learning TOF and the distance between the actual focusing position of the lens, as described in an embodiment of this application.

[0126] refer to Figure 4The focusing system 4 includes: a sample acquisition module 41, used to acquire focusing data samples; wherein the focusing data samples include a binary tuple of the distance between the TOF-measured object distance and the actual focusing position of the lens after successful focusing. A sample filtering module 42, used to perform validity filtering on the focusing data samples based on sampling end limiting, and store the validity-filtered focusing data samples in a circular buffer. A sample binning modeling processing module 43, used to generate a deviation mapping relationship table between the TOF-measured object distance and the deviation amount according to an adaptive non-uniform binning rule for the filtered focusing data samples. A focusing control module 44, used to determine the deviation amount corresponding to the current TOF-measured object distance based on the deviation mapping relationship table when a focusing request is received, perform output end limiting on the deviation amount, and superimpose the output end-limited deviation amount onto the current TOF-measured object distance to obtain the TOF corrected object distance to drive the camera lens.

[0127] In this embodiment, the specific implementation of each module in the focusing system 4 can be referred to the description of the corresponding steps in the above method embodiment, and will not be repeated here. It should be noted that the focusing system based on the deviation between the self-learning TOF and the actual focusing position distance of the lens can realize the focusing method based on the deviation between the self-learning TOF and the actual focusing position distance of the lens described in this application. However, the implementation device of the focusing method based on the deviation between the self-learning TOF and the actual focusing position distance of the lens described in this application includes, but is not limited to, the structure of the focusing system based on the deviation between the self-learning TOF and the actual focusing position distance of the lens listed in this embodiment. All structural modifications and substitutions of the prior art made according to the principles of this application are included within the protection scope of this application.

[0128] In the embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, or methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of modules / units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple modules or units 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 interfaces; the indirect coupling or communication connection of apparatuses or modules or units may be electrical, mechanical, or other forms.

[0129] The modules / units described as separate components may or may not be physically separate. The components shown as modules / units may or may not be physical modules; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules / units can be selected to achieve the objectives of the embodiments of this application, depending on actual needs. For example, the functional modules / units in the various embodiments of this application may be integrated into one processing module, or each module / unit may exist physically separately, or two or more modules / units may be integrated into one module / unit.

[0130] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0131] This application also provides an electronic device, including a memory and a processor. The memory stores a computer program, and when the processor executes the program, it implements the above-described focusing method based on the deviation between the self-learning TOF and the lens's true focus position distance.

[0132] This application also provides a computer-readable storage medium storing a computer program that, when executed by an electronic device, implements the aforementioned focusing method based on the deviation between the Time-of-Flight (TOF) sensor and the lens's true focus position distance. Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing a processor. The program can be stored in a computer-readable storage medium, which is a non-transitory medium, such as random access memory, read-only memory, flash memory, hard disk, solid-state drive, magnetic tape, floppy disk, optical disc, and any combination thereof. The aforementioned storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital video disc (DVD)), or a semiconductor medium (e.g., solid-state disk (SSD)).

[0133] The descriptions of the processes or structures corresponding to the above figures each have their own emphasis. For parts of a process or structure that are not described in detail, please refer to the relevant descriptions of other processes or structures.

[0134] The above embodiments are merely illustrative of the principles and effects of this application and are not intended to limit this application. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of this application. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in this application should still be covered by the claims of this application.

Claims

1. A focusing method based on the deviation between the self-learning Time-of-Flight (TOF) sensor and the lens's true focus position, characterized in that... include: Collect focus data samples; The focus data sample includes a pair of objects measured by TOF after successful focusing and the distance between the actual focus position of the lens. The focus data samples are filtered for validity based on the sampling end limiting, and the filtered focus data samples are stored in a circular buffer. The filtered focus data samples are used to generate a deviation mapping table between the object distance measured by TOF and the deviation amount according to the adaptive non-uniform binning rule; wherein, the deviation amount is the difference between the distance of the lens's true focus position and the object distance measured by TOF. When a focus request is received, the deviation amount corresponding to the current TOF measured object distance is determined based on the deviation mapping table, and the output is limited to the deviation amount. The output-limited deviation amount is then superimposed on the current TOF measured object distance to obtain the TOF corrected object distance, which drives the camera lens.

2. The focusing method based on the deviation between the self-learning TOF and the lens's true focusing position distance as described in claim 1, characterized in that, Also includes: Based on whether the deviation of each node in the deviation mapping table exceeds the reasonable error band, the number of nodes with positive and negative deviation directions is counted; when the total number of valid nodes and the proportion of the direction with the largest proportion meet the preset confidence conditions, the overall bias of the camera lens is determined to be reliable; when the deviation compensation is unavailable and the overall bias is reliable, the starting direction of continuous autofocus search is determined according to the overall bias.

3. The focusing method based on the deviation between the self-learning TOF and the lens's true focusing position distance as described in claim 1, characterized in that, The step of filtering the focus data samples based on sampling end limiting and storing the filtered focus data samples in a circular buffer includes: Calculate the original deviation between the object distance measured by TOF after each successful focus and the distance between the lens's actual focus position. The permissible deviation range corresponding to the object distance measured by the TOF is calculated according to the preset limiting configuration, and the sampling threshold is determined based on the permissible deviation range; If the absolute value of the original deviation is greater than the sampling threshold, the focus data sample is discarded; otherwise, the focus data sample is stored in the circular buffer.

4. The focusing method based on the deviation between the self-learning TOF and the lens's true focusing position distance as described in claim 1, characterized in that, The step of generating a deviation mapping table between the TOF-measured object distance and the deviation amount by applying an adaptive non-uniform binning rule to the filtered focus data samples includes: Whenever a preset number of focus data samples are added to the annular buffer, the width of the corresponding bucket is calculated for all the object distances measured by TOF in the annular buffer; wherein, the width of the bucket changes with the increase of the object distance measured by TOF rather than uniformly. The barrel key is calculated based on the object distance measured by each TOF and its corresponding barrel width, and all focus data samples are merged according to the barrel key. When the number of samples in the bucket is greater than or equal to the preset number, a valid node is generated, and the set of all nodes serves as a deviation mapping table between the object distance measured by TOF and the deviation amount.

5. The focusing method based on the deviation between the self-learning TOF and the lens's true focusing position distance as described in claim 4, characterized in that, Also includes: Whenever a preset number of focus data samples are added to the annular buffer, all existing nodes in the current deviation mapping table are traversed, and the discard count of each node is incremented by 1. If a new focus data sample that has been filtered for validity is stored in a bucket, the discard count of the node generated for that bucket is reset to 0. After reconstructing the deviation mapping table, if the discard count of a certain node reaches the upper limit, then the node is deleted.

6. The focusing method based on the deviation between the self-learning TOF and the lens's true focusing position distance as described in claim 1, characterized in that, When a focus request is received, the deviation amount corresponding to the current TOF-measured object distance is determined based on the deviation mapping table, and the output is limited based on this deviation amount. The output-limited deviation amount is then added to the current TOF-measured object distance to obtain the TOF-corrected object distance, which drives the camera lens. When a focus request is received, if the number of valid nodes in the deviation mapping table is less than the minimum number of nodes, the object distance measured by the current TOF is used as the corrected object distance for the TOF. If the number of valid nodes in the deviation mapping table is greater than or equal to the minimum number of nodes, calculate the theoretical barrel bond based on the object distance measured by the current TOF. If the node corresponding to the bucket key is matched in the deviation mapping table, the deviation amount corresponding to the node is selected; otherwise, the distance difference between the two adjacent nodes closest to the current TOF measured object distance and the current TOF measured object distance is calculated respectively, and the reliability of the two adjacent nodes is determined according to whether the distance difference exceeds the maximum allowable reliable distance limit. If neither side is trustworthy, the deviation is 0; if only one side is trustworthy, the deviation of that side's node is adopted; if both sides are trustworthy, the deviation is obtained by weighted fusion according to the inverse weight of the object distance domain. The deviation is limited at the output end based on the calculated upper limit of the current allowable deviation amplitude, and then quantized and rounded to obtain the TOF corrected object distance.

7. The focusing method based on the deviation between the self-learning TOF and the lens's true focusing position distance as described in claim 6, characterized in that, The step of limiting the output amplitude of the deviation based on the calculated upper limit of the current allowable deviation amplitude, and then quantizing and rounding it to obtain the TOF corrected object distance includes: The allowable deviation range corresponding to the current TOF measured object distance is calculated based on the preset limiting configuration; The deviation is bidirectionally clamped based on the allowable deviation range to control the deviation within the range of the allowable deviation range, and the bidirectionally clamped deviation is quantized and rounded according to a preset granularity.

8. A focusing system based on the deviation between a self-learning Time-of-Flight (TOF) sensor and the actual focusing position of the lens, characterized in that, The focusing system includes: The sample acquisition module is used to acquire focus data samples; wherein the focus data samples include a pair of objects measured by TOF after successful focusing and the distance between the actual focus position of the lens. The sample filtering module is used to perform validity filtering on the focus data samples based on the sampling end limiting, and store the focus data samples after validity filtering into the circular buffer. The sample binning modeling processing module is used to generate a deviation mapping table between the TOF measured object distance and the deviation amount by the filtered focus data samples according to the adaptive non-uniform binning rule; wherein, the deviation amount is the difference between the distance of the lens's true focus position and the TOF measured object distance; The focus control module is used to determine the deviation amount corresponding to the current TOF measured object distance based on the deviation mapping relationship table when a focus request is received, and to perform output limiting on the deviation amount, and to add the output-limited deviation amount to the current TOF measured object distance to obtain the TOF corrected object distance, so as to drive the camera lens.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the program, it implements the focusing method based on the deviation between the self-learning TOF and the actual focusing position distance of the lens as described in any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by an electronic device, it implements the focusing method based on the deviation between the self-learning TOF and the actual focusing position distance of the lens as described in any one of claims 1 to 7.