A hammer identification method and device based on probability program inference
Through a method based on probabilistic program inference, using edge detection and probabilistic programming, combined with the average measure and cuckoo search algorithm, the problem of low hammer identification efficiency and missed detection in the existing technology is solved, and higher identification accuracy and Credibility.
Patent Information
- Application Number
- CN202111493200.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-08
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-12-08
AI Technical Summary
The existing hammer image recognition technology has low detection efficiency and is easily missed in luggage security inspection and industrial production, and cannot effectively improve the accuracy and credibility of identification.
A method based on probabilistic program inference is used to extract hammer contour data through edge detection, and probabilistic programs are designed for claw hammers, masonry hammers and fitter hammers. The average measure and cuckoo search algorithm are used to optimize geometric shapes, and the shape with the greatest similarity is selected as the The final shape is identified.
It improves the accuracy and credibility of hammer tool identification, enhances the robustness and identification ability of imperfect data, reduces noise interference, outputs a more complete outline, and improves the robustness of identification.
Smart Images

Figure CN114266797B
Abstract
Description
Technical Field
[0001] The embodiments of the present invention relate to the field of image recognition technology, and in particular to a hammer recognition method and device based on probability program inference. Background Art
[0002] At present, hammer image recognition is mainly used in areas involving industrial production and public safety, such as luggage security inspection systems and hammer production classification systems. For example, to ensure the safety of airports, railway stations, subway stations and other public places with a large number of people, the detection of dangerous goods in luggage (including the detection of sharp hammers) has become one of the necessary safety measures; automated equipment with good performance and high production efficiency is particularly important in industrial production. Through image recognition, different types of hammers can be accurately delivered to the corresponding production line. The existing method of hammer detection through image recognition does not achieve the best effect. Summary of the invention
[0003] Based on this, the embodiment of the present invention provides a hammer identification method and device based on probability program inference to improve the accuracy and credibility of hammer identification. The technical solution is as follows:
[0004] In a first aspect, an embodiment of the present application provides a hammer identification method based on probability program inference, the method comprising the following steps:
[0005] S1: For a hammer image, edge detection method is used to extract the contour data of the hammer and convert it into a data point set;
[0006] S2: Design corresponding probability programs for claw hammer, masonry hammer and pliers hammer respectively
[0007] S3: For the data point set, inference is performed using a claw hammer probability program, a stoning hammer probability program and a pliers hammer probability program respectively to obtain candidate shapes of a claw hammer, a stoning hammer and a pliers hammer, and then the shape with the greatest similarity is selected from the candidate shapes as the final shape.
[0008] Optionally, the steps of extracting the hammer contour by the edge detection method in S1 are as follows:
[0009] S1-1: compress the read image and convert it into a single-channel grayscale image;
[0010] S1-2: Use the improved Canny detection algorithm to perform edge detection and identify the real edge;
[0011] S1-3: Noise removal: After edge detection is completed, the morphological "open" operation is used to eliminate small noises, and then the "close" operation is used to reconstruct the lost edge parts to fill the inner part of the target object and obtain the outline of the main feature object;
[0012] S1-4: Contour extraction: Each contour in the image corresponds to a point set. First, we decide whether to save the contour based on whether the starting point of the contour is closed, and then build a contour tree. The findContours function provided by OpenCV is used to build the contour. The RETR_EXTERNAL retrieval mode is selected to detect only the outer contour, and the CHAIN_APPROX_NONE approximation method is selected to store all the outer contour points.
[0013] Optionally, the method for constructing the probability program in S2 is as follows:
[0014] Firstly, the number of control points of the hammer head is variable, and the number of control points of the hammer handle is fixed. A cubic B-spline method is used to describe the spline curve approximate fitting. The probability program is described by a closed spline curve of multiple control points.
[0015] Optionally, the steps of the probability program inference in S3 are as follows:
[0016] S3-1: Run the probability program according to the current parameter values and obtain the corresponding geometric shape;
[0017] S3-2: Calculate the similarity between the geometric shape and the image data point set using the average measurement method;
[0018] S3-3: Use the cuckoo search algorithm to update the parameter values of the probability program, and repeat the above steps until the similarity between the geometric shape and the image data point set remains basically unchanged.
[0019] In a second aspect, an embodiment of the present application provides a hammer identification device based on probability program inference, the device comprising:
[0020] An extraction module is used for extracting the contour data of the hammer using an edge detection method for a hammer image, and converting the contour data into a data point set;
[0021] A program design module, used to design corresponding probability programs for claw hammer, masonry hammer and fitter hammer respectively;
[0022] The recognition module is used to use the claw hammer probability program, the stoning hammer probability program and the locksmith hammer probability program to infer the data point set respectively, to obtain the candidate shapes of the claw hammer, the stoning hammer and the locksmith hammer, and then select the shape with the greatest similarity from the candidate shapes as the final shape.
[0023] In order to improve the accuracy and credibility of hammer identification, the present invention designs a hammer identification method based on probabilistic program inference. The key to this method is the use of a hammer similarity metric (called average measure) based on the error from geometric shapes to data point sets, which can robustly evaluate the similarity between geometric shapes and imperfect (noisy, outlier or incomplete) data point sets.
[0024] The principle and beneficial effects of this technical solution:
[0025] The present invention uses edge detection method to extract the contour data of hammer image, designs corresponding probability programs for claw hammer, stoning hammer and fitter's hammer respectively, and then uses claw hammer probability program, stoning hammer probability program and fitter's hammer probability program to infer the same hammer image respectively, obtains candidate shapes of claw hammer, stoning hammer and fitter's hammer, and then selects the shape with the greatest similarity from the candidate shapes as the final shape. One of the key steps is probability program inference, and its principle is to use cuckoo search algorithm to continuously update and optimize geometric shapes so that the contour of the hammer can be fully detected. Compared with other existing technologies, this technology has high data utilization efficiency, good interpretability and strong robustness. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0027] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0028] Figure 1 It is a flowchart of a hammer identification method based on probability program inference shown in an embodiment of the present invention;
[0029] Figure 2a-2d It is a schematic diagram of extracting the contour of a hammer using the edge detection method shown in an embodiment of the present invention;
[0030] Figure 3 A schematic diagram of a probability program inference flow chart shown in an embodiment of the present invention;
[0031] Figure 4 It is a schematic diagram of the overall flow of the hammer identification method shown in an embodiment of the present invention;
[0032] Figures 5a-5f A test result diagram provided for an embodiment of the present invention;
[0033] Figure 6a-6c A diagram showing the similarity evolution process of the hammer probability program inference provided by an embodiment of the present invention;
[0034] Figure 7 It is a schematic diagram of the structure of a hammer identification device based on probability program inference shown in an embodiment of the present invention. DETAILED DESCRIPTION
[0035] In order to make the purpose, technical solution and advantages of the embodiments of the present invention clearer, the technical solution in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0036] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0037] In systems such as luggage security inspection and industrial production classification, hammer identification is often required. A good hammer identification solution helps solve problems such as low detection efficiency and missed detection. The hammer identification method based on probabilistic program inference provided in the embodiment of the present application uses an edge detection method to obtain the hammer contour and uses probabilistic program inference for identification. It is not easily affected by noise and can output a relatively complete contour, thereby improving the accuracy and reliability of identification. Even if the data point set contains a lot of noise, the method in this paper can still maintain good recognition ability, and the program has good robustness.
[0038] Reference Figure 1 As shown, the method comprises the following steps S1-S3:
[0039] S1: For a hammer image, edge detection method is used to extract the contour data of the hammer and convert it into a data point set;
[0040] In the present application, in the above step S1, the step of extracting the hammer contour by the edge detection method specifically includes the following steps:
[0041] S1-1: compress the read image and convert it into a single-channel grayscale image;
[0042] S1-2: Use the improved Canny detection algorithm to perform edge detection and identify the real edge;
[0043] S1-3: Noise removal: After edge detection is completed, the morphological "open" operation is used to eliminate small noises, and then the "close" operation is used to reconstruct the lost edge parts to fill the inner part of the target object and obtain the outline of the main feature object;
[0044] S1-4: Contour extraction: Each contour in the image corresponds to a point set. First, we decide whether to save it based on whether the starting point of the contour is closed, and then build the contour tree. This application uses the findContours function provided by OpenCV to build the contour. Since we only need the outer contour of the hammer, we select the RETR_EXTERNAL retrieval mode to detect only the outer contour, and select the CHAIN_APPROX_NONE approximation method to store all the outer contour points.
[0045] S2: Design corresponding probability programs for claw hammer, masonry hammer and pliers hammer respectively
[0046] The probabilistic program design of the hammer tool should first start from the geometric characteristics of the hammer tool. Based on experience and the analysis of image contour features, the following characteristics are taken into account: ① The hammer tool can usually be divided into two parts with large contour differences: the hammer head and the hammer handle; ② The hammer handle and the hammer head have certain curve characteristics, but basically the outer rectangle can be described by referring to the voxelization method to describe the basic contour; ③ The main difference between different hammers is in the hammer head part, and the difference between the hammer handle is small. According to the above characteristics, the hammer tool program can be described by a closed spline curve with multiple control points, and how to determine the control points of the spline requires a probabilistic program to identify and describe. In the specific implementation, the cubic B-spline method is used to describe the spline curve for approximate fitting. In addition, since the hammer head is the center of the hammer tool, the number of control points of the hammer head is set to be variable in the implementation of this article, while the number of control points of the hammer handle is fixed.
[0047] The probabilistic program of the hammer has four rules: hammer, hammer head, hammer handle and rendering, as shown in Table 1, Table 2, Table 3 and Table 4. The program first calls the hammer rule (Table 1) to obtain the global basic parameters, including the anchor point I, width W, height H and the number of control points K of the cubic spline curve. Then the hammer head rule (Table 2) is called according to the basic parameters obtained. The corresponding K control points will be generated in the hammer head rule, which is used to describe the curve of the hammer head. Then the hammer handle rule (Table 3) is called according to the anchor point and the basic rectangular parameters, namely W and H. The rule will generate a fixed number of control points (set to 5 in this paper) according to the parameters to describe the hammer handle with a simpler shape and structure. Finally, the rendering rule (Table 4) is used to perform linear transformations on the curve point set generated after the control points are calculated by interpolation, including rotation and radial transformation (translation has been implemented through the anchor point variables in the hammer rule). Finally, the hammer model is represented according to the point cloud generated above. Through the analysis of parameter rules, the total number of parameters that can be represented by the probability program is 8+K, and the specific number of variables of the hammer model is obtained through prior knowledge or training.
[0048] Table 1 Hammer rules
[0049]
[0050] Table 2 Hammerhead Rules
[0051]
[0052]
[0053] Table 3 Hammer handle rules
[0054]
[0055] Table 4 Rendering rules
[0056]
[0057] S3: The contour data point set extracted from the hammer image described in S1 is inferred using a claw hammer probability program, a stoning hammer probability program, and a pliers hammer probability program, respectively, to obtain candidate shapes of a claw hammer, a stoning hammer, and a pliers hammer, and then the shape with the greatest similarity is selected from the candidate shapes as the final shape.
[0058] For example, Figure 4As shown, a hammer image to be identified is obtained, and n (n≥3) candidate shapes are obtained by processing through n probability programs respectively. For example, candidate shape 1 is obtained by processing through hammer probability program 1, and candidate shape 2 is obtained by processing through hammer probability program 2…, and the obtained n candidate shapes are compared and analyzed, and the candidate shape with the greatest similarity is selected as the optimal trait, that is, the determined final shape.
[0059] In the embodiment of the present application, the probability program inference in the above step S3 specifically includes the following steps:
[0060] S3-1: Run the probability program according to the current parameter values and obtain the corresponding geometric shape;
[0061] S3-2: Calculate the similarity between the geometric shape and the image data point set using a similarity calculation method (the present invention adopts an average measurement method);
[0062] S3-3: Use an optimization algorithm (the present invention uses the cuckoo search algorithm) to update the parameter values of the probability program, and repeat the above steps until the similarity between the geometric shape and the image data point set remains substantially unchanged.
[0063] like Figure 3 As shown in FIG, the process of probability program inference generally includes: inputting a data point set, inputting a probability program and initializing relevant parameters, obtaining parameters according to an optimization algorithm (which can be specified or randomly generated during initialization) and running the probability program, generating a corresponding geometric model, calculating the similarity between the current model and the data point set through an estimator, and then updating the parameter value according to the proposed density function of the optimization algorithm. The above steps are iterated until the objective function converges, otherwise the updated parameter value is adopted to continue running the probability program.
[0064] The extraction process of the hammer image contour point set includes: edge detection (refer to Figure 2a ); morphological operations (see Figure 2b ); contour extraction (refer to Figure 2c ); The obtained contour point set (refer to Figure 2d ).
[0065] Figures 5a-5f is a schematic diagram of the hammer image and fitting process, where: Figure 5a-5c They are the images of claw hammer, stoning hammer and bench hammer respectively; Figure 5d-5f The probability program is used with a claw hammer, a mason's hammer and a fitter's hammer respectively. Figure 5a-5c The fitting process on the picture, where the blue part is the data point set extracted from the hammer image, and the green part is the fitted geometric shape.
[0066] Figure 6a-6cThe similarity evolution process diagram of the hammer tool probability program inference. In the figure, M1, M2, and M3 represent the probability programs of the claw hammer, mason's hammer, and fitter's hammer, respectively. (a) is the use of M1, M2, and M3 in the claw hammer image (see Figure 6a ) is a diagram of the similarity evolution process of probabilistic program inference on the image of the masonry hammer (see Figure 6b ) is a similarity evolution diagram for probabilistic program inference on the image of the fitter's hammer (see Figure 6c ) using a probabilistic program. From these similarity evolution diagrams, it can be seen that different types of hammers can be correctly identified.
[0067] Figure 7 FIG. 1 is a schematic diagram of a hammer identification device based on probability program inference shown in an embodiment of the present invention; Figure 7 As shown, the hammer identification device comprises:
[0068] An extraction module 701 is used to extract the contour data of the hammer using an edge detection method for a hammer image, and convert it into a data point set;
[0069] Program design module 702, for designing corresponding probability programs for claw hammer, masonry hammer and fitter hammer respectively;
[0070] The recognition module 703 is used to use the claw hammer probability program, the stoning hammer probability program and the locksmith hammer probability program to infer the data point set, obtain the candidate shapes of the claw hammer, the stoning hammer and the locksmith hammer, and then select the shape with the greatest similarity from the candidate shapes as the final shape.
[0071] In summary, the design of a robust similarity estimator, a suitable optimization algorithm, how to properly preprocess image data, and write an appropriate probability program are the core of the recognition method implemented by this technical solution.
[0072] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. A hammer identification method based on probabilistic program inference, characterized in that: The method comprises the following steps: S1: for a hammer image, using an edge detection method to extract the contour data of the hammer, and converting it into a data point set; S2: Design corresponding probability programs for claw hammer, mason's hammer and fitter's hammer respectively; The probability program includes: firstly, calling the hammer tool rule to obtain the global basic parameters, including the anchor point I, the width W, the height H and the number K of control points of the cubic spline curve; then, calling the hammer head rule according to the obtained basic parameters, and generating the corresponding K control points in the hammer head rule; then, calling the hammer handle rule according to the anchor point and the basic rectangle parameters W and H, and the rule generates a fixed number of control points according to the parameters, which is used to describe the hammer handle with a simpler shape and structure; finally, using the rendering rule to perform linear transformation on the curve point set generated after calculating the control points by interpolation, including rotation and radiation transformation; finally, representing the hammer tool model according to the point cloud generated above; through the analysis of the parameter rules, the total number of parameters that can be represented by the probability program is 8+K, and the specific number of variables of the hammer tool model is obtained through prior knowledge or training; S3: For the data point set, inference is performed using a claw hammer probability program, a stoning hammer probability program and a pliers hammer probability program respectively to obtain candidate shapes of a claw hammer, a stoning hammer and a pliers hammer, and then the shape with the greatest similarity is selected from the candidate shapes as the final shape.
2. The method according to claim 1, characterized in that The steps of extracting the hammer contour by the edge detection method in S1 are as follows: S1-1: compressing the read-in image and converting it into a single-channel grayscale image; S1-2: Use the improved Canny detection algorithm to perform edge detection and identify the real edge; S1-3: Noise removal: After edge detection is completed, the morphological "open" operation is used to eliminate small noises, and then the "close" operation is used to reconstruct the lost edge part to fill the inner control of the target object and obtain the contour of the main feature object; S1-4: Contour extraction: Each contour in the image corresponds to a point set. First, decide whether to save it based on whether the starting point of the contour is closed, and then build a contour tree; Among them, the findContours function provided by OpenCV is used to realize the construction of the contour, and the RETR_EXTERNAL retrieval mode is selected to detect only the outer contour, and the CHAIN_APPROX_NONE approximation method is selected to store all peripheral contour points.
3. The method according to claim 1, characterized in that The construction method of the probability program in S2 is as follows: the number of control points of the hammer head is set to be variable, the number of control points of the hammer handle is set to be fixed, and the cubic B-spline method is used to describe the approximate fitting of the spline curve. The probability program is described by a closed spline curve of multiple control points.
4. The method according to claim 1, characterized in that: The steps of probability program inference in S3 are as follows: S3-1: running the probability program according to the current parameter value and obtaining the corresponding geometric shape; S3-2: Calculate the similarity between the geometric shape and the image data point set using the average measurement method; S3-3: Update the parameter value of the probability program using the cuckoo search algorithm, and repeat the above steps S3-1 and S3-2 until the similarity between the geometric shape and the image data point set remains basically unchanged.
5. A hammer identification device based on probability program inference, characterized in that: The device comprises: an extraction module, for extracting the contour data of the hammer using an edge detection method for a hammer image, and converting the contour data into a data point set; A program design module, used to design corresponding probability programs for claw hammer, masonry hammer and fitter hammer respectively; The probability program includes: firstly, calling the hammer tool rule to obtain the global basic parameters, including the anchor point I, the width W, the height H and the number K of control points of the cubic spline curve; then, calling the hammer head rule according to the obtained basic parameters, and generating the corresponding K control points in the hammer head rule; then, calling the hammer handle rule according to the anchor point and the basic rectangle parameters W and H, and the rule generates a fixed number of control points according to the parameters, which is used to describe the hammer handle with a simpler shape and structure; finally, using the rendering rule to perform linear transformation on the curve point set generated after calculating the control points by interpolation, including rotation and radiation transformation; finally, representing the hammer tool model according to the point cloud generated above; through the analysis of the parameter rules, the total number of parameters that can be represented by the probability program is 8+K, and the specific number of variables of the hammer tool model is obtained through prior knowledge or training; The recognition module is used to use the claw hammer probability program, the stoning hammer probability program and the locksmith hammer probability program to infer the data point set respectively, to obtain the candidate shapes of the claw hammer, the stoning hammer and the locksmith hammer, and then select the shape with the greatest similarity from the candidate shapes as the final shape.
