Disclosure of Invention
The invention aims to provide a cutter identification algorithm based on probability program inference, which obtains a cutter outline by using an edge detection method and utilizes the probability program inference to identify, is not easily interfered by noise, and can output a relatively complete outline so as to improve the accuracy and the reliability of identification.
In order to achieve the purpose, the invention provides the following technical scheme:
a tool recognition algorithm based on probabilistic procedural inference, characterized by: the algorithm comprises the following steps:
s1: aiming at any cutter image, extracting contour data of a cutter by adopting an edge detection method, and converting the contour data into a data point set;
s2: designing corresponding probability programs aiming at the straight knife and the curved knife respectively;
s3: and deducing the same cutter image by using a straight cutter probability program and a bent cutter probability program respectively to obtain a straight cutter candidate shape and a bent cutter candidate shape, and selecting a shape with the maximum similarity from the candidate shapes as a final shape.
Preferably, the step of extracting the tool profile by the edge detection method in S1 is as follows:
s1-1: smoothing the image using a gaussian filter;
s1-2: detecting and binarizing by using a Canny algorithm object, and connecting edges;
s1-3: extracting contour data of the processed image in the S1-2 by using an OpenCV algorithm;
s1-4: the profile data is converted into a data set for subsequent use.
Preferably, the construction method of the probability program of the straight knife in S2 is as follows: the cutting edge arc line is a vertical straight line r11 extending to the back of the knife from a connection point of the cutting edge arc line which is completely bent into a straight line, the ray r12 is taken by the cutting edge to the outer side of the back of the knife, r11 and r12 are intersected at a certain point, r11 is r12, meanwhile, the perpendicular line L11 of r11 is taken by the cutting edge as a starting point, the included Angle between r12 and L11 is Angle, and the cutting edge Angle A is (1-sin (Angle))/cos (Angle)).
Preferably, the construction method of the probability program of the knife bending in S2 is as follows: the curved knife usually has two arc-shaped cutting edges, so the two cutting edges are constructed by adopting a straight knife construction method to obtain r11, r12 and Angle1 of a first cutting edge and r21 and r22 of a second cutting edge, and meanwhile, the included Angle between r22 and r12 is made to be Angle2, so that the knife tip Angle is:
A=(1-sin(Angle1))/cos(Angle1)-(1-sin(Angle1+Angle2))/cos(Angle1+Angle2)
or
A=(1-sin(Angle1))/cos(Angle1)-(1-sin(Angle1+Angle2))/cos(Angle1+Angle2)
Preferably, the probabilistic procedure inference step in S3 is as follows:
s3-1: running a probability program according to the current parameter value and obtaining a corresponding geometric shape;
s3-2: calculating the similarity between the geometric shape and the image data point set by using an average measurement method;
s3-3: and updating the parameter value of the probability program by utilizing a rhododendron search algorithm, and repeating the steps until the similarity between the geometric shape and the image data point set is basically unchanged.
The principle and the beneficial effects of the technical scheme are as follows:
the invention utilizes an edge detection method to extract the contour data of a cutter image, designs corresponding probability programs aiming at a straight cutter and a bent cutter respectively, then infers the same cutter image by using the straight cutter probability program and the bent cutter probability program respectively to obtain a straight cutter candidate shape and a bent cutter candidate shape, and then selects a shape with the maximum similarity from the candidate shapes as a final shape. The method has the key steps of probability program inference, and the principle is that the optimized geometric shape is continuously updated by utilizing a rhododendron search algorithm, so that the outline of the cutter can be completely detected, and the method is high in data utilization efficiency, good in interpretability and strong in robustness.
Detailed Description
The invention is described in further detail below with reference to the following figures and embodiments:
as shown in fig. 6, a cutter identification algorithm based on probabilistic procedure inference uses an edge detection method to obtain a cutter contour and utilizes probabilistic procedure inference to identify the cutter contour, which is not easily interfered by noise, and can output a relatively complete contour, so as to improve the accuracy and reliability of identification, even in a huge data point set, the algorithm can still maintain a strong anti-noise capability, and the program has good robustness; the algorithm comprises the following steps:
s1: aiming at any cutter image, extracting contour data of a cutter by adopting an edge detection method, and converting the contour data into a data point set;
the step of extracting the tool profile by the edge detection method in the step S1 is as follows:
s1-1: smoothing the image using a gaussian filter;
s1-2: detecting and binarizing the image by using a Canny algorithm object, and connecting edges;
s1-3: extracting contour data of the processed image in the S1-2 by using an OpenCV algorithm;
s1-4: the profile data is converted into a data set for subsequent use as shown in figures 1 and 2.
The Canny algorithm has the advantages that the Canny algorithm is not easily interfered by noise and can output a complete outline, the detection principle of the Canny algorithm is to find the local maximum value of the image gradient, strong edges and weak edges are respectively detected through a high threshold and a low threshold, and the connection positions of the strong edges and the weak edges are output as edges.
S2: designing corresponding probability programs aiming at the straight knife and the curved knife respectively;
the probability program construction method of the straight knife comprises the following steps:
the shape of a straight blade is described as a shape in which the tip of the blade intersects a line segment with one of the various endpoints of an arc, the other endpoint of which extends outwardly. In common knife types, the fruit knives are mostly in the shape as shown in fig. 1.
The number of the parameters of the straight knife can be determined to be 5 according to the shape of the knife, as shown in figure 3. The detailed meanings of the parameters are:
x0: the tool nose (the intersection of the arc line and the line segment) is on the abscissa of the two-dimensional pixel matrix of the picture.
Y0: the knife tip (the intersection of the arc line and the line segment) is on the ordinate of the two-dimensional pixel matrix of the picture.
Length: the blade arc is displaced horizontally from the bend towards a straight line.
Angle: the angle of deviation of the line from the other side of the arc determines the length of the arc, the angle and the position of the arc relative to the line. The ray passing through the point along the edge will intersect a vertical connecting line (X1, Y1) at a point which is perpendicular to the line at which the point of inflection of the line of the arc gradually tends to the line of the turn. Wherein, the intersection point (X1, Y1) is the center of a circle, the length of the ray and the vertical connecting line are the radiuses, and the arc line is a section of arc of the circle. The nose angle a is shown in the following formula,
A=(1-sin(Angle))/cos(Angle)
the larger Angle, the smaller the nose Angle.
Azimuth: the rotation angle of the knife in the picture is based on the fact that one side of a straight line of the knife is horizontal, one side of an arc line is downward, and the point of the knife is located on the left side.
The probability program construction method of the curved knife comprises the following steps:
the shape of the curved knife is described as that the knife tip intersects with a point by an end point of each of two arcs, and the non-intersecting end points extend outwards to form a line segment to form the knife edge. In common knife types, daggers and mountaineers are mostly in this shape, as shown in fig. 2.
The curved knife is composed of two intersecting arcs, and defining two arcs by the arc definition method of the straight knife leads to excessive parameters, which seriously reduces the fitting effect and speed, so that one arc needs to depend on the change of the other arc. As shown in fig. 4, the parameters have the following meanings:
x0: the horizontal coordinate of the knife tip (the intersection point of two knife edge arcs) on the two-dimensional pixel matrix of the picture
Y0: the vertical coordinate of the knife tip (the intersection point of two knife edge arcs) on the two-dimensional pixel matrix of the picture
Azimuth: the rotation angle of the knife in the picture is horizontal to the X axis in the implementation, the arc line 1 is positioned at the lower side of the X axis, the arc line 2 is positioned at the upper side of the X axis, and the knife point is positioned at the left side as a reference
Angle 1: when Azimuth is 0, the value may be negative for an offset angle of the X-axis with respect to the other side of arc 1. Angle1 determines the length, Angle and position of arc 1 with respect to the X-axis. The ray passing through the point along the edge will intersect a vertical connecting line (X1, Y1) at a point which is perpendicular to the line at which the point of inflection of the line of arc 1 gradually tends toward the line. Wherein, the intersection point (X1, Y1) is the center of a circle, the length of the ray and the vertical connecting line are the radiuses, and the arc line is a section of arc of the circle.
Angle 2: an Angle of counterclockwise rotation with respect to ray Angle 1. The sum of the angles of Angle1 and Angle2 is an offset Angle of the other side of the X-axis with respect to arc 2 (when Azimuth is 0). The ray passing through the point along the edge will intersect a vertical connecting line (X2, Y2) which is the vertical connecting line made by the point where the arc 2 gradually tends towards the turning point of the straight line. Wherein, the intersection point (X2, Y2) is the center of a circle, the length of the ray and the vertical connecting line are the radiuses, and the arc line is a section of arc of the circle. The nose angle is shown in the following two formulas,
A=(1-sin(Angle1))/cos(Angle1)-(1-sin(Angle1+Angle2))/cos(Angle1+Angle2)
A=(1-sin(Angle1))/cos(Angle1)-(1-sin(Angle1+Angle2))/cos(Angle1+Angle2)
angle1 and Angle2 together determine the size of the cutting tip. If the symbol of Angle1 is the same as that of (Angle1+ Angle2), the nose Angle A is the first formula; if the signs are opposite, the nose angle A is a second formula.
PM-a 2: the sign of Angle2 is determined. In order to prevent the blade arc 1 from coinciding with the blade arc 2, it is necessary to ensure that the included Angle between them cannot be too small, so the value of Angle2 needs to be greater than 0, but in order to meet the randomness of the probability program, the value of Angle2 also needs to have a parameter value less than 0, and the parameter PM-a2 is added to determine the positive and negative of Angle 2.
Length 1: the blade arc 1 is displaced horizontally from a bend towards a straight line.
Length 1: the blade arc 2 is displaced horizontally from a bend towards a straight line.
S3: the straight tool probability program and the curved tool probability program are used for deducing the same tool image respectively to obtain a straight tool candidate shape and a curved tool candidate shape, and then a shape with the maximum similarity is selected from the candidate shapes to serve as a final shape, as shown in fig. 6.
As shown in fig. 5, the inference step of the probability program in S3 is as follows:
s3-1: running a probability program according to the current parameter value and obtaining a corresponding geometric shape;
s3-2: calculating the similarity between the geometric shape and the image data point set by using an average measurement method;
s3-3: and updating the parameter value of the probability program by utilizing a rhododendron search algorithm, and repeating the steps until the similarity between the geometric shape and the image data point set is basically unchanged.
Example verification:
the data point sets and the geometric shapes are fitted through a rhododendron search algorithm, the fitting effect of the straight knife and the bent knife is continuously enhanced along with the increase of the number of rhododendron search iterations, and an example effect is shown in fig. 7. In the figure, a red point set is a data point set obtained through OpenCV, a green point set is a geometric shape, and the geometric shape is changed continuously along with the similarity calculated by an optimization algorithm.
As shown in fig. 7, at the very beginning (number of iterations 10000), the shape to which the tool fits has already roughly locked the position of the contour. In fact, when the number of iterations is small, the fitting position of the tool changes continuously, and the shape finally fitted cannot be immediately judged. After a period of fitting (number of iterations 50000), the probability program has tended to stabilize, and more accurate parameters were continuously tried at the same location. After the fitting is judged to be stable for a period of time by observation (the number of iterations is 100000), it is difficult to judge the change of the fitting effect by naked eyes. At the final end stage of the procedure (iteration number 200000), the similarity value also changes very slightly, and the final result of the fitting is also determined approximately around this iteration number.
FIG. 8 shows on the right the similarity evolution process of probabilistic procedure inference on the straight-edged image shown on the left in FIG. 8 using a straight-edged probabilistic procedure. It can be seen that the geometric shape finally obtained by the estimation using the straight-line tool probability program has a higher similarity than the geometric shape finally obtained by the estimation using the curved-line tool probability program, and therefore the straight-line tool image is correctly recognized as a straight-line tool.
FIG. 9 shows on the right the similarity evolution process of probabilistic procedure inference on the curved-blade image shown on the left of FIG. 9 using a curved-blade probabilistic procedure. It can be seen that the geometric shape finally obtained by the estimation using the curved blade probability program has a higher similarity than the geometric shape finally obtained by the estimation using the straight blade probability program, and therefore the curved blade image is correctly recognized as a curved blade.
The foregoing is merely an example of the present invention and common general knowledge in the art of designing and/or characterizing particular aspects and/or features is not described in any greater detail herein. It should be noted that, for those skilled in the art, without departing from the technical solution of the present invention, several variations and modifications can be made, which should also be regarded as the protection scope of the present invention, and these will not affect the effect of the implementation of the present invention and the practicability of the patent. The scope of the claims of the present application shall be determined by the contents of the claims, and the description of the embodiments and the like in the specification shall be used to explain the contents of the claims.