Method for obtaining centroid of multi-line light spot, focusing method, device and computing equipment
By employing a multi-line spot centroid acquisition method and utilizing equidistant parallel beams and sliding window technology, the problem of inaccurate spot centroid calculation was solved, achieving high-precision and stable focusing effects, which are suitable for industrial inspection and microscopic observation.
Patent Information
- Application Number
- CN202511811253.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-03
- Publication Date
- 2026-02-24
- Estimated Expiration
- 2045-12-03
AI Technical Summary
When dealing with complex surfaces, traditional triangular laser focusing technology is susceptible to stray light and noise interference in the calculation of the spot centroid, resulting in inaccurate centroid calculation and affecting focusing accuracy.
A multi-line spot centroid acquisition method is adopted, which forms multi-line spots by equal-spaced parallel linear beams. Combined with sliding window and peak detection, the candidate regions and centroids of the spots are calculated, and stable target centroids are selected.
It improves the accuracy and stability of spot centroid calculation, significantly enhancing the accuracy and stability of the focusing system, and is suitable for high-precision scenarios such as industrial inspection and microscopic observation.
Smart Images

Figure CN121262465B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of triangular laser focusing technology, specifically relating to a method for obtaining the centroid of a multi-line spot, a focusing method, a device, and a computing device. Background Technology
[0002] Traditional focusing techniques have limitations in certain scenarios. When focusing depends on the contrast of light and dark in the image texture, triangular laser focusing does not depend on the texture of the object itself and is not affected by the intensity of ambient light. It is widely used in cameras, industrial inspection, robot vision and other scenarios.
[0003] In the field of microscopic observation, the focusing system includes: a laser 1, a CMOS camera 2, and a microscopic device 3, such as... Figure 1 As shown, laser 1 emits a laser beam to the object being observed, and CMOS camera 2 receives the reflected light spot image. If the object being observed is out of focus, the light spot obtained by the CMOS camera will be offset. Based on this, the amount of defocus of the object being observed is measured, and the focusing axis Z is driven to focus.
[0004] Among these steps, the calculation of the spot centroid is a crucial intermediate step connecting the spot image and the defocusing amount, and its accuracy plays a decisive role in the performance of the entire focusing system. Existing triangular laser focusing processes the entire spot image to obtain the spot offset. However, the calculation of the centroid can be affected by interference from surrounding stray light or noise, and may also be influenced by the sample, resulting in uneven spot shape and thus inaccurate centroid calculation.
[0005] like Figure 2 , Figure 3 As shown, when the surface of the observed object is uneven or has a certain reflectivity, it can cause the light spot to be stretched, bent, uneven in intensity, broken, and multiple reflected light spots to exist on the CMOS camera. This can lead to problems such as unstable extraction of the center point of spot or line spot and focus algorithm defocusing. Summary of the Invention
[0006] To address the aforementioned technical problems, this invention proposes a method for obtaining the centroid of a multi-line light spot, a focusing method, an apparatus, and a computing device.
[0007] To achieve the above objectives, the technical solution of the present invention is as follows:
[0008] In a first aspect, the present invention discloses a method for obtaining the centroid of a multi-line light spot, comprising:
[0009] Step S1: Acquire the original image of the multi-line light spot, which is formed by multiple parallel linear beams of light with equal spacing, after being reflected by the surface of the observed object;
[0010] Step S2: Process the pixel values of the original image to obtain the enhanced image;
[0011] Step S3: Calculate the sum of row pixels for each row along the length of the multi-line spot in the enhanced image, and construct a first dataset containing the index of each row and the corresponding sum of row pixels;
[0012] Where: row pixel sum refers to the sum of the gray values of all pixels in a single row;
[0013] Step S4: Based on a predefined sliding window, perform sliding summation on the row pixels and row-by-row pixels in the first dataset according to the size of the sliding window, and construct a second dataset containing the starting row index of the sliding window and the sum of the row pixels and corresponding row pixels within the sliding window;
[0014] Step S5: Perform peak detection on the row pixels and sums in the second dataset by finding local maxima, obtain multiple candidate peaks and their corresponding sliding window starting row indices, and form a peak set;
[0015] Wherein: the search range for the local maximum value is defined by the size of the neighborhood window;
[0016] Step S6: Select the top N peaks with the largest values in the peak set, and determine the candidate spot region corresponding to each peak based on the starting row index and sliding window size of the sliding window corresponding to each selected peak.
[0017] Step S7: Calculate the centroid of each candidate region of the light spot to obtain multiple candidate centroids;
[0018] Step S8: Sort multiple candidate centroids by numerical value, calculate the distance between adjacent candidate centroids, and filter out multiple target centroids whose distance difference is less than a preset threshold and satisfy the numerical increasing / decreasing order;
[0019] Step S9: Determine the final centroid of the multi-line light spot based on multiple target centroids.
[0020] Based on the above technical solution, the following improvements can be made:
[0021] As a preferred embodiment, step S2 includes the following:
[0022] If the original image is a color image, the enhanced image is obtained using the following methods;
[0023] The pixel value of each pixel in the enhanced image is the sum of the R, G, and B channel pixel values of the corresponding pixel in the original image;
[0024] If the original image is a grayscale image, the enhanced image can be obtained using the following method;
[0025] For pixels whose grayscale values are outside the preset range, their original grayscale values are retained;
[0026] For pixels whose grayscale values are within a preset range, their grayscale values are multiplied by a coefficient greater than 1.
[0027] As a preferred option, step S5 specifically includes:
[0028] Peak detection is performed on the row pixels and sums in the second dataset. All pixels and sums that meet the preset peak conditions and their corresponding sliding window starting row indices are extracted to form a peak set.
[0029] The preset peak condition is: if the sum of the pixel values of a row corresponding to a certain starting row index is greater than the sum of the pixel values of the rows corresponding to a preset number of adjacent starting row indices, then the sum of the pixel values of that row is the peak value.
[0030] Secondly, the present invention discloses a focusing method, including a calibration process and a focusing process;
[0031] The calibration process includes:
[0032] The control drive mechanism creates multiple different relative defocus positions between the observed object and the imaging system;
[0033] At each relative defocus position, the original image of the multi-line light spot, which consists of multiple parallel linear beams of light projected onto the observed object and acquired by the imaging system, is obtained.
[0034] Using any of the above methods for obtaining the centroid of a multi-line spot, calculate the centroid of the spot corresponding to each original image;
[0035] Based on multiple relative defocus positions and their corresponding spot centroids, a calibration function relationship between the defocus amount and the spot centroid is established by fitting.
[0036] The focusing process includes:
[0037] Acquire the original image of the multi-line light spot, which is formed by multiple parallel line beams of light with equal spacing projected onto the observed object and acquired by the imaging system in the current state.
[0038] Using any of the above methods for obtaining the centroid of a multi-line spot, calculate the centroid of the original image in the current state;
[0039] Substitute the calculated current spot centroid into the calibration function to calculate the current defocus amount;
[0040] Based on the calculated current defocus amount, the drive mechanism is controlled to change the relative distance between the observed object and the imaging system, thereby achieving focusing.
[0041] Thirdly, the present invention discloses a device for acquiring the centroid of a multi-line light spot, comprising:
[0042] The image acquisition module is used to acquire the original image of the multi-line light spot, which is formed by multiple parallel linear light beams with equal spacing, after being reflected by the surface of the observed object.
[0043] The enhancement processing module is used to process the pixel values of the original image to obtain an enhanced image;
[0044] The first dataset construction module is used to calculate the sum of row pixels for each row along the length direction of the multi-line spot in the enhanced image, and to construct the first dataset containing the index of each row and the corresponding sum of row pixels;
[0045] Where: row pixel sum refers to the sum of the gray values of all pixels in a single row;
[0046] The second dataset construction module is used to perform sliding summation on the row pixels and row by row in the first dataset based on a predefined sliding window, according to the size of the sliding window, to construct a second dataset containing the starting row index of the sliding window and the sum of the row pixels and corresponding row pixels in the sliding window.
[0047] The peak lookup module is used to perform peak detection on the row pixels and sum of the second dataset by finding the local maximum value, and obtain multiple candidate peaks and their corresponding sliding window starting row indices to form a peak set.
[0048] Wherein: the search range for the local maximum value is defined by the size of the neighborhood window;
[0049] The candidate region determination module is used to select the top N peaks with the largest values in the peak set, and determine the candidate region of the light spot corresponding to each peak according to the starting row index and the size of the sliding window corresponding to each selected peak.
[0050] The candidate centroid calculation module is used to calculate the centroid of each candidate spot region, resulting in multiple candidate centroids.
[0051] The centroid filtering module is used to sort multiple candidate centroids by numerical value, calculate the distance between adjacent candidate centroids, and filter out multiple target centroids whose distance difference is less than a preset threshold and which meet the numerical increasing / decreasing order.
[0052] The final centroid calculation module is used to determine the final centroid of a multi-line light spot based on multiple target centroids.
[0053] As a preferred embodiment, the enhanced processing module includes:
[0054] The color image processing unit is used to obtain an enhanced image when the original image is a color image by the following methods;
[0055] The pixel value of each pixel in the enhanced image is the sum of the R, G, and B channel pixel values of the corresponding pixel in the original image;
[0056] The grayscale image processing unit is used to obtain an enhanced image by means of the following method when the original image is a grayscale image;
[0057] For pixels whose grayscale values are outside the preset range, their original grayscale values are retained;
[0058] For pixels whose grayscale values are within a preset range, their grayscale values are multiplied by a coefficient greater than 1.
[0059] As a preferred approach, the peak lookup module is used to perform the following specific methods:
[0060] Peak detection is performed on the row pixels and sums in the second dataset. All pixels and sums that meet the preset peak conditions and their corresponding sliding window starting row indices are extracted to form a peak set.
[0061] The preset peak condition is: if the sum of the pixel values of a row corresponding to a certain starting row index is greater than the sum of the pixel values of the rows corresponding to a preset number of adjacent starting row indices, then the sum of the pixel values of that row is the peak value.
[0062] Fourthly, the present invention discloses a focusing device, comprising:
[0063] The calibration module is used to execute the calibration process, including:
[0064] The control drive mechanism creates multiple different relative defocus positions between the observed object and the imaging system;
[0065] At each relative defocus position, the original image of the multi-line light spot, which consists of multiple parallel linear beams of light projected onto the observed object and acquired by the imaging system, is obtained.
[0066] Using any of the above-mentioned multi-line spot centroid acquisition devices, calculate the spot centroid corresponding to each original image;
[0067] Based on multiple relative defocus positions and their corresponding spot centroids, a calibration function relationship between the defocus amount and the spot centroid is established by fitting.
[0068] The focusing module, used to execute the focusing process, includes:
[0069] Acquire the original image of the multi-line light spot, which is formed by multiple parallel line beams of light with equal spacing projected onto the observed object and acquired by the imaging system in the current state.
[0070] Using any of the above-mentioned multi-line spot centroid acquisition devices, calculate the spot centroid of the original image in the current state;
[0071] Substitute the calculated current spot centroid into the calibration function to calculate the current defocus amount;
[0072] Based on the calculated current defocus amount, the drive mechanism is controlled to change the relative distance between the observed object and the imaging system, thereby achieving focusing.
[0073] Fifthly, the present invention discloses a computing device, comprising:
[0074] One or more processors;
[0075] Memory;
[0076] And one or more programs, wherein the one or more programs are stored in memory and configured to be executed by one or more processors, the one or more programs including the above-described method for acquiring the centroid of any of the multi-line spot, and / or instructions for the above-described focusing method.
[0077] In a sixth aspect, the present invention discloses a storage medium storing one or more computer-readable programs, the one or more programs including instructions adapted to be loaded by a memory and execute the above-described method for acquiring the centroid of any of the multi-line light spots, and / or the above-described focusing method.
[0078] This invention discloses a method, focusing method, apparatus, and computing device for obtaining the centroid of a multi-line light spot, which has the following beneficial effects:
[0079] First, the present invention uses a multi-line light spot composed of multiple equally spaced parallel linear light beams as the measurement benchmark. Compared with the traditional single-line light spot, it provides more feature information and spatial reference. It not only provides rich feature points for subsequent processing, but also provides reliable geometric constraints for light spot recognition through the equal spacing characteristic, laying the foundation for high-precision centroid calculation.
[0080] Secondly, this invention employs an adaptive pixel value enhancement strategy, optimizing for both color and grayscale images separately, effectively balancing the intensity distribution of light spots. By calculating pixels in the Y direction and combining this with sliding window processing, the complex problem of light spot localization is transformed into a stable peak detection problem, which can accurately locate the main region of each light spot, effectively suppress noise interference, and provide high-quality input for subsequent calculations.
[0081] Third, in practical applications, this invention addresses issues such as light spot distortion, breakage, or the generation of false light spots caused by uneven sample surfaces or high reflectivity. It creatively utilizes known light spot spacing characteristics and, by calculating candidate centroid spacing and performing pattern matching, can intelligently distinguish between real measurement light spots and interference signals.
[0082] Fourth, after accurately selecting the target centroid, the present invention calculates the final centroid by fusing data from multiple target centroids, making full use of the redundant information of the multi-line spot, effectively smoothing the measurement fluctuations caused by local surface undulations, significantly improving the stability of the final output result, and enabling the focusing system to maintain a highly consistent performance under various working conditions.
[0083] Fifth, based on the precise multi-line spot centroid acquisition technology, the calibration process in the focusing method or device can establish a more accurate functional relationship between the defocus amount and the centroid. In the focusing process, through accurate calculation of the current centroid and defocus amount derivation, the mechanism can be driven to adjust the relative distance between the observed object and the imaging system more precisely, which significantly improves the focusing accuracy and stability, and is especially suitable for scenarios with high accuracy requirements such as industrial inspection and microscopic observation. Attached Figure Description
[0084] To more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings used in the embodiments will be briefly introduced below. It should be understood that the following drawings only show some embodiments of the present invention and should not be regarded as a limitation on the scope. For those skilled in the art, other related drawings can be obtained based on these drawings without creative effort.
[0085] Figure 1 This is a schematic diagram of a conventional triangular laser focusing system.
[0086] Figure 2 This is a light spot diagram of the observed object's surface when it reflects light, as shown in existing technologies.
[0087] Figure 3 This is a light spot diagram of the existing technology when the surface of the observed object is uneven.
[0088] Figure 4 This is a flowchart illustrating a method for obtaining the centroid of a multi-line light spot, as provided in an embodiment of the present invention.
[0089] Figure 5 This is a schematic diagram of a triangular laser focusing system provided in an embodiment of the present invention.
[0090] Figure 6 This is a schematic diagram of a three-line film provided in an embodiment of the present invention.
[0091] Figure 7 A flowchart of a focusing method provided in an embodiment of the present invention.
[0092] Among them: 1-laser, 2-CMOS camera, 3-microscopic device, 4-three-line film. Detailed Implementation
[0093] The preferred embodiments of the present invention will now be described in detail with reference to the accompanying drawings.
[0094] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0095] Using ordinal numbers such as “first,” “second,” “third,” etc. to describe ordinary objects merely indicates different instances of similar objects and is not intended to imply that the objects being described must have a given order in time, space, sequence, or any other way.
[0096] Furthermore, the expression "includes" is an "open-ended" expression, which means only that there is a corresponding component or step, and should not be interpreted as excluding additional components or steps.
[0097] To achieve the objectives of this invention, in some embodiments of the method for obtaining the centroid of a multi-line spot, such as... Figure 4 As shown, the acquisition method includes the following steps:
[0098] Step S101: Acquire the original image of the multi-line light spot, which is formed by multiple parallel linear beams of light with equal spacing, after being reflected by the surface of the observed object;
[0099] Step S102: Perform pixel value processing on the original image to obtain the enhanced image;
[0100] Step S103: Calculate the sum of row pixels for each row along the length of the multi-line spot in the enhanced image, and construct a first dataset containing the index of each row and the corresponding sum of row pixels;
[0101] Where: row pixel sum refers to the sum of the gray values of all pixels in a single row;
[0102] Step S104: Based on a predefined sliding window, perform sliding summation on the row pixels and row-by-row pixels in the first dataset according to the size of the sliding window, and construct a second dataset containing the starting row index of the sliding window and the sum of the row pixels and corresponding row pixels in the sliding window;
[0103] Step S105: Perform peak detection on the row pixels and sums in the second dataset by finding local maxima, obtain multiple candidate peaks and their corresponding sliding window starting row indices, and form a peak set;
[0104] Wherein: the search range for the local maximum value is defined by the size of the neighborhood window;
[0105] Step S106: Select the top N peaks with the largest values in the peak set, and determine the candidate area of the light spot corresponding to each peak according to the starting row index and the size of the sliding window corresponding to each selected peak;
[0106] Step S107: Calculate the centroid of each candidate region of the light spot to obtain multiple candidate centroids;
[0107] Step S108: Sort multiple candidate centroids by numerical value, calculate the distance between adjacent candidate centroids, and filter out multiple target centroids whose distance difference is less than a preset threshold and satisfy the numerical increasing / decreasing order.
[0108] Step S109: Determine the final centroid of the multi-line light spot based on multiple target centroids.
[0109] This embodiment uses a triangular laser focusing system to acquire a three-line spot image as an example to explain in detail the process of obtaining the spot centroid. The specific steps are as follows:
[0110] Step S101 is used for image acquisition.
[0111] like Figure 5 As shown, the original image is captured by the CMOS camera 2 and formed by the reflection after being projected onto the surface of the observed object by a linear laser 1 and a three-line film 4. The three-line film has three hollowed-out, equally spaced parallel lines.
[0112] like Figure 6 As shown, the lines on the film are hollowed out and filled with black. The film has lines with the same spacing and the same interval between the lines, so that a single beam of light becomes a three-line light spot after passing through the film.
[0113] In this embodiment, a simple structure of adding a multi-line film in front of an existing laser is used to transform a linear laser spot into a multi-line laser spot, eliminating the need to purchase a dedicated multi-line laser and significantly reducing hardware costs. However, it is worth noting that in other embodiments, a multi-line laser source or other methods can also be used to achieve this.
[0114] Step S102 is used to enhance the original image.
[0115] If the original image is a color image, the enhanced image is obtained using the following methods;
[0116] The pixel value of each pixel in the enhanced image is the sum of the R, G, and B channel pixel values of the corresponding pixel in the original image;
[0117] If the original image is a grayscale image, the enhanced image can be obtained using the following method;
[0118] For pixels whose grayscale values are outside the preset range, their original grayscale values are retained;
[0119] For pixels whose grayscale values are within a preset range, their grayscale values are multiplied by a coefficient greater than 1.
[0120] Specifically, as follows:
[0121] If the original image is a color image, the pixel values of the three channels—red (R), green (G), and blue (B)—are taken, and the pixel value of each pixel in the enhanced image is the sum of the three channel pixel values of the corresponding pixel in the original image, that is:
[0122] ;
[0123] The brightness of all channels is preserved. Even when the sample is reflective, the total brightness of the reflected spot will be lower than the brightness of the laser beam spot received by the CMOS camera. In other words, the sum of the three channels significantly improves the recognizability of the spot.
[0124] If the original image is a grayscale image, the pixel value weights in the brightness-dominant enhancement region of the grayscale data are retained within the range of 40~160. This processing can reduce the processing of background noise and the influence of bright areas, and can increase the grayscale difference of pixels in this range to facilitate the subsequent acquisition of spot areas and calculation of centroid.
[0125] Right now: ;
[0126] in: This represents the grayscale value of the corresponding pixel.
[0127] Step S103 is used to construct the first dataset S1.
[0128] Calculate the sum of row pixels for each row in the enhanced image along the length of the multi-line spot (assuming it's the X-axis). Let the total number of rows in the enhanced image be h, and the total number of columns be w. The calculation formula is:
[0129] ;
[0130] in: To enhance the pixel value of the pixel located in the i-th row and j-th column of the image.
[0131] Find the index i of all rows and its corresponding index. The first dataset S1 is composed of: i, .
[0132] Step S104 is used to construct the second dataset S2.
[0133] Define a predefined sliding window size, which is set based on the estimated height of the light spot in the image and is adjustable.
[0134] Then, a sliding window summation operation is performed on the first dataset S1 row by row.
[0135] The sliding window starts from row 0 and slides down one row at a time, calculating the sum of the row pixel sums for each of the window's consecutive rows. For a window starting at index ii (where ii ranges from 0 to h-window), the total row pixel sum is calculated as follows. The calculation formula is:
[0136] ;
[0137] Calculate the starting row index ii of all windows and their corresponding... The second dataset S2 is formed, namely: , .
[0138] Step S105 is used to form a peak set.
[0139] Peak detection is performed on the row pixels and sums in the second dataset S2. All pixels and sums that meet the preset peak conditions and their corresponding sliding window starting row indices are extracted to form a peak set.
[0140] The preset peak condition is: if the sum of the pixel values of a row corresponding to a certain starting row index is greater than the sum of the pixel values of the rows corresponding to a preset number of adjacent starting row indices, then the sum of the pixel values of that row is the peak value.
[0141] For example: Set the size range of the neighborhood window wn to 1~10, that is... The peak value is determined by meeting the conditions.
[0142] Find the starting row index ii of all windows that meet the above conditions and their corresponding... The set of peaks .
[0143] Step S106 is used to select the peak value and determine the candidate region of the light spot.
[0144] Select the top 5 peak values with the largest values in the peak set, and determine the candidate spot region corresponding to each peak value based on the starting row index and the size of the sliding window corresponding to each selected peak value.
[0145] Specifically, the top 5 peak values can be obtained, but are not limited to, through the following methods:
[0146] Method 1: Sort the peaks in the peak set from largest to smallest by row pixel sum, and select the top 5 peaks.
[0147] Method 2: Create an array of size 5 and initialize it with the minimum value. Iterate through all peak values. If the current value is greater than the minimum value in the array, replace the minimum value. After iteration, the array will contain the 5 largest peak values.
[0148] After obtaining the top 5 peak values with the largest values, the corresponding candidate light spot area is determined based on the starting row index ii and the sliding window size window of each peak value. The area is the range from row ii to row ii+window in the image.
[0149] The above method can effectively locate the three-line light spot and the possible reflection interference area, laying the foundation for subsequent accurate calculation of the centroid.
[0150] Step S107 is used to calculate the centroid of each candidate area of the light spot to obtain multiple candidate centroids.
[0151] For the five candidate light spot regions (areas) obtained above, their centroids are calculated using the gray-scale centroid method to obtain the centroid set (mcs).
[0152] .
[0153] in: Let be the centroid of the m-th candidate region area.
[0154] Step S108 is used to screen the target centroid.
[0155] The five candidate centroids are sorted by numerical value, the distance between adjacent candidate centroids is calculated, and three target centroids with a distance difference less than a preset threshold and satisfying the numerical increasing / decreasing order are selected.
[0156] Specifically:
[0157] First, the candidate centroids in the centroid set mcs are sorted in ascending order of their values using bubble sort or other methods to obtain the sorted centroid set mccs.
[0158] Next, calculate the distance between any two centroids in the centroid set mccs.
[0159] For example: to obtain the set of distances d0, d1, d2, d3, etc., between each centroid and other centroids:
[0160]
[0161]
[0162]
[0163]
[0164] Finally, determine whether the centroid spacing is the same and whether the sorting requirements are met.
[0165] That is, if the difference between the distances d between the centroids is less than 5 pixels (i.e., a preset threshold), and the order of the centroids meets the requirements, then 3 target centroids are obtained. , , .
[0166] Example 1:
[0167] ;
[0168] ;
[0169] when When the difference is less than 5 pixels, and simultaneously satisfies .
[0170] Therefore, the target centroid of the three-line light spot is .
[0171] Example 2:
[0172] ;
[0173] ;
[0174] when If the difference is not less than 5 pixels, continue the judgment. The difference is less than 5, and at the same time .
[0175] Therefore, the target centroid of the three-line light spot is .
[0176] Step S109 determines the final centroid of the multi-line spot by calculating the average of the three target centroids. Specifically:
[0177] .
[0178] However, it is worth noting that the method for obtaining the final centroid of the multi-line spot is not limited to the above arithmetic mean; it can also be a weighted average, median, or other data fusion methods.
[0179] like Figure 7 As shown, in some other embodiments, the present invention discloses a focusing method based on a spot centroid acquisition method, including a calibration process and a focusing process.
[0180] The calibration process includes:
[0181] The control drive mechanism creates multiple different relative defocus positions between the observed object and the imaging system;
[0182] At each relative defocus position, the original image of the multi-line light spot, which is projected onto the observed object by a single-line laser in conjunction with a multi-line film and acquired by the imaging system, is obtained.
[0183] Using any of the above methods for obtaining the centroid of a multi-line spot, calculate the centroid of the spot corresponding to each original image;
[0184] Based on multiple relative defocus positions and their corresponding spot centroids, a calibration function relationship between the defocus amount and the spot centroid is established by fitting.
[0185] The focusing process includes:
[0186] Acquire the original image of the multi-line light spot projected onto the observed object by a single-line laser and multi-line film, and acquired by the imaging system in the current state;
[0187] Using any of the above methods for obtaining the centroid of a multi-line spot, calculate the centroid of the original image in the current state;
[0188] Substitute the calculated current spot centroid into the calibration function to calculate the current defocus amount;
[0189] Based on the calculated current defocus amount, the drive mechanism is controlled to change the relative distance between the observed object and the imaging system, thereby achieving focusing.
[0190] The focusing method described above is explained in detail below.
[0191] The calibration process is as follows:
[0192] 1) Define the current position of the drive mechanism (such as a Z-axis linear motor) as the zero point, which is the theoretically optimal focusing surface position.
[0193] 2) Control the drive mechanism to move the observed object (or imaging system) above the focal plane, and set the starting upper travel position and the ending lower travel position, such as... etc., where 0um is the focal plane position;
[0194] 3) Control the drive mechanism to move from -200µm above the focal plane, in steps of 2µm (or 5µm, etc.), to +200µm below the focal plane. At each defocus position... (q=1,2,...,n), execute steps S101 to S109 above to obtain the corresponding centroid positions of the multi-line light spots. .
[0195] 4) Fit the collected defocus positions to the centroid using the least squares method to obtain linear parameters k1 and k2. The final linear function relating the defocus positions to the centroid is: Specific calculations:
[0196] ;
[0197] In the example above, the upper stroke is -200µm, the lower stroke is 200µm, and the step size is 2µm. Starting from the upper stroke, the centroid of the linear spot image is obtained with a step size of 2µm. The total number of corresponding defocus positions and centroids, n, is 200. The linear function is calculated as follows:
[0198] Obtain the values of k1 and k2.
[0199] The focusing process is as follows:
[0200] 1) When it is necessary to focus on the object under test at an unknown location, acquire the original image of the multi-line spot in the current state.
[0201] 2) Perform steps S101 to S109 above to calculate the centroid of the current image spot. .
[0202] 3) Set the current centroid Substitute into the calibration function: Calculate the current out-of-focus position .
[0203] 4) Based on the calculated defocus position The symbols (positive and negative represent the defocus direction) control the drive mechanism to move the corresponding distance, so that the relative distance between the observed object and the imaging system returns to the focal plane position, thus completing fast and accurate autofocus.
[0204] This invention significantly improves the calculation accuracy and robustness of the spot centroid through unique image processing and region localization methods, thereby achieving high-performance autofocus.
[0205] In other embodiments, the present invention discloses a device for acquiring the centroid of a multi-line light spot, comprising:
[0206] The image acquisition module is used to acquire the original image of the multi-line light spot, which is formed by multiple parallel linear light beams with equal spacing, after being reflected by the surface of the observed object.
[0207] The enhancement processing module is used to process the pixel values of the original image to obtain an enhanced image;
[0208] The first dataset construction module is used to calculate the sum of row pixels for each row along the length direction of the multi-line spot in the enhanced image, and to construct the first dataset containing the index of each row and the corresponding sum of row pixels;
[0209] Where: row pixel sum refers to the sum of the gray values of all pixels in a single row;
[0210] The second dataset construction module is used to perform sliding summation on the row pixels and row by row in the first dataset based on a predefined sliding window, according to the size of the sliding window, to construct a second dataset containing the starting row index of the sliding window and the sum of the row pixels and corresponding row pixels in the sliding window.
[0211] The peak lookup module is used to perform peak detection on the row pixels and sum of the second dataset by finding the local maximum value, and obtain multiple candidate peaks and their corresponding sliding window starting row indices to form a peak set.
[0212] Wherein: the search range for the local maximum value is defined by the size of the neighborhood window;
[0213] The candidate region determination module is used to select the top N peaks with the largest values in the peak set, and determine the candidate region of the light spot corresponding to each peak according to the starting row index and the size of the sliding window corresponding to each selected peak.
[0214] The candidate centroid calculation module is used to calculate the centroid of each candidate spot region, resulting in multiple candidate centroids.
[0215] The centroid filtering module is used to sort multiple candidate centroids by numerical value, calculate the distance between adjacent candidate centroids, and filter out multiple target centroids whose distance difference is less than a preset threshold and which meet the numerical increasing / decreasing order.
[0216] The final centroid calculation module is used to determine the final centroid of a multi-line light spot based on multiple target centroids.
[0217] Furthermore, the enhanced processing module includes:
[0218] The color image processing unit is used to obtain an enhanced image when the original image is a color image by the following methods;
[0219] The pixel value of each pixel in the enhanced image is the sum of the R, G, and B channel pixel values of the corresponding pixel in the original image;
[0220] The grayscale image processing unit is used to obtain an enhanced image by means of the following method when the original image is a grayscale image;
[0221] For pixels whose grayscale values are outside the preset range, their original grayscale values are retained;
[0222] For pixels whose grayscale values are within a preset range, their grayscale values are multiplied by a coefficient greater than 1.
[0223] Furthermore, the peak lookup module is used to execute the following specific methods:
[0224] Peak detection is performed on the row pixels and sums in the second dataset. All pixels and sums that meet the preset peak conditions and their corresponding sliding window starting row indices are extracted to form a peak set.
[0225] The preset peak condition is: if the sum of the pixel values of a row corresponding to a certain starting row index is greater than the sum of the pixel values of the rows corresponding to a preset number of adjacent starting row indices, then the sum of the pixel values of that row is the peak value.
[0226] In other embodiments, the present invention discloses a focusing device, comprising:
[0227] The calibration module is used to execute the calibration process, including:
[0228] The control drive mechanism creates multiple different relative defocus positions between the observed object and the imaging system;
[0229] At each relative defocus position, the original image of the multi-line light spot, which consists of multiple parallel linear beams of light projected onto the observed object and acquired by the imaging system, is obtained.
[0230] Using any of the above-mentioned multi-line spot centroid acquisition devices, calculate the spot centroid corresponding to each original image;
[0231] Based on multiple relative defocus positions and their corresponding spot centroids, a calibration function relationship between the defocus amount and the spot centroid is established by fitting.
[0232] The focusing module, used to execute the focusing process, includes:
[0233] Acquire the original image of the multi-line light spot, which is formed by multiple parallel line beams of light with equal spacing projected onto the observed object and acquired by the imaging system in the current state.
[0234] Using any of the above-mentioned multi-line spot centroid acquisition devices, calculate the spot centroid of the original image in the current state;
[0235] Substitute the calculated current spot centroid into the calibration function to calculate the current defocus amount;
[0236] Based on the calculated current defocus amount, the drive mechanism is controlled to change the relative distance between the observed object and the imaging system, thereby achieving focusing.
[0237] Furthermore, it should be noted that the multi-line spot centroid acquisition device provided in the above embodiments is only illustrated by the division of the above functional modules when calculating the spot centroid. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the multi-line spot centroid acquisition device can be divided into different functional modules to complete all or part of the functions described above.
[0238] Furthermore, the embodiments of the multi-line spot centroid acquisition device and the multi-line spot centroid acquisition method provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.
[0239] In other embodiments, the present invention discloses a computing device comprising:
[0240] One or more processors;
[0241] Memory;
[0242] And one or more programs, wherein the one or more programs are stored in memory and configured to be executed by one or more processors, the one or more programs including the above-described method for acquiring the centroid of any of the multi-line spot, and / or instructions for the above-described focusing method.
[0243] In other embodiments, the present invention discloses a storage medium storing one or more computer-readable programs, the programs including instructions adapted to be loaded by a memory and execute any of the above-described methods for acquiring the centroid of a multi-line spot, and / or the above-described focusing methods.
[0244] This invention discloses a method, focusing method, apparatus, and computing device for obtaining the centroid of a multi-line light spot, which has the following beneficial effects:
[0245] First, the present invention uses a multi-line light spot composed of multiple equally spaced parallel linear light beams as the measurement benchmark. Compared with the traditional single-line light spot, it provides more feature information and spatial reference. It not only provides rich feature points for subsequent processing, but also provides reliable geometric constraints for light spot recognition through the equal spacing characteristic, laying the foundation for high-precision centroid calculation.
[0246] Secondly, this invention employs an adaptive pixel value enhancement strategy, optimizing for both color and grayscale images separately, effectively balancing the intensity distribution of light spots. By calculating pixels in the Y direction and combining this with sliding window processing, the complex problem of light spot localization is transformed into a stable peak detection problem, which can accurately locate the main region of each light spot, effectively suppress noise interference, and provide high-quality input for subsequent calculations.
[0247] Third, in practical applications, this invention addresses issues such as light spot distortion, breakage, or the generation of false light spots caused by uneven sample surfaces or high reflectivity. It creatively utilizes known light spot spacing characteristics and, by calculating candidate centroid spacing and performing pattern matching, can intelligently distinguish between real measurement light spots and interference signals.
[0248] Fourth, after accurately selecting the target centroid, the present invention calculates the final centroid by fusing data from multiple target centroids, making full use of the redundant information of the multi-line spot, effectively smoothing the measurement fluctuations caused by local surface undulations, significantly improving the stability of the final output result, and enabling the focusing system to maintain a highly consistent performance under various working conditions.
[0249] Fifth, based on the precise multi-line spot centroid acquisition technology, the calibration process in the focusing method or device can establish a more accurate functional relationship between the defocus amount and the centroid. In the focusing process, through accurate calculation of the current centroid and defocus amount derivation, the mechanism can be driven to adjust the relative distance between the observed object and the imaging system more precisely, which significantly improves the focusing accuracy and stability, and is especially suitable for scenarios with high accuracy requirements such as industrial inspection and microscopic observation.
[0250] The foregoing has shown and described the basic principles, main features, and advantages of the present invention. Those skilled in the art should understand that the present invention is not limited to the above embodiments. The embodiments and descriptions in the specification are merely illustrative of the principles of the present invention. Various changes and modifications can be made to the present invention without departing from its spirit and scope. All such changes and modifications fall within the scope of the present invention as claimed, which is defined by the appended claims and their equivalents.
Claims
1. A method for obtaining the centroid of a multi-line light spot, characterized in that, include: Step S1: Acquire the original image of the multi-line light spot, which is formed by multiple parallel linear beams of light with equal spacing, after being reflected by the surface of the observed object; Step S2: Process the pixel values of the original image to obtain the enhanced image; Step S3: Calculate the sum of row pixels for each row along the length direction of the multi-line spot in the enhanced image, and construct a first dataset containing the index of each row and the corresponding sum of row pixels; Wherein: the sum of row pixels refers to the sum of the gray values of all pixels in a single row; Step S4: Based on a predefined sliding window, perform sliding summation on the row pixels and row-by-row pixels in the first dataset according to the size of the sliding window, and construct a second dataset containing the starting row index of the sliding window and the sum of the row pixels and corresponding row pixels within the sliding window; Step S5: Perform peak detection on the row pixels and sums in the second dataset by finding local maxima, obtain multiple candidate peaks and their corresponding sliding window starting row indices, and form a peak set; Wherein: the search range for the local maximum value is defined by the size of the neighborhood window; Step S6: Select the top N peaks with the largest values in the peak set, and determine the candidate light spot region corresponding to each peak according to the starting row index and sliding window size of the sliding window corresponding to each selected peak; Step S7: Calculate the centroid of each candidate spot region to obtain multiple candidate centroids; Step S8: Sort the multiple candidate centroids according to their numerical values, calculate the distance between adjacent candidate centroids, and filter out multiple target centroids whose distance difference is less than a preset threshold and which satisfy the numerical increasing / decreasing order. Step S9: Determine the final centroid of the multi-line light spot based on the multiple target centroids.
2. The acquisition method according to claim 1, characterized in that, Step S2 includes the following: If the original image is a color image, the enhanced image is obtained through the following method; The pixel value of each pixel in the enhanced image is the sum of the R, G, and B channel pixel values of the corresponding pixel in the original image; If the original image is a grayscale image, the enhanced image is obtained through the following method; For pixels whose grayscale values are outside the preset range, their original grayscale values are retained; For pixels whose grayscale values are within the preset range, their grayscale values are multiplied by a coefficient greater than 1.
3. The acquisition method according to claim 1, characterized in that, Step S5 specifically includes: Peak detection is performed on the row pixels and sums in the second dataset. All pixels and sums that meet the preset peak conditions and their corresponding sliding window starting row indices are extracted to form a peak set. The preset peak condition is as follows: if the sum of the row pixels corresponding to a certain starting row index is greater than the sum of the row pixels corresponding to a preset number of adjacent starting row indices, then the sum of the row pixels is the peak value.
4. A focusing method, characterized in that, This includes the calibration process and the focusing process; The calibration process includes: The control drive mechanism creates multiple different relative defocus positions between the observed object and the imaging system; At each of the aforementioned relative defocus positions, an original image of a multi-line light spot, consisting of multiple parallel linear beams of light projected onto the observed object and acquired by the imaging system, is obtained. Using the method for obtaining the centroid of a multi-line spot as described in any one of claims 1-3, the centroid of the spot corresponding to each of the original images is calculated; Based on the multiple relative defocus positions and their corresponding spot centroids, a calibration function relationship between the defocus amount and the spot centroid is established by fitting. The focusing process includes: Acquire the original image of the multi-line light spot, which is projected onto the observed object by multiple parallel line beams with equal spacing and captured by the imaging system in the current state; Using the method for obtaining the centroid of a multi-line spot as described in any one of claims 1-3, the centroid of the original image in the current state is calculated; Substitute the calculated current spot centroid into the calibration function to calculate the current defocus amount; Based on the calculated current defocus amount, the drive mechanism is controlled to change the relative distance between the observed object and the imaging system, thereby achieving focusing.
5. A device for acquiring the centroid of a multi-line light spot, characterized in that, include: The image acquisition module is used to acquire the original image of the multi-line light spot, which is formed by multiple parallel linear light beams with equal spacing, after being reflected by the surface of the observed object. The enhancement processing module is used to process the pixel values of the original image to obtain an enhanced image; The first dataset construction module is used to calculate the sum of row pixels for each row along the length direction of the multi-line light spot in the enhanced image, and construct a first dataset containing the index of each row and the corresponding sum of row pixels; Wherein: the sum of row pixels refers to the sum of the gray values of all pixels in a single row; The second dataset construction module is used to perform sliding summation on the row pixels and row-by-row of the first dataset based on a predefined sliding window, according to the size of the sliding window, to construct a second dataset containing the starting row index of the sliding window and the sum of the row pixels and the corresponding row pixels within the sliding window. The peak lookup module is used to perform peak detection on the row pixels and sum of the second dataset by finding the local maximum value, and obtain multiple candidate peaks and their corresponding sliding window starting row indices to form a peak set; Wherein: the search range for the local maximum value is defined by the size of the neighborhood window; The candidate region determination module is used to select the top N peaks with the largest values in the peak set, and determine the candidate region of the light spot corresponding to each peak according to the starting row index and the size of the sliding window corresponding to each selected peak. The candidate centroid calculation module is used to calculate the centroid of each of the candidate light spot regions to obtain multiple candidate centroids. The centroid filtering module is used to sort the multiple candidate centroids according to their numerical values, calculate the distance between adjacent candidate centroids, and filter out multiple target centroids whose distance difference is less than a preset threshold and which satisfy the numerical increasing / decreasing order. The final centroid calculation module is used to determine the final centroid of the multi-line light spot based on the multiple target centroids.
6. The acquiring device according to claim 5, characterized in that, The enhancement processing module includes: A color image processing unit is used to obtain an enhanced image by means of the following method when the original image is a color image; The pixel value of each pixel in the enhanced image is the sum of the R, G, and B channel pixel values of the corresponding pixel in the original image; A grayscale image processing unit is used to obtain an enhanced image by the following method when the original image is a grayscale image; For pixels whose grayscale values are outside the preset range, their original grayscale values are retained; For pixels whose grayscale values are within the preset range, their grayscale values are multiplied by a coefficient greater than 1.
7. The acquiring device according to claim 5, characterized in that, The peak lookup module is used to perform the following specific methods: Peak detection is performed on the row pixels and sums in the second dataset. All pixels and sums that meet the preset peak conditions and their corresponding sliding window starting row indices are extracted to form a peak set. The preset peak condition is as follows: if the sum of the row pixels corresponding to a certain starting row index is greater than the sum of the row pixels corresponding to a preset number of adjacent starting row indices, then the sum of the row pixels is the peak value.
8. A focusing device, characterized in that, include: The calibration module is used to execute the calibration process, including: The control drive mechanism creates multiple different relative defocus positions between the observed object and the imaging system; At each of the aforementioned relative defocus positions, an original image of a multi-line light spot, consisting of multiple parallel linear beams of light projected onto the observed object and acquired by the imaging system, is obtained. Using the multi-line spot centroid acquisition device as described in any one of claims 5-7, the spot centroid corresponding to each of the original images is calculated; Based on the multiple relative defocus positions and their corresponding spot centroids, a calibration function relationship between the defocus amount and the spot centroid is established by fitting. The focusing module, used to execute the focusing process, includes: Acquire the original image of the multi-line light spot, which is projected onto the observed object by multiple parallel line beams with equal spacing and captured by the imaging system in the current state; Using the multi-line spot centroid acquisition device as described in any one of claims 5-7, the spot centroid of the original image in the current state is calculated; Substitute the calculated current spot centroid into the calibration function to calculate the current defocus amount; Based on the calculated current defocus amount, the drive mechanism is controlled to change the relative distance between the observed object and the imaging system, thereby achieving focusing.
9. A computing device, characterized in that, include: One or more processors; Memory; And one or more programs, wherein the one or more programs are stored in the memory and configured to be executed by one or more processors, the one or more programs comprising instructions for the method of obtaining the centroid of a multi-line spot as described in any one of claims 1-3, and / or, instructions for the focusing method as described in claim 4.
10. A storage medium, characterized in that, The storage medium stores one or more computer-readable programs, the programs including instructions adapted to be loaded by a memory and executed as described in any one of claims 1-3 for obtaining the centroid of a multi-line spot, and / or as described in claim 4 for focusing.
Citation Information
Patent Citations
Single-target direction vector multi-aperture combined calculation method and device
CN118859101A
Multi-light-spot centroid extraction method and device based on FPGA, medium and product
CN119444844A