Image annotation method, device, equipment and storage medium
By searching for matching template images from the template library and generating affine matrices, the problem of low image annotation efficiency in industrial machine vision is solved, fast and lightweight automatic annotation is achieved, and sample annotation efficiency is improved.
Patent Information
- Application Number
- CN202410135494.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-31
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-01-31
AI Technical Summary
In the field of industrial machine vision, existing automatic image annotation tools have high requirements on computer hardware configuration and computing power. As a result, image annotation cannot be completed quickly in applications with frequent model switching of small batches and diverse products, affecting the training and deployment progress of detection models.
By searching the template image from the template library that matches the image to be annotated, an affine matrix is generated based on the center point coordinates and angles of the template image, and the annotated area of the template image is mapped to the image to be annotated, and the annotated contour is segmented to achieve fast annotation results. .
There is no need to rely on large model reasoning, which saves system computing power and improves sample labeling efficiency in the field of industrial product defect detection.
Smart Images

Figure CN117670884B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image annotation method, device, equipment and storage medium. Background Art
[0002] Before training a deep learning model, it is necessary to create a data set, that is, to annotate the data set. At present, manual annotation tools can be used to annotate images. When faced with a large number of data sets to be annotated, this annotation method is time-consuming and laborious. Although there are automatic annotation tools in the prior art that can achieve intelligent annotation, these annotation tools often rely on the reasoning ability of large models, and have high requirements on the computer's hardware configuration and computing power. Especially in the application of industrial machine vision (for example, in the application of defect detection of industrial products), small batch products, diversified products, and frequent switching of different models of products are often encountered. If the industrial product images cannot be quickly annotated, the training and deployment of the detection model will not be able to keep up with the production progress requirements.
[0003] Therefore, in the application of industrial machine vision, providing a lightweight and fast automatic labeling technical solution has become a technical problem that needs to be solved urgently by technical personnel in this field. Summary of the invention
[0004] In view of the above, the present application provides an image annotation method, device, equipment and storage medium, the purpose of which is to solve the above technical problems.
[0005] In a first aspect, the present application provides an image annotation method, the method comprising:
[0006] Searching for a template image that matches the image to be annotated from a template library, wherein the template image has an annotated area;
[0007] Generate an affine matrix based on the template center point coordinates of the template image and the template angle of the template image;
[0008] Mapping the annotated region of the template image to the image to be annotated using the affine matrix to obtain the annotated region of the image to be annotated;
[0009] The annotation contour in the annotation area of the image to be annotated is segmented to obtain an annotation result of the contour of the image to be annotated.
[0010] In a second aspect, the present application provides an image annotation device, the device comprising:
[0011] Matching module: used to search for a template image that matches the image to be annotated from a template library, wherein the template image has an annotated area;
[0012] A generating module: used for generating an affine matrix based on the coordinates of the template center point of the template image and the template angle of the template image;
[0013] A first labeling module: used for mapping the labeling area of the template image to the image to be labeled using the affine matrix to obtain the labeling area of the image to be labeled;
[0014] The second annotation module is used to segment the annotation contour in the annotation area of the image to be annotated to obtain the contour annotation result of the image to be annotated.
[0015] In a third aspect, the present application provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0016] Memory, used to store computer programs;
[0017] The processor is used to implement the image annotation method described in any embodiment of the first aspect when executing the program stored in the memory.
[0018] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the image annotation method as described in any embodiment of the first aspect is implemented.
[0019] The above technical solution provided by the embodiment of the present application has the following advantages compared with the prior art:
[0020] The present application searches for a template image that matches the image to be annotated from a template library, wherein the template image has an annotated area, generates an affine matrix based on the template center point coordinates of the template image and the template angle of the template image, and uses the affine matrix to map the annotated area of the template image to the image to be annotated. Since the template library stores various types of template images, the annotated area of the image to be annotated can be quickly obtained by searching for a template image that matches the image to be annotated and combining the affine matrix. When it is necessary to further mark specific contours, the annotated contours in the annotated area of the image to be annotated are segmented to obtain the contour annotation result of the image to be annotated. This method does not require the use of a large model for reasoning, thus saving system computing power and obtaining the contour annotation result of the image to be annotated, thereby improving the sample annotation efficiency in the field of industrial product defect detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0022] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0023] Figure 1 This is a flow chart of an embodiment of the image annotation method of the present application;
[0024] Figure 2 This is a schematic diagram of modules of an embodiment of the image annotation device of the present application;
[0025] Figure 3 A schematic diagram of an electronic device embodiment of the present application;
[0026] The realization of the purpose, functional features and advantages of this application will be further explained in conjunction with embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION
[0027] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are 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 making creative work are within the scope of protection of this application.
[0028] The disclosure below provides many different embodiments or examples to realize the different structures of the present application. In order to simplify the disclosure of the present application, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present application. In addition, the present application can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.
[0029] The present application provides an image annotation method. Figure 1 FIG. 1 is a flow chart of an embodiment of the image annotation method of the present application. The method may be executed by an electronic device, and the electronic device may be implemented by software and / or hardware. The image annotation method includes:
[0030] Step S10: searching a template image matching the image to be annotated from a template library, wherein the template image has an annotated area;
[0031] Step S20: generating an affine matrix based on the template center point coordinates of the template image and the template angle of the template image;
[0032] Step S30: mapping the annotated area of the template image to the image to be annotated using the affine matrix to obtain the annotated area of the image to be annotated;
[0033] Step S40: segmenting the annotation contour in the annotation area of the image to be annotated to obtain the contour annotation result of the image to be annotated.
[0034] In this embodiment, the solution of the present application is explained by taking the image to be annotated as an industrial product image (for example, an image of a standard component or an image of a non-standard component) as an example. It can be understood that in actual application scenarios, the image to be annotated can also be an image that needs to be annotated in other fields such as face detection and object detection.
[0035] The template library stores various types of template images. The template images can be images that have been annotated using automatic annotation tools. For example, the obvious features and high-contrast mask points on the template image are used to locate the area that needs to be annotated to complete the annotation of the relevant area on the template image. For example, the semantic segmentation algorithm is used to determine the contours that need to be annotated on the template image to complete the annotation of the contour area on the template image. When the template image is annotated using an automatic annotation solution and the annotated area is inaccurate or the area that needs to be annotated cannot be located, the template image can be annotated manually.
[0036] The image to be labeled can be a batch of multiple images to be labeled. The template image that matches the image to be labeled refers to the template image with the highest similarity to the image to be labeled. The similarity between the image to be labeled and each template image in the template library is calculated, and the template image with the highest similarity value is selected from the template library as the template image that matches the image to be labeled.
[0037] Specifically, a template image matching the image to be annotated is searched from the template library, including:
[0038] Extracting the first edge contour point of the mask image of each template image in the template library, and calculating the feature vector of the first edge contour point;
[0039] Calculating the coordinates and angles of the first edge contour points;
[0040] Extracting second edge contour points of the mask image of the image to be annotated, and calculating feature vectors of the second edge contour points;
[0041] Calculating the coordinates and angles of the second edge contour points;
[0042] Based on the similarity between the feature vector of the first edge contour point and the feature vector of the second edge contour point, and the similarity between the coordinates and angle of the first edge contour point and the coordinates and angle of the second edge contour point, a template image matching the image to be annotated is determined.
[0043] The edge contour points (referred to as the first edge contour points) of the mask image corresponding to each template image in the template library are extracted respectively, and the feature vector of the first edge contour point is calculated, and the coordinates of the first edge contour point and the angle of the first contour point are calculated. The coordinates of the first edge contour point may be the coordinate values of the edge contour point obtained by the edge detection algorithm, and the angle of the first contour point may be the normal angle of the edge contour point of the mask image, or the angle relative to a preset reference direction (for example, the horizontal direction). The angle information of the contour point may be used to determine the direction of the contour, perform shape matching, etc. Similarly, the edge contour points (referred to as the second edge contour points) of the mask image of the image to be annotated are extracted in the same manner, and the feature vector of the second edge contour point is calculated, and the coordinates of the second edge contour point and the angle of the second contour point are calculated. The angle of the second contour point corresponds to the normal angle of the edge contour point, or the angle relative to a preset reference direction (for example, the horizontal direction).
[0044] Calculate the similarity between the feature vector of the first edge contour point and the feature vector of the second edge contour point. The similarity value can be expressed by Euclidean distance, cosine distance or cosine similarity. Calculate the similarity between the coordinates of the first edge contour point and the coordinates of the second edge contour point, and calculate the similarity between the angle of the first edge contour point and the angle of the second edge contour point. Assign different weights to each similarity, determine the similarity value of each template image and the image to be annotated through weighted calculation, and use the template image with the highest similarity value as the template image that matches the image to be annotated.
[0045] After determining the template image that matches the image to be annotated, an affine matrix is generated based on the template center point coordinates of the template image and the template angle of the template image. Assuming that the template is a rectangular workpiece, the template center point coordinates of the template image refer to the center point coordinates of the rectangular workpiece in the template image, and the template angle of the template image refers to the angle of the rectangular workpiece in the template image, which can be an angle relative to a preset reference direction (for example, the horizontal direction). The affine matrix can map the pixels of the template image to the corresponding positions in the image to be annotated. By setting different parameters of the affine matrix, different image transformation effects can be achieved.
[0046] Specifically, based on the template center point coordinates of the template image and the template angle of the template image, an affine matrix is generated, including:
[0047] Obtaining the template center point coordinates of the template image and the template angle of the template image;
[0048] Determining target coordinates corresponding to the coordinates of the template center point of the template image in the image to be annotated, and determining a target angle corresponding to the template angle of the template image in the image to be annotated;
[0049] An affine matrix is generated according to the center point coordinates, the template angle of the template image, the target coordinates and the target angle.
[0050] Get the template center coordinates of the template image, denoted as (Row, Column), and get the template angle of the template image, denoted as Angle. Determine the target coordinates corresponding to the template center coordinates of the template image in the image to be annotated, denoted as (BaseRow, BaseColumn), and determine the target angle corresponding to the template angle of the template image in the image to be annotated, denoted as BaseAngle. Assuming that the template of the template image is a rectangular workpiece, the target coordinates refer to the center point coordinates of the rectangular workpiece in the image to be annotated, and the target angle refers to the angle of the rectangular workpiece in the image to be annotated. Generate an affine matrix based on the vector from the center point coordinates to the target coordinates and the angle difference between the template angle of the template image and the target angle.
[0051] Wherein, generating an affine matrix according to the center point coordinates, the template angle of the template image, the target coordinates and the target angle includes:
[0052] The affine matrix is calculated using the following formula, which includes:
[0053]
[0054] Among them, Mat2D represents the affine matrix, α represents the angle difference between the template angle of the template image and the target angle, that is, α=Angle-BaseAngle, the value of α is expressed in radians, t represents the vector from the center point coordinates to the target coordinates, Tx represents the difference between the ordinate value of the center point coordinates and the ordinate value of the target coordinates, that is, Tx=Column-BaseColumn, and Ty represents the difference between the abscissa value of the center point coordinates and the abscissa value of the target coordinates, that is, Ty=Row-BaseRow.
[0055] After the affine matrix is generated, the annotated area of the template image is mapped to the image to be annotated using the affine matrix to obtain the annotated area of the image to be annotated, that is, the annotated area on the template image is affine transformed using the affine matrix obtained by the above calculation formula, and the annotated area on the template image is rotated and translated to the image to be annotated that matches the template image, thereby obtaining the annotated area of the image to be annotated. For example, when the template image and the annotated area of the template image are the same shape (for example, the edge contour of the template image is the annotated area), the template image is affine transformed. When the template image and the annotated area of the template image are different shapes (for example, the edge contour of the template image is a rounded rectangle, and the annotated area is a rectangle outside the rounded rectangle area), the annotated area of the template image is affine transformed.
[0056] Furthermore, after obtaining the annotated area of the image to be annotated, the method further includes:
[0057] Acquire attribute information of the image to be annotated, a coordinate point set of a contour of an annotated region of the image to be annotated, and label information of the annotated region of the image to be annotated;
[0058] The attribute information, the coordinate point set and the tag information are stored in JSON format to obtain a storage file;
[0059] The storage file is named with the file name of the image to be annotated.
[0060] The attribute information of the image to be annotated includes the file name of the image, the width of the image, the height of the image, and other information. The coordinate point set of the contour of the annotated area of the image to be annotated refers to the coordinates of the corner points of the contour extracted after the contour of the annotated area of the image to be annotated is generated. The label information of the annotated area of the image to be annotated refers to information such as the preset label type or label shape. The attribute information, the coordinate point set, and the label information are generated into data in JSON format, and a JSON file is obtained as a storage file, and the JSON file is named with the file name of the image.
[0061] The images to be annotated of industrial products include images without defective areas and images with defective areas. When the image to be annotated is an image with defective areas, the defective areas in the image need to be annotated. The image segmentation algorithm can be used to segment the annotation contour in the annotation area of the image to be annotated, and the annotation contour is the contour of the defective area in the image to be annotated, so as to obtain the contour annotation result of the image to be annotated, and obtain the annotation result of the defective area of the image to be annotated, wherein the image segmentation algorithm can be a threshold-based segmentation algorithm, an edge-based segmentation algorithm, a region-based segmentation algorithm, a graph-theory-based segmentation algorithm, etc. Specifically, segmenting the annotation contour in the annotation area of the image to be annotated to obtain the contour annotation result of the image to be annotated includes:
[0062] Get the segmentation parameters and extraction parameters input by the user;
[0063] Determining a segmented area in the annotation area of the image to be annotated;
[0064] According to the segmentation parameters and the extraction parameters, a labeling contour in the labeling area of the image to be labeled is segmented from the segmented area as a contour labeling result of the image to be labeled.
[0065] The user can select the segmentation parameters and extraction parameters in the human-computer interaction interface. The segmentation parameters include segmentation algorithm, color image processing method, smoothing coefficient, grayscale difference, etc. The segmentation parameters are used to segment the contour of the defect area from the background of the image to be annotated. Since contour areas that do not need to be segmented may be segmented during the segmentation process, extraction parameters are needed to screen out contour areas that need to be segmented. The extraction parameters can be the minimum area of the contour that needs to be segmented, that is, contours smaller than the extraction parameters will not be segmented. Determine the segmentation area in the annotation area of the image to be annotated. The segmentation area can be an area drawn by the user through the human-computer interaction interface (for example, a rectangular area, a circular area, etc.). Use the segmentation algorithm to segment and extract the defect area from the segmentation area, generate the contour of the defect area, and use it as the contour annotation result of the image to be annotated, thereby completing the annotation of the defect area. You can also then extract the coordinates of the corner points of the contour of the defect area and save them.
[0066] In one embodiment, after obtaining the annotation result of the image to be annotated, the method further includes:
[0067] Calculating the angle of each character in the image to be labeled respectively;
[0068] Based on the angle of each character, rotating each character to a horizontal direction;
[0069] Identify the character area where each character is located after rotation;
[0070] Each character region is segmented, and each segmented character region is spliced to obtain a rectangular splicing result, and the rectangular splicing result is used as the character annotation result of the image to be annotated.
[0071] Since industrial products usually determine whether there is a mixture by identifying the QR code or product model on the product image, a large amount of sample data is usually required when training the character recognition model of industrial products. When the image to be annotated contains product model (character) information, the present application can also automatically annotate the characters in the image to be annotated. Specifically, since the characters in the image to be annotated may be tilted or italic characters, it is necessary to first calculate the angle of the characters in the image to be annotated. The angle of the characters can be extracted from the background according to the character width, height and contrast, and the extracted character area is expanded and connected together, and then the expanded area circumscribed rectangle is calculated, and the angle between the long side of the circumscribed rectangle and the horizontal line is used as the angle of the character. According to the calculated character angle, each character is rotated to the horizontal direction, and the character area where the rotated character is located is identified using the OCR recognition model, and each character is segmented according to each character area, and each segmented character area is expanded and connected in the width direction. After shape transformation, a rectangular splicing result is obtained, and the rectangular splicing result is used as the character annotation result of the image to be annotated, and each rectangular splicing result corresponds to a line of characters. You can also crop each rectangular stitching result separately, and save the cropped image by naming it with the characters of the rectangular stitching result as the file name.
[0072] Reference Figure 2 , which is a schematic diagram of functional modules of the image annotation device 100 of the present application.
[0073] The image annotation device 100 described in the present application can be installed in an electronic device. According to the functions to be implemented, the image annotation device 100 may include a matching module 110, a generation module 120, a first annotation module 130, and a second annotation module 140. The module described in the present application may also be referred to as a unit, which refers to a series of computer program segments that can be executed by an electronic device processor and can complete fixed functions, which are stored in the memory of the electronic device.
[0074] In this embodiment, the functions of each module / unit are as follows:
[0075] Matching module 110: used to search for a template image matching the image to be annotated from a template library, wherein the template image has an annotated area;
[0076] Generating module 120: used to generate an affine matrix based on the template center point coordinates of the template image and the template angle of the template image;
[0077] A first labeling module 130 is used to map the labeling area of the template image to the image to be labeled using the affine matrix to obtain the labeling area of the image to be labeled;
[0078] The second labeling module 140 is used to segment the labeling contour in the labeling area of the image to be labeled to obtain the contour labeling result of the image to be labeled.
[0079] In one embodiment, the image annotation apparatus 100 further includes a third annotation module, which is used to:
[0080] Calculating the angle of each character in the image to be labeled respectively;
[0081] Based on the angle of each character, rotating each character to a horizontal direction;
[0082] Identify the character area where each character is located after rotation;
[0083] Each character region is segmented, and each segmented character region is spliced to obtain a rectangular splicing result, and the rectangular splicing result is used as the character annotation result of the image to be annotated.
[0084] In one embodiment, searching for a template image matching the image to be annotated from a template library includes:
[0085] Extracting the first edge contour point of the mask image of each template image in the template library, and calculating the feature vector of the first edge contour point;
[0086] Calculating the coordinates and angles of the first edge contour points;
[0087] Extracting second edge contour points of the mask image of the image to be annotated, and calculating feature vectors of the second edge contour points;
[0088] Calculating the coordinates and angles of the second edge contour points;
[0089] Based on the similarity between the feature vector of the first edge contour point and the feature vector of the second edge contour point, and the similarity between the coordinates and angle of the first edge contour point and the coordinates and angle of the second edge contour point, a template image matching the image to be annotated is determined.
[0090] In one embodiment, generating an affine matrix based on the template center point coordinates of the template image and the template angle of the template image includes:
[0091] Obtaining the template center point coordinates of the template image and the template angle of the template image;
[0092] Determining target coordinates corresponding to the coordinates of the template center point of the template image in the image to be annotated, and determining a target angle corresponding to the template angle of the template image in the image to be annotated;
[0093] An affine matrix is generated according to the center point coordinates, the template angle of the template image, the target coordinates and the target angle.
[0094] In one embodiment, generating an affine matrix according to the center point coordinates, the template angle of the template image, the target coordinates and the target angle includes:
[0095] The affine matrix is calculated using the following formula, which includes:
[0096]
[0097] Among them, Mat2D represents the affine matrix, α represents the angle difference between the template angle of the template image and the target angle, the value of α is expressed in radians, t represents the vector from the center point coordinates to the target coordinates, Tx represents the difference between the ordinate value of the center point coordinates and the ordinate value of the target coordinates, and Ty represents the difference between the abscissa value of the center point coordinates and the abscissa value of the target coordinates.
[0098] In one embodiment, segmenting the annotation contour in the annotation area of the image to be annotated to obtain the contour annotation result of the image to be annotated includes:
[0099] Get the segmentation parameters and extraction parameters input by the user;
[0100] Determining a segmented area in the annotation area of the image to be annotated;
[0101] According to the segmentation parameters and the extraction parameters, a labeling contour in the labeling area of the image to be labeled is segmented from the segmented area as a contour labeling result of the image to be labeled.
[0102] In one embodiment, the image annotation apparatus further includes a storage module, and the storage module is used to:
[0103] Acquire attribute information of the image to be annotated, a coordinate point set of a contour of an annotated region of the image to be annotated, and label information of the annotated region of the image to be annotated;
[0104] The attribute information, the coordinate point set and the tag information are stored in JSON format to obtain a storage file;
[0105] The storage file is named with the file name of the image to be annotated.
[0106] Reference Figure 3 , which is a schematic diagram of a preferred embodiment of the electronic device of the present application.
[0107] The electronic device includes a processor 111, a communication interface 112, a memory 113 and a communication bus 114, wherein the processor 111, the communication interface 112, and the memory 113 communicate with each other via the communication bus 114;
[0108] A memory 113, for storing computer programs, for example, an image annotation program;
[0109] In some embodiments, the processor 111 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip. The processor 111 is generally used to control the overall operation of the electronic device, such as performing control and processing related to data interaction or communication. In this embodiment, the processor 111 is used to run the program code stored in the memory 113 or process data, such as running the program code of the image annotation program.
[0110] The communication interface 112 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface), and the communication interface 112 may also be used to establish a communication connection between the electronic device and other electronic devices.
[0111] The memory 113 includes at least one type of readable storage medium, and the readable storage medium includes a flash memory, a hard disk, a multimedia card, a card-type memory (for example, an SD or DX memory, etc.), a random access memory (RAM), a static random access memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a disk, an optical disk, etc. In some embodiments, the memory 113 may be an internal storage unit of the electronic device, such as a hard disk or a memory of the electronic device. In other embodiments, the memory 113 may also be an external storage device of the electronic device, such as a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), etc. equipped with the electronic device. Of course, the memory 113 may also include both the internal storage unit of the electronic device and its external storage device. In this embodiment, the memory 11 is generally used to store an operating system and various computer programs installed in the electronic device, such as the program code of an image annotation program, etc. In addition, the memory 113 may also be used to temporarily store various types of data that have been output or are to be output.
[0112] Figure 3Only an electronic device having components 111 - 114 is shown, but it is understood that implementing all of the components shown is not a requirement, and more or fewer components may alternatively be implemented.
[0113] In one embodiment of the present application, the processor 111 is used to execute the program stored in the memory 113 to implement the image annotation method provided by any of the above method embodiments, including:
[0114] Searching for a template image that matches the image to be annotated from a template library, wherein the template image has an annotated area;
[0115] Generate an affine matrix based on the template center point coordinates of the template image and the template angle of the template image;
[0116] Mapping the annotated region of the template image to the image to be annotated using the affine matrix to obtain the annotated region of the image to be annotated;
[0117] The annotation contour in the annotation area of the image to be annotated is segmented to obtain an annotation result of the contour of the image to be annotated.
[0118] For a detailed description of the above steps, please refer to the above Figure 2 Functional module diagram of the embodiment of the image annotation device 100 and Figure 1 Description of a flowchart of an embodiment of an image annotation method.
[0119] In addition, the embodiment of the present application also proposes a computer-readable storage medium, which may be non-volatile or volatile. The computer-readable storage medium includes a data storage area and a program storage area, and the program storage area stores an image annotation program. When the image annotation program is executed by a processor, the following operations are implemented:
[0120] Searching for a template image that matches the image to be annotated from a template library, wherein the template image has an annotated area;
[0121] Generate an affine matrix based on the template center point coordinates of the template image and the template angle of the template image;
[0122] Mapping the annotated region of the template image to the image to be annotated using the affine matrix to obtain the annotated region of the image to be annotated;
[0123] The annotation contour in the annotation area of the image to be annotated is segmented to obtain an annotation result of the contour of the image to be annotated.
[0124] The specific implementation of the computer-readable storage medium of the present application is substantially the same as the specific implementation of the above-mentioned image annotation method, and will not be described in detail here.
[0125] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0126] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution, in essence, or the part that contributes to the relevant technology, can be embodied in the form of a software product, which can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiment.
[0127] It should be noted that the descriptions involving "first", "second", etc. in this application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the number of technical features indicated. Therefore, the features defined as "first" and "second" may explicitly or implicitly include at least one of the features. In addition, the technical solutions between the various embodiments can be combined with each other, but they must be based on the ability of ordinary technicians in this field to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be deemed that such combination of technical solutions does not exist and is not within the scope of protection required by this application.
[0128] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.
[0129] The above description is only a specific implementation of the present application, so that those skilled in the art can understand or implement the present application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown herein, but will conform to the widest range consistent with the principles and novel features applied for herein.
Claims
1. An image annotation method, characterized in that: The method comprises: Searching for a template image matching the image to be annotated from a template library, wherein the template image has an annotated area, and the image to be annotated is an industrial product image; Generate an affine matrix based on the template center point coordinates of the template image and the template angle of the template image, wherein the template is a rectangular workpiece, the template center point coordinates of the template image refer to the center point coordinates of the rectangular workpiece in the template image, and the template angle of the template image refers to the angle of the rectangular workpiece in the template image relative to a preset reference direction, and the reference direction includes a horizontal direction; Mapping the annotated region of the template image to the image to be annotated using the affine matrix to obtain the annotated region of the image to be annotated; Segmenting the annotation contour in the annotation area of the image to be annotated to obtain the contour annotation result of the image to be annotated; The generating an affine matrix based on the template center point coordinates of the template image and the template angle of the template image includes: Obtaining the template center point coordinates of the template image and the template angle of the template image; Determining, in the image to be annotated, target coordinates corresponding to the coordinates of the template center point of the template image, and determining, in the image to be annotated, a target angle corresponding to the template angle of the template image; Generate an affine matrix according to the center point coordinates, the template angle of the template image, the target coordinates and the target angle; The generating an affine matrix according to the center point coordinates, the template angle of the template image, the target coordinates and the target angle includes: The affine matrix is calculated using the following formula, which includes: Wherein, Mat2D represents the affine matrix, α represents the angle difference between the template angle of the template image and the target angle, the value of α is expressed in radians, t represents the vector from the center point coordinates to the target coordinates, Tx represents the difference between the ordinate value of the center point coordinates and the ordinate value of the target coordinates, Ty represents the difference between the abscissa value of the center point coordinates and the abscissa value of the target coordinates, the target coordinates refer to the center point coordinates of the rectangular workpiece in the image to be annotated, and the target angle refers to the angle of the rectangular workpiece in the image to be annotated; The step of searching for a template image matching the image to be annotated from a template library includes: Extracting the first edge contour point of the mask image of each template image in the template library, and calculating the feature vector of the first edge contour point; Calculating the coordinates and angles of the first edge contour points; Extracting second edge contour points of the mask image of the image to be annotated, and calculating feature vectors of the second edge contour points; Calculating the coordinates and angles of the second edge contour points; Determining a template image matching the image to be annotated based on similarity between a feature vector of the first edge contour point and a feature vector of the second edge contour point, and similarity between coordinates and angles of the first edge contour point and coordinates and angles of the second edge contour point; The segmenting of the annotation contour in the annotation area of the image to be annotated to obtain the contour annotation result of the image to be annotated includes: Get the segmentation parameters and extraction parameters input by the user; Determining a segmented area in the annotation area of the image to be annotated; According to the segmentation parameters and the extraction parameters, a labeling contour in the labeling area of the image to be labeled is segmented from the segmented area as a contour labeling result of the image to be labeled.
2. The image annotation method according to claim 1, characterized in that: After obtaining the annotation result of the image to be annotated, the method further includes: Calculating the angle of each character in the image to be labeled respectively; Based on the angle of each character, rotating each character to a horizontal direction; Identify the character area where each character is located after rotation; Each character region is segmented, and each segmented character region is spliced to obtain a rectangular splicing result, and the rectangular splicing result is used as the character annotation result of the image to be annotated.
3. The image annotation method according to claim 1, characterized in that: After obtaining the annotated area of the image to be annotated, the method further includes: Acquire attribute information of the image to be annotated, a coordinate point set of a contour of an annotated region of the image to be annotated, and label information of the annotated region of the image to be annotated; The attribute information, the coordinate point set and the tag information are stored in JSON format to obtain a storage file; The storage file is named with the file name of the image to be annotated.
4. An image annotation device, characterized in that: The device comprises: Matching module: used to search for a template image matching the image to be annotated from a template library, wherein the template image has an annotated area and the image to be annotated is an industrial product image; A generating module: used to generate an affine matrix based on the template center point coordinates of the template image and the template angle of the template image, wherein the template is a rectangular workpiece, the template center point coordinates of the template image refer to the center point coordinates of the rectangular workpiece in the template image, and the template angle of the template image refers to the angle of the rectangular workpiece in the template image relative to a preset reference direction, and the reference direction includes a horizontal direction; A first labeling module: used for mapping the labeling area of the template image to the image to be labeled using the affine matrix to obtain the labeling area of the image to be labeled; The second annotation module is used to segment the annotation contour in the annotation area of the image to be annotated to obtain the contour annotation result of the image to be annotated; The generating an affine matrix based on the template center point coordinates of the template image and the template angle of the template image includes: Obtaining the template center point coordinates of the template image and the template angle of the template image; Determining target coordinates corresponding to the coordinates of the template center point of the template image in the image to be annotated, and determining a target angle corresponding to the template angle of the template image in the image to be annotated; Generate an affine matrix according to the center point coordinates, the template angle of the template image, the target coordinates and the target angle; The generating an affine matrix according to the center point coordinates, the template angle of the template image, the target coordinates and the target angle includes: The affine matrix is calculated using the following formula, which includes: Wherein, Mat2D represents the affine matrix, α represents the angle difference between the template angle of the template image and the target angle, the value of α is expressed in radians, t represents the vector from the center point coordinates to the target coordinates, Tx represents the difference between the ordinate value of the center point coordinates and the ordinate value of the target coordinates, Ty represents the difference between the abscissa value of the center point coordinates and the abscissa value of the target coordinates, the target coordinates refer to the center point coordinates of the rectangular workpiece in the image to be annotated, and the target angle refers to the angle of the rectangular workpiece in the image to be annotated; The step of searching for a template image matching the image to be annotated from a template library includes: Extracting the first edge contour point of the mask image of each template image in the template library, and calculating the feature vector of the first edge contour point; Calculating the coordinates and angles of the first edge contour points; Extracting second edge contour points of the mask image of the image to be annotated, and calculating feature vectors of the second edge contour points; Calculating the coordinates and angles of the second edge contour points; Determining a template image matching the image to be annotated based on similarity between a feature vector of the first edge contour point and a feature vector of the second edge contour point, and similarity between coordinates and angles of the first edge contour point and coordinates and angles of the second edge contour point; The segmenting of the annotation contour in the annotation area of the image to be annotated to obtain the contour annotation result of the image to be annotated includes: Get the segmentation parameters and extraction parameters input by the user; Determining a segmented area in the annotation area of the image to be annotated; According to the segmentation parameters and the extraction parameters, a labeling contour in the labeling area of the image to be labeled is segmented from the segmented area as a contour labeling result of the image to be labeled.
5. An electronic device, characterized in that: It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, configured to implement the image annotation method according to any one of claims 1 to 3 when executing a program stored in a memory.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the image annotation method according to any one of claims 1 to 3 is implemented.
