CN-121994715-A - Peak wavelength extraction acceleration method based on opencv parallel computation
Abstract
The invention discloses a peak wavelength extraction acceleration method based on opencv parallel computation, which comprises the following steps: the method comprises the steps of firstly collecting a two-dimensional gray level image of a target object through a linear spectrum confocal sensor, then calling an opencv parallel computing frame to build a multi-thread framework, synchronously identifying the maximum gray level value and a corresponding column index of each row of pixels line by line, defining a specific column interval by taking the index as a center, screening effective pixel points according to a preset ratio threshold, finally performing weighted operation on the position information and gray level value of the effective pixel points, and outputting a peak wavelength position parameter. The method adopts a design combining step extraction and parallel calculation, avoids the problem of low efficiency of full data processing through local focusing operation, eliminates singular value interference through effective pixel screening, considers operation speed and extraction precision, meets the requirement of high-speed real-time on-line measurement in industrial production, and is suitable for a peak wavelength extraction scene of a linear spectrum confocal sensor.
Inventors
- Yang Kangyu
- HU YANSONG
- LI MIN
Assignees
- 湖北楚光三维传感技术有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20251231
Claims (10)
- 1. A peak wavelength extraction acceleration method based on opencv parallel calculation is characterized by comprising the following steps of S1, adopting a linear spectrum confocal sensor to collect an image of a target object to obtain two-dimensional gray image data comprising spectrum information, S2, calling an opencv parallel calculation frame to build a multi-thread processing framework, configuring thread scheduling parameters to adapt to the line pixel scale of the two-dimensional gray image data, S3, synchronously processing each line of pixel data of the two-dimensional gray image through an opencv parallel traversing mechanism, identifying a maximum quantized value of a pixel gray value in the line and a column index of a corresponding pixel point line by line, S4, determining a target column interval based on the column index, taking the column index as a center, respectively expanding K pixel points to two sides to form a continuous column set, K is a preset positive integer, S5, setting a pixel gray value ratio threshold, screening pixel point values in the continuous column set, reserving the pixel point which meets the ratio of the gray value to the maximum quantized value to reach the threshold as an effective point of the threshold, and executing the weighted operation on the position of the pixel point corresponding to the peak value and the position of an opencv module, and executing the weighted operation on the position of the pixel point corresponding to the peak value.
- 2. The peak wavelength extraction acceleration method based on opencv parallel computing according to claim 1, wherein the pixel gray value ratio threshold in S5 is determined by the following model: , wherein, Is the gray value of the i-th pixel point, For the column position parameter of the ith pixel point, Is a very small positive number to avoid nonsensical logarithmic operations, In order to adjust the parameters of the device, As the weight coefficient of the light-emitting diode, For the pixel distribution dispersion parameter, For a total number of pixels in a single row.
- 3. The peak wavelength extraction acceleration method based on opencv parallel computing according to claim 1, wherein the weighting operation in S6 uses the following model: , wherein, As a parameter of the position of the peak wavelength, For the column position index of the jth valid pixel point, Is the gray value of the j-th effective pixel point, And n is the total number of the effective pixel points, and is the phase adjustment parameter corresponding to the j-th effective pixel point.
- 4. The peak wavelength extraction acceleration method based on opencv parallel computing according to claim 1, wherein the maximum quantized value identification in S3 adopts the following model: , wherein, Is the maximum quantized value of the k-th row of pixels, The gray value of the I pixel point of the kth line, For the row weight adjustment coefficient, k is the row index number, and m is the total number of pixels in a single row and a column.
- 5. The peak wavelength extraction acceleration method based on opencv parallel computing according to claim 1, wherein the boundary parameters of the target column interval in S4 are determined by the following model: floor , wherein, For the left boundary column index of the target column interval, For the right boundary column Index of the target column section, index is the column Index obtained in step S3, For the preset expansion coefficient to be set, For the gray value of the corresponding row pixel point, m is the total number of pixels in a single row, floor is a downward rounding function, ceil is an upward rounding function.
- 6. The peak wavelength extraction acceleration method based on opencv parallel computing according to claim 1, wherein the peak wavelength position parameter correction model output in S6 is: , wherein, In order to correct the peak wavelength position parameter, For the result of the initial weighting operation, For the column position index of the jth valid pixel point, Is the gray value of the j-th effective pixel point, Is the coefficient of the exponential decay, Is the coefficient of the second order of the attenuation, And n is the total number of effective pixel points for the correction coefficient.
- 7. The peak wavelength extraction acceleration method based on opencv parallel computing is characterized by comprising the following steps of S31, distributing independent processing threads for each row of pixel data of a two-dimensional gray image through a thread pool distribution mechanism of an opencv parallel computing framework, binding corresponding row indexes and gray values and column position data of all pixels of each thread, S32, comparing pixel gray values in the bound rows one by one according to a preset pixel traversal sequence, recording the maximum gray value and the corresponding column position mark appearing in the current traversal process, S33, collecting processing results of all threads through a thread synchronization mechanism, establishing a mapping relation between the row indexes and the corresponding row maximum quantized values and column index, forming an intermediate data set, S34, conducting consistency check on the intermediate data set, eliminating the maximum quantized values and the column index corresponding to abnormal row data, and reserving results meeting preset data validity conditions.
- 8. The peak wavelength extraction acceleration method based on opencv parallel computing according to claim 1, wherein the step S4 includes the steps of S41 extracting a core column position parameter corresponding to each row from an effective column index obtained in the step S3, determining a distribution range of the parameter in a two-dimensional gray image column dimension, S42 calculating a column number K1 expanded to the left of each core column position parameter and a column number K2 expanded to the right of each core column position parameter according to a preset expansion coefficient K, wherein K1 and K2 are equal to K and are positive integers, S43 subtracting K1 from the core column position index on the left side based on the core column position parameter, obtaining a right boundary column index from the core column position index plus K2 on the right side, and S44 defining all columns between the left boundary column index and the right boundary column index as target column intervals and recording target column interval range parameters corresponding to each row.
- 9. The peak wavelength extraction acceleration method based on opencv parallel computing according to claim 1, wherein the step S5 comprises the steps of S51, setting a fixed pixel gray value ratio threshold which is a preset value larger than 0 and smaller than 1 based on the overall gray value distribution characteristic of a two-dimensional gray image, S52, traversing all pixel points in a target column interval corresponding to each row to obtain a gray value of each pixel point and a maximum quantized value of a corresponding row, S53, calculating a ratio of the gray value of each pixel point to the maximum quantized value of the corresponding row, comparing the ratio with the preset pixel gray value ratio threshold, S54, screening out pixel points with the ratio larger than or equal to the threshold, recording column position indexes and gray values of the pixel points, and forming an effective pixel point data set.
- 10. The peak wavelength extraction acceleration method based on opencv parallel computing according to any one of claims 1 to 9 is characterized by being realized by different units and comprises an image data acquisition unit, a target column interval construction unit, a parallel computing scheduling unit, a line pixel processing unit, a target column interval construction unit and an effective pixel unit, wherein the image data acquisition unit is used for carrying out spectrum image capturing on a target object through a line spectrum confocal sensor, generating two-dimensional gray image data comprising pixel gray values and position information, transmitting the two-dimensional gray image data to the parallel computing scheduling unit, the parallel computing scheduling unit is used for receiving the two-dimensional gray image data transmitted by the image data acquisition unit, constructing an opencv multithread processing architecture, configuring thread allocation rules and synchronization mechanisms, distributing the image data to a line pixel processing unit, the line pixel processing unit is used for receiving the image data distributed by the parallel computing scheduling unit, identifying a maximum quantized value and a corresponding column index line by line through the opencv parallel traversing mechanism, the target column interval construction unit is used for receiving column index transmitted by the line pixel processing unit, the target column interval construction unit is used for receiving column index transmitted by the line pixel processing unit, and expanding preset K pixel points with the index as a center to form a continuous column set, transmitting the column set information to an effective pixel unit, the effective pixel unit is used for transmitting the peak value and the effective pixel unit to the effective pixel unit, and the effective pixel unit is used for transmitting the peak value and the effective pixel unit and the peak value is used for transmitting the peak value.
Description
Peak wavelength extraction acceleration method based on opencv parallel computation Technical Field The invention relates to the technical field of spectrum measurement, in particular to a peak wavelength extraction acceleration method based on opencv parallel calculation. Background In the high-speed real-time online measurement scene of industrial production, the measurement precision of the linear spectrum confocal sensor is directly related to the performance of a peak wavelength extraction algorithm, and the stable, efficient and rapid peak wavelength extraction algorithm becomes a key for improving the overall efficiency of a measurement system. There are various algorithms in the current peak wavelength extraction field, including a maximum value method, a centroid method, a square weighted centroid method, a parabolic fitting method, a gaussian fitting method, a sine 2 fitting method, etc., and these algorithms are applied in different scenes. The maximum value method has simple operation flow, small operation amount, intuitive principle of the centroid method and moderate calculation amount, the square weighted centroid method is used as an improvement scheme of the centroid method, the accuracy is improved, and although various fitting methods can realize higher-accuracy extraction, the operation complexity is obviously increased. Along with the continuous improvement of the requirements of industrial production on measurement efficiency, the actual demands of the high-speed measurement system are gradually difficult to adapt to by the existing algorithm in the balance of operation speed and precision, and a technical scheme capable of considering efficient operation and accurate extraction is needed to meet the core requirements of real-time measurement in industrial scenes. The existing linear spectrum confocal sensor peak wavelength extraction algorithm has two prominent disadvantages. On the one hand, the partial algorithm has insufficient anti-interference capability, for example, the maximum value method directly uses the wavelength corresponding to the maximum point of the light intensity as the peak value, is easily affected by noise, cannot realize sub-pixel precision extraction, and is difficult to meet the use requirement of a high-precision measurement scene. On the other hand, the algorithm operation efficiency and the industrial actual demand have a gap, although the square weighted centroid method has certain advantages in accuracy and efficiency, the operation speed is still insufficient to adapt to the rhythm of high-speed online measurement, and the high-precision algorithms such as the parabolic fitting method and the Gaussian fitting method are difficult to apply to real-time measurement scenes due to large calculation amount and long time consumption, and the application expansion of the linear spectrum confocal sensor in the industrial high-speed measurement field is limited in both cases. Disclosure of Invention In order to overcome the defects and shortcomings in the prior art, the invention provides a peak wavelength extraction acceleration method based on opencv parallel computing. The technical scheme includes that S1, a linear spectrum confocal sensor is adopted to collect images of a target object to obtain two-dimensional gray image data comprising spectrum information, S2, a multithread processing framework is built by invoking an opencv parallel computing framework, thread scheduling parameters are configured to adapt to the line pixel scale of the two-dimensional gray image data, S3, synchronous processing is carried out on each line of pixel data of the two-dimensional gray image through an opencv parallel traversing mechanism, the maximum quantized value of a pixel gray value in the line and a column index of a corresponding pixel point are identified line by line, S4, a target column interval is determined based on the column index, K pixel points are respectively expanded to two sides to form a continuous column set with the column index as a center, K is a preset positive integer, a pixel gray value ratio threshold is set, gray values of each pixel point in the continuous column set are screened, the ratio value meeting the maximum quantized value and the threshold value is reserved, and the pixel point corresponding to the position of the pixel point corresponding to the peak value is calculated through the opencv module, and the position of the pixel point corresponding to the peak value is calculated, and the position of the pixel point corresponding to the pixel point is calculated. Further, the pixel gray value ratio threshold in S5 is determined by the following model: , wherein, Is the gray value of the i-th pixel point,For the column position parameter of the ith pixel point,Is a very small positive number to avoid nonsensical logarithmic operations,In order to adjust the parameters of the device,As the weight coefficient of the light-emitting diode,Fo