Image size calibration method based on improved zhang zhengyou calibration method and wood defect area calculation method

By combining genetic algorithms and LM algorithms to optimize Zhang Zhengyou's calibration method, the problem of the calibration method easily getting trapped in local minima is solved, thereby improving the accuracy of camera calibration and the accuracy of defect area calculation.

CN116740194BActive Publication Date: 2026-04-14SHANDONG COMP SCI CENTNAT SUPERCOMP CENT IN JINAN +2
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHANDONG COMP SCI CENTNAT SUPERCOMP CENT IN JINAN
Filing Date
2023-06-20
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

The existing Zhang Zhengyou calibration method is prone to getting trapped in local minima when solving the maximum likelihood estimation, which affects the accuracy of camera calibration and the accuracy of subsequent defect size calculation.

Method used

By combining genetic algorithms and LM algorithms, the genetic algorithm is used to globally optimize the LM algorithm, binary encoding and roulette wheel selection are used to improve the solution accuracy, and gradient descent is combined to perform local optimization to obtain the global optimal solution.

Benefits of technology

This improves the accuracy of camera calibration and defect area calculation, ensuring the precision of distortion correction and defect detection during the camera imaging process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116740194B_ABST
    Figure CN116740194B_ABST
Patent Text Reader

Abstract

The application discloses an image size calibration method based on an improved Zhang Zhengyou calibration method and a wood defect area calculation method. When the Zhang Zhengyou calibration method uses an L-M method to solve a maximum likelihood estimation minimum value, a problem of easily falling into a local extreme value is solved by using the advantage of globally searching for an optimal value of a genetic algorithm to optimize the defect that the L-M algorithm easily falls into a local minimum value. In the genetic algorithm, binary coding is selected as an encoding type according to a parameter type. On the basis of considering calculation efficiency, a function f(x) = e st is selected as a use function. A roulette method is selected as a selection operation method. A simple and effective one-point crossover is selected as a crossover operation method. Then, only an approximate solution is obtained near a global optimal solution by using the genetic algorithm. Then, the approximate solution is optimized by using an L-M local search algorithm. The advantages of the global genetic algorithm and the local optimization L-M method are effectively combined.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention discloses an image size calibration method and a wood defect area calculation method based on the improved Zhang Zhengyou calibration method, belonging to the technical field of image analysis using computer models. Background Technology

[0002] In visual applications and image measurement, to obtain the relationship between the three-dimensional geometric position of a point on the surface of a spatial object and its corresponding point in an image, a geometric model of camera imaging must be established. The parameters of this geometric model are the camera parameters. These parameters include intrinsic parameters, extrinsic parameters, and distortion parameters, which are generally obtained through calculation and experimentation. The process of solving for these parameters is called camera calibration. Whether in visual applications or image measurement, camera calibration is a crucial step. The accuracy of the calibrated parameters and the stability of the algorithm directly affect the accuracy of the camera's operation. Therefore, completing camera calibration is a prerequisite for subsequent work, and improving the accuracy of camera calibration is one of the important issues addressed in current technology.

[0003] The purpose of calibration is mainly to solve two problems: 1. Determine the transformation relationship between three-dimensional spatial points and pixel points in the pixel plane under the world coordinate system, which is the aforementioned intrinsic and extrinsic parameters; 2. Determine the distortion coefficients in the camera imaging process for image correction.

[0004] Currently available camera calibration methods include:

[0005] There are several methods for camera calibration, including traditional methods, active vision camera calibration methods, camera self-calibration methods, and Zhang Zhengyou's calibration method. Traditional methods require calibration objects and have complex algorithms. Active vision camera calibration methods are costly and require expensive equipment. Camera self-calibration methods suffer from low accuracy and poor robustness. Compared to these methods, Zhang Zhengyou's calibration method offers advantages such as simple calibration, clear corner points, and high calibration accuracy. Furthermore, it requires no additional equipment; a printed checkerboard is sufficient, and the camera and calibration board can be placed arbitrarily.

[0006] Zhang Zhengyou's calibration method and camera imaging process

[0007] Zhang Zhengyou's calibration method uses a checkerboard calibration board for camera calibration. Before calibration, we need to understand the camera's imaging process. The camera imaging system contains four coordinate systems: pixel coordinate system, image coordinate system, camera coordinate system, and world coordinate system.

[0008] The overall transformation image of the four coordinate systems, which is the camera's imaging process, is shown in the attached figure. Figure 1 As shown, in the transformation from the camera coordinate system to the image coordinate system, for mathematical convenience, we swap the positions of the camera coordinate system and the image coordinate system, resulting in the arrangement shown in the following figure:

[0009] In the appendix Figure 1 In the process of camera imaging

[0010] P: A point in the world coordinate system

[0011] p: The corresponding point of point P in the pixel coordinate system, with coordinates (u,v) in the pixel coordinate system and (x,y) in the image coordinate system.

[0012] f: Camera focal length, equal to o and O C distance

[0013] The transformation relationships between these four coordinate systems are as follows:

[0014]

[0015]

[0016] In formula (1) and subsequent formulas, (U,V,W) are the physical coordinates of any point in the world coordinate system; (u,v) are the pixel coordinates of that point in the pixel coordinate system; Z is the scale factor; f is the image distance; dX and dY represent the physical length of a pixel on the camera's photosensitive plate in the X and Y directions, respectively, i.e., how many millimeters a pixel is on the photosensitive plate; u0 and v0 represent the coordinates of the center of the camera's photosensitive plate in the pixel coordinate system, i.e., the principal point of the coordinates; R represents the rotation matrix; T represents the translation matrix; θ represents the angle between the horizontal and vertical sides of the photosensitive plate, 90° indicates no error, and θ is generally taken as 90°.

[0017] Calibration requires first acquiring a set of images containing the calibration board. Then, using the corresponding image detection algorithm, corner points on the calibration board can be detected from each image, and the pixel coordinates (u,v) of each corner point on the image can be calculated.

[0018] Before calibrating the camera, a checkerboard calibration board needs to be selected, as shown in the attached image. Figure 2 As shown, the world coordinate system is defined. Typically, the calibration plate is placed on a plane, and its upper left corner is defined as the origin of the world coordinate system. In this case, the size of each square on the checkerboard can be set to a known value, such as one unit length (which could be centimeters, millimeters, etc.), allowing the calculation of the physical coordinates of each corner point in the world coordinate system. Zhang Zhengyou's calibration method fixes the camera's world coordinate system on the checkerboard, so the physical coordinates of any point on the checkerboard are W=0. Since the world coordinate system of the calibration plate is predefined, and the size of each square on the calibration plate is known, the physical coordinates of each corner point in the world coordinate system (U, V, W=0) can be calculated. Then, the camera's intrinsic and extrinsic parameter matrices and distortion parameters can be obtained.

[0019] When using the maximum likelihood estimation method, we obtain n images of the model plane, with m points on the model plane. Assuming that the noise at each pixel in the image follows an independent identical distribution, the maximum likelihood estimate can be obtained by minimizing the following function.

[0020]

[0021] In formula (2), the two-dimensional pixel corresponding to the three-dimensional spatial point P on the image is p; the three-dimensional spatial point P j The two-dimensional pixel obtained after transformation of the camera's intrinsic parameters A and extrinsic parameters R and T is p′; the rotation matrix R is represented by a vector r with three parameters; r is parallel to the rotation axis and its size is equal to the rotation angle; the relationship between R and r conforms to the Rodriguez formula. Considering the influence of lens distortion, since the influence of radial distortion is relatively significant, the radial distortion parameters are mainly considered. Based on experience, usually only the first two radial distortion parameters j1 and j2 are considered. Solving for the minimum value of formula (2) is a nonlinear optimization problem, which can be solved using the LM algorithm.

[0022] The basic principle of the LM algorithm is as follows: Let x k Let E(x) represent the column vector of output values ​​at the k-th iteration, and let E(x) be the error summation function. Let the column vector e(x) represent the error between the output value and the true value. T (x) represents the transpose of e(x), Taking the square of e(x), we get:

[0023]

[0024] The gradient of the sum of errors function:

[0025]

[0026] Iterative form of the LM algorithm:

[0027] x k+1 =x k -[J T (x k )J(x k )+uI] -1 J T (x)e(x) (5)

[0028] In formulas (3), (4), and (5), J(x) is the Jacobian matrix; u is the damping coefficient; I is the identity matrix; J T J(x) is invertible.

[0029] From formulas (3), (4), and (5), it can be seen that the LM algorithm is a combination of the Gauss-Newton method and the gradient descent method: when u is very small, it is equivalent to the Gauss-Newton method, and the iteration convergence speed is fast; when u is very large, it is equivalent to the gradient descent method, and the iteration convergence speed is slow. Therefore, the LM algorithm has the advantage of fast convergence speed of the Gauss-Newton method and the characteristic of stable approximation of the optimal solution of the gradient descent method.

[0030] Zhang Zhengyou's calibration method uses the Levenberg-Marquardt (LM) method to calculate the maximum likelihood estimate. The LM method is a commonly used least-squares estimation method for regression parameters in nonlinear regression. The steepest descent method is suitable for the initial stage of iteration when the parameter estimates are far from the optimal value, while the linearization method, i.e., the Gauss-Newton method, is suitable for the later stage of iteration when the parameter estimates are close to the optimal value. Combining these two methods can quickly find the optimal value. However, the LM method is very sensitive to the initial guess. The choice of the initial guess may cause the algorithm to get stuck in a local optimum or the iteration process to be very slow. Without a suitable initial guess, the LM method may fail or require a large number of iterations to converge to the optimal solution. This will result in the calculated intrinsic and extrinsic parameters and distortion parameters not being globally optimal, affecting the accuracy of the subsequent scale factor Z, and thus affecting the calculation of the defect size.

[0031] Chinese patent document CN113284196A discloses a method for pixel-by-pixel calibration of camera distortion. After obtaining the intrinsic and extrinsic parameters using the Zhang Zhengyou calibration method, the LM method is used to find the minimum value of the mean square error of the non-zero values ​​in the mapping matrix to optimize the intrinsic and extrinsic parameters. The parameters of the objective function to be calculated only include the intrinsic and extrinsic parameters, so the LM algorithm, which is more suitable for small-scale parameter spaces and local optimization problems, is more appropriate. Summary of the Invention

[0032] To address the shortcomings of existing technologies, this invention discloses an image size calibration method based on an improved Zhang Zhengyou calibration method.

[0033] The present invention also discloses a method for calculating the area of ​​wood defects using the above-mentioned image size calibration method. Invention Overview:

[0035] This invention calibrates the camera by calculating pixel coordinates (u,v) in the pixel coordinate system and physical coordinates (U,V,W=0) in the world coordinate system, obtaining the camera's intrinsic and extrinsic parameter matrices and distortion parameters. This invention utilizes the genetic algorithm (GA) to optimize the LM method, thereby fitting the global minimum of the maximum likelihood estimation in Zhang Zhengyou's calibration method. The LM algorithm and the genetic algorithm are two fundamentally different optimization methods, differing significantly in their basic principles and operational methods. The LM algorithm is an iterative optimization algorithm that finds the optimal solution by updating parameter values, while the genetic algorithm is a global optimization method based on population evolution. These two methods have different thinking and operational methods, making it difficult to immediately combine them. The genetic algorithm is generally suitable for problems with large parameter spaces and complex search spaces to find the global optimum, while the LM algorithm is more suitable for small parameter spaces and local optimization problems. Furthermore, the genetic algorithm is more complex than the LM algorithm, involving operations such as population selection, crossover, and mutation, requiring the design and adjustment of many parameters. Therefore, the difficulty in applying genetic algorithms to optimize the LM algorithm lies in the need to make appropriate modifications and adaptations to the genetic algorithm, and to carefully weigh the adaptability and efficiency of the two methods to ensure that the two algorithms can work together effectively.

[0036] Compared to existing patent literature, this invention solves for the minimum value of the maximum likelihood estimation, which includes intrinsic parameters and distortion parameters. Due to the greater complexity of the parameters, a genetic algorithm, typically applicable to problems with large parameter spaces and complex search spaces, is used to optimize the LM algorithm. In this genetic algorithm, the invention employs binary encoding as the encoding method, and f(x) = e st The fitness function is used, and roulette wheel selection and crossover are used as selection and crossover operations, respectively, to improve the accuracy of genetic algorithms in finding solutions near the global minimum.

[0037] The detailed technical solution of this invention is as follows:

[0038] An image size calibration method based on the improved Zhang Zhengyou calibration method, characterized in that it includes:

[0039] The LM algorithm used in Zhang Zhengyou's calibration method to solve the maximum likelihood estimation equation has the drawback of easily getting trapped in local minima. This invention improves upon this by utilizing the advantage of genetic algorithms in globally finding the optimal value. By incorporating a genetic algorithm for global optimization before using the LM algorithm (GAL-M algorithm), accuracy and reliability are improved, and errors are reduced. Therefore, using the GAL-M algorithm to solve the maximum likelihood estimation equation is feasible. The following section will detail how to optimize the LM algorithm using a genetic algorithm.

[0040] Before using the LM algorithm, a genetic algorithm is added for global optimization:

[0041] The genetic algorithm can continuously select, crossover, and mutate from the initial population to generate the next generation of species. Based on the principle of survival of the fittest, individuals with high adaptability can be selected.

[0042] The genetic algorithm includes: encoding, fitness function, and initial population.

[0043] The aforementioned encoding is used because the parameters of the genetic algorithm in the problem space cannot be directly processed. By using encoding, the problem to be solved is transformed into chromosomes or individuals in a genetic system. After solving the problem, the result is then decoded. In Zhang Zhengyou's calibration method, when solving for the global minimum of maximum likelihood estimation, the intrinsic parameters, extrinsic parameters, and distortion parameters are encoded into genotype strings that can be processed by the genetic algorithm for subsequent calculations or solutions. Commonly used encoding methods include binary encoding, real number encoding, and tree encoding, etc. For continuous parameters, real number encoding may be more suitable, while for discrete parameters, binary encoding may be more suitable.

[0044] The parameters of the maximum likelihood estimation are discrete parameters, so this invention chooses to use binary encoding for representation and optimization. Binary encoding converts the above parameters into a binary string, where each binary bit corresponds to a solution variable of a problem. During the operation of the genetic algorithm, crossover and mutation operations can be used to operate on these binary strings to generate new individuals and continuously iterate to find the optimal solution. Finally, the result is obtained by decoding. The encoding is generally evaluated from three aspects: completeness, comprehensiveness, and non-redundancy.

[0045] The fitness function can be used as an indicator to judge the quality of individuals in a population. It is a quantitative indicator for the selection of selection operators. Its evaluation mainly depends on the function of the target problem. The fitness function is determined according to the maximum likelihood estimation in Zhang Zhengyou's calibration method. It needs to meet the following four aspects: First, it should be a single value, continuous, positive and zero, and have a maximum value; Second, it should be reasonable and consistent, and simple to calculate; Finally, it should be applicable to other places.

[0046] In practical applications, it's best to address each problem individually. In genetic algorithms, comparing the fitness of individuals requires comparing fitness values, and then deriving the selection probability. Therefore, in most cases, it's preferable to maximize the objective function, and ideally, the obtained fitness function value should be positive or zero. Considering these factors, this invention chooses the computationally simple and efficient exponential function method.

[0047] f(x) = e st (6)

[0048] Formula (6) serves as the fitness function, where st is the initial value of an individual. The characteristic of the exponential function is that as st gradually approaches the optimal solution, the fitness value of the individual will increase rapidly, thereby improving the computational efficiency of the genetic algorithm.

[0049] The initial population is generated randomly, and the generation strategy includes:

[0050] First: the entire problem space must be included; second: the most advantageous group is selected from the initially randomly generated group and added to the initial group, and this process is repeated until the initial group reaches the expected size.

[0051] The genetic algorithm also includes genetic operations, including three basic genetic operators: selection genetic operator, crossover genetic operator, and mutation genetic operator;

[0052] The selection genetic operator identifies dominant individuals and eliminates suboptimal ones. Generally, individuals with higher probabilities of being selected have stronger fitness, while those with relatively lower probabilities of being selected have weaker fitness. The purpose of selection is to directly pass on dominant individuals to the next generation or to pair and crossbreed to produce new individuals for the next generation. A roulette wheel selection method is used, and the selection formula is defined as follows:

[0053]

[0054]

[0055] In formulas (7) and (8), the population size is M; the fitness of individual i is f. i The probability that individual i is selected is P. i The cumulative probability of individual i being selected is q. i ; This represents calculating the fitness values ​​of all individuals in the population and summing them to obtain the total fitness.

[0056] The process of the roulette wheel selection method is as follows:

[0057] S1: Calculate the probability P of each individual being selected. i ;

[0058] S2: Calculate the cumulative probability q for each part. i ;

[0059] S3: Randomly generate an array R, where the elements in the array take values ​​between 0 and 1, and sort the array in ascending order:

[0060] If the cumulative probability q i Greater than the element R in the array iIf , then individual i is selected;

[0061] If less than R i Then compare the next individual i+1 until an individual is selected;

[0062] S4: If N individuals need to be transferred, repeat step S3 N times;

[0063] The principle of roulette wheel selection is that the higher the fitness value, the greater the proportion on the roulette wheel, thus increasing the probability of being selected. In this way, individuals with higher fitness values ​​are more likely to be selected as the parents of the next generation, thus leaving behind better genetic information. At the same time, in order to maintain population diversity, roulette wheel selection also allows individuals with lower fitness values ​​to have a certain probability of being selected.

[0064] The core operation of the crossover genetic operator is pairing individuals in the matching pool for reproduction. The crossover frequency is determined by the crossover probability; a higher crossover probability results in faster reproduction, but excessively fast reproduction can lead to the destruction of individuals, while a low probability can cause stagnation. Through this operation, the genetic algorithm can possess a more powerful search capability. If the crossover operation is utilized effectively, the global optimum can be found more quickly. This invention chooses to use one-point crossover as the crossover method, and the specific steps are as follows:

[0065] S5: Select an intersection point, usually a random location;

[0066] S6: Initially divide the two parent individuals into two segments at the intersection point;

[0067] S7: After exchanging fragments, two new individuals are formed:

[0068] Child generation 1 = the first half of parent generation 1 + the second half of parent generation 2;

[0069] Child generation 2 = the first half of parent generation 2 + the second half of parent generation 1;

[0070] The mutation genetic operator alters certain genes in an individual. This invention uses bit mutation, applicable to binary systems, to flip the value of a specific gene bit (changing 0 to 1 and 1 to 0). A mutation probability is set; this invention sets the mutation probability to 0.03, ensuring the algorithm is not too random and fails to converge effectively to a better solution, nor does it get trapped in local optima and struggle to escape local searches. The mutation location can be determined using a random number generator to create a random position index, and then the corresponding gene bit is flipped. The operation steps include:

[0071] S8: Determine whether all individuals have completed mutation based on the pre-set mutation probability;

[0072] S9: The randomly selected location for mutation enhances the local search capability of the intelligent algorithm. When the intelligent algorithm uses the crossover operator to approach the vicinity of the optimal solution, the mutation genetic operator is used to approach the optimal solution even faster. Another purpose is to maintain population diversity with the help of the genetic algorithm to prevent convergence failure. The probability of this mutation is generally not too high; a high probability would reduce search capability.

[0073] In summary, the algorithm proposed in this invention first uses a genetic algorithm to fit the parameters of the maximum likelihood estimate. The genetic algorithm starts with random values ​​for the parameters of the nonlinear function, and each iteration approximates the nonlinear function. Since the genetic algorithm is a global optimization algorithm, it is computationally expensive. This method first uses the genetic algorithm to escape the problem of local minima, estimating a solution near the global minimum. Once an approximation of the global minimum is found, gradient descent is performed using the solution found by the genetic algorithm as a starting point. By using gradient descent around the optimal solution determined by the genetic algorithm, faster convergence and more accurate results can be achieved.

[0074] This invention obtains only an approximate solution by using a computationally intensive genetic algorithm, and then optimizes it using an efficient LM local search algorithm, effectively combining the advantages of global genetic algorithms and local optimization LM methods.

[0075] A method for calculating the area of ​​wood defects using the above-mentioned image size calibration method, characterized in that it includes:

[0076] After correcting the distortion of the wood image, target detection and recognition are performed. Then, the pixel coordinates are converted to physical coordinates using the camera calibration results to calculate the actual distance between the two points of the defect box in the real world, corresponding to the pixel distance between the two points.

[0077]

[0078] After transforming formula (9), we get:

[0079]

[0080] in,

[0081] And A -1 Let R be the inverse matrix of A. -1 Let R be the inverse matrix; substitute any previous pixel value (u1, v1) and next pixel value (u2, v2) into it.

[0082]

[0083]

[0084] At this point, W1 = W2 = 0. Subtracting the two equations above, we get:

[0085]

[0086] In formulas (9)-(14), Δu and Δv are the pixel difference, and ΔU and ΔV are the difference in actual distance in the world coordinate system. By eliminating the translation matrix using the above formulas, the Z-axis of the world coordinate system and the camera coordinate system can be compared. W and Z C The axes are defined as parallel. Since rotation is a rigid body transformation and each column of the rotation matrix has a modulus of 1, the rotation matrix R has no effect on subsequent calculations, and A -1 Given that the scale factor Z is calculated, in order to eliminate the influence of individual corner point errors, the average value of all obtained Z values ​​is calculated to obtain the most suitable scale Z;

[0087] It is obtained through formula (14), where and Use f respectively x ,f y express:

[0088]

[0089]

[0090] As shown in formulas (15) and (16), R has no effect on subsequent calculations, so

[0091]

[0092] When Δu = Δv = 1, the area of ​​each pixel is obtained:

[0093]

[0094] After the wood image is processed by deep learning to detect the defect type, if the defect type is a dry scar or a dead knot, as shown in the figure, the detection box of the defect is used as the boundary, and thresholding is performed inside the detection box to calculate the number of pixels in the defect area, and then the area of ​​the defect is calculated.

[0095] Thresholding is an image segmentation method used to extract desired parts from an image, such as separating the foreground and background. Its basic principle is to use the pixel differences between different parts of an image and extract the desired parts by setting a threshold. There are three types of thresholding: fixed thresholding, adaptive thresholding, and Otsus's thresholding (maximum inter-class variance). This invention chooses to use the fixed thresholding method.

[0096] The technical advantages of this invention are:

[0097] 1. This invention addresses the problem of the Zhang Zhengyou calibration method easily getting trapped in local minima when using the LM method to solve the maximum likelihood estimation minimum. It leverages the advantage of the genetic algorithm's ability to globally find the optimal value to optimize the LM algorithm's tendency to get trapped in local minima. In the genetic algorithm, binary encoding is chosen as the encoding type based on the parameter type, and the function f(x) = e is selected based on computational efficiency. st The fitness function was selected using the efficient roulette wheel selection method, and a simple and effective one-point crossover method was used. Then, a genetic algorithm was used to obtain only an approximate solution near the global optimum, and then the LM local search algorithm was used to optimize it. This effectively combined the advantages of the global genetic algorithm and the local optimization LM method.

[0098] 2. Based on the accurate intrinsic and extrinsic parameters and distortion parameters obtained by the GAL-M algorithm, a distortion-free image after distortion correction is obtained. Then, deep learning is used for target detection to identify defects. The scale factor Z between every two pixels is obtained using the formula for calculating the difference between pixels. The mean of the scale factor Z is then calculated, and the area s per unit pixel is obtained through calculation. p Then, the actual number of defect pixels is obtained through thresholding, and finally the precise area of ​​the defect is obtained. Attached Figure Description

[0099] Figure 1 This is a schematic diagram of the imaging process of the overall transformation image of four coordinate systems in the existing technology;

[0100] Figure 2 It's a chessboard pattern;

[0101] Figure 3 This is a flowchart of an image size calibration method based on the improved Zhang Zhengyou calibration method described in this invention, where G is the population evolution generation; GEN is the maximum number of population iterations set.

[0102] Figure 4 The large hole and its size were identified in the embodiment;

[0103] Figure 5 The large hole and its size were identified in the embodiment;

[0104] Figure 6 The dried meat and its size were identified in the embodiment;

[0105] Figure 7 The dead knot and its size were identified in the example. Detailed Implementation

[0106] The present invention will now be described in detail with reference to the embodiments and accompanying drawings, but is not limited thereto.

[0107] Example 1

[0108] like Figure 3 As shown, an image size calibration method based on the improved Zhang Zhengyou calibration method includes:

[0109] The LM algorithm used in Zhang Zhengyou's calibration method to solve the maximum likelihood estimation equation has the drawback of easily getting trapped in local minima. This invention improves upon this by utilizing the advantage of genetic algorithms in globally finding the optimal value. By incorporating a genetic algorithm for global optimization before using the LM algorithm (GAL-M algorithm), accuracy and reliability are improved, and errors are reduced. Therefore, using the GAL-M algorithm to solve the maximum likelihood estimation equation is feasible. The following section will detail how to optimize the LM algorithm using a genetic algorithm.

[0110] Before using the LM algorithm, a genetic algorithm is added for global optimization:

[0111] The genetic algorithm can continuously select, crossover, and mutate from the initial population to generate the next generation of species. Based on the principle of survival of the fittest, individuals with high adaptability can be selected.

[0112] The genetic algorithm includes: encoding, fitness function, and initial population.

[0113] The aforementioned encoding is used because the parameters of the genetic algorithm in the problem space cannot be directly processed. By using encoding, the problem to be solved is transformed into chromosomes or individuals in a genetic system. After solving the problem, the result is then decoded. In Zhang Zhengyou's calibration method, when solving for the global minimum of maximum likelihood estimation, the intrinsic parameters, extrinsic parameters, and distortion parameters are encoded into genotype strings that can be processed by the genetic algorithm for subsequent calculations or solutions. Commonly used encoding methods include binary encoding, real number encoding, and tree encoding, etc. For continuous parameters, real number encoding may be more suitable, while for discrete parameters, binary encoding may be more suitable.

[0114] The parameters of the maximum likelihood estimation are discrete parameters, so this invention chooses to use binary encoding for representation and optimization. Binary encoding converts the above parameters into a binary string, where each binary bit corresponds to a solution variable of a problem. During the operation of the genetic algorithm, crossover and mutation operations can be used to operate on these binary strings to generate new individuals and continuously iterate to find the optimal solution. Finally, the result is obtained by decoding. The encoding is generally evaluated from three aspects: completeness, comprehensiveness, and non-redundancy.

[0115] The fitness function can be used as an indicator to judge the quality of individuals in a population. It is a quantitative indicator for the selection of selection operators. Its evaluation mainly depends on the function of the target problem. The fitness function is determined according to the maximum likelihood estimation in Zhang Zhengyou's calibration method. It needs to meet the following four aspects: First, it should be a single value, continuous, positive and zero, and have a maximum value; Second, it should be reasonable and consistent, and simple to calculate; Finally, it should be applicable to other places.

[0116] In practical applications, it's best to address each problem individually. In genetic algorithms, comparing the fitness of individuals requires comparing fitness values, and then deriving the selection probability. Therefore, in most cases, it's preferable to maximize the objective function, and ideally, the obtained fitness function value should be positive or zero. Considering these factors, this invention chooses the computationally simple and efficient exponential function method.

[0117] f(x) = e st (6)

[0118] Formula (6) serves as the fitness function, where st is the initial value of an individual. The characteristic of the exponential function is that as st gradually approaches the optimal solution, the fitness value of the individual will increase rapidly, thereby improving the computational efficiency of the genetic algorithm.

[0119] The initial population is generated randomly, and the generation strategy includes:

[0120] First: the entire problem space must be included; second: the most advantageous group is selected from the initially randomly generated group and added to the initial group, and this process is repeated until the initial group reaches the expected size.

[0121] The genetic algorithm also includes genetic operations, including three basic genetic operators: selection genetic operator, crossover genetic operator, and mutation genetic operator;

[0122] The selection genetic operator identifies dominant individuals and eliminates suboptimal ones. Generally, individuals with higher probabilities of being selected have stronger fitness, while those with relatively lower probabilities of being selected have weaker fitness. The purpose of selection is to directly pass on dominant individuals to the next generation or to pair and crossbreed to produce new individuals for the next generation. A roulette wheel selection method is used, and the selection formula is defined as follows:

[0123]

[0124]

[0125] In formulas (7) and (8), the population size is M; the fitness of individual i is f. i The probability that individual i is selected is P. iThe cumulative probability of individual i being selected is q. i ; This represents calculating the fitness values ​​of all individuals in the population and summing them to obtain the total fitness.

[0126] The process of the roulette wheel selection method is as follows:

[0127] S1: Calculate the probability P of each individual being selected. i ;

[0128] S2: Calculate the cumulative probability q for each part. i ;

[0129] S3: Randomly generate an array R, where the elements in the array take values ​​between 0 and 1, and sort the array in ascending order:

[0130] If the cumulative probability q i Greater than the element R in the array i If , then individual i is selected;

[0131] If less than R i Then compare the next individual i+1 until an individual is selected;

[0132] S4: If N individuals need to be transferred, repeat step S3 N times;

[0133] The principle of roulette wheel selection is that the higher the fitness value, the greater the proportion on the roulette wheel, thus increasing the probability of being selected. In this way, individuals with higher fitness values ​​are more likely to be selected as the parents of the next generation, thus leaving behind better genetic information. At the same time, in order to maintain population diversity, roulette wheel selection also allows individuals with lower fitness values ​​to have a certain probability of being selected.

[0134] The core operation of the crossover genetic operator is pairing individuals in the matching pool for reproduction. The crossover frequency is determined by the crossover probability; a higher crossover probability results in faster reproduction, but excessively fast reproduction can lead to the destruction of individuals, while a low probability can cause stagnation. Through this operation, the genetic algorithm can possess a more powerful search capability. If the crossover operation is utilized effectively, the global optimum can be found more quickly. This invention chooses to use one-point crossover as the crossover method, and the specific steps are as follows:

[0135] S5: Select an intersection point, usually a random location;

[0136] S6: Initially divide the two parent individuals into two segments at the intersection point;

[0137] S7: After exchanging fragments, two new individuals are formed:

[0138] Child generation 1 = the first half of parent generation 1 + the second half of parent generation 2;

[0139] Child generation 2 = the first half of parent generation 2 + the second half of parent generation 1;

[0140] The mutation genetic operator alters certain genes in an individual. This invention uses bit mutation, applicable to binary systems, to flip the value of a specific gene bit (changing 0 to 1 and 1 to 0). A mutation probability is set; this invention sets the mutation probability to 0.03, ensuring the algorithm is not too random and fails to converge effectively to a better solution, nor does it get trapped in local optima and struggle to escape local searches. The mutation location can be determined using a random number generator to create a random position index, and then the corresponding gene bit is flipped. The operation steps include:

[0141] S8: Determine whether all individuals have completed mutation based on the pre-set mutation probability;

[0142] S9: The randomly selected location for mutation enhances the local search capability of the intelligent algorithm. When the intelligent algorithm uses the crossover operator to approach the vicinity of the optimal solution, the mutation genetic operator is used to approach the optimal solution even faster. Another purpose is to maintain population diversity with the help of the genetic algorithm to prevent convergence failure. The probability of this mutation is generally not too high; a high probability would reduce search capability.

[0143] In summary, the algorithm proposed in this invention first uses a genetic algorithm to fit the parameters of the maximum likelihood estimate. The genetic algorithm starts with random values ​​for the parameters of the nonlinear function, and each iteration approximates the nonlinear function. Since the genetic algorithm is a global optimization algorithm, it is computationally expensive. This method first uses the genetic algorithm to escape the problem of local minima, estimating a solution near the global minimum. Once an approximation of the global minimum is found, gradient descent is performed using the solution found by the genetic algorithm as a starting point. By using gradient descent around the optimal solution determined by the genetic algorithm, faster convergence and more accurate results can be achieved.

[0144] This invention obtains only an approximate solution by using a computationally intensive genetic algorithm, and then optimizes it using an efficient LM local search algorithm, effectively combining the advantages of global genetic algorithms and local optimization LM methods.

[0145] Example 2

[0146] A method for calculating the area of ​​wood defects using the image size calibration method as described in Example 1, comprising:

[0147] After correcting the distortion of the wood image, target detection and recognition are performed. Then, the pixel coordinates are converted to physical coordinates using the camera calibration results to calculate the actual distance between the two points of the defect box in the real world, corresponding to the pixel distance between the two points.

[0148]

[0149] After transforming formula (9), we get:

[0150]

[0151] in,

[0152] And A -1 Let R be the inverse matrix of A. -1 Let R be the inverse matrix; substitute any previous pixel value (u1, v1) and next pixel value (u2, v2) into it.

[0153]

[0154]

[0155] At this point, W1 = W2 = 0. Subtracting the two equations above, we get:

[0156]

[0157] In formulas (9)-(14), Δu and Δv are the pixel difference, and ΔU and ΔV are the difference in actual distance in the world coordinate system. By eliminating the translation matrix using the above formulas, the Z-axis of the world coordinate system and the camera coordinate system can be compared. W and Z C The axes are defined as parallel. Since rotation is a rigid body transformation and each column of the rotation matrix has a modulus of 1, the rotation matrix R has no effect on subsequent calculations, and A -1 Given that the scale factor Z is calculated, in order to eliminate the influence of individual corner point errors, the average value of all obtained Z values ​​is calculated to obtain the most suitable scale Z;

[0158] It is obtained through formula (14), where and Use f respectively x ,f y express:

[0159]

[0160]

[0161] As shown in formulas (15) and (16), R has no effect on subsequent calculations, so

[0162]

[0163] When Δu = Δv = 1, the area of ​​each pixel is obtained:

[0164]

[0165] After the wood images are processed by deep learning to detect the types of defects, such as... Figure 4 , 5 As shown in Figures 6 and 7, the detection bounding box of the defect detection is used as the boundary. Thresholding is performed inside the detection bounding box. In this invention, the threshold is set to 128. Pixels with a brightness higher than 128 will turn white, and those lower than 128 will turn black. Then, by traversing the thresholded image, the number of black pixels (pixel values ​​of 0) is counted to obtain the number of pixels occupied by the defect. After calculating the number of pixels in the defect area, the area s of each pixel is used... p The area of ​​the defect is calculated by multiplying it by the number of defective pixels, such as... Figure 4 , 5 The total defect areas for defects 6 and 7 are 320mm, 643mm, 274mm and 243mm respectively.

[0166] Thresholding is an image segmentation method used to extract desired parts from an image, such as separating the foreground and background. Its basic principle is to use the pixel differences between different parts of an image and extract the desired parts by setting a threshold. There are three types of thresholding: fixed thresholding, adaptive thresholding, and Otsus's thresholding (maximum inter-class variance). This invention chooses to use the fixed thresholding method.

Claims

1. An image size calibration method based on the improved Zhang Zhengyou calibration method, characterized in that, include: Collect a set of wood images including the calibration board; The improved Zhang Zhengyou calibration method was used to calibrate the wood image containing the calibration board to obtain the camera calibration results; The improved Zhang Zhengyou calibration method is an optimization of the LM algorithm in the Zhang Zhengyou calibration method using the genetic algorithm (GA), and is referred to as the GAL-M algorithm. The optimization of the LM algorithm in Zhang Zhengyou's calibration method using the genetic algorithm (GA) specifically includes: Before using the LM algorithm, a genetic algorithm (GA) is added for global optimization. The genetic algorithm (GA) includes: encoding, fitness function, and initial population; The encoding, in the Zhang Zhengyou calibration method, when solving for the global minimum of the maximum likelihood estimation, converts the intrinsic parameters, extrinsic parameters, and distortion parameters into genotype strings processed by the genetic algorithm for subsequent calculation or solution. The fitness function is an exponential function; The initial population is generated randomly. The genetic algorithm also includes genetic operations, including three basic genetic operators: selection genetic operator, crossover genetic operator, and mutation genetic operator.

2. The image size calibration method based on the improved Zhang Zhengyou calibration method according to claim 1, characterized in that, The fitness function is: (6) Formula (6) serves as the fitness function, where It is the initial value of an individual.

3. The image size calibration method based on the improved Zhang Zhengyou calibration method according to claim 1, characterized in that, The selection of genetic operators uses a roulette wheel selection algorithm, specifically including: S1: Calculate the probability of each individual being selected. ; S2: Calculate the cumulative probability of each part. ; S3: Randomly generate an array R, where the elements in the array take values ​​between 0 and 1, and sort the array in ascending order: If the cumulative probability Greater than the elements in the array Then the individual Selected; If the cumulative probability Less than the element in the array Then compare the next individual. Until an individual is selected; S4: If N individuals need to be selected, repeat step S3 N times.

4. The image size calibration method based on the improved Zhang Zhengyou calibration method according to claim 3, characterized in that, The probability of each individual being selected for: (7) The cumulative probability of each part for: (8) In formulas (7) and (8), the population size is... ;individual fitness is ,individual The probability of being selected is ;individual The cumulative probability of being selected is ; This represents calculating the fitness values ​​of all individuals in the population and summing them to obtain the total fitness. Indicates the first The probability of an individual being selected.

5. The image size calibration method based on the improved Zhang Zhengyou calibration method according to claim 1, characterized in that, The crossover genetic operator selects one-point crossover as the crossover method, and the specific steps are as follows: S5: Select an intersection point; S6: Initially divide the two parent individuals into two segments at the intersection point; S7: After exchanging fragments, two new individuals are formed: Child generation 1 = the first half of parent generation 1 + the second half of parent generation 2; Child generation 2 = the first half of parent generation 2 + the second half of parent generation 1.

6. The image size calibration method based on the improved Zhang Zhengyou calibration method according to claim 1, characterized in that, The mutation genetic operator, with a set mutation probability, includes the following steps: S8: Determine whether all individuals have completed mutation based on the pre-set mutation probability; S9: The location where the mutation is randomly selected.

7. A method for calculating the area of ​​wood defects using the image size calibration method based on the improved Zhang Zhengyou calibration method as described in any one of claims 1 to 6, characterized in that, include: Target detection and recognition are performed on the distorted wood image to generate defect bounding boxes; The camera calibration results obtained using the improved Zhang Zhengyou calibration method are used to transform the pixel coordinates in the defect box to physical coordinates for calculation. Furthermore, the actual distance between two points on the defect box in the real world, corresponding to the pixel distance between two points on the defect box, is calculated to determine the scale factor between each pair of pixels. ; The scale factor among all obtained pixels The target scale factor is obtained by calculating the mean. ; Using the target scale factor Calculate the area per unit pixel The actual number of defect pixels is obtained by thresholding, and the precise area of ​​the wood defect is finally obtained.

8. The method for calculating the area of ​​timber defects according to claim 7, characterized in that, The calculation of the pixel distance between two points in the defect box corresponds to the actual distance between the two points in the real world, in order to solve for the scale factor between every two pixels. Specifically: (9) In formula (9), Scale factor; Represents the rotation matrix; Represents the translation matrix; The physical coordinates of any point in the world coordinate system; This represents the pixel coordinates of that point in the pixel coordinate system. dX and dY represent the physical length of a pixel on the camera's image sensor in the X and Y directions, respectively, i.e., how many millimeters a pixel is on the image sensor. This represents the coordinates of the center of the camera's image sensor in the pixel coordinate system, i.e., the principal point coordinates; Indicates the angle between the horizontal and vertical edges of the photosensitive plate; After transforming formula (9), we get: (10) in, (11) In formulas (10) and (11), Represents the camera intrinsic parameter matrix; for The inverse matrix, for The inverse matrix; Set the value of any preceding pixel in the defect box. and the next pixel value Substituting each into formula (10), we get: (12) (13) In formulas (12) and (13), , , These represent the values ​​of the previous pixel in the defect box. Three-dimensional coordinate components in the world coordinate system; , , These represent the value of the next pixel in the defect box. Three-dimensional coordinate components in the world coordinate system; at this time Subtracting formula (12) from formula (13) yields: (14) In formula (14), and Pixel value and The difference in pixels between them and Pixel value and The difference in the actual distance between the corresponding points in the world coordinate system.

9. The method for calculating the area of ​​timber defects according to claim 8, characterized in that, Using the target scale factor Calculate the area per unit pixel The actual number of defect pixels is obtained through thresholding, ultimately yielding the precise area of ​​the wood defect. Officials (15), (16), = ; = ; and It has no impact on subsequent calculations, so when When, the area per unit pixel is obtained. for: After the wood image is processed by deep learning to detect the defect type, the detection bounding box of the defect is used as the boundary. Thresholding is performed inside the detection box to calculate the number of pixels in the defect area, and then the area of ​​the defect is calculated.

Citation Information

Patent Citations

  • Camera distortion pixel-by-pixel calibration method

    CN113284196A

  • High-precision calibration method based on genetic algorithm

    CN103871068A

  • Camera calibration method based on lens regional distortion function model

    CN109754436A