Disclosure of Invention
The application aims to provide a magnet piece detection method which can solve the technical problem of how to detect the magnet piece to a certain extent. The application also provides a magnet piece detection system, equipment and a computer readable storage medium.
In order to achieve the above purpose, the present application provides the following technical solutions:
a magnet piece inspection method comprising:
acquiring a target image of the magnet piece to be detected;
acquiring a preset template of a region to be detected;
determining a region to be detected corresponding to the region template to be detected in the target image based on an indirect adjustment method;
calculating gray value information of the area to be detected;
and determining the detection result of the magnet piece to be detected based on the gray value information and a preset threshold value.
Preferably, the determining, based on the indirect adjustment method, the to-be-detected region corresponding to the to-be-detected region template in the target image includes:
determining locating point information of the target image;
determining a two-dimensional steel body transformation matrix between the template of the area to be detected and the positioning point information through an operation formula based on the indirect adjustment method;
mapping the template of the area to be detected to the target image based on the two-dimensional steel body transformation matrix to obtain the area to be detected;
the operation formula comprises:
wherein R is
bRepresenting the two-dimensional steel body transformation matrix;
expressing the local variation of the adjustment parameters, wherein six adjustment parameters express corresponding parameter values in the two-dimensional steel body transformation matrix; r is a radical of hydrogen
1、r
2、r
3、r
4Representing multiple rotation terms; t is t
rx、t
ryRepresenting a translation term; b represents a mapping matrix constructed based on the template of the area to be detected and the locating point information; p represents an identity matrix; b is
TRepresents a transpose of B; and l represents the difference value between the observed value and the corresponding approximate value in the indirect adjustment method.
Preferably, the determining the anchor point information of the target image includes:
converting the target image into a grey-scale map;
carrying out binarization operation on the gray level image to obtain a target binarization image;
and respectively carrying out integral projection in the horizontal direction and the vertical direction on the target binary image, and determining the positioning point information according to the projection result.
Preferably, the binarizing the gray-scale map to obtain a target binarized map includes:
carrying out binarization operation on the gray level image to obtain an initial binarization image;
performing morphological operation on the initial binary image to obtain a processed image;
extracting the longest straight line in the processed image based on Hough transform;
correcting the gray level image based on the longest straight line to obtain a corrected gray level image;
and carrying out binarization operation on the positive-turning gray level image to obtain the target binarization image.
Preferably, the calculating gray scale value information of the region to be detected includes:
calculating a target gray mean value and a target first-order gray derivative mean value of the area to be detected;
the determining the detection result of the magnet piece to be detected based on the gray value information and the preset threshold value comprises the following steps:
selecting a to-be-detected sub-region in the to-be-detected region;
calculating a first gray mean value and a first one-step gray derivative mean value of the subarea to be detected;
calculating a first difference value between the first gray level mean value and the target gray level mean value;
calculating a second difference value between the first-order gray derivative mean value and the target first-order gray derivative mean value;
and comparing the first difference value and the second difference value with the preset threshold value, and determining the detection result according to the comparison result.
Preferably, the comparing the first difference and the second difference with the preset threshold and determining the detection result according to the comparison result includes:
judging whether the first difference value is larger than a first threshold value or not and whether the second difference value is larger than a second threshold value or not, and if the first difference value is larger than the first threshold value and the second difference value is larger than the second threshold value, determining that the detection result that the magnet piece to be detected is whitish exists;
and/or
And judging whether the first difference value is smaller than a third threshold value and whether the second difference value is smaller than a fourth threshold value, and if the first difference value is smaller than the third threshold value and the second difference value is smaller than the fourth threshold value, determining that the magnet piece to be detected has a bright detection result.
Preferably, the acquiring a preset template of the area to be detected includes:
and acquiring a preset template of the area to be detected, wherein the template of the area to be detected comprises templates consisting of runways on two sides and a middle rectangle.
A magnet sheet inspection system, comprising:
the first acquisition module is used for acquiring a target image of the magnet piece to be detected;
the second acquisition module is used for acquiring a preset area template to be detected;
the first determining module is used for determining a to-be-detected area corresponding to the to-be-detected area template in the target image based on an indirect adjustment method;
the first calculation module is used for calculating gray value information of the to-be-detected region;
and the second determining module is used for determining the detection result of the magnet piece to be detected based on the gray value information and a preset threshold value.
A magnet piece inspection apparatus, comprising:
a memory for storing a computer program;
a processor for implementing the steps of the magnet piece detecting method as described above when the computer program is executed.
A computer-readable storage medium having stored thereon a computer program which, when executed by a processor, implements the steps of the magnet piece detecting method as described in any one of the above.
According to the magnet piece detection method, the target image of the magnet piece to be detected is obtained; acquiring a preset template of a region to be detected; determining a region to be detected corresponding to a region template to be detected in a target image based on an indirect adjustment method; calculating gray value information of the area to be detected; and determining the detection result of the magnet piece to be detected based on the gray value information and the preset threshold value. According to the method, the to-be-detected area corresponding to the to-be-detected area template can be rapidly determined in the target image through an indirect adjustment method, the detection result of the to-be-detected magnet piece can be determined based on the gray value information and the preset threshold value only by calculating the gray value information of the to-be-detected area, and the performance of the to-be-detected magnet piece can be rapidly detected. The application provides a magnet piece detecting system, equipment and computer readable storage medium has also solved corresponding technical problem.
Detailed Description
The technical solutions in the embodiments of the present application will be described clearly and completely with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only some embodiments of the present application, and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, fig. 1 is a flowchart of a magnet piece detecting method according to an embodiment of the present disclosure.
The magnet piece detection method provided by the embodiment of the application can comprise the following steps:
step S101: and acquiring a target image of the magnet piece to be detected.
In practical applications, the performance of the magnet piece can be detected by the image information of the magnet piece, so that the target image of the magnet piece to be detected can be acquired first.
Step S102: and acquiring a preset template of the area to be detected.
In practical application, the size influence of the target image is considered, if all the target images are calculated to determine the performance of the magnet piece to be detected, the detection process is possibly complicated, the efficiency is low, in order to avoid the problem, a preset template of the area to be detected can be obtained, the corresponding area to be detected is determined in the target image by means of the template of the area to be detected, and the performance detection is performed on the magnet piece to be detected by the area to be detected.
Step S103: and determining a region to be detected corresponding to the region template to be detected in the target image based on an indirect adjustment method.
In practical application, in order to quickly determine the region to be detected, the region to be detected corresponding to the template of the region to be detected can be determined in the target image based on an indirect adjustment method. The indirect adjustment is an adjustment method for obtaining the most probable value of the unknown quantity according to the principle of least square method by selecting independent quantities without any condition relation between the independent quantities as the unknown quantity to form a functional relation for expressing measurement by the unknown quantity, listing an error equation and obtaining the most probable value of the unknown quantity when determining the most probable value of a plurality of unknown quantities.
Step S104: and calculating gray value information of the area to be detected.
Step S105: and determining the detection result of the magnet piece to be detected based on the gray value information and the preset threshold value.
In practical application, after the area to be detected is determined, the gray information of the area to be detected can be calculated, and the detection result of the magnet piece to be detected is determined based on the gray information and the preset threshold.
It should be noted that, since the color and brightness of each point of the region to be detected are different, and the calculated gray value information is different, the whitening or brightening detection can be performed on the magnet piece to be detected by means of the gray value information and the preset threshold, that is, the detection result can be the whitening or brightening of the magnet piece to be detected.
According to the magnet piece detection method, the target image of the magnet piece to be detected is obtained; acquiring a preset template of a region to be detected; determining a to-be-detected area corresponding to the to-be-detected area template in the target image based on an indirect adjustment method; calculating gray value information of the area to be detected; and determining the detection result of the magnet piece to be detected based on the gray value information and the preset threshold value. According to the method, the to-be-detected area corresponding to the to-be-detected area template can be rapidly determined in the target image through an indirect adjustment method, the detection result of the to-be-detected magnet piece can be determined based on the gray value information and the preset threshold value only by calculating the gray value information of the to-be-detected area, and the performance of the to-be-detected magnet piece can be rapidly detected.
In the method for detecting a magnet sheet provided in the embodiment of the present application, in the process of determining the to-be-detected region corresponding to the to-be-detected region template in the target image based on the indirect adjustment method, the method may include the following steps:
determining locating point information of a target image;
determining a two-dimensional steel body transformation matrix between the template of the area to be detected and the positioning point information through an operational formula based on an indirect adjustment method;
mapping a template of the area to be detected to a target image based on a two-dimensional steel body transformation matrix to obtain the area to be detected;
the operation formula comprises:
wherein R is
bRepresenting a two-dimensional steel body transformation matrix;
expressing the local variation of the adjustment parameters, wherein six adjustment parameters express corresponding parameter values in a two-dimensional steel body transformation matrix; r is a radical of hydrogen
1、r
2、r
3、r
4Representing multiple rotation terms; t is t
rx、t
ryRepresenting a translation term; b represents a mapping matrix constructed based on the template of the area to be detected and the locating point information; p represents an identity matrix; b is
TRepresents the transpose of B; and l represents the difference between the observed value and the corresponding approximate value in the indirect adjustment method.
The derivation process of the operation formula is as follows:
suppose a transformation matrix such as R
bAs shown, according to the indirect adjustment theory, the error equation is:
wherein V represents an error value in the indirect adjustment; the adjustment criterion is: v
TPV is min; according to the least square principle, the method can be obtained as follows:
finally, the following can be obtained:
in a specific application scenario, in the process of determining a two-dimensional steel body transformation matrix between a template of a region to be detected and positioning point information through an operational formula based on an indirect adjustment method, template point information corresponding to the positioning point information can be determined in the template of the region to be detected, and then the two-dimensional steel body transformation matrix between the positioning point information and the template point information is determined through the operational formula based on the indirect adjustment method; correspondingly, in the process of mapping the template of the area to be detected to the target image based on the two-dimensional steel body transformation matrix to obtain the area to be detected, the point set of the template of the area to be detected and the two-dimensional steel body transformation matrix can be operated to obtain the point set information of the area to be detected, and the area to be detected and the like can be determined on the target image according to the point set information of the area to be detected.
In the magnet piece detection method provided by the embodiment of the application, in the process of determining the locating point information of the target image, the locating point information can be quickly determined by means of operations such as gray scale, binaryzation and the like, that is, the method can also comprise the following steps:
converting the target image into a gray scale image;
carrying out binarization operation on the gray level image to obtain a target binarization image;
and respectively carrying out integral projection in the horizontal direction and the vertical direction on the target binary image, and determining positioning point information according to the projection result.
Referring to fig. 2, in a specific application scenario, the process of determining the anchor point information of the target image may include the following steps:
step S201: the target image is converted into a grayscale image.
Step S202: and carrying out binarization operation on the gray level image to obtain an initial binarization image.
In practical applications, in order to facilitate processing of the image, the target image may be first converted into a gray-scale map, a schematic result diagram of which may be as shown in fig. 3, and then the gray-scale map is binarized to obtain an initial binary diagram, a schematic result diagram of which may be as shown in fig. 4.
Step S203: and performing morphological operation on the initial binary image to obtain a processed image.
In practical applications, in consideration of image processing errors caused by noise influence, background influence and the like in an image, morphological operations can be performed on the initial binary image to obtain a processed image without error influence, and a schematic result diagram of the processed image can be as shown in fig. 5 to accurately process the image. The morphological operation in the image processing is used in scenes such as image and processing operation (denoising, shape simplification and the like), image enhancement (skeleton extraction, refinement, convex hull and object marking), object background segmentation, object morphological quantification and the like.
Step S204: based on the hough transform, the longest straight line in the processed image is extracted.
Step S205: and (5) correcting the gray scale image based on the longest straight line to obtain a corrected gray scale image.
In practical applications, because the template of the region to be detected is forward, if the target image is not forward, the final locating point information may not match the template of the region to be detected, after the processed image is obtained, the longest straight line in the processed image needs to be extracted based on hough transform, and the grayscale map is converted into forward based on the longest straight line, so as to obtain a converted grayscale map, where a schematic result map may be as shown in fig. 6.
Step S206: and carrying out binarization operation on the positive gray map to obtain a target binarization map.
In practical application, after the positive-transition gray scale map is obtained, the positive-transition gray scale map needs to be binarized again to obtain a target binary map, and a schematic result map of the target binary map can be shown in fig. 7.
Step S207: and respectively carrying out integral projection in the horizontal direction and the vertical direction on the target binary image, and determining positioning point information according to the projection result.
In practical application, after the target binary image is obtained, integral projection in the horizontal direction and integral projection in the vertical direction can be performed on the target binary image, the projection result can be as shown in fig. 8, and positioning point information can be determined according to the projection result, wherein the positioning point information can include coordinate information of three points, namely, an upper left corner, an upper right corner and a lower left corner, and the like, and at this time, the positioning point information can be as shown in fig. 9, and certainly, the positioning point information can be flexibly determined according to actual needs.
In the magnet sheet detection method provided by the embodiment of the application, in the process of calculating the gray value information of the area to be detected, the following steps may be performed:
calculating a target gray level mean value and a target first-order gray level derivative mean value of a region to be detected;
accordingly, in the process of determining the detection result of the magnet piece to be detected based on the gray value information and the preset threshold, it may be:
selecting a to-be-detected sub-region in a to-be-detected region;
calculating a first gray mean value and a first one-order gray derivative mean value of a subregion to be detected;
calculating a first difference value between the first gray level mean value and the target gray level mean value;
calculating a second difference value between the first-order gray derivative mean value and the target first-order gray derivative mean value;
and comparing the first difference value and the second difference value with a preset threshold value, and determining a detection result according to the comparison result.
It should be noted that, the sub-region to be detected and the region to be detected may be divided into fine fractions according to actual needs, for example, the region to be detected may be divided into a plurality of portions to be detected first, and a corresponding sub-region to be detected is determined in each portion to be detected, so that in the process of calculating the target gray level mean value and the target first-order gray level derivative mean value of the region to be detected, the target gray level mean value and the target first-order gray level derivative mean value of each portion to be detected need to be calculated; and in the process of calculating a first difference value between the first gray mean value and the target gray mean value and calculating a second difference value between the first-order gray derivative mean value and the target first-order gray derivative mean value, calculating a first difference value between the first gray mean value and the target gray mean value of the part to be detected corresponding to the sub-region to be detected, and calculating a second difference value between the first-order gray derivative mean value and the target first-order gray derivative mean value of the part to be detected corresponding to the sub-region to be detected, so as to accurately determine the detection result under the condition of reducing the region difference value between the region to be detected and the sub-region to be detected.
In practical application, in the process of comparing the first difference and the second difference with the preset threshold and determining the detection result according to the comparison result, the following steps may be performed:
judging whether the first difference value is greater than a first threshold value and whether the second difference value is greater than a second threshold value, and if the first difference value is greater than the first threshold value and the second difference value is greater than the second threshold value, determining that the to-be-detected magnet piece has a whitish detection result;
and/or
And judging whether the first difference value is smaller than a third threshold value and the second difference value is smaller than a fourth threshold value, and if the first difference value is smaller than the third threshold value and the second difference value is smaller than the fourth threshold value, determining that the magnet piece to be detected has a bright detection result.
It should be noted that, because the first difference and the second difference are differences of corresponding parameters, in practical applications, the corresponding thresholds may be set to be the same, that is, the values of the first threshold and the second threshold may be the same, and the values of the third threshold and the fourth threshold may be the same.
In the magnet sheet detection method provided by the embodiment of the application, in the process of obtaining the preset template of the area to be detected, the preset template of the area to be detected can be obtained, the template of the area to be detected comprises templates formed by runways on two sides and a middle rectangle, and a schematic diagram of the template can be shown in fig. 10. The part to be detected may be five parts, wherein two parts are provided on each of the two side runways, and the middle rectangle is one part, as indicated by the reference numerals 1 to 5 in fig. 10.
Referring to fig. 11, fig. 11 is a schematic structural diagram of a magnet piece detecting system according to an embodiment of the present application.
The magnet piece detecting system that this application embodiment provided can include:
the first acquisition module 101 is used for acquiring a target image of the magnet piece to be detected;
the second obtaining module 102 is configured to obtain a preset template of the area to be detected;
the first determining module 103 is configured to determine, based on an indirect adjustment method, a to-be-detected region corresponding to a to-be-detected region template in the target image;
the first calculation module 104 is configured to calculate gray value information of the to-be-detected region;
and the second determining module 105 is configured to determine a detection result of the magnet piece to be detected based on the gray value information and a preset threshold.
In an embodiment of the present application, a magnet piece detecting system, a first determining module may include:
the first determining submodule is used for determining positioning point information of the target image;
the second determining submodule is used for determining a two-dimensional steel body transformation matrix between the template of the area to be detected and the positioning point information through an operational formula based on an indirect adjustment method;
the third determining submodule is used for mapping the template of the area to be detected to the target image based on the two-dimensional steel body transformation matrix to obtain the area to be detected;
the operational formula comprises:
wherein R is
bRepresenting a two-dimensional steel body transformation matrix;
expressing local variation of adjustment parameters, wherein six adjustment parameters express corresponding parameter values in a two-dimensional steel body transformation matrix; r is
1、r
2、r
3、r
4Representing multiple rotation terms; t is t
rx、t
ryRepresenting a translation term; b represents a mapping matrix constructed based on the template of the area to be detected and the locating point information; p represents an identity matrix; b is
TRepresents the transpose of B; and l represents the difference between the observed value and the corresponding approximate value in the indirect adjustment method.
In an embodiment of the present application, a first determining submodule of a magnet piece detecting system may include:
the first conversion submodule is used for converting the target image into a gray map;
the first operation submodule is used for carrying out binarization operation on the gray level image to obtain a target binarization image;
and the fourth determining submodule is used for respectively performing integral projection in the horizontal direction and the vertical direction on the target binary image and determining the positioning point information according to the projection result.
In an embodiment of the present application, the first operation sub-module may include:
the first binarization unit is used for carrying out binarization operation on the gray scale image to obtain an initial binarization image;
the first operation unit is used for performing morphological operation on the initial binary image to obtain a processed image;
a first extraction unit, configured to extract a longest straight line in a processed image based on hough transform;
the first correction unit is used for correcting the gray-scale image based on the longest straight line to obtain a corrected gray-scale image;
and the second binarization unit is used for carrying out binarization operation on the positive rotation gray level map to obtain a target binarization map.
In an embodiment of the present application, a magnet piece detecting system, a first calculating module may include:
the first calculation submodule is used for calculating a target gray level mean value and a target first-order gray level derivative mean value of the area to be detected;
the second determining module may include:
the first selection submodule is used for selecting a sub-region to be detected in the region to be detected;
the second calculation submodule is used for calculating a first gray average value and a first one-step gray derivative average value of the sub-region to be detected;
the third calculation submodule is used for calculating a first difference value of the first gray level mean value and the target gray level mean value;
the fourth calculation submodule is used for calculating a second difference value between the first-order gray derivative average value and the target first-order gray derivative average value;
and the fifth determining submodule is used for comparing the first difference value and the second difference value with a preset threshold value and determining a detection result according to a comparison result.
In an embodiment of the present application, the fifth determining sub-module may include:
the first judging unit is used for judging whether the first difference value is larger than a first threshold value and whether the second difference value is larger than a second threshold value, and if the first difference value is larger than the first threshold value and the second difference value is larger than the second threshold value, determining that the detection result that the magnet piece to be detected is whitish exists;
and/or
And the second judgment unit is used for judging whether the first difference value is smaller than a third threshold value and whether the second difference value is smaller than a fourth threshold value, and if the first difference value is smaller than the third threshold value and the second difference value is smaller than the fourth threshold value, determining that the magnet piece to be detected has a bright detection result.
The embodiment of the application provides a magnet piece detecting system, the second acquires the module and can include:
the first acquisition unit is used for acquiring a preset area template to be detected, and the area template to be detected comprises templates consisting of runways on two sides and a middle rectangle.
The application also provides a magnet piece detection device and a computer readable storage medium, which have corresponding effects of the magnet piece detection method provided by the embodiment of the application. Referring to fig. 12, fig. 12 is a schematic structural view of a magnet piece detecting apparatus according to an embodiment of the present application.
The magnet piece detection device provided by the embodiment of the application comprises a memory 201 and a processor 202, wherein a computer program is stored in the memory 201, and the processor 202 executes the computer program to realize the steps of the magnet piece detection method described in any one of the embodiments.
Referring to fig. 13, another magnet piece inspection apparatus provided in an embodiment of the present application may further include: an input port 203 connected to the processor 202, for transmitting externally input commands to the processor 202; a display unit 204 connected to the processor 202, for displaying the processing result of the processor 202 to the outside; and a communication module 205 connected to the processor 202 for communicating the magnet piece detecting apparatus with the outside. The display unit 204 may be a display panel, a laser scanning display, or the like; the communication method adopted by the communication module 205 includes, but is not limited to, mobile high definition link technology (HML), Universal Serial Bus (USB), High Definition Multimedia Interface (HDMI), and wireless connection: wireless fidelity technology (WiFi), bluetooth communication technology, bluetooth low energy communication technology, ieee802.11s based communication technology.
A computer-readable storage medium is provided in an embodiment of the present application, in which a computer program is stored, and when the computer program is executed by a processor, the computer program implements the following steps:
the computer-readable storage media to which the present application relates include Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage media known in the art.
For a description of relevant portions of the magnet piece detection system, the magnet piece detection apparatus, and the computer-readable storage medium provided in the embodiments of the present application, reference is made to the detailed description of corresponding portions of the magnet piece detection method provided in the embodiments of the present application, and details are not repeated herein. In addition, parts of the above technical solutions provided in the embodiments of the present application, which are consistent with the implementation principles of corresponding technical solutions in the prior art, are not described in detail so as to avoid redundant description.
It is further noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present application. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the application. Thus, the present application is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.