Disclosure of Invention
The invention aims to provide a method, a device, equipment and a storage medium for detecting surface defects of an object, so as to reduce the waste of computing and storage resources in an intelligent detection machine.
In a first aspect, an embodiment of the present invention provides a method for detecting a surface defect of an object, including:
generating a series of anchor frames corresponding to the distribution rule of the positions of the marking frames of the detection object, wherein the distribution of the center points of the anchor frames forms an anchor frame distribution graph corresponding to the detection object;
training a detection model according to a series of anchor frames corresponding to the anchor frame distribution pattern to obtain a trained detection model;
and detecting the surface defects of the detection object by using the trained detection model to obtain a surface defect generation frame.
In a possible implementation manner, in the method provided in an embodiment of the present invention, the generating a series of anchor frames corresponding to a distribution rule of positions of a labeled frame of a detection object, where a distribution of center points of the series of anchor frames forms an anchor frame distribution pattern corresponding to the detection object includes:
acquiring a target image corresponding to the detection object;
labeling the target image to obtain a labeled data set corresponding to the target object;
counting the coordinates of the central point of each labeling frame in the labeling data set to obtain a statistical result;
and according to the statistical result, mapping the current square anchor frame distribution graph into a series of anchor frames corresponding to the distribution rule of the positions of the marking frames of the detection object by adopting a collapse operator, wherein the distribution of the center points of the anchor frames forms the anchor frame distribution graph corresponding to the detection object.
In a possible implementation manner, in the foregoing method provided by the embodiment of the present invention, the collapse operator uses a first calculation formula:
wherein, (x, y) is the transformed coordinates; (x)0,y0) The coordinates before transformation; (a, b) are center coordinates; k is the collapse factor.
In a possible implementation manner, in the foregoing method provided by the embodiment of the present invention, the collapse factor adopts a second calculation formula:
in a second aspect, an embodiment of the present invention provides an apparatus for detecting surface defects of an object, including:
the generating module is used for generating a series of anchor frames corresponding to the distribution rule of the positions of the marking frames of the detection object, and the distribution of the center points of the anchor frames forms an anchor frame distribution graph corresponding to the detection object;
the training module is used for training the detection model according to a series of anchor frames corresponding to the anchor frame distribution pattern to obtain a trained detection model;
and the detection module is used for detecting the surface defects of the detection object by using the trained detection model to obtain a surface defect generation frame.
In a possible implementation manner, in the apparatus provided in an embodiment of the present invention, the generating module includes:
an acquisition unit, configured to acquire a target image corresponding to the detection object;
the marking unit is used for marking the target image to obtain a marking data set corresponding to the target object;
the statistical unit is used for carrying out statistics on the coordinate of the central point of each labeling frame in the labeling data set to obtain a statistical result;
and the mapping unit is used for mapping the current square anchor frame distribution graph into a series of anchor frames corresponding to the distribution rule of the positions of the marking frames of the detection object by adopting a collapse operator according to the statistical result, and the distribution of the center points of the anchor frames forms the anchor frame distribution graph corresponding to the detection object.
In a possible implementation manner, in the foregoing apparatus provided in an embodiment of the present invention, the collapse operator uses a first calculation formula:
wherein, (x, y) is the transformed coordinates; (x)0,y0) The coordinates before transformation; (a, b) are center coordinates; k is the collapse factor.
In a possible implementation manner, in the foregoing apparatus provided in an embodiment of the present invention, the collapse factor uses a second calculation formula:
in a third aspect, an embodiment of the present invention provides an electronic device, including: a memory and a processor;
the memory for storing a computer program;
wherein the processor executes the computer program in the memory to implement the method described in the first aspect and the various embodiments of the first aspect.
In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, where a computer program is stored, and the computer program is used, when executed by a processor, to implement the method described in the first aspect and the implementation manners of the first aspect.
Compared with the prior art, the method, the device, the equipment and the storage medium for detecting the surface defects of the object provided by the invention have the advantages that a series of anchor frames corresponding to the distribution rule of the positions of the marking frames of the detected object are generated, the distribution of the center points of the anchor frames forms the anchor frame distribution graph corresponding to the detected object, then the detection model is trained according to the anchor frames corresponding to the anchor frame distribution graph until the offset of the marking frames and the generation frames relative to the anchor frames is minimum, the trained detection model is obtained, the surface defects of the detected object are detected by using the trained detection model, and the surface defect generation frame is obtained, so that the surface defect detection result of the target object is more accurate, the generation of meaningless anchor frame data is reduced, and the waste of calculation and storage resources is reduced.
Detailed Description
The following detailed description of the present invention is provided in conjunction with the accompanying drawings, but it should be understood that the scope of the present invention is not limited to the specific embodiments.
Throughout the specification and claims, unless explicitly stated otherwise, the word "comprise", or variations such as "comprises" or "comprising", will be understood to imply the inclusion of a stated element or component but not the exclusion of any other element or component.
Fig. 1 is a schematic flow chart of a networked resource allocation method according to an embodiment of the present invention, as shown in fig. 1, the method includes the following steps S101 to S103:
s101, generating a series of anchor frames corresponding to the distribution rule of the positions of the marking frames of the detection object, wherein the distribution of the center points of the anchor frames forms an anchor frame distribution graph corresponding to the detection object.
In this embodiment, the labeling frame may be obtained by manual labeling, and the anchor frame is an artificial preset value. The target object may be various fruits, such as navel orange, or other objects, which is not limited in this application.
In practical applications, the execution subject of this embodiment may be an apparatus for detecting surface defects of an object, and the apparatus for detecting surface defects of an object may be implemented by a virtual apparatus, such as a software code, or an entity apparatus written with a relevant execution code, such as a usb disk, or an entity apparatus integrated with a relevant execution code, such as a chip, an intelligent detection machine, or the like.
Examples are made in connection with actual scenarios: take the execution subject of the present embodiment as an intelligent detection machine as an example. In practical application, the intelligent detection machine firstly generates an anchor frame marking graph corresponding to the shape of a target object, for example, if the target object is an apple, the central point distribution graph of the anchor frame for detection is designed to be the shape of a marking frame statistical result corresponding to the apple, and if the target object is an navel orange, the central point distribution graph of the anchor frame for detection is designed to be the shape of a marking frame statistical result corresponding to the navel orange. After generating the anchor frame annotation figure corresponding to the shape of the target object, step S102 may be performed.
S102, training a detection model according to a series of anchor frames corresponding to the anchor frame distribution graph to obtain the trained detection model.
Specifically, after an anchor frame marking graph corresponding to the shape of the target object is generated, a series of anchor frames are generated, other parameters of the anchor frames and the detection model are set, the detection model is trained according to the generated series of anchor frames until the offset of the marking frame and the generating frame relative to the anchor frames is minimum, the trained detection model is obtained, and detection is carried out after training. The generation box is the output of the detection model.
S103, detecting the surface defects of the detection object by using the trained detection model to obtain a surface defect generation frame.
In this embodiment, the trained detection model is used to detect the surface defect of the detection object, the obtained detection result is a surface defect generation frame, and the expression form of the detection result is to generate a frame to frame the defect.
In this embodiment, the detection result may include a type of the defect, a center point coordinate, a confidence coefficient, and the like, and the type of the defect may be preset. For example, after the navel orange is subjected to surface defect detection, the type of the defect A is rotten, the confidence coefficient is 80%, the type of the defect B is damaged by worms, and the confidence coefficient is 90%.
The method for detecting the surface defects of the object provided by this embodiment includes generating a series of anchor frames corresponding to a distribution rule of positions of a mark frame of a detection object, where a distribution of center points of the anchor frames forms an anchor frame distribution pattern corresponding to the detection object, training a detection model according to the anchor frames corresponding to the anchor frame distribution pattern until offsets of the mark frame and the generation frame relative to the anchor frames are minimum, obtaining the trained detection model, and detecting the surface defects of the detection object by using the trained detection model to obtain a surface defect generation frame, so that a surface defect detection result of the target object is more accurate, generation of meaningless anchor frame data is reduced, and waste of calculation and storage resources is reduced.
In this embodiment, there are various embodiments for generating the anchor frame distribution pattern corresponding to the detection object labeling frame, and in a preferred embodiment, as shown in fig. 2, based on the above embodiment, the step S101 may include the following steps:
s201, acquiring a target image corresponding to the detection object.
S202, labeling the target image to obtain a labeled data set corresponding to the target object.
Specifically, the labeling of the target image may be manual labeling, which is not limited in this application.
S203, counting the coordinates of the central point of each labeling frame in the labeling data set to obtain a statistical result.
Specifically, the coordinates of the center point of each labeling frame in the labeling data set can be counted in the coordinate system, so that the distribution rule of the positions of the labeling frames of the detection object can be obtained.
And S204, according to the statistical result, mapping the current square anchor frame distribution graph into a series of anchor frames corresponding to the distribution rule of the positions of the marking frames of the detection object by adopting a collapse operator, wherein the distribution of the center points of the anchor frames forms the anchor frame distribution graph corresponding to the detection object.
Specifically, according to the statistical result corresponding to the marking frame of the detection object, the pre-designed collapse operator is adopted to map the current anchor frame with square distribution into a distribution graph corresponding to the distribution rule of the position of the marking frame of the detection object.
Preferably, the collapse operator may use the following first calculation formula:
wherein, (x, y) is the transformed coordinates; (x)0,y0) The coordinates before transformation; (a, b) are center coordinates; k is the collapse factor.
Wherein, according to the difference of target object, need adopt different collapse factors to the intelligent detection machine detects the screening as the example to the surface defect of navel orange, and the collapse factor adopts the second computational formula:
the transformation of the anchor frame marking graph corresponding to the navel orange is shown in fig. 3, wherein small black points in the graph are point coordinates in a square, and larger points are circular coordinates after transformation by a collapse operator.
The anchor frame marking graph corresponding to the shape of the target object can be accurately generated through the embodiment, and the subsequent detection of the surface defects of the target object is facilitated.
The following are embodiments of the apparatus of the present application that may be used to perform embodiments of the method of the present application. For details which are not disclosed in the embodiments of the apparatus of the present application, reference is made to the embodiments of the method of the present application.
Fig. 4 is a schematic structural diagram of an apparatus for detecting surface defects of an object according to a second embodiment of the present invention, as shown in fig. 4, the apparatus may include:
the generating module 410 is configured to generate a series of anchor frames corresponding to a distribution rule of positions of a labeling frame of a detection object, where distribution of center points of the series of anchor frames forms an anchor frame distribution pattern corresponding to the detection object;
the training module 420 is configured to train a detection model according to a series of anchor frames corresponding to the anchor frame distribution pattern to obtain a trained detection model;
the detection module 430 is configured to detect the surface defect of the detection object by using the trained detection model, so as to obtain a surface defect generation frame.
The device for detecting surface defects of an object, provided by this embodiment, first generates a series of anchor frames corresponding to a distribution rule of positions of a mark frame of a detection object, where distribution of center points of the anchor frames forms an anchor frame distribution pattern corresponding to the detection object, and then trains a detection model according to the anchor frames corresponding to the anchor frame distribution pattern until offsets of the mark frame and the generation frame relative to the anchor frames are minimum, so as to obtain the trained detection model, and detects surface defects of the detection object by using the trained detection model, so as to obtain a surface defect generation frame, so that a surface defect detection result of a target object is more accurate, generation of meaningless anchor frame data is reduced, and waste of calculation and storage resources is reduced.
Preferably, as shown in fig. 5, the generating module 410 includes:
an acquiring unit 411, configured to acquire a target image corresponding to the detection object;
an annotation unit 412, configured to annotate the target image to obtain an annotation data set corresponding to the target object;
a counting unit 413, configured to count coordinates of a center point of each labeling frame in the labeling data set, so as to obtain a statistical result;
and the mapping unit 414 is configured to map the current square anchor frame distribution pattern into a series of anchor frames corresponding to the distribution rule of the positions of the labeled frames of the detection object by using a collapse operator according to the statistical result, where the distribution of the center points of the series of anchor frames forms the anchor frame distribution pattern corresponding to the detection object.
Preferably, the collapse operator uses a first calculation formula:
wherein, (x, y) is the transformed coordinates; (x)0,y0) The coordinates before transformation; (a, b) are center coordinates; k is the collapse factor.
Preferably, when detecting surface defects of a round object such as navel orange, the collapse factor may adopt a second calculation formula:
by the embodiment, the anchor frame marking graph corresponding to the distribution rule of the marking frame positions of the detection object can be accurately generated, and the subsequent detection of the surface defects of the target object is facilitated.
Fig. 6 is a schematic structural diagram of an electronic device according to a third embodiment of the present invention, and as shown in fig. 6, the electronic device includes: a memory 601 and a processor 602;
a memory 601 for storing a computer program;
wherein the processor 602 executes the computer program in the memory 601 to implement the methods provided by the method embodiments as described above.
In the embodiment, the detection device for the object surface defect provided by the invention is exemplified by an electronic device. The processor may be a Central Processing Unit (CPU) or other form of processing unit having data processing capabilities and/or instruction execution capabilities, and may control other components in the electronic device to perform desired functions.
The memory may include one or more computer program products that may include various forms of computer-readable storage media, such as volatile memory and/or non-volatile memory. Volatile memory can include, for example, Random Access Memory (RAM), cache memory (or the like). The non-volatile memory may include, for example, Read Only Memory (ROM), a hard disk, flash memory, and the like. One or more computer program instructions may be stored on a computer-readable storage medium and executed by a processor to implement the methods of the various embodiments of the present application above and/or other desired functions. Various contents such as an input signal, a signal component, a noise component, etc. may also be stored in the computer-readable storage medium.
A fourth embodiment of the present invention provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the computer program is configured to implement the methods provided by the method embodiments described above.
In practice, the computer program in this embodiment may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + +, python, etc., and conventional procedural programming languages, such as the "C" programming language or similar programming languages, for performing the operations of embodiments of the present invention. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server.
In practice, the computer-readable storage medium may take any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may include, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or a combination of any of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The foregoing descriptions of specific exemplary embodiments of the present invention have been presented for purposes of illustration and description. It is not intended to limit the invention to the precise form disclosed, and obviously many modifications and variations are possible in light of the above teaching. The exemplary embodiments were chosen and described in order to explain certain principles of the invention and its practical application to enable one skilled in the art to make and use various exemplary embodiments of the invention and various alternatives and modifications as are suited to the particular use contemplated. It is intended that the scope of the invention be defined by the claims and their equivalents.