Camera auto-focus test method, system, electronic device, and storage medium
By acquiring the focusing results and real-time images from the camera device, and calculating the sharpness evaluation value and background-to-foreground ratio, the problem of lacking objective evaluation criteria in existing technologies is solved, thereby improving the reliability and automation of focusing results.
Patent Information
- Application Number
- CN202611330022.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2046-08-31
AI Technical Summary
Existing camera autofocus testing methods lack objective evaluation criteria independent of the device under test's own specifications, resulting in insufficient reliability and automation of autofocus results.
By acquiring the self-reported focus completion results and real-time images from the tested camera device, the pixel grayscale features inside and outside the focus window are determined, the sharpness evaluation value is calculated, and the reliability of the focus completion results is determined by combining the preset judgment benchmark and the background-foreground sharpness ratio.
It enables objective and reliable judgment of focusing results without relying on the device under test's own performance indicators or human visual inspection, thus improving the reliability and automation of camera autofocus testing.
Smart Images

Figure CN122870978B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of camera testing technology, and in particular to a camera autofocus testing method, system, electronic device, and computer-readable storage medium. Background Technology
[0002] Autofocus technology for cameras is widely used in various imaging devices such as mobile phones, computer webcams, and video conferencing terminals to obtain a clear image of the subject on the imaging plane during shooting. During the research, development, debugging, and mass production testing of imaging devices, it is necessary to confirm the focusing results of the device to verify whether the reported focus completion truly results in a clear image of the subject. Therefore, the device under test typically maintains a focus state machine in its internal firmware: during the focusing process, it collects focus evaluation parameters (such as contrast, sharpness, and phase difference), controls the movement of the focus motor accordingly, and upon convergence, provides feedback that the focus is complete, along with the motor position at the focal point and the sharpness value calculated internally by the device.
[0003] Currently, the verification of camera focus results mainly employs two methods. The first method relies on the focus determination results of the device's firmware itself. This involves directly using the focus completion event reported by the device after focusing, along with internally calculated sharpness values, motor positions, and other information, as the criteria for judging the correctness of the focus result. The second method is manual visual judgment, where testers observe the device's real-time preview and rely on their subjective experience to determine whether the subject is clearly imaged and whether the focus is successful.
[0004] Both of the aforementioned methods for verifying focus results rely on the focus assessment information provided by the device under test or the subjective observation of the tester, lacking objective evaluation criteria independent of the device's own specifications. Specifically, the device's focus completion conclusion and the focus evaluation metric it relies on both originate from the same test object, making cross-verification impossible. Furthermore, manual visual judgment is limited by the observer's subjective experience, resulting in inconsistent and variable conclusions. Consequently, existing methods struggle to objectively and reliably determine whether the device's self-reported focus completion truly corresponds to a clear image of the subject. Summary of the Invention
[0005] The main purpose of this application is to provide a camera autofocus testing method, system, electronic device, and computer-readable storage medium, aiming to solve the problem that existing autofocus result verification lacks objective evaluation criteria independent of the device under test's own indicators. It aims to objectively judge whether the autofocus completion results reported by the device are true and reliable in a way independent of the device under test, thereby improving the reliability and automation of camera autofocus testing.
[0006] To achieve the above objectives, this application provides a method for testing camera autofocus, the method comprising: Obtain the self-reported focus completion result of the camera device under test, as well as the real-time image output by the camera device under test; Determine the focus window in the real-time image, and calculate a first sharpness evaluation value based on the grayscale features of the first pixel within the focus window; The background region located outside the focus window in the real-time image is determined, and a second sharpness evaluation value is calculated based on the second pixel grayscale features within the background region; Calculate the background-to-foreground sharpness ratio of the second sharpness rating value to the first sharpness rating value; Based on the first sharpness evaluation value, the preset judgment benchmark, and the background-to-foreground sharpness ratio, the reliability of the focusing result is determined; wherein, the preset judgment benchmark includes at least one of the preset sharpness threshold, the preset sharpness grading range, and the preset scoring model.
[0007] Optionally, the step of determining whether the focusing completion result is reliable further includes: When the background-to-foreground sharpness ratio is greater than or equal to a first preset threshold, the focusing result is determined to be unreliable. When the background-to-foreground sharpness ratio is less than a first preset threshold and greater than or equal to a second preset threshold, the focus motor position information reported by the camera device under test is obtained, and the focus direction is determined according to the change of the focus motor position information relative to the focus triggering time, wherein the first preset threshold is greater than the second preset threshold. If the focusing direction is zooming out, the focusing result is determined to be unreliable; otherwise, the reliability of the focusing result is determined based on the first sharpness evaluation value and the preset judgment benchmark. When the background-to-foreground sharpness ratio is less than the second preset threshold, the reliability of the focusing result is determined based on the first sharpness evaluation value and the preset judgment benchmark.
[0008] Optionally, the step of determining whether the focusing completion result is reliable further includes: Determine the historical maximum value of the first sharpness evaluation value within this test session to obtain the session sharpness peak. The mean of the first sharpness evaluation value of the first preset number of frames before the focus triggering time is determined to obtain the sharpness baseline before focusing. Calculate the average of the first sharpness evaluation values of the second preset number of frames before and after the focus completion time to obtain the average sharpness after focus completion; Calculate the peak rank ratio of the average sharpness after focus completion to the peak sharpness of the session, and the focus gain of the average sharpness after focus completion to the baseline sharpness before focus. The sharpness stability coefficient is obtained by calculating the ratio of the standard deviation of the first sharpness evaluation value of the second preset number of frames to the mean sharpness of the focus completion. The reliability of the focusing result is determined based on the peak ranking ratio, the focus gain, and the sharpness stability coefficient.
[0009] Optionally, the step of determining whether the focusing completion result is reliable further includes: Based on the change in the focus motor position information reported by the camera device under test relative to the focus trigger time, the focus direction is determined to be zooming in, zooming out, or not moving. When the focusing direction is zooming in or zooming out, the reliability of the focusing result is determined based on the peak ranking ratio, the sharpness stability coefficient, and the focusing gain. When the focusing direction is not moved, the reliability of the focusing completion result is determined based on the peak ranking ratio.
[0010] Optionally, the step of calculating the first sharpness evaluation value based on the grayscale features of the first pixel within the focus window includes: Based on the grayscale features of the first pixel within the focusing window, a number of different dimensions of sharpness evaluation are calculated. Among the multiple different dimensions of sharpness evaluation, a primary index is determined, and the primary index is determined as the first sharpness evaluation value.
[0011] Optionally, the step of acquiring the self-reported focus completion result of the camera device under test and the real-time image output by the camera device under test includes: The focus completion result reported by the camera under test and the video frame output by the camera under test are obtained through the focus information acquisition thread and the video frame acquisition thread, respectively. Based on the same timeline, timestamps are marked on the focusing completion result and the video frame, and delay compensation corresponding to the video frame acquisition thread is applied to the timestamp of the video frame. Based on the annotation results, the real-time image corresponding to the focus completion result is obtained from the video frame.
[0012] Furthermore, to achieve the above objectives, this application also provides a camera autofocus testing system, including a host computer set independently of the camera device under test, the host computer comprising: The acquisition module is used to acquire the focusing completion result reported by the camera device under test, as well as the real-time image output by the camera device under test. The sharpness evaluation module is used to determine the focus window in the real-time image and calculate a first sharpness evaluation value based on the grayscale features of the first pixel within the focus window. The authenticity discrimination module is used to determine whether the focus completion result is credible based on the first sharpness evaluation value, the preset judgment benchmark and the background-foreground sharpness ratio; wherein, the preset judgment benchmark includes at least one of the preset sharpness threshold, the preset sharpness grading interval and the preset scoring model.
[0013] In addition, to achieve the above objectives, this application also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of the method described above.
[0014] In addition, to achieve the above objectives, this application also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described above.
[0015] The camera autofocus testing method proposed in this application specifically acquires the autofocus completion result reported by the camera device under test and its real-time image, determines the focus window in the real-time image, and calculates a first sharpness evaluation value based on the grayscale features of the first pixel within the focus window. The reliability of the autofocus completion result is then determined based on the first sharpness evaluation value, a preset judgment benchmark, and the background-to-foreground sharpness ratio. This application eliminates reliance on the camera device's own autofocus indicators and manual visual inspection by independently calculating the sharpness evaluation value of the real-time image on the host computer side. This provides an independent and objective preset judgment benchmark for determining the authenticity of the autofocus completion result. Furthermore, it can combine background-to-foreground sharpness ratio, session-level relative quantities, multi-dimensional evaluation quantities, and dual-channel time alignment to further improve the accuracy and robustness of the judgment, effectively enhancing the reliability and automation of camera autofocus testing. Attached Figure Description
[0016] Figure 1 This is a schematic diagram of the device structure of the hardware operating environment involved in the embodiments of this application; Figure 2 This is a flowchart illustrating Embodiment 1 of the camera autofocus testing method of this application; Figure 3 This is a schematic diagram of the camera autofocus test system architecture for this application.
[0017] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0018] It should be understood that the specific embodiments described herein are merely illustrative of this application and are not intended to limit this application.
[0019] like Figure 1 As shown, Figure 1 This is a schematic diagram of the electronic device structure of the hardware operating environment involved in the embodiments of this application.
[0020] The electronic devices in the embodiments of this application can be host computers, PCs, servers, smart terminals, etc.
[0021] like Figure 1 As shown, the electronic device may include: a processor 1001, such as a CPU; a network interface 1004; a user interface 1003; a memory 1005; and a communication bus 1002. The communication bus 1002 is used to enable communication between these components. The user interface 1003 may include a display screen or an input unit such as a keyboard; optionally, the user interface 1003 may also include a standard wired interface or a wireless interface. The network interface 1004 may optionally include a standard wired interface or a wireless interface (such as a Wi-Fi interface). The memory 1005 may be high-speed RAM or stable non-volatile memory, such as a disk drive. Optionally, the memory 1005 may also be a storage device independent of the aforementioned processor 1001.
[0022] Those skilled in the art will understand that Figure 1 The device structure shown does not constitute a limitation on the electronic device of this application, and may include more or fewer components than shown, or combine certain components, or have different component arrangements.
[0023] like Figure 1 As shown, the memory 1005, which serves as a computer storage medium, may include an operating system, a network communication module, a user interface module, and an executable program.
[0024] The operating system is a program that manages and controls electronic devices and software resources, and supports the operation of the network communication module, user interface module, executable program and other programs or software; the network communication module is used to manage and control the network interface 1004; the user interface module is used to manage and control the user interface 1003.
[0025] exist Figure 1 In the electronic device shown, the electronic device calls the executable program stored in the memory 1005 through the processor 1001 and performs the operations in the various embodiments of the camera autofocus test method described below.
[0026] Example 1: The camera autofocus testing method provided in this application is applicable to scenarios such as automated production line testing or R&D verification of camera modules. For ease of description, the camera device undergoing the focus test is hereinafter referred to as the device under test (DUT), and the test host that executes the method of this application independently of the DUT is hereinafter referred to as the host computer. The DUT and the host computer are connected through two independent channels: a video output channel and a focus information upload channel. The video output channel is used for the DUT to output real-time images to the host computer, and the focus information upload channel is used for the DUT to report focus status information to the host computer.
[0027] In this embodiment, the testing process first involves the host computer acquiring the self-reported focus completion result from the device under test via the focus information upload channel and acquiring the real-time image output by the device under test via the video output channel. Then, the host computer determines the focus window in the real-time image and calculates the first sharpness evaluation value based on the pixel grayscale features within the window. Finally, the credibility of the self-reported focus completion result from the device under test is determined based on the first sharpness evaluation value, the preset judgment benchmark, and the background-to-foreground sharpness ratio. Thus, the authenticity of the focus result can be objectively judged without relying on the focus index of the device under test itself or on human visual inspection.
[0028] The following provides a detailed description of the specific steps of the camera autofocus testing method according to embodiments of this application.
[0029] Reference Figure 2 Step S100: Obtain the focusing completion result reported by the camera device under test, and the real-time image output by the camera device under test. In this embodiment, after the device under test (DUT) completes the focusing action, it sends a signal or data indicating that the focusing is complete to the outside world through the focusing information upload channel. The host computer receives the signal or data and obtains the focusing completion result reported by the DUT. At the same time, the DUT continuously outputs the image to the outside world through the video output channel. The host computer captures the image at the current moment from this channel and obtains the real-time image.
[0030] Specifically, the reporting channel for the focus completion result is not limited to a specific interface. It can be any digital communication channel that can send the focus status of the device under test to the host computer, such as USB video extension channel, human-machine interface device (HID) channel, communication device (CDC) virtual serial port channel, traditional serial port, network, etc. Real-time images can be obtained through general video interfaces such as USB VideoClass or other video channels that can output real-time images.
[0031] The purpose of this step is to obtain the "focus completion result reported by the device under test" as the object to be judged, and to obtain the "real-time image" as the objective basis for independent judgment by the host computer, thereby getting rid of the dependence on a single indicator source of the device under test.
[0032] Step S200: Determine the focus window in the real-time image, and calculate the first sharpness evaluation value based on the first pixel grayscale feature within the focus window; In this embodiment, after acquiring a real-time image, the host computer first determines a region of interest in the image for sharpness evaluation as a focus window; then it extracts the grayscale features of the pixels within the focus window and calculates a value that characterizes the sharpness of the image within the window, namely the first sharpness evaluation value.
[0033] The focus window refers to the area in a real-time image used for sharpness assessment. Specifically, the focus window can be determined based on the output resolution according to a pre-stored window geometry configuration, or based on window parameters reported by the device under test via the communication channel, or determined by the host computer adaptively detecting the area where the subject is located based on the image content. The first pixel grayscale feature refers to the feature presented by the pixel grayscale within the focus window that can be used to measure image sharpness, such as pixel grayscale gradient, second derivative, grayscale difference, etc.; the first sharpness evaluation value is a numerical value that characterizes the image sharpness within the focus window, calculated based on the above grayscale features. It can be a single sharpness index or a comprehensive index synthesized from multiple sharpness indices.
[0034] The aforementioned focus window is designed to be positioned in the same place as the focus statistics window inside the device, thereby ensuring that the area in the image where the host computer evaluates sharpness is consistent with the area where the device is actually focused, so that the sharpness calculated by the host computer can truly reflect the subject that the device is focusing on.
[0035] The purpose of this step is to independently calculate the first sharpness evaluation value on the host computer side, making it an objective basis for judging the reliability of the focusing result. Since this value is calculated by the host computer on the real-time image and is independent of the index calculated internally by the device under test, it can serve as independent corroborating evidence of the results reported by the device under test.
[0036] Step S300: Determine the background area outside the focus window in the real-time image, and calculate the second sharpness evaluation value based on the second pixel grayscale features within the background area; In this embodiment, based on the focus window and the first sharpness evaluation value obtained in step S200 of embodiment 1, the host computer further determines the part outside the focus window in the real-time image as the background area, and extracts the grayscale features of the pixels in the background area. Based on this, a value representing the image sharpness of the background area is calculated, namely the second sharpness evaluation value. The meanings of the second pixel grayscale features and the second sharpness evaluation value are analogous to the first pixel grayscale features and the first sharpness evaluation value in embodiment 1, respectively, with the only difference being that the calculation area is changed from the focus window to the background area.
[0037] Specifically, there are several ways to determine the background area: In one implementation, the area remaining after subtracting the focus window from the entire real-time image is used as the background area; in another implementation, one or more fixed background sub-regions (such as sub-ROIs at the four corners of the image) can be pre-defined outside the focus window as the background area; in yet another implementation, the host computer can perform semantic segmentation of the real-time image between the subject and the background, and treat the non-subject parts as the entire background area. The calculation method for the second sharpness evaluation value is the same as that for the first sharpness evaluation value, and it can be obtained based on features such as the gradient, second derivative, and gray-level difference of the background area pixels.
[0038] The purpose of this step is to obtain a background-side sharpness evaluation value that is independent of the sharpness of the focus window and can reflect whether the focus is on the background, so as to provide a reference for subsequent identification of misfocus.
[0039] Step S400: Calculate the background-to-foreground sharpness ratio of the second sharpness evaluation value to the first sharpness evaluation value; In this embodiment, the host computer divides the second sharpness evaluation value by the first sharpness evaluation value to obtain the background-foreground sharpness ratio, that is, the background-foreground sharpness ratio = second sharpness evaluation value / first sharpness evaluation value.
[0040] The physical meaning of this ratio is: if the background area is as sharp as or even sharper than the focus window, it means the overall image is sharp. In this case, the focus may be on the background rather than the subject, resulting in a false focus where the subject is blurry but the background is sharp. Conversely, if the background is significantly blurrier than the foreground, the focus is more likely to be on the subject. It should be noted that, in addition to using a direct ratio, the background-to-foreground sharpness ratio can also be expressed as its logarithm or other monotonic transformations as an equivalent criterion, as long as the monotonic relationship that a larger ratio corresponds to a sharper background is maintained.
[0041] The purpose of this step is to convert foreground sharpness and background sharpness into a relative quantity that can be directly used for threshold comparison, thereby characterizing the rationality of the focus point in a unit-independent manner.
[0042] Step S500: Determine whether the focusing result is reliable based on the first sharpness evaluation value, the preset judgment benchmark, and the background-to-foreground sharpness ratio; wherein, the preset judgment benchmark includes at least one of the following: a preset sharpness threshold, a preset sharpness grading range, and a preset scoring model. In this embodiment, after obtaining the first sharpness evaluation value and the background-foreground sharpness ratio, the host computer comprehensively judges whether the focusing completion result reported by the device under test is true and valid based on the first sharpness evaluation value, the preset judgment benchmark and the background-foreground sharpness ratio, and outputs the judgment conclusion.
[0043] Specifically, this application determines whether the focusing completion result is reliable by comprehensively evaluating the first sharpness evaluation value, the preset judgment benchmark, and the background-to-foreground sharpness ratio. The preset judgment benchmark is a pre-set standard used to evaluate the reliability of the focusing completion result, including at least one of the following: preset sharpness threshold, preset sharpness grading interval, and preset scoring model.
[0044] The preset sharpness threshold refers to a pre-set critical value for direct comparison with the first sharpness evaluation value; when the first sharpness evaluation value is not lower than the preset sharpness threshold, the focusing result is determined to be reliable, otherwise it is determined to be unreliable.
[0045] The preset sharpness grading interval refers to a set of pre-defined sharpness value intervals, each interval corresponding to a confidence level. During the judgment, the first sharpness evaluation value is matched with the grading interval, and the confidence level corresponding to the interval falls into is used as the judgment conclusion, such as qualified, barely qualified, questionable, unqualified, or background misfocus.
[0046] The preset scoring model refers to a pre-established evaluation model used to output a reliable conclusion on the focus completion result. In one embodiment, the preset scoring model uses the first sharpness evaluation value as the sole input feature. The model internally includes: a feature normalization layer, which normalizes the first sharpness evaluation value to a preset numerical range; a fully connected mapping layer, which maps the normalized feature values to the latent space representation corresponding to each confidence level; and a softmax output layer, which outputs the probability distribution corresponding to each confidence level and uses the level with the highest probability as the judgment conclusion. The model parameters of the preset scoring model are obtained offline through training on multiple sets of sample images labeled with real focus results. During training, the first sharpness evaluation value and its corresponding real confidence level constitute the supervision signal, and the cross-entropy loss function is used to optimize the model parameters. During judgment, the first sharpness evaluation value is input into the preset scoring model, and the model outputs the corresponding confidence conclusion.
[0047] It should be noted that the above three preset judgment criteria can be used individually or in combination; the corresponding credible conclusions can be either binary conclusions of "credible / uncredible" or multi-level conclusions such as "qualified / barely qualified / doubtful / unqualified / background misfocus".
[0048] The purpose of this step is to provide an objective conclusion on the authenticity of the focusing result, so that testers or automated systems can directly judge whether the focusing function of the device under test meets the standard based on the conclusion.
[0049] This embodiment independently calculates the first sharpness evaluation value and the background-foreground sharpness ratio on the host computer side, and uses the first sharpness evaluation value, the preset judgment benchmark, and the background-foreground sharpness ratio as the basis to determine whether the focus completion result reported by the device under test is credible. This achieves the determination of the authenticity of the focus result without relying on the focus index of the device under test or on human visual inspection.
[0050] Example 2: Based on the above embodiments, another embodiment of the camera autofocus testing method of this application is proposed. The difference between this embodiment and the above embodiments is that, when determining whether the focus completion result is reliable based on the first sharpness evaluation value and the background-foreground sharpness ratio, the movement direction of the focus motor reported by the device under test is further combined to introduce motor direction discrimination in order to identify false completions due to reverse motor movement.
[0051] Step a: Determine whether the focusing result is reliable based on the first sharpness evaluation value, the preset judgment benchmark, and the background-to-foreground sharpness ratio.
[0052] In this embodiment, the host computer combines the first sharpness evaluation value, the preset judgment benchmark, and the background-foreground sharpness ratio to determine whether the focusing result is reliable according to the following rules. For ease of explanation, the first preset threshold is set to be greater than the second preset threshold. Both are empirical values that can be calibrated based on actual test scenarios (in specific implementation, values greater than 1 and less than 1 can be used as illustrations, for example, the first preset threshold is 1.0 and the second preset threshold is 0.5, and the actual values are based on the distribution of the measured samples).
[0053] Specifically, the determination process includes the following branches: First, when the background-to-foreground sharpness ratio is greater than or equal to the first preset threshold, the focus completion result is deemed unreliable. At this point, the background sharpness has reached or even exceeded the foreground sharpness, indicating that the focus is likely on the background, which is a typical case of background misfocusing. Even if the first sharpness evaluation value itself is not low, it should still be judged as unreliable.
[0054] Secondly, when the background-to-foreground sharpness ratio is less than a first preset threshold and greater than or equal to a second preset threshold, the host computer further acquires the focusing motor position information reported by the device under test, and determines the focusing direction based on the change of the focusing motor position information relative to the focusing trigger time. Specifically, the focusing motor position information can be acquired through the same focusing information upload path as the focusing completion result; the focusing direction is determined based on the increase or decrease of the motor position relative to the trigger time, for example, an increase in the motor position corresponds to zooming in, and a decrease corresponds to zooming out. If the determined focusing direction is zooming out, the focusing completion result is determined to be unreliable; otherwise, the reliability of the focusing completion result is determined based on the first sharpness evaluation value (i.e., reverting to the determination logic of step S300 in Embodiment 1). It should be noted that, in addition to zooming in and zooming out, the focusing direction may also be basically stationary, and the complete three state classifications are explained together in Embodiment 3 combined with session-level relative quantities.
[0055] Third, when the background-to-foreground sharpness ratio is less than the second preset threshold, the background sharpness is significantly lower than the foreground, and the focus is more likely to fall on the subject. In this case, the reliability of the focusing result is directly determined based on the first sharpness evaluation value and the preset judgment benchmark.
[0056] It should be noted that the "unreliable / reliable" determination mentioned above in this embodiment can be performed using a priority decision-making method: each item is judged in sequence according to a preset priority, and a conclusion is given upon a hit, with background misfocus judgment having the highest priority. In addition, the above conclusion can be further subdivided into five levels: qualified, barely qualified, questionable, unqualified, and background misfocus; under the background misfocus branch, it is uniformly judged as "background misfocus", and the other branches give corresponding grades based on the ratio of foreground sharpness to background foreground sharpness.
[0057] The purpose of this step is to provide a comprehensive and reliable conclusion that integrates foreground and background sharpness, supplemented by the direction of focus motor movement, so that misfocusing, especially false completion caused by background misfocusing and reverse motor movement, can be effectively identified.
[0058] This embodiment, by further combining the movement direction of the focusing motor with path determination based on embodiment 1, achieves effective identification of false completion of motor reverse movement, while retaining the ability to distinguish background misfocusing by comparing the sharpness of the background and foreground.
[0059] Example 3: Based on the above embodiments, another embodiment of the camera autofocus testing method of this application is proposed. The difference between this embodiment and the above embodiments is that, when determining whether the focus completion result is reliable, it no longer relies solely on the first sharpness evaluation value of a single frame or foreground-background comparison, but further introduces multiple relative quantities within the current test session—session sharpness peak, sharpness baseline before focusing, average sharpness after focusing, peak ranking ratio, focusing gain, and sharpness stability coefficient—and makes a determination based on the path of the focusing motor's movement direction. The steps of acquiring real-time images, determining the focus window, and calculating the first sharpness evaluation value in Embodiment 1, and the sharpness calculation of the focus window and background area in Embodiment 2, are also applicable in this embodiment. The following focuses on a detailed explanation of the calculation of session-level relative quantities and the path determination.
[0060] Step d: Determine the historical maximum value of the first sharpness evaluation value within the current test session to obtain the session sharpness peak; determine the average value of the first sharpness evaluation value of the first preset number of frames before the focus triggering time to obtain the sharpness baseline before focus; calculate the average value of the first sharpness evaluation value of the second preset number of frames before and after the focus completion time to obtain the average sharpness after focus completion. In this embodiment, during the continuous testing of the device under test, the host computer calculates the first sharpness evaluation value frame by frame (the calculation method is the same as step S200 in embodiment 1), and performs session-level maintenance on these frame-by-frame values to obtain three basic statistics.
[0061] Specifically, the peak sharpness of the session is the historical maximum value of the first sharpness evaluation value since the start of this test session, updated with each frame; the pre-focus sharpness baseline is the average of the first sharpness evaluation values of a first preset number of frames (e.g., the 5 frames before triggering) before the focus trigger moment, used to characterize the overall sharpness level before focus initiation; the average sharpness after focus completion is the average of the first sharpness evaluation values of a second preset number of frames (e.g., a small window near the completion moment) before and after the focus completion moment, used to characterize the stable sharpness level after focus completion. It should be noted that the specific values of the first and second preset number of frames are calibrable empirical parameters that can be adjusted according to the frame rate and focus duration; in another implementation, the pre-focus sharpness baseline can also be characterized by an exponentially weighted average or the lowest value over a period of time, and the average sharpness after focus completion can also be represented by the median to suppress interference from outlier frames. Furthermore, when the peak value has not yet been reliably established at the beginning of the session, the device under test can be guided to complete one focus attempt to accumulate statistics and avoid misjudgments caused by early frames.
[0062] It should be noted that when maintaining session history, in addition to updating the session sharpness peak with each frame and latching the pre-focus sharpness baseline when a focus trigger event is received, a rolling index buffer of the most recent time (e.g., 4 seconds) can also be maintained, and expired frames can be removed by rolling out the time window, thereby providing a smoother and more timely statistical basis for the calculation of relative quantities.
[0063] The purpose of this step is to expand from single-frame sharpness to multiple statistics at the session level, providing a benchmark for subsequent relative quantity calculations.
[0064] Step e: Calculate the peak ranking ratio of the average sharpness after focus completion to the peak sharpness of the session, and the focus gain of the average sharpness after focus completion to the sharpness baseline before focus; calculate the ratio of the standard deviation of the first sharpness evaluation value of the second preset number of frames to the average sharpness after focus completion, and obtain the sharpness stability coefficient. In this embodiment, the host computer further calculates three relative quantities based on the three basic statistics obtained in step d.
[0065] Specifically, the peak ranking ratio = average sharpness after focus completion / peak sharpness of the session. The closer this ratio is to 1, the closer the sharpness at the time of focus completion is to the historical best of this session, and the more ideal the focus point. Focus gain = average sharpness after focus completion / baseline sharpness before focus. A ratio greater than 1 indicates that the image is sharper after focus than before, meaning that the focus was effective. Sharpness stability coefficient = standard deviation of the first sharpness evaluation value of the second preset number of frames / average sharpness after focus completion, i.e., the coefficient of variation. The smaller this coefficient, the more stable the image quality is near the time of focus completion. It should be noted that the above relative quantities are all given in the form of ratios, and therefore are unit-independent, allowing direct comparison across devices and resolutions. In another implementation, the logarithm or other monotonic transformations can also be used as equivalent discriminants.
[0066] The purpose of this step is to convert absolute sharpness into a relative quantity that can be compared horizontally, so that the judgment no longer depends on a fixed sharpness measure.
[0067] Step f: Determine whether the focusing result is reliable based on the peak ranking ratio, the focus gain, and the sharpness stability coefficient. In this embodiment, the host computer determines whether the focusing result is reliable by combining the above three relative quantities, and further combines the movement direction of the focusing motor for path processing.
[0068] Specifically, the host computer first determines the focusing direction as zooming in, zooming out, or not moving based on the change in the focusing motor position information reported by the device under test relative to the focusing trigger time (the acquisition of the focusing motor position information and the determination of the focusing trigger time are the same as in Example 2; here, a complete classification of the three states is given: the motor position increases relative to the trigger time as zooming in, decreases as zooming out, and remains basically unchanged as not moving).
[0069] The following path division rules are then used for determination: When the focusing direction is zooming in or zooming out (i.e. the motor is actually moving), the focusing result is determined by a combination of the peak ranking ratio, the sharpness stability coefficient, and the focus gain. For example, if the peak ranking ratio is not lower than the indicated threshold (e.g., 0.8), the focus gain is not lower than the indicated threshold (e.g., 1.2), and the sharpness stability coefficient is not higher than the indicated threshold (e.g., 0.2), the focusing result is considered reliable; otherwise, it is considered unreliable (the above thresholds are all indicated values and are based on the actual sample distribution).
[0070] When the focus direction is not moved, the difference between focus gain and stability coefficient decreases because the motor is not moving. At this time, the judgment is based solely on the peak ranking ratio: if the peak ranking ratio is not lower than the indicated threshold (e.g., 0.8), the judgment is reliable; otherwise, the judgment is unreliable.
[0071] Furthermore, based on the focusing motor position information, the host computer can calculate the percentage of the landing point's position within the motor's movable stroke and determine whether the landing point is close to the stroke endpoint (near focal end or far focal end). When the landing point is close to the stroke endpoint, this is noted in the judgment conclusion as supporting evidence, indicating that the algorithm may be forced to stop at the extreme position and the scene may not actually be able to focus. The purpose of this processing is to use the motor stroke position as supplementary supporting evidence to make the judgment conclusion more rigorous in terms of physical feasibility, and to avoid misjudging "forced to stop at the extreme position" as normal focusing completion.
[0072] It should be noted that the "credible / unreliable" conclusions of the above branches can be further subdivided into five levels: acceptable, barely acceptable, questionable, unacceptable, and background misfocus. Specifically, for paths where movement is completed, the corresponding classification can be given by combining the peak ranking ratio, focus gain, and sharpness stability coefficient (e.g., if the peak ranking ratio is not lower than the good threshold and the focus gain is not lower than the good improvement threshold, it is considered acceptable; if both are lower than the failure threshold, it is considered unacceptable; in the middle, it is considered barely acceptable; otherwise, it is considered questionable). For paths where movement is not completed, the classification can be given by combining the peak ranking ratio and the background-foreground sharpness ratio (e.g., if the peak ranking ratio is not lower than the good threshold and the background-foreground sharpness ratio is less than 1, it is considered acceptable; if the peak ranking ratio is lower than the failure threshold, it is considered unacceptable; in the middle, it is considered barely acceptable; otherwise, it is considered questionable). The above classification thresholds are all illustrative values and are based on the actual measured sample distribution.
[0073] The purpose of this step is to provide a credible conclusion that integrates session-level relative quantities and motor movement direction, so as to distinguish between focus improvement and stable results, and focus without improvement or image quality jitter.
[0074] This embodiment introduces session-level relative quantities and motor direction path determination based on the above embodiments, realizing the quantitative discrimination of the degree of dynamic improvement in the focusing process. Since the peak ranking ratio, focus gain, and sharpness stability coefficient are all relative quantities and are unit-independent, they can consistently characterize whether the focus is sharper than before, whether session-optimal has been achieved, and whether the result is stable across devices. At the same time, by switching the criterion set based on whether the motor moves, the misuse of failure gain and stability coefficient is avoided when there is no movement, further improving the discrimination accuracy and robustness of camera autofocus testing in complex scenarios.
[0075] Example 4: Based on the above embodiments, another embodiment of the camera autofocus testing method of this application is proposed. The difference between this embodiment and the above embodiments is that, in the step of "calculating the first sharpness evaluation value based on the grayscale features of the first pixel within the focus window," it is no longer limited to a single sharpness index. Instead, multiple sharpness evaluation quantities of different dimensions are calculated first, and then the main index is determined as the first sharpness evaluation value. Furthermore, the robustness of the evaluation can be improved through cross-verification of other indicators and brightness anomaly gating. The steps of acquiring real-time images and determining the focus window in Embodiment 1 are also applicable in this embodiment. The following focuses on a detailed explanation of the determination of multi-dimensional sharpness evaluation quantities and the main index.
[0076] Step g: Calculate multiple different dimensions of sharpness evaluation based on the grayscale features of the first pixel within the focusing window; In this embodiment, based on the focus window determined in step S200 of embodiment 1, the host computer extracts the grayscale features of the pixels in the window (i.e., the grayscale features of the first pixel) and calculates multiple different dimensions of sharpness evaluation values accordingly, thus characterizing the sharpness of the image in the focus window from multiple perspectives.
[0077] Specifically, multiple dimensions of sharpness evaluation metrics can include one or more of the following: Laplacian response variance based on second-order derivatives, which is most sensitive to defocus blur and can be used as the default primary indicator; Tenengrad evaluation metrics based on first-order gradients (characterized by the sum of squares of Sobel gradient magnitudes); Brenner gray-level difference evaluation metrics (characterized by the sum of squares of gray-level differences between adjacent pixels); Canny edge density evaluation metrics (characterized by the proportion of detected edge pixels); frequency domain evaluation metrics (such as taking the proportion of high-frequency energy after performing discrete cosine transform or Fourier transform on the window image); and statistical evaluation metrics such as gray-level variance or image entropy. It should be noted that the above evaluation metrics are only examples. In another implementation, other gray-level features that can reflect the image sharpness can also be used. The specific types and numbers of evaluation metrics can be selected according to the scenario. The evaluation metrics are independent or weakly correlated with each other for subsequent cross-verification.
[0078] The purpose of this step is to expand from a single indicator to a multi-dimensional clarity evaluation metric, so that clarity assessment has a multi-perspective and cross-verifiable basis.
[0079] Step h: Determine a primary index from the multiple different dimensions of sharpness evaluation, and set the primary index as the first sharpness evaluation value; In this embodiment, after obtaining the clarity evaluation values of multiple dimensions, the host computer determines a main indicator and directly uses the value of the main indicator as the first clarity evaluation value for use in the judgment stage of Embodiment 1 and subsequent embodiments.
[0080] Specifically, there are several ways to determine the primary indicator: in one implementation, the Laplacian response variance, which is most sensitive to defocus and noise and has the highest discriminative power, is selected as the fixed primary indicator; in another implementation, the primary indicator can be obtained by weighting multiple evaluation quantities according to their sensitivity; in yet another implementation, the system can adaptively select the evaluation quantity with the highest discriminative power as the primary indicator based on the texture features of the current scene. Furthermore, in addition to determining the primary indicator, other evaluation dimensions can be used for cross-verification: if the trends of the other evaluation quantities are consistent with the primary indicator, the credibility of the first sharpness evaluation value is enhanced; if a significant deviation occurs (e.g., the primary indicator shows sharpness but the edge density evaluation value drops sharply), the frame can be marked as questionable, downweighted, or trigger a review. In addition, a brightness anomaly gating can be introduced: when the grayscale mean or grayscale standard deviation of the focus window falls into the abnormal range corresponding to overexposure, underexposure, or occlusion, it indicates that the sharpness evaluation of the current frame is unreliable. In this case, the first sharpness evaluation value of the frame is downweighted or eliminated to avoid extreme lighting interference in the evaluation.
[0081] It should be noted that the aforementioned comprehensive evaluation method, which uses the primary indicator to determine the grade and other indicators for cross-verification, is only one possible form of multi-indicator comprehensive evaluation. In another implementation, each clarity metric can be normalized separately and then weighted and summed according to preset weights to obtain a single comprehensive clarity metric, from which the aforementioned relative quantities and grades can be derived; alternatively, each clarity metric can be independently graded, and the final grade can be determined by majority vote. The aforementioned two methods, "primary indicator plus cross-verification" and "multi-indicator weighted fusion or majority vote," can be chosen individually or used in combination, and both fall within the scope of protection of this scheme.
[0082] The purpose of this step is to provide a primary sharpness evaluation value that can be used for unified judgment based on the main indicator, while using cross-validation and brightness gating to suppress misjudgment of a single indicator and interference from abnormal frames, thereby improving the robustness of sharpness evaluation.
[0083] This embodiment introduces a multi-dimensional sharpness evaluation metric and a main index mechanism based on Embodiment 1, achieving multi-perspective and robust sharpness assessment. Since the main index provides a unified judgment benchmark and other indicators can be cross-verified, it can maintain stable judgment even when a certain indicator is affected by noise or special texture interference. Simultaneously, the brightness anomaly gating excludes unreliable frames such as overexposed, underexposed, and occluded frames from the evaluation, further reducing the misjudgment rate under abnormal lighting conditions. This makes the sharpness evaluation value independently calculated by the host computer more reliable as an objective basis for judging the authenticity of the focus completion result.
[0084] Example 5: Based on the above embodiments, another embodiment of the camera autofocus testing method of this application is proposed. The difference between this embodiment and the above embodiments is that, in the step of "acquiring the autofocus completion result reported by the camera device under test and the real-time image output by the camera device under test," dual-channel parallel acquisition of focus information and video frame acquisition is adopted. Time alignment is achieved by uniformly labeling the two data streams with timestamps and applying delay compensation to the video frames, thereby ensuring that the acquired real-time image strictly corresponds to the self-reported autofocus completion result. The steps of focus window determination, sharpness calculation, and judgment in Embodiment 1 are also applicable in this embodiment. The following focuses on a detailed explanation of dual-channel acquisition and time alignment.
[0085] Step i: The focus completion result reported by the camera under test and the video frame output by the camera under test are obtained by the focus information acquisition thread and the video frame acquisition thread, respectively. In this embodiment, the host computer starts two independent acquisition threads: the focus information acquisition thread continuously monitors and acquires the focus completion result and related focus status (such as the focus motor position information described in Embodiment 2) reported by the device under test via a focus information upload path (such as a USB expansion unit, HID, CDC virtual serial port, traditional serial port, or network); the video frame acquisition thread continuously captures video frames output by the device under test via a video output path (such as a USB Video Class video interface). The two threads work in parallel without blocking each other, accumulating event streams and image streams respectively.
[0086] Specifically, there are several ways to implement dual-channel parallel acquisition: one implementation uses two operating system threads to drive the reading of the two channels respectively; another implementation can use coroutines, interrupt service routines, or independent process communication (IPC) to achieve concurrent acquisition of the two channels; yet another implementation, if the device under test is connected to the host computer through two physical channels (such as one HID channel reporting focus events and one UVC channel outputting video), then the two data streams are already parallelized at the hardware level. It should be noted that the physical channels on which the two acquisitions rely are not limited to specific interfaces, as long as they can respectively send the focus information and video image of the device under test to the host computer.
[0087] Specifically, the focus information acquisition and parsing module reads the focus information uploaded by the device line by line according to the agreed format, and parses it into a unified triplet of "host timestamp, event type, and numerical field" for use in subsequent steps. It should be noted that the content reported by the device through the focus information upload channel can be in text format or binary structured fields. After the focus information acquisition and parsing module of the host computer parses it into the above unified triplet according to the agreed format, it can be connected to the same discrimination process. By using the same discrimination method and replacing the acquisition and parsing front end, it can be adapted to any of the above communication interfaces.
[0088] The purpose of this step is to obtain two raw data streams—the focus event and the video footage—through two independent and non-interfering channels, laying the foundation for subsequent time alignment.
[0089] Step j: Based on the same timeline, timestamps are added to the focusing completion result and the video frame, and delay compensation corresponding to the video frame acquisition thread is applied to the timestamp of the video frame. In this embodiment, the host computer uses its local clock as a unified timeline to mark an event timestamp for each focusing completion result received by the focusing information acquisition thread, and marks a frame timestamp for each video frame captured by the video frame acquisition thread. Because there is an inherent delay in the video frame's journey from imaging by the device under test to reaching the host computer via the acquisition and transmission links (including sensor readout, encoding, transmission, buffering, and decoding), the time when the video frame is received by the host computer is often later than its actual imaging time. Therefore, the host computer further applies delay compensation corresponding to the video frame acquisition thread to the timestamp of the video frame, resetting the frame timestamp back to the actual imaging time, thus placing the two timestamps on the same comparable time base.
[0090] Specifically, the value of delay compensation can be determined in several ways: In one implementation, a fixed compensation value calibrated at the factory is used, that is, the end-to-end delay is measured once under known hardware and link conditions and then fixed for use; in another implementation, a dynamic measurement method is used, which calculates the time difference between the video frame and the host computer in real time and updates the compensation value accordingly; in yet another implementation, the compensation value can also be calculated based on the model parameters of each link in the acquisition pipeline (exposure, transmission, decoding). It should be noted that the focus information acquisition link usually has a small delay. This embodiment only applies delay compensation to the video frame. However, if there is also a significant delay in the focus information link during implementation, the timestamp can also be compensated accordingly to further improve the alignment accuracy.
[0091] The purpose of this step is to eliminate the time misalignment caused by video link delay, so that the timestamp of the focus completion event can accurately correspond to the actual video frame of the image.
[0092] Step k: Based on the annotation results, obtain the real-time image corresponding to the focus completion result from the video frame.
[0093] In this embodiment, after the host computer obtains two timestamps with a unified time reference and compensation and alignment in the above steps, it searches for the corresponding video frame in the video frame sequence based on the event timestamp carried by the focus completion result, and uses the video frame as the real-time image corresponding to the focus completion result, and delivers it to step S200 of embodiment 1 and subsequent embodiments for focus window determination and sharpness evaluation.
[0094] Specifically, there are several ways to obtain the corresponding frame: In one implementation, the video frame closest to the event timestamp is selected based on the closest timestamp matching; in another implementation, the video frame can be replayed within a short buffer window near the event timestamp, and the most representative frame can be selected by combining a delayed windowing strategy after focusing (such as delaying windowing by several milliseconds after the event occurs); in yet another implementation, if both channels have hardware timestamps (such as the display timestamp PTS of the video frame), then precise matching can be performed directly based on the hardware time. It should be noted that the windowing time can be flexibly set in conjunction with the session-level statistics described in Embodiments 2 and 3, for example, delaying windowing by a short period of time (such as 0.3 seconds) after the focusing completion event occurs to wait for the image quality to stabilize.
[0095] The purpose of this step is to accurately map the self-reported focus completion result to the real-time image of the actual image, thereby ensuring that the image used for subsequent sharpness assessment is the image at the moment of focus completion, and avoiding misjudgment.
[0096] This embodiment, by introducing dual-thread parallel acquisition, timestamp alignment, and delay compensation mechanisms based on Embodiment 1, achieves precise correspondence between focusing events and image frames. Because the two data streams are unified to the same timeline and targeted delay compensation is applied to the video frames, the self-reported focusing completion result can be mapped to the video frame at the actual imaging moment, avoiding misjudgment of the pre-focusing image due to video link delay. Simultaneously, the non-blocking dual-thread acquisition structure ensures the integrity and real-time nature of events and images, ensuring that the real-time image relied upon for independent sharpness assessment on the host computer always strictly corresponds to the focusing completion result, further improving the accuracy of camera autofocus testing.
[0097] This application also provides a camera autofocus testing system. (See reference...) Figure 3 The camera autofocus testing system includes a host computer set independently of the device under test. The host computer includes a data acquisition module 10, a sharpness evaluation module 20, and a authenticity discrimination module 30. The three functional modules respectively undertake the actions defined in steps S100, S200, and S300 of the method in Embodiment 1.
[0098] Specifically, the camera device under test is connected to the host computer through two independent channels: a video output channel and a focus information upload channel. The video output channel is used by the device under test to output real-time images to the host computer, while the focus information upload channel is used by the device under test to report focus status information to the host computer.
[0099] The acquisition module is used to acquire the self-reported focus completion result of the device under test and the real-time image output by the device under test, corresponding to step S100 in Embodiment 1. In one implementation, the acquisition module can be composed of two parallel acquisition units: a focus information acquisition thread and a video frame acquisition thread, or it can be composed of a single-channel alternating acquisition or interrupt-triggered acquisition unit. The sharpness evaluation module is used to determine the focus window in the real-time image and calculate the first sharpness evaluation value based on the grayscale features of the first pixel within the focus window, corresponding to step S200 in Embodiment 1. In one implementation, the sharpness evaluation module can further include a multi-dimensional evaluation quantity calculation submodule and a main index selection submodule, and can also include a background area sharpness calculation submodule. The authenticity discrimination module is used to determine whether the focus completion result is credible based on the first sharpness evaluation value and a preset judgment benchmark, corresponding to step S300 in Embodiment 1. In one implementation, the authenticity discrimination module can further include a background-to-foreground ratio discrimination submodule, a session-level relative quantity discrimination submodule, and corresponding sub-path judgment logic.
[0100] It should be noted that the above division of the three functional modules is only a logical division. In actual deployment, each module can be deployed within the same host computer process or distributed across different systems. In one implementation, the host computer itself is a general-purpose computer running the methods of the embodiments of this application. In another implementation, the host computer can also be a hardware box or test fixture specifically for focus testing, which internally implements the above three modules in software. The purpose of this system is to solidify the method flow of independently calculating sharpness on the host computer side and judging the authenticity of the focus completion result accordingly into a reusable test device.
[0101] This embodiment also provides an electronic device, including a processor and a memory, wherein the memory stores a computer program, and when the computer program is executed by the processor, the electronic device performs the camera autofocus test method as described in any of the above embodiments.
[0102] The processor can be implemented in various ways: in one implementation, the processor is a general-purpose central processing unit (CPU); in another, the processor can be a microcontroller (MCU), digital signal processor (DSP), system-on-a-chip (SoC), graphics processing unit (GPU), neural network processor (NPU), or application-specific integrated circuit (ASIC), etc.; the memory can be random access memory (RAM), read-only memory (ROM), flash memory, or any combination thereof. In yet another implementation, the electronic device itself is the host computer described in the above embodiments, and the acquisition, evaluation, and discrimination functions required for focus testing are all implemented by the processor in the electronic device executing the program in the memory. The purpose of this electronic device is to carry out the method of this solution on a standardized hardware carrier, so that focus testing can be stably run on production line industrial control computers, testing instruments, or embedded terminals.
[0103] This embodiment also provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it implements the camera autofocus testing method as described in any of the above embodiments.
[0104] Specifically, the computer-readable storage medium can be implemented in various forms: in one implementation, it is a removable medium such as an optical disc, USB flash drive, or secure digital card (SD card); in another implementation, it can be a fixed storage medium such as a solid-state drive (SSD), an embedded multimedia card (eMMC), or non-volatile memory (such as EEPROM, flash memory chips); in yet another implementation, the computer program can also be stored on the network side or in cloud storage (such as network attached storage, NAS), and remotely invoked and executed by a processor. It should be noted that the above storage media are merely examples; any medium capable of storing a computer program and being read and executed by a processor to implement the method of this solution is within the scope of protection of this application. The purpose of this medium is to enable the method of this solution to be widely deployed and reused in a distributable and reusable form.
[0105] Furthermore, this solution outputs the results and basis for focus authenticity judgment in a machine-readable structured format to support automated regression testing. Specifically, each judgment result can be written to a data log file in real time (the log file includes fields and values such as peak ranking ratio, focus gain, sharpness stability coefficient, background-foreground sharpness ratio, focus direction, motor displacement, and landing point travel position), printed to the console, and displayed in a graded color-coded overlay on the real-time preview screen (e.g., green for qualified, yellow for barely qualified, orange for questionable, magenta for background misfocus, and red for unqualified). The system also supports saving the current image along with all the overlaid judgment information as an image during the preview process with one click, for test evidence and manual review. Since the judgment conclusion is quantifiable and machine-readable, the same set of test scenarios can be batch- and automatically performed on different firmware versions, and the qualified percentage and distribution of each level can be automatically calculated. This allows for a horizontal comparison of the focus quality of different firmware versions in an objective and reproducible manner, achieving automated regression testing.
[0106] In this embodiment, the various thresholds involved in the aforementioned embodiments (such as the first preset threshold and the second preset threshold in Embodiment 2, and the peak ranking ratio threshold, focus gain threshold, and sharpness stability coefficient threshold in Embodiment 3) and various quantitative parameters (such as the first preset number of frames and the second preset number of frames in Embodiment 3) are all calibrable empirical parameters, and their specific values are determined based on the distribution of measured samples of the device under test. Among them, the preset sharpness threshold, which is one of the preset judgment criteria in Embodiment 1, is also a calibrable empirical parameter. Its specific value is determined based on the distribution of qualified and unqualified samples on the first sharpness evaluation value, and is independent of the various thresholds in Embodiments 2 and 3, and can be calibrated separately.
[0107] Specifically, there are several calibration methods: In one implementation, a sample set is first constructed using a batch of sample devices with known focusing results. The numerical distribution of focusing qualified and unqualified samples in each relative quantity is statistically analyzed, and the boundary points of each threshold are determined based on the overlapping areas of the distributions. In another implementation, testers can iteratively fine-tune the thresholds based on experience and combined with on-site trial results. It should be noted that since this embodiment extensively uses relative quantities such as background-to-foreground sharpness ratio, peak ranking ratio, focus gain, and sharpness stability coefficient as the discrimination criteria, these relative quantities are all dimensionless ratios. Therefore, the calibration results are transferable between different resolutions, different photosensitive devices, and even different camera models. There is no need to redesign the absolute threshold for each model, which is precisely the implementation convenience brought about by the unit independence of this solution. The purpose of this explanation is to enable those skilled in the art to reproduce the threshold setting according to the methodology disclosed in this solution without relying on a fixed value.
[0108] In this embodiment, for the technical features disclosed in the foregoing embodiments, any equivalent substitutions that use substantially the same means, achieve substantially the same function, and reach substantially the same effect, and that could be conceived by a person skilled in the art without inventive effort before the application date, are all within the scope of protection of this solution. For example: replacing the ratio of foreground sharpness in the focus window with a relative quantity such as logarithmic or normalized monotonic transformations; replacing sharpness evaluation from a single main indicator to a multi-indicator weighted fusion or majority voting; replacing dual-channel acquisition from thread parallelism to coroutines, interrupts, or physical dual-channel; replacing system modules from software logic division to hardware logic circuit implementation—all of the above equivalent transformations do not depart from the inventive concept of this solution.
[0109] The camera autofocus testing method, system, equipment, and computer-readable storage medium provided in this application can be practically applied in at least one of the following industrial scenarios: First, automated autofocus testing on camera module mass production lines, quickly determining the authenticity and validity of the self-reported autofocus completion results of each module upon its production line completion; Second, R&D verification and performance sampling of camera modules, evaluating the stability of the autofocus algorithm under different lighting and texture scenarios; Third, factory quality inspection of terminal devices (such as video conferencing terminals, mobile phones, and computer cameras), verifying whether the autofocus function of the entire device meets the standards; Fourth, automated regression testing and quality traceability, using the credible conclusions and process records output by this solution in a structured manner to continuously compare the autofocus performance after firmware version iterations. Because this solution uses independent image sharpness as the criterion and is easy to deploy in software or embedded form, it can be directly embedded into existing production lines and quality inspection processes, possessing clear industrial applicability.
[0110] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.
[0111] The sequence numbers of the embodiments in this application are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0112] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods described in the various embodiments of this application.
Claims
1. A method for testing automatic focus of a camera, characterized in that, The camera autofocus testing method includes: Acquire the self-reported focus completion result of the camera device under test, and the real-time image output by the camera device under test corresponding to the focus completion result; Determine the focus window in the real-time image, and calculate a first sharpness evaluation value based on the grayscale features of the first pixel within the focus window; The background region located outside the focus window in the real-time image is determined, and a second sharpness evaluation value is calculated based on the second pixel grayscale features within the background region; Calculate the background-to-foreground sharpness ratio of the second sharpness rating value to the first sharpness rating value, wherein the background-to-foreground sharpness ratio is obtained by dividing the second sharpness rating value by the first sharpness rating value; Based on the first sharpness evaluation value, the preset judgment benchmark, and the background-to-foreground sharpness ratio, the reliability of the focusing result is determined; wherein, the preset judgment benchmark includes at least one of the following: a preset sharpness threshold, a preset sharpness grading range, and a preset scoring model; The step of determining whether the focusing result is reliable based on the first sharpness evaluation value, the preset judgment benchmark, and the background-to-foreground sharpness ratio includes: When the background-to-foreground sharpness ratio is greater than or equal to a first preset threshold, the focusing result is determined to be unreliable. When the background-to-foreground sharpness ratio is less than a first preset threshold and greater than or equal to a second preset threshold, the focus motor position information reported by the camera device under test is obtained, and the focus direction is determined to be zooming in, zooming out, or not moving based on the change of the focus motor position information relative to the focus triggering time. If the focusing direction is zooming out, the focusing result is determined to be unreliable; otherwise, the reliability of the focusing result is determined based on the first sharpness evaluation value and the preset judgment benchmark. When the background-to-foreground sharpness ratio is less than a second preset threshold, the reliability of the focusing result is determined based on the first sharpness evaluation value and the preset judgment criterion. Wherein, the first preset threshold is greater than the second preset threshold.
2. The camera autofocus testing method according to claim 1, characterized in that, The step of calculating the first sharpness evaluation value based on the grayscale features of the first pixel within the focus window includes: Based on the grayscale features of the first pixel within the focusing window, a number of different dimensions of sharpness evaluation are calculated. Among the multiple different dimensions of sharpness evaluation, a primary index is determined, and the primary index is determined as the first sharpness evaluation value.
3. The camera autofocus testing method according to claim 1, characterized in that, The steps of obtaining the focus completion result reported by the camera device under test and the real-time image output by the camera device under test corresponding to the focus completion result include: The focus completion result reported by the camera under test and the video frame output by the camera under test are obtained through the focus information acquisition thread and the video frame acquisition thread, respectively. Based on the same timeline, timestamps are marked on the focusing completion result and the video frame, and delay compensation corresponding to the video frame acquisition thread is applied to the timestamp of the video frame. Based on the annotation results, the real-time image corresponding to the focus completion result is obtained from the video frame.
4. A camera autofocus testing system, characterized in that, Includes a host computer that is independent of the camera device being tested, the host computer comprising: The acquisition module is used to acquire the focus completion result reported by the camera device under test, and the real-time image output by the camera device under test corresponding to the focus completion result. A sharpness evaluation module is used to determine the focus window in the real-time image, calculate a first sharpness evaluation value based on the grayscale features of a first pixel within the focus window, determine the background area outside the focus window in the real-time image, calculate a second sharpness evaluation value based on the grayscale features of a second pixel within the background area, and calculate the background-foreground sharpness ratio of the second sharpness evaluation value to the first sharpness evaluation value, wherein the background-foreground sharpness ratio is obtained by dividing the second sharpness evaluation value by the first sharpness evaluation value; The authenticity determination module is used to determine whether the focus completion result is credible based on the first sharpness evaluation value, the preset judgment benchmark and the background-foreground sharpness ratio; wherein, the preset judgment benchmark includes at least one of the preset sharpness threshold, the preset sharpness grading interval and the preset scoring model; The step of determining whether the focusing result is reliable based on the first sharpness evaluation value, the preset judgment benchmark, and the background-to-foreground sharpness ratio includes: When the background-to-foreground sharpness ratio is greater than or equal to a first preset threshold, the focusing result is determined to be unreliable. When the background-to-foreground sharpness ratio is less than the first preset threshold but greater than or equal to a second preset threshold, the focusing motor position information reported by the tested camera device is obtained, and the focusing direction is determined to be zooming in, zooming out, or not moving based on the change in the focusing motor position information relative to the focusing trigger time. If the focusing direction is zooming out, the focusing result is determined to be unreliable; otherwise, the reliability of the focusing result is determined based on the first sharpness evaluation value and the preset judgment benchmark. When the background-to-foreground sharpness ratio is less than the second preset threshold, the reliability of the focusing result is determined based on the first sharpness evaluation value and the preset judgment benchmark, wherein the first preset threshold is greater than the second preset threshold.
5. An electronic device comprising a processor and a memory, characterized in that, The memory stores a computer program, which, when executed by the processor, causes the electronic device to perform the camera autofocus test method as described in any one of claims 1 to 3.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the camera autofocus testing method as described in any one of claims 1 to 3.
Citation Information
Patent Citations
Automatic focusing effect detection method, device and equipment
CN117119172A
Image processing device, image processing method, and a computer readable medium
US20140072221A1
