Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the 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 invention.
Fig. 1 is a flowchart of a defect labeling method according to an embodiment of the present invention.
As shown in fig. 1, the defect labeling method according to the embodiment of the present invention may include the following steps:
and S1, acquiring a target detection image set of the product to be detected.
Specifically, when a product to be detected (for example, a mobile phone shell and the like) is subjected to target detection, a plurality of target detection images of the product to be detected can be acquired through a shooting device (for example, a camera) to generate a target detection image set.
S2, a target detection region is framed in the target detection image set.
Specifically, for each target detection image in the target detection image set, the target detection area can be selected from the same position frame in each target detection image according to the user requirement.
The target detection area may be a rectangular area, and in this case, the rectangular area is drawn by canvas. Specifically, canvas can be used as a drawing label, a mouse click event and a mouse movement event are monitored, a point when the mouse clicks is used as an origin of the upper left corner of the rectangle, and the distance x and the distance y of the movement of the mouse after the mouse moves is monitored as the width and the height of the rectangular area. After determining the width and height of the rectangular area, a canvas is used to draw the rectangular area.
And S3, labeling different defect types of the products to be detected in the target detection image set by adopting different labeling modes, and calculating the minimum circumscribed rectangle of each labeled defect.
Specifically, when defect detection is performed on the target detection image, defect data of the target detection image is required to be supplied to the algorithm model. For different types of defect types, different labeling modes are required to be adopted for labeling, wherein the labeling modes can include circular labeling, rectangular labeling, polygonal labeling, fold line labeling and the like. For example, for crack defects appearing in the mobile phone shell detection image, the defects can be marked out by adopting a rectangle; aiming at the scratch defect appearing in the mobile phone shell detection image, the defect can be marked by adopting a fold line.
Further, after marking the defects, the minimum bounding rectangle of each marked defect may be calculated.
And S4, acquiring coordinates of four end points of the minimum bounding rectangle.
After the minimum circumscribed rectangle of each marked defect is calculated, the coordinates of four end points of the minimum circumscribed rectangle can be obtained and stored.
And S5, judging whether the corresponding marking defects are located in the target detection area according to the coordinates of the four end points of the minimum circumscribed rectangle.
According to an embodiment of the present invention, determining whether the corresponding annotation defect is located in the target detection region according to the coordinates of the four endpoints of the minimum bounding rectangle includes: if the four end points of the minimum circumscribed rectangle are all located in the target detection area, judging that the corresponding marking defects are located in the target detection area; and if the four end points of the minimum circumscribed rectangle are all positioned outside the target detection area, judging that the corresponding marking defects are positioned outside the target detection area.
According to an embodiment of the present invention, determining whether the corresponding annotation defect is located in the target detection area according to the coordinates of the four endpoints of the minimum bounding rectangle further includes: if N endpoints of the minimum circumscribed rectangle are located in the target detection area, calculating the overlapping area of the minimum circumscribed rectangle and the target detection area, wherein N is an integer which is more than or equal to 1 and less than 4; judging whether the ratio of the overlapping area of the minimum circumscribed rectangle and the target detection area to the area of the minimum circumscribed rectangle is larger than a preset value or not; if so, judging that the corresponding marking defect is positioned in the target detection area; if not, judging that the corresponding marking defect is positioned outside the target detection area.
Specifically, whether the corresponding labeling defect is located in the target detection area can be judged according to the coordinates of the four endpoints of the minimum circumscribed rectangle and the coordinates of the endpoints of the corresponding target detection area. If the four end points of the minimum external rectangle are all located in the target detection area, judging that the corresponding marking defects are located in the target detection area; if the four end points of the minimum external rectangle are all located outside the target detection area, judging that the corresponding marking defects are located outside the target detection area; if only N endpoints are located in the target detection area, calculating the overlapping area of the minimum external rectangle and the target detection area, and judging whether the ratio of the overlapping area of the minimum external rectangle and the target detection area to the area of the minimum external rectangle is larger than a preset value, for example, judging whether the ratio of the overlapping area of the minimum external rectangle and the target detection area to the area of the minimum external rectangle is larger than 90%, if so, judging that the corresponding marking defect is located in the target detection area, otherwise, judging that the corresponding marking defect is located outside the target detection area.
S6, if yes, obtaining the marking information for marking the defect.
Specifically, in the process of labeling each defect, for the case of many defects, a snowflake algorithm needs to be combined to generate unique identification information for each labeled defect.
It should be noted that, since the ID generated by the conventional snowflake algorithm is 64 bits and is converted into an integer of 19 digits, but only 16-bit integer digits can be identified at most in the H5 environment, and an overflow calculation is sent for the overflow part, in the embodiment of the present invention, the conventional snowflake algorithm needs to be improved to convert into a 15-bit integer number. Specifically, 10 bits used for recording the working machine ID can be replaced by 5 bits, that is, 32 different numbers of 0 to 31 can be used for representing the machine ID and the digital center ID, and the length of the timestamp is partially cut out to be part of the generated ID, so that the uniqueness of each ID is ensured.
Therefore, when the mark defect is located in the target detection area, the unique identification information of the mark defect can be obtained, and the mark information of the mark defect can be obtained according to the unique identification information, wherein the mark information comprises the defect type and the number of the defect types located in the target detection area.
And S7, generating a thermal analysis chart of the defects of the product to be detected in the target detection area according to the marking information of the marked defects.
Specifically, after the labeling information of each labeling defect is acquired, a chart can be established for analysis, wherein x-axis and y-axis coordinates of the target detection area can be used as x-axis and y-axis coordinates of the chart, and the chart is marked by adopting different colors according to the labeling information of each labeling defect. The defect types with different times can be marked by different colors, for example, the defect types with less times can be marked by lighter color, and the defect types with more times can be marked by darker color, so that a corresponding thermal analysis chart can be formed.
Therefore, in the embodiment of the invention, not only can the defects in the target detection image be labeled, but also the distribution condition of each defect in a specific direction of the target detection image can be accurately and effectively acquired.
It should be noted that, in order to provide the developer with more convenient and faster invocation, the defect labeling statistical algorithm and the thermal area display application are packaged into a single application installation package.
In summary, according to the defect labeling method of the embodiment of the present invention, a target detection image set of a product to be detected is obtained, a target detection area is selected from a frame of the target detection image set, different labeling methods are used to label different defect types of the product to be detected in the target detection image set, a minimum circumscribed rectangle of each labeled defect is calculated, coordinates of four endpoints of the minimum circumscribed rectangle are obtained, whether a corresponding labeled defect is located in the target detection area is judged according to the coordinates of the four endpoints of the minimum circumscribed rectangle, labeling information of the labeled defect is obtained when the labeled defect is judged to be located in the target detection area, and a thermal analysis graph of the defect of the product to be detected in the target detection area is generated according to the labeling information of the labeled defect. Therefore, the defects in the target detection image can be labeled, and the distribution condition of each defect in a specific direction of the target detection image can be accurately and effectively acquired.
Corresponding to the defect labeling method of the above embodiment, the invention further provides a defect labeling device.
As shown in fig. 2, the defect labeling apparatus according to the embodiment of the present invention may include a first obtainingmodule 100, aframe selecting module 200, alabeling module 300, a second obtainingmodule 400, a determiningmodule 500, a third obtainingmodule 600, and agenerating module 700.
The first obtainingmodule 100 is configured to obtain a target detection image set of a plurality of products to be detected; theframing module 200 is configured to frame out a target detection area in the target detection image set; thelabeling module 300 is configured to label different defect types of the product to be detected in the target detection image set by using different labeling modes, and calculate a minimum circumscribed rectangle of each labeled defect; the second obtainingmodule 400 is configured to obtain coordinates of four endpoints of the minimum bounding rectangle; thejudging module 500 is configured to judge whether the corresponding annotation defect is located in the target detection region according to coordinates of four endpoints of the minimum circumscribed rectangle; the third obtainingmodule 600 is configured to obtain labeling information of a labeling defect when the labeling defect is located in the target detection area; thegenerating module 700 is configured to generate a thermal analysis diagram of the defect of the product to be detected in the target detection area according to the labeling information of the labeled defect.
According to an embodiment of the present invention, the determiningmodule 500 is specifically configured to: if the four end points of the minimum circumscribed rectangle are all located in the target detection area, judging that the corresponding marking defects are located in the target detection area; and if the four end points of the minimum external rectangle are all positioned outside the target detection area, judging that the corresponding marking defects are positioned outside the target detection area.
According to an embodiment of the present invention, the determiningmodule 500 is specifically configured to: if N endpoints of the minimum circumscribed rectangle are located in the target detection area, calculating the overlapping area of the minimum circumscribed rectangle and the target detection area, wherein N is an integer which is more than or equal to 1 and less than 4; judging whether the ratio of the overlapping area of the minimum circumscribed rectangle and the target detection area to the area of the minimum circumscribed rectangle is larger than a preset value or not; if so, judging that the corresponding marking defect is positioned in the target detection area; if not, judging that the corresponding marking defect is positioned outside the target detection area.
It should be noted that, for a more specific implementation of the defect labeling apparatus according to the embodiment of the present invention, reference may be made to the above-mentioned embodiment of the defect labeling method, which is not described herein again.
According to the defect labeling device of the embodiment of the invention, the first acquisition module is used for acquiring the target detection image sets of a plurality of products to be detected, and selecting a target detection area in the target detection image set frame by the frame selection module, marking different defect types of the products to be detected in the target detection image set by the marking module in different marking modes, and calculating the minimum circumscribed rectangle of each marked defect, and acquiring coordinates of four end points of the minimum circumscribed rectangle through a second acquisition module, and judging whether the corresponding marking defect is positioned in the target detection area or not by the judging module according to the coordinates of the four end points of the minimum circumscribed rectangle, and the third acquisition module acquires the marking information of the marking defect when the marking defect is positioned in the target detection area, and generating a thermal analysis chart of the defects of the product to be detected in the target detection area by the generation module according to the marking information of the marked defects. Therefore, the defects in the target detection image can be labeled, and the distribution condition of each defect in a specific direction of the target detection image can be accurately and effectively acquired.
The invention further provides a computer device corresponding to the embodiment.
The computer device of the embodiment of the invention comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, and when the processor executes the program, the defect labeling method of the embodiment is realized.
According to the computer equipment provided by the embodiment of the invention, not only can the defects in the target detection image be labeled, but also the distribution condition of each defect in a specific direction of the target detection image can be accurately and effectively acquired.
The invention also provides a non-transitory computer readable storage medium corresponding to the above embodiment.
A non-transitory computer-readable storage medium of an embodiment of the present invention stores thereon a computer program, which when executed by a processor implements the defect labeling method described above.
The non-transitory computer-readable storage medium according to the embodiment of the present invention not only can label defects in the target detection image, but also can accurately and effectively obtain the distribution of each defect in a specific orientation of the target detection image.
In the description of the present invention, the terms "first" and "second" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implying any number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. The meaning of "plurality" is two or more unless specifically limited otherwise.
In the present invention, unless otherwise expressly stated or limited, the terms "mounted," "connected," "secured," and the like are to be construed broadly and can, for example, be fixedly connected, detachably connected, or integrally formed; can be mechanically or electrically connected; either directly or indirectly through intervening media, either internally or in any other relationship. The specific meanings of the above terms in the present invention can be understood by those skilled in the art according to specific situations.
In the present invention, unless otherwise expressly stated or limited, the first feature "on" or "under" the second feature may be directly contacting the first and second features or indirectly contacting the first and second features through an intermediate. Also, a first feature "on," "over," and "above" a second feature may be directly or diagonally above the second feature, or may simply indicate that the first feature is at a higher level than the second feature. A first feature being "under," "below," and "beneath" a second feature may be directly under or obliquely under the first feature, or may simply mean that the first feature is at a lesser elevation than the second feature.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps of the process, and alternate implementations are included within the scope of the preferred embodiment of the present invention in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the present invention.
The logic and/or steps represented in the flowcharts or otherwise described herein, e.g., an ordered listing of executable instructions that can be considered to implement logical functions, can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor-containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For the purposes of this description, a "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of the computer-readable medium would include the following: an electrical connection (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium could even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
It will be understood by those skilled in the art that all or part of the steps carried by the method for implementing the above embodiments may be implemented by hardware related to instructions of a program, which may be stored in a computer readable storage medium, and when the program is executed, the program includes one or a combination of the steps of the method embodiments.
In addition, functional units in the embodiments of the present invention may be integrated into one processing module, or each unit may exist alone physically, or two or more units are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium.
The storage medium mentioned above may be a read-only memory, a magnetic or optical disk, etc. Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention, and that variations, modifications, substitutions and alterations can be made to the above embodiments by those of ordinary skill in the art within the scope of the present invention.