A method and system for automatic identification of controlled tools based on image processing
Through the automatic identification method and system for controlling tool identification based on image processing, the problem of fixing tool measurement sites and inaccurate results in the prior art is solved, and flexible, accurate and real-time tool type determination is achieved.
Patent Information
- Application Number
- CN202410147837.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-02-02
- Publication Date
- 2025-02-07
- Estimated Expiration
- 2044-02-02
AI Technical Summary
In the prior art, the measurement and use location of controlled tools is fixed, the measurement results are inaccurate, and the on-site cannot be judged in time, resulting in insufficient flexibility, accuracy and real-time data processing of tool measurement.
Using the controlled tool identification automatic recognition method and system based on image processing, by building an automatic recognition model, receiving user requests in real time, acquiring and processing tool images, performing cropping, noise reduction and graphic recognition, analyzing and calculating, and comparing and determining parameters to achieve rapid and Accurate tool type judgment.
It improves the flexibility and accuracy of tool measurement, enhances the real-time nature of data processing and result feedback, and can be flexibly used in different places to quickly and accurately determine tool type.
Smart Images

Figure CN118196768B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of graphic image recognition and data processing, and more specifically, to an automatic recognition method and system for controlled tool identification based on image processing. Background Art
[0002] Controlled knives are the tools that are closest to the production and life of the general public among the dangerous goods listed by the public security organs' public security departments. They are also the tools that criminals currently like to use the most. The reason lies in the concealedness of controlled knives and their easy access compared to firearms and explosives.
[0003] Article 32 of the Civil Code stipulates that anyone who illegally carries firearms, ammunition, crossbows, daggers, or other controlled instruments prescribed by the state shall be detained for not more than five days and may be fined not more than 500 yuan; if the circumstances are relatively minor, he shall be given a warning or fined not more than 200 yuan. Anyone who illegally carries firearms, ammunition, crossbows, daggers, or other controlled instruments prescribed by the state into public places or public transportation shall be detained for not less than five days but not more than ten days and may be fined not more than 500 yuan. Controlled knives are one of the categories of controlled instruments. At present, the identification standards for controlled knives are based on the national standard documents GA 1334-2016 "Classification and Safety Requirements for Controlled Knives", GA / T 1335-2016 "Classification and Safety Requirements for Daily Knives" and the "Controlled Knife Identification Standard (Public Communication No.
[2007] 2)" formulated by the Ministry of Public Security. The means of identifying controlled knives are mainly based on the parameters of the knife's total length, blade length, handle length, tip angle, whether there is a blood groove, whether it is a folding knife, etc. At present, the method for measuring and distinguishing controlled knives by public security police in accordance with management requirements is mainly to manually measure the knives using standard rulers and protractors, and compare the measured data with the comparison parameters in the above management requirements to determine whether they are controlled knives. Compared with manual measurement to obtain tool parameters, the main problem is that the places where the police confiscate knives (subway security checkpoints, airport security checkpoints, large-scale event security checkpoints, etc.) are not fixed, and the measurement operation requires high standardization, high accuracy, and strong real-time performance, resulting in the need for manual measurement personnel to have a certain degree of professionalism, inaccurate measurement results, and the inability to make timely judgments on the spot.
[0004] Based on this, it is necessary to introduce a new method and system that can flexibly, conveniently and accurately measure the tools and quickly determine the tool type according to the usage requirements in different places, so as to solve the technical problems existing in the prior art that the tool measurement is fixed in the use place, the measurement results are inaccurate, and the timely judgment cannot be made on site, thereby improving the flexibility and accuracy of tool measurement, as well as the real-time nature of tool data processing and result feedback. Summary of the invention
[0005] In response to the technical problems mentioned above, the present invention provides an automatic identification method and system for controlled tool identification based on image processing, which can flexibly, conveniently and accurately measure tools and quickly determine tool types according to usage requirements in different locations, so as to solve the technical problems existing in the prior art of fixed tool measurement locations, inaccurate measurement results, and the inability to make timely judgments on site, thereby improving the flexibility and accuracy of tool measurement, as well as the real-time nature of tool data processing and result feedback.
[0006] The present invention provides an automatic identification method for controlled tool identification based on image processing, the method comprising:
[0007] S1, build an automatic recognition model, create a view, and determine the actual area and actual length of the ruler according to the processing flow of automatic recognition of tool identification, as well as automatic recognition auxiliary parameters, tool data structure and view data structure; S2, receive user requests in real time, obtain the original tool graphic image according to the user request, and crop and denoise the original tool graphic image to generate a denoised tool graphic image; S3, based on the automatic recognition model, and according to the automatic recognition auxiliary parameters and the tool data structure, perform graphic recognition processing on the denoised tool graphic image to obtain tool data, analyze and calculate the tool data, and obtain the analysis and calculation results; S4, compare the analysis and processing results with the tool judgment parameters, and return the comparison results.
[0008] As described above, the step S1 further includes: S11, based on the processing flow of tool identification and automatic identification, constructing the automatic identification model according to the automatic identification auxiliary parameters and the tool data structure, and initializing the automatic identification model; S12, creating the view according to the view data structure, determining the view height and view width of the view, and the scale length and scale width of the scale in the view; S13, determining the actual area of the scale according to the scale length and the scale width;
[0009] Among them, the automatic identification auxiliary parameters include: standard scale, dividing dotted line, standard ruler, protractor, ruler head and ruler tail; the tool data structure includes: knife tip, top of knife, bottom of knife, blade, handle, knife tail, blood groove, blade body, knife guard, knife length, tool type, knife tip angle; the view data structure includes: ruler length, ruler width, view height and view width; the tool type includes: controlled knives and daily knives.
[0010] As described above, in step S2, the step of receiving a user request in real time, obtaining an original tool graphic image according to the user request, and performing cropping and noise reduction processing on the original tool graphic image further includes: S21, responding to the user request, and cropping the original tool graphic image according to the view height and view width of the view, and the positions of the tool and the ruler, to obtain the width and height of the tool graphic image; S22, adding a Gaussian filter to the cropped tool graphic image, and determining the coordinates of each pixel point, and using the Gaussian filter function to eliminate details and noise in the cropped tool graphic image; S23, determining the origin of the tool graphic image based on the width and height of the cropped tool graphic image, and using the origin to establish a rectangular coordinate system and divide the quadrants to generate the tool graphic image after noise reduction;
[0011] Wherein, the Gaussian filter function is (x, y) is the coordinate of each pixel point in the cropped tool graphic image, and σ is the standard deviation.
[0012] As described above, the step of determining the origin of the tool graphic image based on the width and height of the cropped tool graphic image, and using the origin to establish a rectangular coordinate system and divide the quadrants further includes: S23-1, determining the origin (Dx, Dy) of the tool graphic image based on the width Hd and height Ld of the tool graphic image; S23-2, establishing and drawing a rectangular coordinate system with the origin (Dx, Dy) as the center, and dividing the cropped tool graphic image into four quadrants according to the rectangular coordinate system, as well as the quadrants to which each point (m, n) in the cropped tool graphic image belongs;
[0013] in,
[0014] When m is greater than Dx and n is less than Dy, the point (m, n) belongs to the first quadrant;
[0015] When m is less than Dx, and n is less than Dy, the point (m, n) belongs to the second quadrant;
[0016] When m is less than Dx and n is greater than Dy, the point (m, n) belongs to the third quadrant;
[0017] When m is greater than Dx, and n is greater than Dy, the point (m, n) belongs to the fourth quadrant.
[0018] As described above, in step S3, the step of performing graphic recognition processing on the tool graphic image after denoising based on the automatic recognition model and according to the automatic recognition auxiliary parameters and the tool data structure further includes: S31-1, according to the binary graph structure, obtaining all contours and contour levels of the tool graphic image after denoising; S31-2, based on the automatic recognition model and the contour, and according to the automatic recognition auxiliary parameters and the tool data structure, identifying the scale graphic and the tool graphic in the tool graphic image after denoising; S31-3, traversing the tool graphic, identifying and determining the blade, handle, tip, top, bottom and tail of the tool in the tool graphic one by one;
[0019] The binary graph structure includes: an outer contour, an inner contour, a parent contour, a child contour and the contour level; the tool data includes: the coordinates of the blade, handle, tip, top, bottom and tail of the tool in the tool graph.
[0020] As described above, in step S3, the step of analyzing and calculating the tool data and obtaining the analysis and calculation results further includes: S32-1, adjusting and obtaining the area of the ruler graphic, and when the area of the ruler graphic is equal to the actual area of the ruler, determining the actual positions of the ruler graphic and the tool graphic relative to the origin (Dx, Dy); S32-2, based on the actual position, the origin (Dx, Dy) and the rectangular coordinate system, determining the coordinates of the ruler graphic, as well as the coordinates of the blade, handle, tip, top, bottom and tail of the tool in the tool graphic, and calculating the pixel length of the ruler graphic, as well as the handle pixel length and blade pixel length and tip angle of the tool in the tool graphic; S32-3, determining the actual length per pixel according to the pixel length of the ruler graphic and the actual length of the ruler, and determining the actual length of the handle and the actual length of the blade according to the handle pixel length and the blade pixel length, as well as the actual length per pixel;
[0021] The analysis and calculation results include the knife tip angle, the actual length of the knife handle, the actual length of the blade and the blood groove.
[0022] As described above, the step S32-2 includes the steps of calculating the scale area and the tool tip angle;
[0023] The steps of calculating the scale area are: 1) obtaining the first coordinates (Fx, Fy) and the first coordinates (Gx, Gy) of the scale figure; 2) calculating the pixel length and pixel width of the scale figure according to the first coordinates (Fx, Fy) and the first coordinates (Gx, Gy); wherein the first coordinates (Fx, Fy) and the first coordinates (Gx, Gy) are the coordinates of two corresponding corners in the scale figure; the pixel width of the scale figure = |Fx-Gx|; the pixel length of the scale figure = |Fy-Gy|;
[0024] The step of calculating the tool tip angle is: based on the coordinates of the tool tip, the coordinates on the tool and the coordinates under the tool, determine the slope k1 of the line connecting the tool tip and the top of the tool, and the slope k2 of the line connecting the tool tip and the bottom of the tool, and calculate and obtain the tool tip angle θ using the trigonometric function of the tool tip angle; or determine the vector k1 between the tool tip and the top of the tool based on the point A (x, y) corresponding to the coordinates of the tool tip, the point C (x, y) corresponding to the coordinates on the tool and the point B (x, y) corresponding to the coordinates under the tool. Vector of knife tip and knife bottom According to the vector and the vector The tool tip angle θ is calculated and obtained by using a cosine function, an arccosine function and a radian angle system formula;
[0025] in,
[0026] The trigonometric function of the tool tip angle is:
[0027] Wherein, X is a point determined at a predetermined distance on the line connecting the knife tip and the two points below the knife, and Y is a point determined at a predetermined distance on the line connecting the knife tip and the two points above the knife;
[0028] The cosine function is:
[0029] The arc cosine function: hudu=arccos(cosθ), hudu is the radian corresponding to the tool tip angle θ;
[0030] The radian angle system formula is:
[0031] As described above, the step S32-3 further includes: 1) determining the actual length Lm of the unit pixel according to the pixel length Lc of the ruler graphic and the actual length Bc of the ruler, wherein: 2) determining the actual handle length BL and the actual blade length RL of the tool according to the handle pixel length BLm, the blade pixel length RLm, and the actual unit pixel length Lm;
[0032] Among them, BL=BLm×Lm; RL=RLm×Lm.
[0033] As described above, in step S4, the step of comparing the analysis and processing result with the tool judgment parameters and returning the comparison result further includes: comparing the analysis and processing result with the tool judgment parameters and returning the comparison result: if the analysis and processing result includes a blood groove, the comparison result returned is that the tool is a controlled tool; if the analysis and processing result does not include a blood groove, but the actual length of the tool handle and the actual length of the blade are within the range of the tool judgment parameters, the comparison result returned is that the tool is a controlled tool; otherwise, the comparison result returned is that the tool is a daily-use tool.
[0034] Accordingly, the present invention also provides an automatic recognition system for controlled tool identification based on image processing, the system comprising a model building module, a graphic processing module, a model processing module and a result comparison module;
[0035] The model building module is used to build an automatic recognition model, create a view, and determine the actual area and actual length of the ruler according to the processing flow of automatic recognition of tool identification, as well as automatic recognition auxiliary parameters, tool data structure and view data structure;
[0036] The graphic processing module is used to obtain the original tool graphic image according to the user request, and to perform cropping and noise reduction processing on the original tool graphic image to generate a tool graphic image after noise reduction;
[0037] The model processing module is used to perform graphic recognition processing on the tool graphic image after noise reduction based on the automatic recognition model and according to the automatic recognition auxiliary parameters and the tool data structure to obtain tool data, analyze and calculate the tool data to obtain analysis and calculation results;
[0038] The result comparison module is used to compare the analysis and processing result with the tool determination parameter and return the comparison result;
[0039] The system also includes a control module for coordinating and managing the interaction between the model and the view, receiving user requests in real time, updating and calling the automatic recognition model, and displaying the comparison results in a visual manner through the view.
[0040] The present invention applies the above technical solution, builds an automatic recognition model, creates a view, and based on the actual area and actual length of the ruler and the automatic recognition model, crops, reduces noise, performs graphic recognition processing, and performs tool data analysis and calculation on the original tool graphic image, and then returns the comparison result, thereby realizing the use requirements of different places, and can flexibly, conveniently and accurately measure the tool and quickly determine the tool type in a visual way, so as to solve the technical problems existing in the prior art that the tool measurement use place is fixed, the measurement results are inaccurate, and the on-site judgment cannot be made in time, thereby improving the flexibility and accuracy of tool measurement, and the real-time performance of tool data processing and result feedback. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0042] Figure 1 A schematic diagram showing an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention;
[0043] Figure 2 A schematic diagram of image cropping of an automatic recognition method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0044] Figure 3 A schematic diagram of a graphic identification of an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0045] Figure 4 A schematic diagram of quadrant division of a controlled tool identification automatic recognition method based on image processing proposed in an embodiment of the present invention is shown;
[0046] Figure 5 A schematic diagram of the movement of the center of a circle of an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0047] Figure 6 A schematic diagram showing an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention;
[0048] Figure 7 A schematic diagram showing an outline of an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention;
[0049] Figure 8A schematic diagram showing the position determination of a method for automatic identification of controlled tools based on image processing proposed in an embodiment of the present invention is shown;
[0050] Fig. 9 A schematic diagram of length recognition of an automatic recognition method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0051] Fig.10 A schematic diagram of tool tip marking of an automatic recognition method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0052] Fig.11 An abstract schematic diagram of a tool tip angle of an automatic recognition method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0053] Fig.12 A schematic diagram of a tool according to an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0054] Fig.13 A schematic diagram of a ruler showing an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention;
[0055] Fig.14 A schematic diagram of image capture of an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0056] Fig.15 A schematic diagram of a tool type determination process of an automatic identification method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0057] Fig.16 A schematic diagram of tool marking of an automatic recognition method for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown;
[0058] Fig.17 The schematic diagram of the structure of an automatic recognition system for controlled tool identification based on image processing proposed in an embodiment of the present invention is shown. DETAILED DESCRIPTION
[0059] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0060] The present invention provides an automatic recognition method for controlled tool identification based on image processing, such as Figure 1 As shown, the method comprises the following steps:
[0061] S1, according to the processing flow of tool identification and automatic recognition, as well as automatic recognition auxiliary parameters, tool data structure and view data structure, build an automatic recognition model, create a view, and determine the actual area and actual length of the ruler.
[0062] In this embodiment, the step S1 further includes:
[0063] S11, based on the processing flow of tool identification and automatic recognition, construct the automatic recognition model according to the automatic recognition auxiliary parameters and the tool data structure, and initialize the automatic recognition model;
[0064] S12, creating the view according to the view data structure, and determining a view height and a view width of the view, and a scale length and a scale width of a scale in the view;
[0065] S13, determining the actual area of the scale according to the scale length and the scale width;
[0066] in,
[0067] The automatic recognition auxiliary parameters include: standard scale, dividing dotted line, standard ruler, protractor, ruler head and ruler tail;
[0068] The tool data structure includes: tool tip, top, bottom, blade, handle, tail, blood groove, blade, guard, length, tool type, and tool tip angle;
[0069] The view data structure includes: ruler length, ruler width, view height and view width;
[0070] The types of knives include: controlled knives and daily knives.
[0071] S2, receiving a user request in real time, acquiring an original tool graphic image according to the user request, and performing cropping and noise reduction processing on the original tool graphic image to generate a tool graphic image after noise reduction.
[0072] In this embodiment, in step S2, the step of receiving a user request in real time, acquiring an original tool graphic image according to the user request, and performing cropping and noise reduction processing on the original tool graphic image further includes:
[0073] S21, in response to the user request, and according to the view height and view width of the view, and the positions of the tool and the ruler, the original tool graphic image is cropped to obtain the width and height of the tool graphic image;
[0074] S22, adding a Gaussian filter to the cropped tool graphic image, determining the coordinates of each pixel point, and using the Gaussian filter function to eliminate details and noise in the cropped tool graphic image;
[0075] S23, determining the origin of the tool graphic image based on the width and height of the cropped tool graphic image, and using the origin to establish a rectangular coordinate system and divide quadrants to generate the tool graphic image after noise reduction;
[0076] in,
[0077] The Gaussian filter function is
[0078] (x, y) is the coordinate of each pixel point in the cropped tool graphic image, and σ is the standard deviation.
[0079] In this embodiment, in step S23, the step of determining the origin of the tool graphic image based on the width and height of the cropped tool graphic image, and using the origin to establish a rectangular coordinate system and divide the quadrants further includes:
[0080] S23-1, determining the origin (Dx, Dy) of the tool graphic image based on the width Hd and height Ld of the tool graphic image;
[0081] S23-2, establishing and drawing a rectangular coordinate system with the origin (Dx, Dy) as the center, and dividing the cropped tool graphic image into four quadrants and the quadrants to which each point (m, n) in the cropped tool graphic image belongs according to the rectangular coordinate system;
[0082] in,
[0083]
[0084] When m is greater than Dx and n is less than Dy, the point (m, n) belongs to the first quadrant;
[0085] When m is less than Dx, and n is less than Dy, the point (m, n) belongs to the second quadrant;
[0086] When m is less than Dx and n is greater than Dy, the point (m, n) belongs to the third quadrant;
[0087] When m is greater than Dx, and n is greater than Dy, the point (m, n) belongs to the fourth quadrant.
[0088] S3, based on the automatic recognition model, and according to the automatic recognition auxiliary parameters and the tool data structure, the tool graphic image after noise reduction is subjected to graphic recognition processing to obtain tool data, and the tool data is analyzed and calculated to obtain the analysis and calculation results.
[0089] In this embodiment, in step S3, the step of performing graphic recognition processing on the tool graphic image after noise reduction based on the automatic recognition model and according to the automatic recognition auxiliary parameters and the tool data structure further includes:
[0090] S31-1, acquiring all contours and contour levels of the tool graphic image after noise reduction according to the binary image structure;
[0091] S31-2, based on the automatic recognition model and the contour, and according to the automatic recognition auxiliary parameters and the tool data structure, identifying the scale graphic and the tool graphic in the tool graphic image after noise reduction;
[0092] S31-3, traversing the tool graph, identifying and determining the blade, handle, tip, top, bottom and tail of the tool in the tool graph one by one;
[0093] in,
[0094] The binary image structure includes: an outer contour, an inner contour, a parent contour, a child contour and the contour level;
[0095] The tool data includes the coordinates of the blade, handle, tip, top, bottom and tail of the tool in the tool graphic.
[0096] In this embodiment, in step S3, the step of analyzing and calculating the tool data and obtaining the analysis and calculation results further includes:
[0097] S32-1, adjusting and acquiring the area of the ruler graphic, and when the area of the ruler graphic is equal to the actual area of the ruler, determining the actual positions of the ruler graphic and the tool graphic relative to the origin (Dx, Dy);
[0098] S32-2, based on the actual position, the origin (Dx, Dy) and the rectangular coordinate system, determine the coordinates of the ruler graphic, as well as the coordinates of the blade, handle, tip, top, bottom and tail of the tool in the tool graphic, and calculate and obtain the pixel length of the ruler graphic, as well as the pixel length of the handle and the pixel length of the blade and the tip angle of the tool in the tool graphic;
[0099] S32-3, determining the actual length per unit pixel according to the pixel length of the ruler graphic and the actual length of the ruler, and determining the actual length of the handle and the actual length of the blade of the tool according to the pixel length of the handle and the pixel length of the blade, as well as the actual length per unit pixel;
[0100] in,
[0101] The analysis and calculation results include the knife tip angle, the actual length of the knife handle, the actual length of the blade and the blood groove.
[0102] In this embodiment, the step S32-2 includes a step of calculating the scale area and a step of calculating the tool tip angle;
[0103] The steps of calculating the scale area are as follows:
[0104] 1) Obtaining the first coordinate (Fx, Fy) and the first coordinate (Gx, Gy) of the ruler graphic;
[0105] 2) calculating the pixel length and pixel width of the ruler graphic according to the first coordinates (Fx, Fy) and the first coordinates (Gx, Gy);
[0106] in,
[0107] The first coordinates (Fx, Fy) and the first coordinates (Gx, Gy) are the coordinates of two corresponding angles in the ruler graphic;
[0108] The pixel width of the ruler graphic = |Fx-Gx|;
[0109] The pixel length of the ruler graphic = |Fy-Gy|;
[0110] The steps of calculating the tool tip angle are:
[0111] Based on the coordinates of the knife tip, the coordinates on the knife and the coordinates under the knife, determine the slope k1 of the line connecting the knife tip and the top of the knife, and the slope k2 of the line connecting the knife tip and the bottom of the knife, and calculate and obtain the knife tip angle θ using the trigonometric function of the knife tip angle;
[0112] Or based on the coordinates of the tool tip corresponding to point A (x, y), the coordinates of the tool corresponding to point C (x, y) and the coordinates of the tool under the tool corresponding to point B (x, y), determine the vector between the tool tip and the tool Vector of knife tip and knife bottom According to the vector and the vector The tool tip angle θ is calculated and obtained by using a cosine function, an arccosine function and a radian angle system formula;
[0113] in,
[0114] The trigonometric function of the tool tip angle is:
[0115] Wherein, X is a point determined at a predetermined distance on the line connecting the knife tip and the two points below the knife, and Y is a point determined at a predetermined distance on the line connecting the knife tip and the two points above the knife;
[0116] The cosine function is:
[0117] The arc cosine function: hudu=arccos(cosθ), hudu is the radian corresponding to the tool tip angle θ;
[0118] The radian angle system formula is:
[0119] In this embodiment, the step S32-3 further includes:
[0120] 1) Determine the actual length per unit pixel Lm according to the pixel length Lc of the ruler graphic and the actual length Bc of the ruler, wherein:
[0121] 2) determining the actual handle length BL and the actual blade length RL of the tool according to the handle pixel length BLm, the blade pixel length RLm, and the actual unit pixel length Lm;
[0122] in,
[0123] BL = BLm × Lm;
[0124] RL=RLm×Lm.
[0125] S4, comparing the analysis result with the tool determination parameter, and returning the comparison result.
[0126] In this embodiment, in step S4, the step of comparing the analysis result with the tool determination parameter and returning the comparison result further includes:
[0127] The analysis and processing result is compared with the tool determination parameter, and the comparison result is returned:
[0128] If the analysis and processing result includes a blood groove, the comparison result returned is that the tool is a controlled tool;
[0129] If the analysis result does not include the blood groove, but the actual length of the tool handle and the actual length of the blade are within the tool determination parameter range, the comparison result returned is that the tool is a controlled tool;
[0130] Otherwise, the comparison result returned is that the tool is a daily-use tool.
[0131] By applying the above technical solution, by constructing an automatic recognition model, creating a view, and based on the actual area and actual length of the ruler and the automatic recognition model, the original tool graphic image is cropped, denoised, processed by graphic recognition, and tool data analysis and calculation is performed, and then the comparison result is returned. This realizes the use requirements of different places, and the tool can be measured and the tool type can be quickly determined in a visual way, that is, flexibly, conveniently and accurately. This solves the technical problems existing in the prior art that the tool measurement use place is fixed, the measurement results are inaccurate, and the on-site judgment cannot be made in time, thereby improving the flexibility and accuracy of tool measurement, and the real-time nature of tool data processing and result feedback.
[0132] In order to enable those skilled in the art to have a deeper understanding of the automatic identification method for controlled tool identification based on image processing provided by the present invention, the method provided by the present invention is further supplemented by examples.
[0133] like Figure 2 to Figure 16 As shown, the tool to be tested is placed on a specific background cloth, and the tool is photographed and the result is obtained through the automatic identification APP for controlled tools. Both the background cloth and the automatic identification APP for controlled tools are independently designed and developed by our company. The background cloth is made of natural rubber and Jiaji fabric, which ensures the premise of softness and durability while meeting the characteristics of not easy to be stained and flat. Auxiliary patterns such as standard scale, dividing dotted line, standard ruler, protractor, etc. are marked on the background cloth. The purpose of using white for the auxiliary pattern is to form a clear contrast with the brown background, which is more conducive to the automatic recognition program to identify the standard scale, achieve image denoising effect, and reduce measurement errors; the dividing dotted line is mainly used to standardize the position of the tool, indicating that the placement is accurate when taking pictures, so that the main position of the tool can be automatically positioned more accurately; the standard ruler and protractor are used to easily judge whether the results obtained by the automatic recognition program are deviated from the actual value.
[0134] It should be noted that the controlled tool automatic identification APP is natively developed in the ANDROID system. By building the MVC model, namely the model, view and controller, the model is responsible for processing data and business logic, including data storage, reading, verification and other operations. The model is the core component of the application, which is independent of the view and controller and can be reused by other applications. The view is responsible for displaying the user interface and presenting data to the user. The view is usually generated based on the data in the model and can be customized and modified as needed. The controller is responsible for coordinating and managing the interaction between the model and the view, and processing user input and operations. The controller receives user requests, updates the model and view, and returns the results to the user. OpenCV is used in graphic recognition to process graphics. The implementation principle of OpenCV (Open Source Computer Vision Library) is mainly based on computer vision and image processing algorithms and technologies to realize image processing. OpenCV is a cross-platform computer vision library that provides a large number of image processing and computer vision functions that can be easily used in Android applications. The specific implementation process is as follows:
[0135] (1) Place the knife on the designated position of the background cloth, open the controlled knife automatic identification app, take a photo of the knife, and crop it to ensure that only the knife and ruler are in the picture.
[0136] (2) Add a Gaussian filter to the image to remove details and noise, improve the quality of the tool image, and enhance the characteristics of the tool.
[0137] Gaussian filtering is a linear smoothing filter that is suitable for eliminating Gaussian noise and is widely used in the noise reduction process of image processing. In layman's terms, Gaussian filtering is the process of weighted averaging the entire image. The value of each pixel is obtained by weighted averaging the value of itself and other pixels in the neighborhood. The specific operation of Gaussian filtering is: use a template (or convolution, mask) to scan each pixel in the image, and use the weighted average grayscale value of the pixels in the neighborhood determined by the template to replace the value of the central pixel of the template.
[0138] By applying a Gaussian filter to an image, noise and details in the image can be removed, making the image smoother. This smoothing process helps reduce noise and details in the image, improve the visual quality of the image and the effect of subsequent processing. Therefore, Gaussian filters are widely used in tasks such as preprocessing and noise removal in the field of image processing and computer vision. The core formula is:
[0139]
[0140] Where (x, y) are the coordinates of a point in the image, σ is the standard deviation, and the Gaussian template is calculated using this function. Here, x and y represent the coordinate values with the center point of the kernel as the origin of the coordinate system.
[0141] (3) Select the corresponding points in the image. By dragging the points, move the "cross" mark to the specified position. When the finger drags on the screen, the system can automatically obtain the coordinates of the "cross".
[0142] Since the points are relatively small on the screen, when the finger actually drags the points, it will block the points, making it impossible to accurately move the points to the specified position. Similarly, due to factors such as the irregular placement position of the tool, when the automatic recognition of the points is inaccurate, it may be default placed at other positions or on the edge of the image, making it even more difficult to drag the points. Therefore, in combination with the actual situation, use width / 2 and height / 2 in the graph to obtain the origin (o1, o2), and establish a rectangular coordinate system based on the origin. The point coordinates are X(m, n). When m > o1 and n < o2, the point is in the first quadrant; when m < o1 and n < o2, the point is in the second quadrant; when m < o1 and n > o2, the point is in the third quadrant; when m > o1 and n > o2, the point is in the fourth quadrant. According to the quadrant where the point is located, then take a line segment of a fixed length parallel to the diagonal in the reverse quadrant direction, as follows Figure 1 , when the point is in the second quadrant, take the opposite direction and a position parallel to the diagonal AB, draw the line segment XY, and draw a circle for dragging the point with point Y as the center. By dragging the circle, the position of the point can be controlled. In this way, the positioning position of the point can be seen clearly, and it is also convenient to flexibly drag the control point.
[0143] (4) In OpenCV, finding an element is done through the contour method, so first obtain all the contours of the object
[0144] A contour is a curve composed of a series of connected points, representing the basic shape of an object. Compared with the edge, the contour is continuous, while the edge is not entirely continuous. The operation of finding contours is generally used for binary images, so usually threshold segmentation or Canny edge detection is used to obtain the binary image first.
[0145] As Figure 6 and Figure 7 shown, there are a total of 8 contours in the figure. 2 and 2a represent the outer and inner contours respectively, and the same goes for 3 and 3a. It can be seen from the figure that:
[0146] Contours 0 / 1 / 2 are the outermost contours, and we can say that they are at the same contour level: level 0
[0147] Contour 2a is a sub - contour of contour 2. Conversely, 2 is the parent contour of 2a. Contour 2a counts as one level: level 1;
[0148] Likewise, 3 is a sub-contour of 2a, and contour 3 is at a level: level 2;
[0149] Similarly, 3a is a subcontour of 3;
[0150] For our controlled tool identification, the position of the ruler is the outermost contour.
[0151] The contour can calculate the perimeter, area, center of mass, minimum enclosing rectangle, etc. of an object. Commonly used OpenCV functions include: cv2.contourArea(), cv2.arcLength(), cv2.approxPolyDP(), etc.
[0152] (5) In the final figure, only two items are retained, a ruler and a tool, so two contours can be obtained in the APP. The ruler is fixed, so the area of the ruler is also known. Assuming that the known area of the ruler is S, the area of the ruler obtained by the APP is A, and the area of the tool is B, then when S=A, we can determine the position of the ruler. Combined with the dragging point, we can also determine the actual position of the ruler.
[0153] The photo we want to identify is displayed in outline form, with the outline of the ruler displayed on the top and the outline of the tool displayed on the bottom. Since the handle and blade are placed in the middle when placing the tool, the center of the picture is used as the standard. The blade is on the left below the ruler, and the handle is on the right below the ruler. When traversing, the system traverses from top to bottom, so the first outline found is the ruler. Combining the two coordinate points of the ruler, the position of the ruler can be found.
[0154] (6) With the ruler as the reference, the tool is below the ruler. The corresponding positions of the tool tip, blade, handle and tail are found through the absolute position of the ruler. The tool tip is below and slightly to the left of the ruler, so the absolute position of the ruler is compared with the Y value of each point. When the Y value of the measured point is greater than the Y value of the first point on the ruler and the X value of the measured point is less than the X value of the first point on the ruler, the actual position of the tool tip can be determined. Similarly, the actual position of the top and bottom of the tool can be confirmed.
[0155] (7) According to the coordinates of the elements, use the coordinates to calculate the pixel length of the ruler, handle, and blade on the image. From the perspective of the Android program, our collection screen is equivalent to the fourth quadrant in mathematics. The point (0, 0) is in the upper left corner of the screen. When the coordinates of each point on the screen are obtained, such as A (x1, y1) on the left side of the ruler and B (x2, y2) on the right side of the ruler, the pixel width of the ruler is (X2-X1). Similarly, the pixel length of the blade and handle can be obtained.
[0156] (8) The actual length value of the ruler is obtained through the background interface. This parameter can be dynamically configured in the background according to the actual standard size of the background cloth.
[0157] (9) Calculate the length represented by each pixel. Divide the actual ruler length by the number of pixels on the ruler in the image to calculate the actual length represented by each pixel using the following formula:
[0158] M=B / L
[0159] Where M represents the actual length of each pixel, B represents the actual length of the ruler, and L represents the actual length of the ruler in pixels.
[0160] (10) Calculate the actual length of the ruler, handle, and blade. The actual length of the handle and blade is calculated by combining the actual pixels of the image with the actual length of the pixels. The following formula is used:
[0161] RL = RM * M;
[0162] BL = BM * M;
[0163] Among them, RL represents the actual length of the blade, RM represents the pixel value of the blade, M represents the actual length per pixel, BL represents the actual length of the handle, and BM represents the number of pixels of the handle.
[0164] By using the three points of the knife tip, the top of the knife, and the bottom of the knife, the knife tip angle is
[0165] The formula for the angle between two straight lines is: tanθ=|k1-k2 / 1+k1k2|, where k1 and k2 are the slopes of the two straight lines, and θ is the angle between the two straight lines.
[0166] Slope calculation:
[0167] like Fig. 9 and Fig.10 As shown in the figure, through the tip, top and bottom of the knife, we get two line segments AO and BO extending from the tip to the top and bottom of the knife, then ∠AOB is the measurement angle of the tool. According to the guidance of the "Standards for the Identification of Controlled Knives (Public Communication No.
[2007] 2)", the standard for measuring the tip angle is: Tip angle: refers to the angle between the point on the blade and the back of the knife (or the other side of the blade) 10 mm away from the tip vertex and the tip vertex. Through the previous step to obtain the actual length of each pixel, the upper point X of the knife that is 10 mm away from the actual length of the knife tip can be found in the upper extension line OA, and the lower point Y of the knife that is 10 mm away from the actual length of the knife tip can be found in the lower extension line OB, forming a new ∠XOY.
[0168] Vector angle calculation method:
[0169]
[0170]
[0171]
[0172] radians = arccos(cosθ);
[0173]
[0174] Among them, X is a point determined at a predetermined distance on the line connecting the knife tip and the two points below the knife, and Y is a point determined at a predetermined distance on the line connecting the knife tip and the two points above the knife; the radian is the radian corresponding to the knife tip angle θ.
[0175] (11) The actual length and quantity of the knife, whether it has a blood groove, whether it is a folding knife, angle and other information are uploaded through the network and compared with the background setting rules, and the comparison result of whether it is a controlled knife is returned. Finally, the police choose whether to confiscate and report the knife based on the results obtained by this program.
[0176] By applying the above technical solution, by constructing an automatic recognition model, creating a view, and based on the actual area and actual length of the ruler and the automatic recognition model, the original tool graphic image is cropped, denoised, processed by graphic recognition, and tool data analysis and calculation is performed, and then the comparison result is returned. This realizes the use requirements of different places, and the tool can be measured and the tool type can be quickly determined in a visual way, that is, flexibly, conveniently and accurately. This solves the technical problems existing in the prior art that the tool measurement use place is fixed, the measurement results are inaccurate, and the on-site judgment cannot be made in time, thereby improving the flexibility and accuracy of tool measurement, and the real-time nature of tool data processing and result feedback.
[0177] In addition, by applying the above technical solution, in different occasions such as subway security checkpoints, airport security checkpoints, large-scale event security checkpoints, etc., the method provided by the present invention can quickly and accurately determine whether a knife is a controlled knife. It is convenient, fast, easy to carry, highly real-time, and low-cost.
[0178] Corresponding to the automatic identification method for controlled tool identification based on image processing in one embodiment of the present invention, the present invention also discloses an automatic identification system for controlled tool identification based on image processing, such as Fig.17 As shown, the system includes a model building module, a graphics processing module, a model processing module and a result comparison module;
[0179] The model building module is used to build an automatic recognition model, create a view, and determine the actual area and actual length of the ruler according to the processing flow of automatic recognition of tool identification, as well as automatic recognition auxiliary parameters, tool data structure and view data structure;
[0180] The graphic processing module is used to obtain the original tool graphic image according to the user request, and to perform cropping and noise reduction processing on the original tool graphic image to generate a tool graphic image after noise reduction;
[0181] The model processing module is used to perform graphic recognition processing on the tool graphic image after noise reduction based on the automatic recognition model and according to the automatic recognition auxiliary parameters and the tool data structure to obtain tool data, analyze and calculate the tool data to obtain analysis and calculation results;
[0182] The result comparison module is used to compare the analysis and processing result with the tool determination parameter and return the comparison result;
[0183] The system also includes a control module for coordinating and managing the interaction between the model and the view, receiving user requests in real time, updating and calling the automatic recognition model, and displaying the comparison results in a visual manner through the view.
[0184] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referenced to each other, and each embodiment focuses on the differences from other embodiments.
[0185] 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 method for automatically identifying controlled tools based on image processing, characterized in that: The method comprises: S1, according to the processing flow of tool identification and automatic recognition, as well as automatic recognition auxiliary parameters, tool data structure and view data structure, build an automatic recognition model, create a view, and determine the actual area and actual length of the ruler; S2, receiving a user request in real time, acquiring an original tool graphic image according to the user request, and performing cropping and noise reduction processing on the original tool graphic image to generate a tool graphic image after noise reduction; S3, based on the automatic recognition model, and according to the automatic recognition auxiliary parameters and the tool data structure, as well as the actual area and actual length of the ruler, performing graphic recognition processing on the tool graphic image after noise reduction to obtain tool data, and performing analysis and calculation on the tool data to obtain analysis and calculation results; S4, comparing the analysis and calculation result with the tool determination parameter, and returning the comparison result; in, The step of S1 further comprises: S11, based on the processing flow of tool identification and automatic recognition, construct the automatic recognition model according to the automatic recognition auxiliary parameters and the tool data structure, and initialize the automatic recognition model; S12, creating the view according to the view data structure, and determining a view height and a view width of the view, and a scale length and a scale width of a scale in the view; S13, determining the actual area of the ruler according to the ruler length and the ruler width; The automatic recognition auxiliary parameters include: standard scale, dividing dotted line, standard ruler, protractor, ruler head and ruler tail; The tool data structure includes: tool tip, top, bottom, blade, handle, tail, blood groove, blade, guard, length, tool type, and tool tip angle; The view data structure includes: ruler length, ruler width, view height and view width; The types of knives include: controlled knives and daily knives; In step S3, the step of analyzing and calculating the tool data and obtaining the analysis and calculation results further includes: S32-1, adjusting and acquiring the area of the ruler graphic, and when the area of the ruler graphic is equal to the actual area of the ruler, determining the actual positions of the ruler graphic and the tool graphic relative to the origin (Dx, Dy); S32-2, based on the actual position, the origin (Dx, Dy) and the rectangular coordinate system, determine the coordinates of the ruler graphic, as well as the coordinates of the blade, handle, tip, top, bottom and tail of the tool in the tool graphic, and calculate and obtain the pixel length of the ruler graphic, as well as the pixel length of the handle and the pixel length of the blade and the tip angle of the tool in the tool graphic; S32-3, determining the actual length per unit pixel according to the pixel length of the ruler graphic and the actual length of the ruler, and determining the actual length of the handle and the actual length of the blade of the tool according to the pixel length of the handle and the pixel length of the blade, as well as the actual length per unit pixel; in, The analysis and calculation results include the knife tip angle, the actual length of the knife handle, the actual length of the blade and the blood groove.
2. The method according to claim 1, characterized in that In step S2, the step of receiving a user request in real time, acquiring an original tool graphic image according to the user request, and performing cropping and noise reduction processing on the original tool graphic image further comprises: S21, responding to the user request, and according to the view height and view width of the view, and the positions of the tool and the ruler, cropping the original tool graphic image to obtain the width and height of the tool graphic image; S22, adding a Gaussian filter to the cropped tool graphic image, determining the coordinates of each pixel point, and using the Gaussian filter function to eliminate details and noise in the cropped tool graphic image; S23, determining the origin of the tool graphic image based on the width and height of the cropped tool graphic image, and using the origin to establish a rectangular coordinate system and divide quadrants to generate the tool graphic image after noise reduction; in, The Gaussian filter function is (x, y) is the coordinate of each pixel point in the cropped tool graphic image, and σ is the standard deviation.
3. The method according to claim 2, characterized in that In step S23, the step of determining the origin of the tool graphic image based on the width and height of the cropped tool graphic image, and using the origin to establish a rectangular coordinate system and divide the quadrants further includes: S23-1, determining the origin (Dx, Dy) of the tool graphic image based on the width Hd and height Ld of the tool graphic image; S23-2, establishing and drawing a rectangular coordinate system with the origin (Dx, Dy) as the center, and dividing the cropped tool graphic image into four quadrants and the quadrants to which each point (m, n) in the cropped tool graphic image belongs according to the rectangular coordinate system; in, When m is greater than Dx and n is less than Dy, the point (m, n) belongs to the first quadrant; When m is less than Dx, and n is less than Dy, the point (m, n) belongs to the second quadrant; When m is less than Dx and n is greater than Dy, the point (m, n) belongs to the third quadrant; When m is greater than Dx, and n is greater than Dy, the point (m, n) belongs to the fourth quadrant.
4. The method according to claim 1, characterized in that In step S3, the step of performing graphic recognition processing on the tool graphic image after noise reduction based on the automatic recognition model and according to the automatic recognition auxiliary parameters and the tool data structure further includes: S31-1, acquiring all contours and contour levels of the tool graphic image after noise reduction according to the binary image structure; S31-2, based on the automatic recognition model and the contour, and according to the automatic recognition auxiliary parameters and the tool data structure, identifying the scale graphic and the tool graphic in the tool graphic image after noise reduction; S31-3, traversing the tool graph, identifying and determining the blade, handle, tip, top, bottom and tail of the tool in the tool graph one by one; in, The binary image structure includes: an outer contour, an inner contour, a parent contour, a child contour and the contour level; The tool data includes the coordinates of the blade, handle, tip, top, bottom and tail of the tool in the tool graphic.
5. The method according to claim 1, characterized in that The step S32-2 includes a step of calculating the scale area and a step of calculating the tool tip angle; The steps of calculating the scale area are as follows: 1) Obtaining the first coordinate (Fx, Fy) and the second coordinate (Gx, Gy) of the ruler graphic; 2) calculating the pixel length and pixel width of the ruler graphic according to the first coordinates (Fx, Fy) and the second coordinates (Gx, Gy); in, The first coordinate (Fx, Fy) and the second coordinate (Gx, Gy) are the coordinates of two corresponding angles in the ruler graphic; The pixel width of the ruler graphic = |Fx-Gx|; The pixel length of the ruler graphic = |Fy-Gy|; The steps of calculating the tool tip angle are: Based on the coordinates of the knife tip, the coordinates on the knife and the coordinates under the knife, determine the slope k1 of the line connecting the knife tip and the top of the knife, and the slope k2 of the line connecting the knife tip and the bottom of the knife, and calculate and obtain the knife tip angle θ using the trigonometric function of the knife tip angle; Or based on the coordinates of the tool tip corresponding to point A (x, y), the coordinates of the tool corresponding to point C (x, y) and the coordinates of the tool under the tool corresponding to point B (x, y), determine the vector between the tool tip and the tool Vector of knife tip and knife bottom According to the vector and the vector The tool tip angle θ is calculated and obtained by using a cosine function, an arccosine function and a radian angle system formula; in, The trigonometric function of the tool tip angle is: Wherein, X is a point determined at a predetermined distance on the line connecting the knife tip and the two points below the knife, and Y is a point determined at a predetermined distance on the line connecting the knife tip and the two points above the knife; The cosine function is: The arc cosine function: hudu=arccos(cosθ), hudu is the radian corresponding to the tool tip angle θ; The radian angle system formula is:
6. The method according to claim 1, characterized in that The step of S32-3 further includes: 1) Determine the actual length per unit pixel Lm according to the pixel length Lc of the ruler graphic and the actual length Bc of the ruler, wherein: 2) determining the actual handle length BL and the actual blade length RL of the tool according to the handle pixel length BLm, the blade pixel length RLm, and the actual unit pixel length Lm; in, BL = BLm × Lm; RL=RLm×Lm.
7. The method according to claim 1, characterized in that In step S4, the step of comparing the analysis and calculation result with the tool determination parameter and returning the comparison result further includes: Compare the analysis and calculation results with the tool determination parameters, and return the comparison results: If the analysis and calculation result includes the blood groove, the comparison result returned is that the tool is a controlled tool; If the analysis and calculation result does not include the blood groove, but the actual length of the tool handle and the actual length of the blade are within the tool determination parameter range, the comparison result returned is that the tool is a controlled tool; Otherwise, the comparison result returned is that the tool is a daily-use tool.
8. A system for implementing the method for automatically identifying controlled tools based on image processing as claimed in claim 1, characterized in that: The system includes a model building module, a graphics processing module, a model processing module and a result comparison module; The model building module is used to build an automatic recognition model, create a view, and determine the actual area and actual length of the ruler according to the processing flow of automatic recognition of tool identification, as well as automatic recognition auxiliary parameters, tool data structure and view data structure; The graphic processing module is used to obtain the original tool graphic image according to the user request, and perform cropping and noise reduction processing on the original tool graphic image to generate a tool graphic image after noise reduction; The model processing module is used to perform graphic recognition processing on the tool graphic image after noise reduction based on the automatic recognition model and according to the automatic recognition auxiliary parameters and the tool data structure to obtain tool data, and to analyze and calculate the tool data to obtain analysis and calculation results; The result comparison module is used to compare the analysis and calculation result with the tool determination parameter and return the comparison result; The system also includes a control module for coordinating and managing the interaction between the model and the view, receiving user requests in real time, updating and calling the automatic recognition model, and displaying the comparison results in a visual manner through the view.
Citation Information
Patent Citations
Cutter detection method and device
CN110119734A
Method for security inspection,detection and identification of controlled cutter
CN110853019A