Focusing control method and device of industrial camera, equipment and medium
By using an auxiliary light source group and an automatic focusing control method with adaptive step size adjustment, the problems of low efficiency and inconsistent accuracy of manual focusing in industrial cameras are solved, and fast and high-precision automatic focusing is achieved.
Patent Information
- Application Number
- CN202511557580.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-29
- Publication Date
- 2026-01-13
AI Technical Summary
The focusing operation of existing industrial cameras relies on manual methods, which is inefficient and makes it difficult to guarantee accuracy and consistency, thus failing to meet the high-speed requirements of modern automated production lines.
Automatic focusing control is achieved by using an auxiliary light source group (including multiple point light sources and area light sources of different colors). By judging the color and area fraction of the light spots in the image and combining it with an adaptive step size adjustment strategy, automatic focusing of the industrial camera is realized.
It improves the focusing effect and accuracy of industrial cameras, reduces the impact of multi-peak interference, shortens the search time, and enhances the overall focusing efficiency and accuracy.
Smart Images

Figure CN121334503A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of industrial camera focusing, in particular to an industrial camera focusing control method, device, equipment and medium. BACKGROUND
[0002] Industrial cameras are a key component in machine vision systems, which can convert optical signals into ordered electrical signals. With the development of industrial automation, industrial cameras are widely used in industrial detection, which can be applied to identification, surface quality, image processing, image acquisition and other fields.
[0003] Since industrial cameras need to be applied to environments with different shooting distances, but in most industrial application scenarios, the focusing operation of industrial cameras still relies on manual methods. Specifically, a technician adjusts the focus ring of the industrial camera lens manually, and observes the real-time collected image, and judges the sharpness of the image with the naked eye until the best position of focusing is found.
[0004] However, this manual focusing operation has the following significant defects: low efficiency: every time the detection workpiece is replaced or the focal point drifts due to environmental temperature changes, a technician needs to intervene and adjust repeatedly, which takes a long time and is difficult to meet the high rhythm requirements of modern automated production lines. The accuracy and consistency are difficult to guarantee: the focusing result is highly dependent on the experience and subjective judgment of the operator, and the effects of adjustment by different personnel or the same person at different times often differ, resulting in uneven focusing accuracy and unable to guarantee the quality stability in batch applications.
[0005] Therefore, the existing manual focusing operation has deficiencies in efficiency, accuracy and consistency, which has become a technical bottleneck for improving the automation level and reliability of industrial detection, and an industrial camera automatic focusing control technical solution that can replace manual operation is urgently needed. SUMMARY
[0006] In order to improve the focusing effect and focusing accuracy of the industrial camera, the present application provides an industrial camera focusing control method, device, equipment and medium.
[0007] In a first aspect, the present application provides an industrial camera focusing control method, which adopts the following technical solution: An industrial camera focusing control method, comprising: acquiring a first image collected by an industrial camera, and judging whether the first image meets a preset first end condition; the first image contains images corresponding to an auxiliary light source group, the auxiliary light source group includes a plurality of point light sources and a plurality of area light sources, the colors of the plurality of point light sources are different from each other, the colors of the plurality of area light sources are different from each other, and the distance between every two area light sources is less than the distance between every two point light sources; If the first image does not reach the first end condition, the focusing mechanism is adjusted by a first angle, and the steps of collecting a new first image based on the industrial camera and judging whether the first image reaches the first end condition are repeated until the new first image reaches the first end condition. If the first image reaches the first end condition, the light source focusing is completed, a second image collected by the industrial camera is obtained, and it is judged whether the second image reaches a preset second end condition; the second image is an image corresponding to a focusing background plate; and the second end condition is that a sharpness of the focusing background plate in the second image reaches a sharpness threshold. If the second image does not reach the second end condition, the focusing mechanism is adjusted by a second angle, and the steps of collecting a new second image based on the industrial camera and judging whether the second image reaches the second end condition are repeated until the new second image reaches the second end condition. If the second image reaches the second end condition, the industrial camera completes the automatic focusing control.
[0008] By adopting the above technical solutions, the automatic focusing of the industrial camera is realized, and the focusing effect and focusing accuracy of the industrial camera are improved. Through the light source focusing stage of the auxiliary light source, the influence of the multi-peak interference in the focusing process of the focusing calibration plate is reduced. The focusing mechanism can quickly and directly approach the vicinity of the best focusing position, the search time and the calculation number are reduced, and the overall focusing efficiency is improved.
[0009] Optionally, the first image collected by the industrial camera is obtained, and it is judged whether the first image reaches a preset first end condition. If the first image does not reach the first end condition, the focusing mechanism is adjusted by a first angle, and the steps of collecting a new first image based on the industrial camera and judging whether the first image reaches the first end condition are repeated until the new first image reaches the first end condition, comprising: For each auxiliary light source of the auxiliary light source group, based on the first image, the spot color and the area fraction corresponding to the auxiliary light source are obtained; the auxiliary light source is the point light source or the area light source; The area fractions corresponding to each point light source are weighted and calculated to obtain a first weighted fraction; If the first weighted score reaches a preset first score threshold, then verify whether the spot state of the surface light source meets the auxiliary verification condition; if it does, then determine that the first image meets the first end condition; if it does not, then determine that the first image does not meet the first end condition, obtain the verification failure reason that the surface light source does not meet the auxiliary verification condition, and based on the verification failure reason, determine the adjustment direction and angle adjustment step of the focusing mechanism to perform the first angle adjustment, and repeatedly acquire a new first image captured by the industrial camera. For each auxiliary light source in the auxiliary light source group, based on the new first image, obtain the spot color and area fraction corresponding to the auxiliary light source, until the new first image meets the first end condition. If the first weighted score does not reach the first score threshold, it is determined that the first image has not met the first termination condition, and it is determined whether the current first image is the first first image captured by the industrial camera. If so, the focusing mechanism is controlled to adjust the first angle according to the preset adjustment direction and angle adjustment step size, and the new first image captured by the industrial camera is repeatedly acquired. For each auxiliary light source in the auxiliary light source group, the step of obtaining the spot color and area fraction corresponding to the auxiliary light source based on the new first image is repeated until the new first image reaches the first termination condition. If not, then based on the first weighted score and the second weighted score, obtain the score change trend. The second weighted score is the weighted area fraction of the point light source calculated based on the first image acquired at the previous angle of the focusing mechanism. Based on the score change trend, determine the adjustment direction and angle adjustment step size of the focusing mechanism to perform the first angle adjustment, and repeatedly acquire the new first image acquired by the industrial camera. For each auxiliary light source in the auxiliary light source group, based on the new first image, obtain the spot color and area fraction corresponding to the auxiliary light source, until the new first image reaches the first termination condition.
[0010] By adopting the above technical solution and introducing a dual judgment mechanism of point light source master search and surface light source state verification, the risk of traditional focusing algorithms getting trapped in local optima due to the multi-peak characteristics of the evaluation function curve is reduced, thus ensuring the credibility of the light source focusing results.
[0011] Optionally, verifying whether the spot state of the surface light source meets the auxiliary verification conditions includes: Based on the first image, identify the intersection regions between the light spots of the multiple surface light sources; Based on the image parameters of the intersection region, it is determined whether the intersection region meets the preset evaluation conditions. The image parameters include at least one of saturation, shape regularity, and color matching degree with the preset expected mixed color. The area fractions corresponding to each of the surface light sources are weighted and calculated to obtain a third weighted score; If the third weighted score reaches the second score threshold, and the light spots of each of the surface light sources are separated from each other, and the intersection region satisfies the evaluation condition, then it is determined that the light spot state of each of the surface light sources meets the auxiliary verification condition.
[0012] Only when the above three conditions are met by adopting the above technical solution can the spot state of the surface light source be considered verified. This ensures that the light spot is not only separated, but its optical quality also reaches the level that an ideal focusing state should have.
[0013] Optionally, after the first image reaches the first termination condition, the method further includes: Based on the first image, obtain the auxiliary coordinates corresponding to each auxiliary light source, and based on each of the auxiliary coordinates, determine the theoretical center coordinates corresponding to the focusing background plate; Based on the current light source focus and corresponding light source confidence, the current search radius is determined from a predefined lookup table, and the search area is obtained based on the theoretical center coordinates and the current search radius; Based on the search area, the matching positions corresponding to each of the multiple feature points in the second image are obtained; the feature points are specific patterns predefined on the focus background plate. Based on each of the matching positions, the actual center coordinates corresponding to the focused background in the second image are obtained, and the sharpness is calculated based on the actual center coordinates.
[0014] By adopting the above technical solution, a stable and consistent reference position is provided for each sharpness calculation of the background panel by calculating the actual center coordinates in real time. The search efficiency is improved by introducing a dynamic search area based on light source confidence.
[0015] Optionally, acquiring the second image captured by the industrial camera and determining whether the second image meets a preset second termination condition includes: Based on the actual length of the focusing background plate, the horizontal field of view and camera pixels of the industrial camera, the theoretical pixels corresponding to the focusing background plate are obtained. Based on the theoretical pixels and the actual center coordinates, the target region is obtained; Based on the target region, the second image is cropped to obtain the cropped focus pattern; Based on a preset sharpness evaluation function, the sharpness score corresponding to the focused pattern is calculated, and it is determined whether the sharpness score reaches the sharpness threshold. If yes, the second image meets the second termination condition; otherwise, the second image does not meet the second termination condition.
[0016] By adopting the above technical solution and calculating theoretical pixels, it is ensured that the image area used for evaluation always corresponds to the same physical size at different focusing distances, thus improving the accuracy and reliability of background focusing. By combining the actual center coordinates to delineate the target area and through cropping operations, the interference of irrelevant background and unevenly lit areas in the image on the sharpness evaluation function is reduced.
[0017] Optionally, adjusting the focusing mechanism at the second angle includes: Based on the current light source focus and corresponding light source confidence, the initial step size for the second angle adjustment is determined from a predefined step size mapping table; the step size mapping table defines the correspondence between different light source confidence intervals and the initial step size, wherein the higher the light source confidence, the smaller the initial step size; After adjusting the second angle based on the initial step size, a new sharpness score is calculated based on the newly acquired second image; Based on the historical focus ring angle, historical sharpness score, and the new sharpness score, update the sharpness focus ring angle curve and extract the current curve features; Based on the current curve characteristics, the step size of the second angle adjustment is dynamically adjusted for the next adjustment.
[0018] By adopting the above technical solution and using an adaptive step size adjustment strategy, the step size of the next step can be dynamically adjusted according to the curve characteristics, thereby reducing the number of iterations to locate near the optimal focal point and shortening the time of the entire light source focusing process.
[0019] Optionally, before acquiring the first image captured by the industrial camera and determining whether the first image has reached a preset first termination condition, the method further includes: The auxiliary light source group is controlled to be lit at the current operating parameters, and the industrial camera is controlled to acquire preview images; the operating parameters include at least one of brightness and color temperature; Identify and extract the spot areas of each auxiliary light source from the preview image; For each spot region, calculate multiple image quality evaluation sub-scores corresponding to that spot region, wherein the image quality evaluation sub-scores include at least a shape sub-score for characterizing the regularity of the spot shape and a sharpness sub-score for characterizing the sharpness of the spot edge; A comprehensive quality score is obtained by fusing and calculating the scores of each of the image quality evaluation sub-scores. Determine whether the overall quality score meets the preset optimization convergence condition; If the conditions are met, the current working parameters are determined as the optimal working parameters, and the process proceeds to the step of acquiring the first image captured by the industrial camera. If the conditions are not met, new operating parameters are generated based on a preset optimization algorithm, and the current operating parameters of the auxiliary light source group are updated. The step of controlling the auxiliary light source group to light up with the current operating parameters is repeated until the optimal operating parameters are obtained.
[0020] By adopting the above technical solutions, the working parameters of the auxiliary light source group are enhanced to resist problems such as light interference and electrical drift, thereby improving the success rate and accuracy of final focusing.
[0021] Secondly, this application provides a focusing control device for an industrial camera, which adopts the following technical solution: A focusing control device for an industrial camera, comprising: The first image judgment module is used to acquire a first image captured by an industrial camera and determine whether the first image has reached a preset first end condition; the first image includes an image corresponding to an auxiliary light source group, the auxiliary light source group includes multiple point light sources and multiple surface light sources, the multiple point light sources have different colors, the multiple surface light sources have different colors, and the distance between each two surface light sources is smaller than the distance between each two point light sources. The first adjustment module is used to adjust the first angle of the focusing mechanism when the first image has not reached the first end condition, and repeatedly execute the step of acquiring a new first image based on the industrial camera and determining whether the first end condition has been reached, until the new first image reaches the first end condition. The second image judgment module is used to acquire the second image captured by the industrial camera when the first image reaches the first ending condition, and to determine whether the second image reaches the preset second ending condition; the second image is the image corresponding to the focused background board; the second ending condition is that the clarity of the focused background board in the second image reaches a clarity threshold. The second adjustment module is used to adjust the focusing mechanism at a second angle when the second image has not reached the second end condition, and repeatedly execute the step of determining whether the second end condition has been reached based on the acquisition of a new second image by the industrial camera, until the new second image reaches the second end condition. The determination completion module is used to enable the industrial camera to complete automatic focusing control when the second image reaches the second termination condition.
[0022] Thirdly, this application provides an electronic device that adopts the following technical solution: An electronic device includes a processor and a memory, wherein the processor is coupled to the memory; The processor is configured to execute a computer program stored in the memory, causing the electronic device to perform the method as described in any of the first aspects.
[0023] Fourthly, this application provides a computer-readable storage medium, which adopts the following technical solution: A computer-readable storage medium includes a computer program or instructions that, when executed on a computer, cause the computer to perform the method as described in any of the first aspects. Attached Figure Description
[0024] Figure 1 This is a schematic diagram illustrating the distribution of the auxiliary light source group in one embodiment of this application.
[0025] Figure 2 This is a schematic flowchart of a focusing control method for an industrial camera according to one embodiment of this application.
[0026] Figure 3 This is a schematic diagram of the first image in a defocused state in one embodiment of this application.
[0027] Figure 4 This is a schematic diagram of the first image when the light source is focused, according to one embodiment of this application.
[0028] Figure 5 This is a structural block diagram of a focusing control device for an industrial camera according to one embodiment of this application.
[0029] Figure 6 This is a structural block diagram of an electronic device according to one embodiment of this application.
[0030] In the diagram, 1 is the first point light source; 2 is the second point light source; 3 is the first surface light source; 4 is the second surface light source; and 5 is the focused background panel. Detailed Implementation
[0031] The principles and features of the present invention are described below. The examples given are only for explaining the present invention and are not intended to limit the scope of the present invention.
[0032] The present application will be further described in detail below with reference to the accompanying drawings.
[0033] In this embodiment, a focusing control method for an industrial camera can be applied to an industrial camera auxiliary focusing system, such as... Figure 1As shown, the industrial camera auxiliary focusing system may include a control platform, a focusing background plate 5, an auxiliary light source group, an industrial camera, a focusing mechanism, and a distance adjustment mechanism. The industrial camera includes a camera body and an industrial lens. The industrial lens can be mounted on the front of the camera body via a standard interface (such as a C-mount, F-mount, or CS-mount). It is easy to understand that the industrial lens includes a focusing ring. When the relative angle between the industrial lens and the focusing ring is changed, the relative position of the internal lens elements of the industrial lens can be changed, thereby changing the focal length and making the object appear sharp.
[0034] The auxiliary light source group includes multiple point light sources and multiple surface light sources. The multiple point light sources are all different colors, and the multiple surface light sources are all different colors. The distance between any two surface light sources is smaller than the distance between any two point light sources.
[0035] like Figure 1 and Figure 4 As shown in this embodiment, the point light source may include a first point light source 1 and a second point light source 2, and the surface light source may include a first surface light source 3 and a second surface light source 4. The emission color of the first point light source 1 may be white, the emission color of the second point light source 2 may be red, the emission color of the first surface light source 3 may be blue, and the emission color of the second surface light source 4 may be red. The center point of the first point light source 1 and the center point of the second point light source 2 are at the same height, and the distance between the center points of the first point light source 1 and the second point light source 2 may be 17000mm to 18000mm, preferably 17500mm. The center point of the first surface light source 3 and the center point of the second surface light source 4 are at the same height, and the distance between the center points of the first surface light source 3 and the second surface light source 4 may be 3000mm to 4000mm, preferably 3700mm. The distance between the adjacent sides of the first surface light source 3 and the second surface light source 4 may be 800mm. The height difference between the center point of the first point light source 1 and the center point of the first surface light source 3 may be 21800mm to 21900mm, preferably 21884mm. It is easy to understand that the distance between two surface light sources can refer to the distance between the center points of the two surface light sources, and the distance between two point light sources can refer to the distance between the center points of the two point light sources.
[0036] The industrial camera and focusing mechanism are securely mounted on a mechanical structure such as a bracket to ensure stability and reduce the possibility of deviation due to vibration during focusing. During installation, the optical axis of the camera body and the industrial lens is located at the center of the pattern in the focusing background plate 5, and point light sources and area light sources are evenly arranged around the focusing background plate 5.
[0037] For example, the focusing mechanism may include a servo motor and a worm gear pair connected to the output of the servo motor. The camera body and the industrial lens can be fixed together to form a rigid body, allowing the camera body and the industrial lens to rotate synchronously. The focusing ring can be fixed by a custom-designed fixture or other mechanical structure, preventing it from rotating during focusing. When a rotation command is issued, the stepper motor rotates, thereby driving the worm gear to rotate the worm wheel. The worm wheel drives the industrial lens-camera body assembly to rotate by a corresponding angle. Because the focusing ring is fixed, the lens group inside the industrial lens moves relative to the focusing ring, thereby changing the lens spacing and achieving focusing.
[0038] The focusing background plate 5 and the auxiliary light source group are mounted on the distance adjustment mechanism. Using the distance adjustment mechanism, the focusing background plate 5 and the auxiliary light source group can be moved to a specified position. The distance between this position and the industrial camera is the shooting distance, which can be completely determined by the actual shooting distance of the industrial camera when it is about to start working.
[0039] The distance adjustment mechanism can move the focusing background plate 5 and the auxiliary light source group along the optical axis to set the shooting distance. The distance adjustment mechanism may include a servo motor, a synchronous pulley assembly, a mounting platform, and a linear guide rail. The synchronous pulley assembly converts the rotational motion of the servo motor into linear motion. The focusing background plate 5 and the auxiliary light source group are fixed to the mounting platform, and the synchronous pulley assembly drives them to move back and forth along the linear guide rail to change the distance between the focusing background plate 5, the auxiliary light source group, and the industrial camera. The linear guide rail ensures that the mounting platform moves smoothly along a straight line.
[0040] The control platform allows a series of core parameters to be input into the system. These parameters can include device parameters and scene parameters. Device parameters include camera parameters such as resolution, pixel size, exposure time, and gain, while lens parameters include maximum aperture and field of view (FOV). Scene parameters include shooting distance, light source parameters, and background parameters. Light source parameters include the color, size, and brightness of each auxiliary light source, while background parameters include the actual physical size of the pattern on the focus background (Figure 5). The control focusing mechanism rotates the relative angle between the focusing ring and the industrial lens to a preset starting point, providing a starting point for the subsequent focusing search process.
[0041] This application provides a focusing control method for an industrial camera. This method can be executed by a device, which can be a server or a terminal device. The server can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server providing cloud computing services. The terminal device can be a smartphone, tablet computer, desktop computer, etc., but is not limited to these.
[0042] like Figure 2 As shown, a focusing control method for an industrial camera, using an electronic device as the execution subject, is described in its main flow as follows (steps S101 to S105): Step S101: Acquire the first image captured by the industrial camera and determine whether the first image has reached the preset first termination condition; the first image includes the image corresponding to the auxiliary light source group, the auxiliary light source group includes multiple point light sources and multiple surface light sources, the multiple point light sources have different colors, the multiple surface light sources have different colors, and the distance between each two surface light sources is less than the distance between each two point light sources.
[0043] After adjusting the distance between the industrial camera, the auxiliary light source group, and the background plate to the shooting distance, each auxiliary light source in the auxiliary light source group is turned on, and the industrial camera captures the first image. The first image may include the image corresponding to the auxiliary light source group and the image corresponding to the focus calibration plate, such as... Figure 3 As shown, it may also include only the image corresponding to the auxiliary light source group.
[0044] Step S102: If the first image does not meet the first end condition, the focusing mechanism performs a first angle adjustment and repeats the step of acquiring a new first image based on the industrial camera and determining whether the first end condition has been met, until the new first image meets the first end condition.
[0045] Figure 3 The first image that did not meet the first termination condition. Figure 4 The first image that meets the first termination condition, such as Figure 4 As shown, in this embodiment, the first termination condition can be a condition indicating that the light spot of the auxiliary light source in the first image meets the corresponding requirements. After adjusting the angle of the focusing mechanism (i.e., the relative angle between the focusing ring and the industrial lens), a new first image is acquired again until the light spot of the auxiliary light source in the new first image meets the corresponding requirements.
[0046] Step S103: If the first image reaches the first termination condition, the light source focusing is completed, the second image captured by the industrial camera is obtained, and it is determined whether the second image reaches the preset second termination condition; the second image is the image corresponding to the focused background board; the second termination condition is that the clarity of the focused background board in the second image reaches the clarity threshold.
[0047] In this embodiment, the focusing process of the industrial camera can be divided into light source focusing and background focusing. When the first image reaches the first termination condition, light source focusing based on the auxiliary light source group ends, and background focusing can begin. When capturing the second image, all auxiliary light sources can be turned off, and only the background is captured.
[0048] Active illumination from auxiliary light sources reduces the impact of ambient light variations, especially in low-light or highly reflective scenes, while still capturing light spot characteristics. The combined design of point and area light sources provides redundant information; even if some light sources are blocked or contaminated, focusing can still be achieved through other light sources, enhancing the fault tolerance and adaptability of the focusing method.
[0049] Step S104: If the second image does not meet the second termination condition, the focusing mechanism is adjusted to a second angle, and the step of determining whether the second termination condition is met based on the acquisition of a new second image by the industrial camera is repeated until the new second image meets the second termination condition.
[0050] After adjusting the angle of the focusing mechanism, a new second image is acquired until the image of the background plate in the new second image meets the corresponding requirements.
[0051] Step S105: If the second image meets the second termination condition, the industrial camera completes the automatic focusing control.
[0052] When the second image meets the second termination condition, the background panel focusing ends, and the industrial camera completes automatic focusing control.
[0053] In this embodiment, a two-stage focusing strategy is adopted, first using an auxiliary light source for coarse focusing, and then using a focusing calibration plate for fine focusing. This strategy has the following advantages: In the focusing process using only a focusing calibration plate, the sharpness evaluation function curve of the calibration pattern often exhibits a multi-peak phenomenon (i.e., multiple local extrema) due to the influence of diffraction and speckle. This makes the search method for the optimal focus point prone to getting stuck in local optima, requiring multiple iterations to find the globally optimal focus point. In this embodiment, by using auxiliary light sources (point light sources and area light sources) in the light source focusing stage, the change in light spot area and the light spot fusion effect are used as evaluation indicators, thereby reducing the impact of multi-peak interference. This allows the focusing mechanism to quickly and directly approach the vicinity of the optimal focus position, reducing search time and the number of calculations, and improving the overall focusing efficiency.
[0054] Background images, when out of focus, can have altered features due to the expansion of blur spots, leading to distorted sharpness evaluations. Auxiliary light sources (such as point and area lights) possess high brightness and specific colors; their light spots are easier to extract and quantize in the image and are less affected by blur spots. During the light source focusing stage, utilizing the brightness differences and distance characteristics of the light sources (e.g., large spacing between point lights and close proximity and different colors of area lights) can effectively reduce interference from background patterns, ensuring the reliability of the evaluation data. This makes the light source focusing results more stable and reliable, providing a high-quality initial point for background focusing.
[0055] In summary, the two-stage focusing strategy in this embodiment effectively solves the multi-peak problem and mechanical deviation problem in traditional focusing methods by rapidly approximating the light source focus and positioning the background plate focus, thus achieving fast, high-precision, and highly reliable automatic focusing.
[0056] As an optional implementation in this embodiment, the step of acquiring a first image captured by an industrial camera and determining whether the first image meets a preset first end condition, and if the first image does not meet the first end condition, involves the focusing mechanism adjusting the first angle and repeating the step of acquiring a new first image based on the industrial camera and determining whether the first end condition is met, until the new first image meets the first end condition. Specifically, this includes the following processing: For each auxiliary light source in the auxiliary light source group, based on the first image, the spot color and area fraction corresponding to that auxiliary light source are obtained; the auxiliary light source is either the point light source or the area light source. The area fraction corresponding to each of the point light sources is weighted and calculated to obtain a first weighted score; If the first weighted score reaches a preset first score threshold, then verify whether the spot state of the surface light source meets the auxiliary verification condition; if it does, then determine that the first image meets the first end condition; if it does not, then determine that the first image does not meet the first end condition, obtain the verification failure reason that the surface light source does not meet the auxiliary verification condition, and based on the verification failure reason, determine the adjustment direction and angle adjustment step of the focusing mechanism to perform the first angle adjustment, and repeatedly acquire a new first image captured by the industrial camera. For each auxiliary light source in the auxiliary light source group, based on the new first image, obtain the spot color and area fraction corresponding to the auxiliary light source, until the new first image meets the first end condition. If the first weighted score does not reach the first score threshold, it is determined that the first image has not met the first termination condition, and it is determined whether the current first image is the first first image captured by the industrial camera. If so, the focusing mechanism is controlled to adjust the first angle according to the preset adjustment direction and angle adjustment step size, and the new first image captured by the industrial camera is repeatedly acquired. For each auxiliary light source in the auxiliary light source group, the step of obtaining the spot color and area fraction corresponding to the auxiliary light source based on the new first image is repeated until the new first image reaches the first termination condition. If not, then based on the first weighted score and the second weighted score, obtain the score change trend. The second weighted score is the weighted area fraction of the point light source calculated based on the first image acquired at the previous angle of the focusing mechanism. Based on the score change trend, determine the adjustment direction and angle adjustment step size of the focusing mechanism to perform the first angle adjustment, and repeatedly acquire the new first image acquired by the industrial camera. For each auxiliary light source in the auxiliary light source group, based on the new first image, obtain the spot color and area fraction corresponding to the auxiliary light source, until the new first image reaches the first termination condition.
[0057] The first image is split into RGB three-channel images, which are then converted into HSV images. The hue is determined based on the H channel values in the HSV image, thereby identifying the color of each light spot. For each auxiliary light source (including point and area light sources) in the light source group, its respective light spot region can be identified using image segmentation algorithms (e.g., threshold segmentation based on a preset color range in the HSV color space). The area fraction of each light spot is calculated, and the area fraction is inversely proportional to the area of the light spot (i.e., the smaller the area, the higher the fraction), representing the quality of focusing.
[0058] The formula for calculating the area fraction can be expressed as:
[0059] The theoretical minimum pixel value is a preset known value, while the actual pixel value is the imaging area corresponding to the spot of the auxiliary light source. The area fraction is maximized when the actual pixel value is closer to the minimum pixel value.
[0060] In this optional implementation, point light sources that are more sensitive to defocusing are given priority. The first area fraction of all point light sources is weighted and calculated (for example, different weights can be assigned according to the position of the light source) to obtain a comprehensive first weighted score. The first weighted score is then compared with a preset first score threshold.
[0061] If the first weighted score reaches the first score threshold, it indicates that the point light source indicator is close to the optimal point. However, the light source focusing is not immediately stopped; instead, the area light source verification mechanism is activated to check whether the spot state of the area light source also meets the auxiliary verification conditions.
[0062] If the spot state of the area light source also meets the conditions, the verification is successful, indicating that the indicators of the point light source and the area light source are consistent, and the light source is determined to be successfully focused, allowing the process to proceed to the background focusing stage. If the spot state of the area light source does not meet the conditions, the verification fails, and the relative angle between the industrial camera and the focusing ring may be at a false peak. In this case, analyze the reason for the verification failure and determine the next adjustment direction and angle adjustment step size based on the reason. Reasons for verification failure may include an excessively large spot area of the area light source, overlapping spots between different area light sources, and substandard optical quality. Substandard optical quality may refer to insufficient saturation, irregular shape, or poor color matching in the overlapping area. For example: If verification fails due to an excessively large spot area of the surface light source, it indicates a possible false peak. When the point light source has reached its optimal state, the area of the surface light source should also be reduced accordingly. If the surface light source area remains large, it indicates that the point light source is trapped in a local optimum that only benefits itself, while the overall imaging state remains poor. In this case, it can be confidently determined to be a false peak, and an "escape" strategy can be implemented. The "escape" strategy involves taking the direction opposite to the current adjustment direction as the new adjustment direction, calculating a new escape step size based on the current angle adjustment step size, and using this escape step size as the new angle adjustment step size. For example, escape step size = current angle adjustment step size × escape coefficient (the escape coefficient can be set to 1.8 by default), and the escape step size does not exceed the maximum allowable step size of the focusing mechanism.
[0063] If the verification fails because the light spots between the surface light sources are not separated, even though their areas are normal, the point light source is in good condition, and the area of the surface light source has reached the preset state (indicating that the focus is indeed very accurate), but the light spots are not completely separated. Possible reasons for this verification failure include: hardware problems: the two surface light sources are installed too close to each other, and cannot be separated on the sensor even under ideal focusing; lens field of view / resolution problems: the lens's field of view is too small or the camera's resolution is insufficient, causing the two light spots that should be separated to be connected together in the image.
[0064] At this point, a fine-tuning confirmation strategy can be initiated. This involves fine-tuning within a small range (e.g., ±1°) centered on the peak value of the light source at the current position, using a preset small step size, while simultaneously monitoring the first weighted score corresponding to the point light source. If the first weighted score corresponding to the point light source remains stable and high, it indicates that the current position represents a stable and high-quality peak value. This should be determined as an abnormality in the area light source or a hardware limitation. The result of the point light source should be trusted, the light source focusing should be considered complete, and a warning log for an abnormal area light source can be recorded. If the first weighted score corresponding to the point light source drops sharply, it indicates that the peak value at the current position is very sharp, and the current position is not the optimal point. The aforementioned "escape" strategy should be executed to determine the adjustment direction and angle adjustment step size of the focusing mechanism.
[0065] If the verification fails due to substandard optical quality, but the spot separation and area between the surface light sources are normal, it is highly suspected that the system is trapped in a local optimum and the current position is not the optimal point. The above-mentioned "escape" strategy can be executed to obtain the adjustment direction and angle adjustment step size of the focusing mechanism.
[0066] If the first weighted score does not reach the threshold, it indicates that the optimal point has not yet been reached. At this point, it is determined whether the current image is the first image. If it is the first, since there is no historical data for reference, an initial exploration can be conducted according to a preset, safe adjustment strategy (i.e., a fixed adjustment direction and angle adjustment step size). If the first weighted score does not meet the threshold, and the current image is not the first image (i.e., it has already undergone at least one adjustment), an adaptive search mode can be entered. The second weighted score of the point light source calculated at the previous angle of the focusing mechanism is retrieved and compared with the current first weighted score to calculate the score change trend.
[0067] By conducting multiple focusing experiments, the first weighted score obtained under different focusing mechanism adjustment step sizes can be recorded, thus plotting a score baseline curve. The horizontal axis of the score baseline curve represents the adjustment step size, and the vertical axis represents the first weighted score. The score baseline curve exhibits a clear single-peak shape, and the horizontal coordinate value corresponding to the peak point is the theoretical total step size required to achieve the optimal first weighted score. Based on the score change trend, the adjustment direction and angle adjustment step size for the next adjustment are determined. Specifically: During real-time focusing, the current first weighted score is known. By querying the preset score baseline curve, the theoretical step size position corresponding to the current first weighted score can be found. The step size difference ΔX between the step size position corresponding to the current first weighted score and the step size position corresponding to the optimal first weighted score is calculated. ΔX represents the distance that still needs to be adjusted from the current position to the optimal focusing point. The calculated difference ΔX is directly used as the angle adjustment step size for the next adjustment.
[0068] At the same time, the direction is determined by combining the trend of score changes (such as the difference ΔS between the current first weighted score and the previous second weighted score). If ΔS is positive (i.e., the weighted score is rising), ΔX can be adjusted in the original direction; if ΔS is negative (i.e., the weighted score is falling), ΔX can be adjusted in the opposite direction to the original direction.
[0069] By introducing a dual judgment mechanism of point light source master search and area light source state verification, the risk of traditional focusing algorithms getting trapped in local optima (i.e., "false peaks") due to the multi-peak characteristics of the evaluation function curve is reduced. Point light sources provide rapid guidance, while area light sources provide cross-verification of physical states, ensuring the reliability of the light source focusing results and laying the foundation for subsequent background plate focusing.
[0070] By adopting an adaptive step size adjustment strategy, the step size and direction of the next step can be dynamically adjusted according to the changing trend of the weighted area fraction, thereby reducing the number of iterations to locate near the optimal focal point and significantly shortening the time of the entire light source focusing process.
[0071] When the surface light source verification fails, the step size and direction of the next step can be obtained based on the reason for the verification failure, so as to recover from the abnormal state.
[0072] In this embodiment, verifying whether the light spot state of the surface light source meets the auxiliary verification conditions specifically includes the following processing: Based on the first image, the intersection regions between the light spots of the multiple surface light sources are identified; based on the image parameters of the intersection regions, it is determined whether the intersection regions meet the preset evaluation conditions, the image parameters including at least one of saturation, shape regularity, and color matching degree with the preset expected mixed color; the area fractions corresponding to each of the surface light sources are weighted and calculated to obtain a third weighted score; if the third weighted score reaches the second score threshold, and the light spots of each of the surface light sources are separated from each other, and the intersection regions meet the evaluation conditions, then it is determined that the light spot state of each of the surface light sources meets the auxiliary verification conditions.
[0073] First, the intersection regions of the light spots from the surface light sources are identified in the first image. Specifically, after converting the first image from RGB to HSV color space, the light spots corresponding to each surface light source are segmented using a preset HSV range. Then, a logical AND operation is performed on the binarized mask, and the resulting overlapping region is the intersection region.
[0074] For the segmented intersection regions, calculate the following key parameters: Saturation: Calculates the average saturation value of pixels within the intersection area. When the focus is good, the light intensity is concentrated, the colors are fully mixed, and the saturation is high.
[0075] Shape regularity: Calculates shape descriptors such as the roundness of the intersection area. When the focus is good, the shape of the intersection area is more regular.
[0076] Color matching degree with the preset expected mixed color: compare the actual color of the intersection area (e.g., magenta that should be produced at the intersection of red and blue surface light sources) with the theoretical expected mixed color and calculate the degree of matching (e.g., calculate the color difference in the Lab color space).
[0077] While analyzing the intersection region, the state of each surface light source can be evaluated in parallel. By weighting the area fractions of each surface light source, a comprehensive third weighted score can be obtained. This score reflects the overall degree to which the surface light sources approach their optimal focusing state. It is easy to understand that the weighting coefficients for each surface light source can be preset values.
[0078] When the third weighted score reaches the second score threshold, it indicates that the overall spot area of the surface light source has been reduced to an acceptable range. When the spots of each surface light source are separated from each other in the image, it means that the blur spots have shrunk and no longer overlap. When the intersection region meets the preset evaluation conditions, that is, when the extracted image parameters (at least one of saturation, shape regularity, and color matching) meet the preset standards, it ensures that the spots are not only separated, but their optical quality (color, brightness, and shape) also reaches the level that an ideal focusing state should have. Only when all three conditions are met is the spot state of the surface light source considered to have passed the verification; if any one of the conditions is not met, the spot state verification of the surface light source fails.
[0079] In this embodiment, when calculating the area fraction of the light spot from the surface light source, it is first determined whether there are overlapping regions of the light spots. If so, the overlapping regions can be subtracted from the original light spot mask to obtain the independent part of each light spot. Then, morphological algorithms (such as ellipse fitting or convex hull fitting based on boundary curves) are used to repair the shape of the independent parts, fitting the complete light spot shape under the assumption of no overlap, and calculating its pixel area as the base area value. Based on this base area value, the actual light source pixel value is obtained.
[0080] As an optional implementation of this embodiment, the base area value can be used as the actual light source pixel value to calculate the area fraction.
[0081] As another optional implementation of this embodiment, after calculating the basic area value, several key image features of the spot region can be extracted. These key image features may include: Shape matching degree: Calculate the shape descriptor of the repaired spot (such as the Hu moment invariant) and compare it with the Hu moment of the ideal spot shape template obtained under the best focusing state. Calculate the similarity as the shape matching degree score.
[0082] Edge sharpness: Calculates the average gradient magnitude of pixels at the edge of the light spot (e.g., using the Sobel operator), which directly reflects the sharpness of the light spot edge.
[0083] Brightness uniformity: Calculates the standard deviation of pixel brightness within the light spot region. This value is used to assess the concentration of light spot energy.
[0084] The aforementioned key image features are fused into an area confidence coefficient, which can range from [0,1]. The formula for calculating the area confidence coefficient is as follows: Area confidence coefficient = w1 * shape matching degree + w2 * edge sharpness + w3 * brightness uniformity Among them, w1, w2, and w3 are preset weighting coefficients. The closer the shape is to the template, the sharper the edges, and the more uniform the internal brightness, the closer the area confidence coefficient is to 1, indicating a higher confidence level in the calculated area.
[0085] Multiplying the base area value by the area confidence coefficient yields the final effective area, which can be used as the actual light source pixel value for subsequent area fraction calculations.
[0086] In this embodiment, after the first image reaches the first termination condition, the method further includes: based on the first image, obtaining the auxiliary coordinates corresponding to each auxiliary light source, and determining the theoretical center coordinates corresponding to the focusing background plate based on each of the auxiliary coordinates; based on the light source confidence corresponding to the current light source focus, determining the current search radius from a predefined lookup table, and obtaining the search area based on the theoretical center coordinates and the current search radius; based on the search area, obtaining the matching positions corresponding to each of the multiple feature points in the second image; the feature points are predefined specific patterns on the focusing background plate; based on each of the matching positions, obtaining the actual center coordinates corresponding to the focusing background plate in the second image, and calculating the sharpness based on the actual center coordinates.
[0087] When the light source is focused, based on the first image of the last frame (i.e., the image illuminated by the auxiliary light sources), the pixel coordinates of each auxiliary light source (point light source and area light source) in the image are obtained, i.e., the auxiliary coordinates. According to each auxiliary coordinate and the fixed geometric relationship between them and the center of the focusing background plate, the theoretical center coordinates of the focusing background plate in the image are obtained through geometric calculation. The theoretical center coordinates are the expected position of the focusing background plate calculated based on the ideal geometric model.
[0088] For example, the theoretical center coordinates of the focused background plate can be expressed as ( , The center coordinates of the first point light source can be expressed as ( , The center coordinates of the second point light source can be represented as ( , The center coordinates of the first light source can be represented as ( , The center coordinates of the second light source can be expressed as ( , A fixed geometric relationship can be expressed as:
[0089] Light source confidence is a comprehensive evaluation of the quality and reliability of the light source focusing process. For example, during light source focusing, an angle-fraction curve can be formed based on the angle of the focusing mechanism and the corresponding weighted area fraction of the point light source in each iteration. The curve smoothness, convergence judgment result, and peak sharpness can be obtained from this curve. Specifically, the curve smoothness can be evaluated by calculating the standard deviation of the weighted area fraction sequence; the smaller the fluctuation, the higher the curve smoothness. The trend of weighted area fraction changes in the last few iterations of the light source focusing process is analyzed. For example, linear regression analysis can be used to analyze the trend of weighted area fraction changes of N data points in the last few iterations to determine whether a stable convergence trend is observed (i.e., the slope tends to zero), thus obtaining a convergence judgment result. The second derivative of the fractional peak region of the weighted area fraction is calculated to obtain the peak sharpness. The size range of the fractional peak region can be a preset parameter. The extracted curve smoothness, convergence judgment result, and peak sharpness are input into a predefined scoring model. This scoring model assigns weights to curve smoothness, convergence judgment result, and peak sharpness respectively, and outputs a scalar value between 0 and 1 through weighted fusion calculation. This scalar value is the confidence level of the light source.
[0090] Based on the light source confidence level, a predefined lookup table is consulted to dynamically determine the current search radius. It's easy to understand that a high light source confidence level indicates reliable focusing results and that the theoretical center coordinates (…) are likely accurate. , If the error is small, a smaller search radius is used; if the confidence level of the light source is low, the focusing error may be large, requiring a larger search radius to ensure that no target is missed. Finally, the theoretical center coordinates (…) can be used. , Using the current search radius (R) as the radius, a circular search area is drawn on the second image.
[0091] The auxiliary light source is turned off, and a second image containing only the background is captured. Within the defined search area, a template matching algorithm is used to find multiple predefined feature points on the focused background, such as the black circle at the center of the background, the crosshairs at the four corners, etc. For each found feature point, the matching position of that feature point can be output (…). , There is a pre-defined direct geometric relationship between the matching position of the feature point and the actual center coordinates. Based on the matching position of the feature point, the actual center coordinates of the background panel can be obtained.
[0092] Due to mechanical limitations, the camera's optical axis and focusing rotation axis cannot be aligned in a straight line. Therefore, the center position of focus in the camera image changes after rotating the camera body. By calculating the actual center coordinates in real time, a stable and consistent reference position is provided for the sharpness calculation of each background focus. Regardless of the rotation of the camera body and industrial lens, the same region of interest (ROI) can be located for sharpness evaluation, thus ensuring the comparability and stability of sharpness scores and fundamentally solving the evaluation distortion problem caused by mechanical deviation.
[0093] By introducing a dynamic search region based on light source confidence, search efficiency is improved. A small-area search under high light source confidence reduces computational waste from full-image scanning and speeds up processing; a large-area search under low light source confidence ensures fault tolerance and reduces positioning failures caused by slight misfocusing of the light source.
[0094] In this embodiment, acquiring the second image captured by the industrial camera and determining whether the second image meets the preset second termination condition specifically includes the following processing: based on the actual length of the focusing background plate, the horizontal field of view of the industrial camera, and the camera pixels, acquiring the theoretical pixels corresponding to the focusing background plate; based on the theoretical pixels and the actual center coordinates, acquiring the target area; based on the target area, cropping the second image to acquire the cropped focusing pattern; based on a preset sharpness evaluation function, calculating the sharpness score corresponding to the focusing pattern, and determining whether the sharpness score reaches the sharpness threshold. If yes, the second image meets the second termination condition; otherwise, the second image does not meet the second termination condition.
[0095] Based on known physical parameters, the pixel size that the focusing background should occupy under the current imaging state is calculated. Specifically, based on the actual physical length of the focusing background (e.g., the width of the checkerboard pattern), the horizontal field of view (FOV) of the industrial camera, and the camera's horizontal resolution (number of pixels), the theoretical pixel size of the focusing background image under ideal focusing conditions is calculated using geometric optics principles. The formula for calculating the theoretical pixels can be expressed as:
[0096] Using theoretical pixels as the size basis (e.g., as diameter or side length) and the determined actual center coordinates as the center point, the target region (i.e., region of interest, ROI) is delineated on the second image. Based on the determined target region, the acquired original second image is cropped to extract a sub-image containing only the target focused background pattern, i.e., the cropped focused pattern.
[0097] The cropped focus pattern is input into a preset sharpness evaluation function, such as the Laplace function. The sharpness evaluation function calculates a quantified sharpness score. The sharpness score is compared with a preset sharpness threshold. If the sharpness score reaches or exceeds the sharpness threshold, the second image is determined to have met the second termination condition, and the background is focused; otherwise, the angle of the focusing mechanism needs to be adjusted and the process repeated.
[0098] By calculating theoretical pixels, it is ensured that the image area used for evaluation always corresponds to the same physical size at different focusing distances, thus improving the accuracy and reliability of background focusing. By combining the actual center coordinates to define the target area, and through cropping operations, the interference of irrelevant background and unevenly lit areas in the image on the sharpness evaluation function is reduced.
[0099] In this embodiment, the second angle adjustment of the focusing mechanism specifically includes the following processes: Based on the current light source focus corresponding to the light source confidence level, an initial step size for the second angle adjustment is determined from a predefined step size mapping table; the step size mapping table defines the correspondence between different light source confidence level intervals and the initial step size, wherein the higher the light source confidence level, the smaller the initial step size; after the second angle adjustment is performed based on the initial step size, a new sharpness score is calculated based on the newly acquired second image; based on the historical focusing ring angle, the historical sharpness score, and the new sharpness score, the sharpness focusing ring angle curve is updated, and the current curve features are extracted; based on the current curve features, the step size for the next second angle adjustment is dynamically adjusted.
[0100] When background focusing begins, the light source confidence level obtained from the light source focusing stage is first queried. Based on the light source confidence level, a predefined step size mapping table is consulted to determine the initial step size for background focusing. The higher the light source confidence level in this step size mapping table, the smaller the initial step size.
[0101] After adjusting based on the initial step size and acquiring a new second image, a new sharpness score is calculated. Subsequently, the historical focus ring angle, historical sharpness score, and new sharpness score are integrated to update and plot the sharpness focus ring angle curve, which reflects the trend of sharpness changing with angle in real time.
[0102] The historical focus ring angle refers to the angular position of the focusing mechanism during historical focusing operations. The historical sharpness score refers to the sharpness evaluation value of the focused pattern calculated at various angles of the focusing mechanism during historical focusing operations. After each adjustment of the focusing mechanism's angle, the current angle and the corresponding sharpness score are recorded. Whenever a new adjustment angle and sharpness score are obtained, the current sharpness focus ring angle curve is cleared, and the entire sharpness focus ring angle curve is redrawn based on the historical focus ring angle, historical sharpness score, new adjustment angle, and sharpness score.
[0103] The updated sharpness focus ring angle curve is analyzed in real time to extract current curve features. Current curve features include, but are not limited to, the curve's slope (trend of change), curvature (rate of change), and whether extreme points (peaks) occur.
[0104] If the current curve characteristics indicate a monotonous and steep upward or downward trend, it means the optimal focal point is still far away. In this case, the step size can be increased from the current angle adjustment step size to accelerate convergence towards the peak region. If the current curve characteristics indicate a decreasing slope, a flattening trend, or a trend reversal (from rising to falling or from falling to rising), it means the optimal point is very close or has already been passed. In this case, the step size can be decreased from the current angle adjustment step size, and possibly adjusted in the opposite direction to the current adjustment to locate the peak position near the optimal point.
[0105] In this embodiment, before acquiring the first image captured by the industrial camera and determining whether the first image has reached a preset first termination condition, the method further includes: The auxiliary light source group is controlled to be lit at the current operating parameters, and the industrial camera is controlled to acquire preview images; the operating parameters include at least one of brightness and color temperature; Identify and extract the spot areas of each auxiliary light source from the preview image; For each spot region, calculate multiple image quality evaluation sub-scores corresponding to that spot region, wherein the image quality evaluation sub-scores include at least a shape sub-score for characterizing the regularity of the spot shape and a sharpness sub-score for characterizing the sharpness of the spot edge; A comprehensive quality score is obtained by fusing and calculating the scores of each of the image quality evaluation sub-scores. Determine whether the overall quality score meets the preset optimization convergence condition; If the conditions are met, the current working parameters are determined as the optimal working parameters, and the process proceeds to the step of acquiring the first image captured by the industrial camera. If the conditions are not met, new operating parameters are generated based on a preset optimization algorithm, and the current operating parameters of the auxiliary light source group are updated. The step of controlling the auxiliary light source group to light up with the current operating parameters is repeated until the optimal operating parameters are obtained.
[0106] The auxiliary light source group is controlled to illuminate with an initial (or previous) set of operating parameters, and an industrial camera is controlled to acquire preview images. These preview images are used to diagnose the current light source status. The operating parameters may include at least one of brightness and color temperature.
[0107] The preview image is processed, and the light spot area corresponding to each auxiliary light source is identified and extracted by image segmentation algorithm (such as threshold segmentation in HSV color space).
[0108] For each spot region, calculate image quality evaluation sub-scores across multiple dimensions, mainly including: Shape sub-fraction: Used to characterize the regularity of the light spot shape. For example, the circularity of the light spot is calculated and used as the shape sub-fraction. For point light sources, the ideal light spot should be a regular circle, rather than a "star-shaped" diffraction pattern caused by overexposure or a broken shape caused by insufficient brightness.
[0109] Sharpness sub-score: Used to characterize the sharpness of the spot's edge. For example, the average gradient value of the spot's edge region is calculated and used as the sharpness sub-score. The better the focus, the sharper the spot edge, and the higher the average gradient value.
[0110] The individual image quality evaluation sub-scores are weighted and fused to obtain a single comprehensive quality score, which reflects the overall imaging quality of the light spot under the current operating parameters.
[0111] The overall quality score is compared with a preset optimization convergence condition. The optimization convergence condition can be a preset threshold corresponding to the overall quality score (e.g., above 0.9), which can be pre-calibrated experimentally. If the condition is met, it indicates that the spot quality under the current operating parameters has reached the standard, and the current operating parameters are locked as the optimal operating parameters. If the condition is not met, it indicates that the current parameters are unsatisfactory, and a preset optimization algorithm (e.g., Bayesian optimization algorithm or grid search algorithm) can be invoked to generate a new set of candidate operating parameters that are expected to improve the overall score. These candidate operating parameters are then updated to the auxiliary light source group. Taking the grid search algorithm as an example, the brightness range can be 0%-100%, and the color temperature range can be 3000K-6000K. A grid adjustment step size is defined for each parameter; for example, the brightness adjustment step size is 10%, and the color temperature adjustment step size is 500K. Starting from a preset initial point, new combinations are generated incrementally according to the grid adjustment step size. For example: the first set of working parameters: brightness is 0%, color temperature is 3000K; the second set of working parameters: brightness is 0%, color temperature is 3500K; ... until the full range of parameters is covered.
[0112] The light source parameter configuration is transformed into a fully automated optimization process based on image quality feedback. Calibration can be automatically completed upon power-on or in response to environmental changes, reducing the technical requirements for operators and improving the ease of use and deployment efficiency of the equipment. The auxiliary light source group's operating parameters are enhanced to resist problems such as light interference and electrical drift, improving the success rate and accuracy of final focusing.
[0113] Based on the same technical concept, this application also provides a focusing control device for an industrial camera, such as... Figure 5 As shown, the focusing control device 200 of the industrial camera mainly includes: The first image judgment module 201 is used to acquire a first image captured by an industrial camera and determine whether the first image has reached a preset first end condition; the first image includes an image corresponding to an auxiliary light source group, the auxiliary light source group includes multiple point light sources and multiple surface light sources, the multiple point light sources have different colors, the multiple surface light sources have different colors, and the distance between each two surface light sources is less than the distance between each two point light sources. The first adjustment module 202 is used to adjust the first angle of the focusing mechanism when the first image has not reached the first end condition, and repeatedly execute the step of acquiring a new first image based on the industrial camera and determining whether the first end condition has been reached, until the new first image reaches the first end condition. The second image judgment module 203 is used to acquire the second image captured by the industrial camera when the light source is focused after the first image reaches the first end condition, and to determine whether the second image reaches the preset second end condition; the second image is the image corresponding to the focused background board; the second end condition is that the clarity of the focused background board in the second image reaches a clarity threshold. The second adjustment module 204 is used to adjust the focusing mechanism to a second angle when the second image has not reached the second end condition, and repeatedly execute the step of determining whether the second end condition has been reached based on the acquisition of a new second image by the industrial camera, until the new second image reaches the second end condition. The determination completion module 205 is used to enable the industrial camera to complete automatic focusing control when the second image reaches the second termination condition.
[0114] In one example, the module in any of the above devices may be one or more integrated circuits configured to implement the above methods, such as one or more application-specific integrated circuits (ASICs), or one or more digital signal processors (DSPs), or one or more field-programmable gate arrays (FPGAs), or a combination of at least two of these integrated circuit forms.
[0115] For example, when modules in a device can be implemented via a processing element scheduler, the processing element can be a general-purpose processor, such as a central processing unit (CPU) or other processor capable of calling programs. Alternatively, these modules can be integrated together as a system-on-a-chip (SOC).
[0116] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and modules described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.
[0117] Based on the same technical concept, this application also provides an electronic device, such as... Figure 6 As shown, the electronic device 300 includes a processor 301 and a memory 302, and may further include one or more of an information input / output (I / O) interface 303, a communication component 304, and a communication bus 305.
[0118] The processor 301 controls the overall operation of the electronic device 300 to complete all or part of the steps in the aforementioned industrial camera focusing control method. The memory 302 stores various types of data to support the operation of the electronic device 300. This data may include, for example, instructions for any application or method operating on the electronic device 300, as well as application-related data. The memory 302 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM).
[0119] I / O interface 303 provides an interface between processor 301 and other interface modules, such as keyboards, mice, and buttons. These buttons can be virtual or physical. Communication component 304 is used to test wired or wireless communication between electronic device 300 and other devices. Wireless communication includes Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, or 4G, or a combination thereof. Therefore, the corresponding communication component 304 may include a Wi-Fi component, a Bluetooth component, and an NFC component.
[0120] The communication bus 305 may include a path for transmitting information between the aforementioned components. The communication bus 305 may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. The communication bus 305 can be divided into an address bus, a data bus, a control bus, etc.
[0121] Electronic device 300 may include, but is not limited to, mobile terminals such as digital broadcast receivers, PDAs (personal digital assistants), and PMPs (portable multimedia players), as well as fixed terminals such as digital TVs and desktop computers, and may also be servers.
[0122] Based on the same technical concept, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the above-described focusing control method for an industrial camera.
[0123] The computer-readable storage medium may include various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0124] The terms “comprising,” “including,” or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.
[0125] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "multiple" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0126] Although embodiments of this application have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting this application. Those skilled in the art can make changes, modifications, substitutions and variations to the above embodiments within the scope of this application.
Claims
1. A focusing control method for an industrial camera, characterized in that, include: Acquire the first image captured by the industrial camera and determine whether the first image has reached the preset first termination condition; The first image includes an image corresponding to an auxiliary light source group, which includes multiple point light sources and multiple surface light sources. The multiple point light sources have different colors, and the multiple surface light sources have different colors. The distance between any two surface light sources is smaller than the distance between any two point light sources. If the first image does not meet the first termination condition, the focusing mechanism performs a first angle adjustment and repeats the steps of acquiring a new first image based on the industrial camera and determining whether the first termination condition has been met, until the new first image meets the first termination condition. If the first image meets the first termination condition, the light source focusing is completed, the second image captured by the industrial camera is acquired, and it is determined whether the second image meets the preset second termination condition; the second image is the image corresponding to the focused background board; the second termination condition is that the clarity of the focused background board in the second image reaches a clarity threshold; If the second image does not meet the second termination condition, the focusing mechanism is adjusted to a second angle, and the steps of acquiring a new second image based on the industrial camera and determining whether the second termination condition is met are repeated until the new second image meets the second termination condition. If the second image meets the second termination condition, the industrial camera completes the autofocus control.
2. The method according to claim 1, characterized in that, The process of acquiring a first image from an industrial camera and determining whether the first image meets a preset first end condition, and if the first image does not meet the first end condition, involves the focusing mechanism adjusting the first angle and repeating the steps of acquiring a new first image from the industrial camera and determining whether the first end condition is met, until the new first image meets the first end condition. This includes: For each auxiliary light source in the auxiliary light source group, based on the first image, the spot color and area fraction corresponding to that auxiliary light source are obtained; the auxiliary light source is either the point light source or the area light source. The area fraction corresponding to each of the point light sources is weighted and calculated to obtain a first weighted score; If the first weighted score reaches a preset first score threshold, then verify whether the spot state of the surface light source meets the auxiliary verification condition; if it does, then determine that the first image meets the first end condition; if it does not, then determine that the first image does not meet the first end condition, obtain the verification failure reason that the surface light source does not meet the auxiliary verification condition, and based on the verification failure reason, determine the adjustment direction and angle adjustment step of the focusing mechanism to perform the first angle adjustment, and repeatedly acquire a new first image captured by the industrial camera. For each auxiliary light source in the auxiliary light source group, based on the new first image, obtain the spot color and area fraction corresponding to the auxiliary light source, until the new first image meets the first end condition. If the first weighted score does not reach the first score threshold, it is determined that the first image has not met the first termination condition, and it is determined whether the current first image is the first first image captured by the industrial camera. If so, the focusing mechanism is controlled to adjust the first angle according to the preset adjustment direction and angle adjustment step size, and the new first image captured by the industrial camera is repeatedly acquired. For each auxiliary light source in the auxiliary light source group, the step of obtaining the spot color and area fraction corresponding to the auxiliary light source based on the new first image is repeated until the new first image reaches the first termination condition. If not, then based on the first weighted score and the second weighted score, obtain the score change trend. The second weighted score is the weighted area fraction of the point light source calculated based on the first image acquired at the previous angle of the focusing mechanism. Based on the score change trend, determine the adjustment direction and angle adjustment step size of the focusing mechanism to perform the first angle adjustment, and repeatedly acquire the new first image acquired by the industrial camera. For each auxiliary light source in the auxiliary light source group, based on the new first image, obtain the spot color and area fraction corresponding to the auxiliary light source, until the new first image reaches the first termination condition.
3. The method according to claim 2, characterized in that, The verification of whether the light spot state of the surface light source meets the auxiliary verification conditions includes: Based on the first image, identify the intersection regions between the light spots of the multiple surface light sources; Based on the image parameters of the intersection region, it is determined whether the intersection region meets the preset evaluation conditions. The image parameters include at least one of saturation, shape regularity, and color matching degree with the preset expected mixed color. The area fractions corresponding to each of the surface light sources are weighted and calculated to obtain a third weighted score. If the third weighted score reaches the second score threshold, and the light spots of each of the surface light sources are separated from each other, and the intersection region satisfies the evaluation condition, then it is determined that the light spot state of each of the surface light sources meets the auxiliary verification condition.
4. The method according to claim 2, characterized in that, After the first image reaches the first termination condition, the process further includes: Based on the first image, obtain the auxiliary coordinates corresponding to each auxiliary light source, and based on each of the auxiliary coordinates, determine the theoretical center coordinates corresponding to the focusing background plate; Based on the current light source focus and corresponding light source confidence, the current search radius is determined from a predefined lookup table, and the search area is obtained based on the theoretical center coordinates and the current search radius; Based on the search area, the matching positions corresponding to multiple feature points in the second image are obtained; the feature points are specific patterns predefined on the focus background plate. Based on each of the matching positions, the actual center coordinates corresponding to the focused background in the second image are obtained, and the sharpness is calculated based on the actual center coordinates.
5. The method according to claim 4, characterized in that, The step of acquiring the second image captured by the industrial camera and determining whether the second image meets the preset second termination condition includes: Based on the actual length of the focusing background plate, the horizontal field of view and camera pixels of the industrial camera, the theoretical pixels corresponding to the focusing background plate are obtained. Based on the theoretical pixels and the actual center coordinates, the target region is obtained; Based on the target region, the second image is cropped to obtain the cropped focus pattern; Based on a preset sharpness evaluation function, the sharpness score corresponding to the focused pattern is calculated, and it is determined whether the sharpness score reaches the sharpness threshold. If yes, the second image meets the second termination condition; otherwise, the second image does not meet the second termination condition.
6. The method according to claim 5, characterized in that, The second angle adjustment of the focusing mechanism includes: Based on the current light source focus and corresponding light source confidence, the initial step size for the second angle adjustment is determined from a predefined step size mapping table; the step size mapping table defines the correspondence between different light source confidence intervals and the initial step size, wherein the higher the light source confidence, the smaller the initial step size; After adjusting the second angle based on the initial step size, a new sharpness score is calculated based on the newly acquired second image; Based on the historical focus ring angle, historical sharpness score, and the new sharpness score, update the sharpness focus ring angle curve and extract the current curve features; Based on the current curve characteristics, the step size of the second angle adjustment is dynamically adjusted for the next adjustment.
7. The method according to claim 1, characterized in that, Before acquiring the first image captured by the industrial camera and determining whether the first image has reached a preset first termination condition, the method further includes: The auxiliary light source group is controlled to be lit at the current operating parameters, and the industrial camera is controlled to acquire preview images; the operating parameters include at least one of brightness and color temperature; Identify and extract the spot areas of each auxiliary light source from the preview image; For each spot region, calculate multiple image quality evaluation sub-scores corresponding to that spot region, wherein the image quality evaluation sub-scores include at least a shape sub-score for characterizing the regularity of the spot shape and a sharpness sub-score for characterizing the sharpness of the spot edge; A comprehensive quality score is obtained by fusing and calculating the scores of each of the image quality evaluation sub-scores. Determine whether the overall quality score meets the preset optimization convergence condition; If the conditions are met, the current working parameters are determined as the optimal working parameters, and the process proceeds to the step of acquiring the first image captured by the industrial camera. If the conditions are not met, new operating parameters are generated based on a preset optimization algorithm, and the current operating parameters of the auxiliary light source group are updated. The step of controlling the auxiliary light source group to light up with the current operating parameters is repeated until the optimal operating parameters are obtained.
8. A focusing control device for an industrial camera, characterized in that, include: The first image judgment module is used to acquire the first image captured by the industrial camera and determine whether the first image has reached the preset first end condition. The first image includes an image corresponding to an auxiliary light source group, which includes multiple point light sources and multiple surface light sources. The multiple point light sources have different colors, and the multiple surface light sources have different colors. The distance between any two surface light sources is smaller than the distance between any two point light sources. The first adjustment module is used to adjust the first angle of the focusing mechanism when the first image has not reached the first end condition, and repeatedly execute the step of acquiring a new first image based on the industrial camera and determining whether the first end condition has been reached, until the new first image reaches the first end condition. The second image judgment module is used to acquire the second image captured by the industrial camera when the first image reaches the first ending condition, and to determine whether the second image reaches the preset second ending condition; the second image is the image corresponding to the focused background board; the second ending condition is that the clarity of the focused background board in the second image reaches a clarity threshold. The second adjustment module is used to adjust the focusing mechanism at a second angle when the second image has not reached the second end condition, and repeatedly execute the step of determining whether the second end condition has been reached based on the acquisition of a new second image by the industrial camera, until the new second image reaches the second end condition. The determination completion module is used to enable the industrial camera to complete automatic focusing control when the second image reaches the second termination condition.
9. An electronic device, characterized in that, It includes a processor and a memory, wherein the processor is coupled to the memory; The processor is configured to execute a computer program stored in the memory to cause the electronic device to perform the method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, It includes a computer program or instructions that, when run on a computer, cause the computer to perform the method as described in any one of claims 1 to 7.