Disclosure of Invention
In view of the above, it is necessary to provide a method for constructing a graphic code extraction model, a graphic code identification method, an apparatus, a computer device and a storage medium for solving the above technical problems.
A method of constructing a graphical code extraction model, the method comprising:
acquiring a graphic code original image sample and a material background image sample;
obtaining a corresponding graphic code standard image sample according to the graphic code original image sample;
obtaining an augmented image sample based on the fusion of the graphic code standard image sample and the material background image sample;
and constructing a graphic code extraction model by using the augmented image sample, the graphic code original image sample and the graphic code standard image sample.
A method for identifying a graphic code, the method comprising:
acquiring a graphic code extraction model constructed according to the method;
inputting a graphic code image to be identified into the graphic code extraction model;
obtaining a graphic code candidate area in the graphic code image to be recognized according to a graphic code recognition result output by the graphic code extraction model aiming at the graphic code image to be recognized;
and performing graph code edge fitting processing on the graph code candidate area to determine the graph code area in the graph code image to be identified.
An apparatus for constructing a graphic code extraction model, comprising:
the sample acquisition module is used for acquiring a graphic code original image sample and a material background image sample;
the sample generation module is used for obtaining a corresponding graphic code standard image sample according to the graphic code original image sample;
the sample fusion module is used for obtaining an augmented image sample based on the fusion of the graphic code standard image sample and the material background image sample;
and the model construction module is used for constructing a graphic code extraction model by utilizing the augmented image sample, the graphic code original image sample and the graphic code standard image sample.
A graphic code recognition device comprises:
the model acquisition module is used for acquiring the graphic code extraction model constructed according to the method;
the image input module is used for inputting the graphic code image to be identified to the graphic code extraction model;
the rough positioning module is used for obtaining a graphic code candidate area in the graphic code image to be identified according to a graphic code identification result output by the graphic code extraction model aiming at the graphic code image to be identified;
and the fine positioning module is used for performing graphic code edge fitting processing on the graphic code candidate area and determining the graphic code area in the graphic code image to be identified.
A computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
acquiring a graphic code original image sample and a material background image sample; obtaining a corresponding graphic code standard image sample according to the graphic code original image sample; obtaining an augmented image sample based on the fusion of the graphic code standard image sample and the material background image sample; and constructing a graphic code extraction model by using the augmented image sample, the graphic code original image sample and the graphic code standard image sample.
A computer device comprising a memory and a processor, the memory storing a computer program, the processor implementing the following steps when executing the computer program:
acquiring a graphic code extraction model constructed according to the method; inputting a graphic code image to be identified into the graphic code extraction model; obtaining a graphic code candidate area in the graphic code image to be recognized according to a graphic code recognition result output by the graphic code extraction model aiming at the graphic code image to be recognized; and performing graph code edge fitting processing on the graph code candidate area to determine the graph code area in the graph code image to be identified.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, carries out the steps of:
acquiring a graphic code original image sample and a material background image sample; obtaining a corresponding graphic code standard image sample according to the graphic code original image sample; obtaining an augmented image sample based on the fusion of the graphic code standard image sample and the material background image sample; and constructing a graphic code extraction model by using the augmented image sample, the graphic code original image sample and the graphic code standard image sample.
A computer-readable storage medium, on which a computer program is stored which, when executed by a processor, carries out the steps of:
acquiring a graphic code extraction model constructed according to the method; inputting a graphic code image to be identified into the graphic code extraction model; obtaining a graphic code candidate area in the graphic code image to be recognized according to a graphic code recognition result output by the graphic code extraction model aiming at the graphic code image to be recognized; and performing graph code edge fitting processing on the graph code candidate area to determine the graph code area in the graph code image to be identified.
The method, the device, the computer equipment and the storage medium obtain the graphic code original image sample and the material background image sample, then obtain the corresponding graphic code standard image sample according to the graphic code original image sample, then obtain the augmented image sample based on the fusion of the graphic code standard image sample and the material background image sample, and construct the graphic code extraction model by utilizing the augmented image sample, the graphic code original image sample and the graphic code standard image sample. According to the scheme, the standard graphic code and various material backgrounds can be fused in a model training stage to form the augmented image samples with various material background styles, the graphic code original image samples and the graphic code standard image samples are used as model training data to perform model training, a graphic code extraction model suitable for various application scenes can be constructed, and the accuracy of the model in recognizing the graphic code is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application.
The following sections firstly introduce the method for constructing the graphic code extraction model provided by the application, and then introduce the method for identifying the graphic code provided by the application. The method for constructing the graphic code extraction model provided by the application can be mainly executed by a server, and the server can be realized by an independent server or a server cluster consisting of a plurality of servers; the graphic code identification method provided by the application can be mainly executed by a terminal, and the terminal can be but is not limited to various personal computers, notebook computers, smart phones, tablet computers and portable wearable devices.
In one embodiment, as shown in fig. 1, there is provided a method for constructing a graphic code extraction model, which may include the following steps:
step S101, obtaining a graphic code original image sample and a material background image sample;
in the description of the relevant features such as the image and the like in the model construction stage, description modes such as an image sample and the like are uniformly adopted so as to be distinguished from the model application, namely the graphic code identification stage. In this step, the graphic code original image sample and the material background image sample may be obtained by data acquisition and web crawler technology, the graphic code original image sample is an image containing a graphic code such as a two-dimensional code, the material background image sample is a background image containing a plurality of materials, the materials may include various materials that can be used for printing the graphic code, such as paper of various colors, various wood materials and plastic materials, and the like, and may further include such materials under various lighting conditions (such as different light and shade conditions) to cover application scenes where the graphic code may exist as much as possible.
Step S102, obtaining a corresponding graphic code standard image sample according to the graphic code original image sample;
the method mainly comprises the steps of generating a graphic code standard image sample corresponding to graphic code information contained in an original graphic code image sample according to the graphic code information, namely, converting the original image sample to form a new graphic code image for subsequent fusion processing on the basis of basically reserving the original graphic code information, wherein the new graphic code image is called the graphic code standard image sample, the conversion can be, for example, changing the position, the direction or the shape of the graphic code on the image, and the like, and can be used for enriching or standardizing the form of the graphic code on the image in some embodiments.
In one embodiment, the step S102 may include: generating a graphic code standard image initial sample according to the graphic code information carried by the graphic code original image sample; and performing morphological transformation processing on the graphic code points of the initial sample of the graphic code standard image to obtain the graphic code standard image sample.
The method mainly comprises the steps of generating a corresponding graphic code standard image initial sample according to graphic code information carried by a graphic code original image sample, specifically, extracting the graphic code information (character information) carried by the graphic code original image sample, changing the character information into standard graphic code image information through the code system of graphic codes such as two-dimensional codes, and setting a quadrilateral area to perform affine transformation on the standard graphic code image information, so that the graphic code standard image initial sample can be obtained. On the basis, in order to enrich the form of the graphic code so that the model can adapt to more diversified and changeable application scenes, the graphic code points of the initial sample of the standard image of the graphic code are further subjected to morphological transformation processing to obtain the standard image sample of the graphic code, and the morphological transformation processing at least comprises one of expansion, corrosion or random noise. Specifically, the probability P may be set to perform random morphological transformation (expansion, erosion, random noise, and the like) on the shape of the graphic code point in the initial sample of the graphic code standard image, so as to obtain the graphic code standard image sample.
Step S103, obtaining an augmented image sample based on the fusion of the graphic code standard image sample and the material background image sample;
in this step, the material background image sample can be used as the background of the graphic code standard image sample, and the graphic code standard image sample is fused into the material background image sample to obtain the augmented image sample. In a specific application, the number of the material background image samples may be multiple, and for this, in an embodiment, the step S103 may include:
performing contrast preservation fusion on the graphic code standard image sample and a plurality of material background image samples to obtain an augmented image initial sample; and screening the augmented image initial sample according to the semantic distance between the augmented image initial sample and the graphic code original image sample to obtain the augmented image sample.
The contrast-preserving blending (histograppervirngblending) is an algorithm for performing contrast-preserving blending on two pictures by calculating the color distribution of the pictures. In this embodiment, the contrast preservation fusion of the image code standard image sample and the multiple material background image samples may include performing the contrast preservation fusion of the image code standard image sample and each material background image sample, and may further include performing the contrast preservation fusion of the image code standard image sample and two or more material background image samples simultaneously, and performing multiple fusions with different material background combinations, so as to enrich the sample form, obtain the augmented image initial sample, where the number of the augmented image initial samples is multiple. Then, it is necessary to screen qualified augmented image samples from the augmented image initial samples, in this embodiment, the augmented image initial samples may be screened according to the semantic distance (D (I _ AUG) -D (I _ DM)) between the obtained augmented image initial samples (I _ AUG) and the original image samples (I _ DM) of the graphic code, and for example, if the semantic distance is lower than or equal to the semantic distance threshold, the augmented image initial samples may be screened as the augmented image samples.
And step S104, constructing a graphic code extraction model by using the augmented image sample, the graphic code original image sample and the graphic code standard image sample.
In this step, for the graphic code extraction model, the decoder may be formed by using a skip-connection between layers, using ImageNet pre-trained ResNet34 as a backbone network. Specifically, the augmented image sample and the original image sample of the graphic code can be used as input data of model training, the standard image sample of the graphic code can be used as label data of the model training, and the input data and the label data are used for constructing a graphic code extraction model. The graphic code standard image sample is mainly a graphic code standard image sample generated according to graphic code information carried by a graphic code original image sample, and is referred to as a graphic code standard image initial sample, i.e., a graphic code standard image sample which is not subjected to morphological transformation, as in the above embodiment.
In one embodiment, step S104 specifically includes: inputting the augmented image sample and the graphic code original image sample into a graphic code extraction model to be trained, and acquiring a graphic code extraction result sample output by the graphic code extraction model to be trained aiming at the augmented image sample and the graphic code original image sample; performing loss function calculation by using the graphic code extraction result sample and the graphic code standard image sample to obtain a loss calculation result; and training the graphic code extraction model to be trained by using the loss calculation result, and constructing to obtain the graphic code extraction model.
In the training process of this embodiment, an augmented image sample and a graphic code original image sample, which are input data for model training, are input into a graphic code extraction model to be trained, the graphic code extraction model to be trained outputs a corresponding graphic code extraction result sample for the augmented image sample and the graphic code original image sample, a graphic code standard image sample, which is label data for model training, and the graphic code extraction result sample perform loss function calculation to obtain a loss calculation result or a loss function calculation result, and then the loss calculation result can be used to adjust model network parameters of the graphic code extraction model to be trained, so as to train the graphic code extraction model to be trained and construct the graphic code extraction model. In a specific application, after an augmented image sample and a graphic code original image sample are input into a graphic code extraction model to be trained, a graphic code part in a graphic code extraction result sample output by the graphic code extraction model and a graphic code part in a graphic code standard image sample can be subjected to line loss function calculation, a loss weight is added to a graphic code quiet zone (quietzone) part, and the graphic code extraction model is constructed after certain iteration.
The method for constructing the graphic code extraction model comprises the steps of obtaining a graphic code original image sample and a material background image sample, obtaining a corresponding graphic code standard image sample according to the graphic code original image sample, obtaining an augmented image sample based on the fusion of the graphic code standard image sample and the material background image sample, and constructing the graphic code extraction model by utilizing the augmented image sample, the graphic code original image sample and the graphic code standard image sample. According to the scheme, the standard graphic code and various material backgrounds can be fused in a model training stage to form the augmented image samples with various material background styles, the graphic code original image samples and the graphic code standard image samples are used as model training data to perform model training, a graphic code extraction model suitable for various application scenes can be constructed, and the accuracy of the model in recognizing the graphic code is improved.
In one embodiment, as shown in fig. 2, there is provided a pattern code recognition method, which may include the steps of:
step S201, obtaining a graphic code extraction model constructed according to the method in the embodiment;
step S202, inputting a graphic code image to be identified into a graphic code extraction model;
in this step, after the image of the graphic code to be recognized is obtained, the image of the graphic code to be recognized may be scaled to a set scale space, and a series of basic preprocessing operations such as graying, sharpening and denoising may be performed before being input into the graphic code extraction model.
Step S203, obtaining a graph code candidate area in the graph code image to be identified according to a graph code identification result output by the graph code extraction model aiming at the graph code image to be identified;
the method mainly comprises the step of roughly positioning an area where the graphic code in the graphic code image to be recognized is located by a graphic code extraction model. After the graphic code image to be recognized is input into the graphic code extraction model, the graphic code extraction model outputs a corresponding graphic code recognition result, so that a graphic code candidate area in the graphic code image to be recognized is obtained according to the graphic code recognition result, namely, the area where the graphic code positioned on the graphic code image to be recognized by the graphic code extraction model is located is used as the graphic code candidate area.
And step S204, performing graph code edge fitting processing on the graph code candidate area, and determining the graph code area in the graph code image to be identified.
The method comprises the following steps of carrying out edge fitting processing on a candidate region of the graphic code on the basis of rough positioning of a graphic code extraction model so as to accurately position a graphic code region in a graphic code image to be identified.
In one embodiment, step S204 specifically includes: extracting at least one layer of outer layer edge points of the candidate region of the graphic code to obtain an outer layer edge point set; performing robust regression fitting on the outer layer edge point set to obtain a graphic code region edge fitting result in the graphic code image to be identified; and determining the graphic code area in the graphic code image to be identified according to the edge fitting result of the graphic code area.
The method mainly comprises the steps of extracting at least one layer of outer layer edge points from a graph code candidate area of the graph code extraction model rough positioning to form an outer layer edge point set, then carrying out robust regression fitting processing on the outer layer edge point set to determine the edge of the graph code area according to the graph code area edge fitting result, and accurately positioning the graph code area in the graph code image to be identified according to the edge. Wherein, the robust regression fitting refers to a statistical robust regression theory, such as Theil-Sen estimation to complete the fitting of the edge of the graphic code area. In specific application, for the extraction of the outer edge point, an edge extraction algorithm such as canny operator can be used for extracting the edge point of a candidate area of the graphic code, for example, a layer of edge points (corresponding to the outer edge point) are extracted from the outer side area of the candidate area to serve as an outer edge point set for fitting the boundary of the graphic code area, then the outer edge point set can be fitted by using Theil-Sen estimation to obtain the edge fitting result of the graphic code area, the graphic code area in the graphic code image to be identified is located according to the edge fitting result, and after the graphic code area is located, the image data corresponding to the graphic code area can be output to a graphic code decoding module to complete decoding processing.
According to the graphic code identification method, high-precision optimization of the edges of the graphic code candidate area rough positioning is achieved by applying a statistical method of edge extraction and robust regression on the basis of model rough positioning, the graphic code identification accuracy is improved, the method can adapt to continuously changing application scenes, has strong robustness, and is beneficial to improving the readability and decoding rate of graphic codes such as two-dimensional codes (QR and DM codes).
It should be understood that, although the steps in the above flowcharts are shown in sequence as indicated by the arrows, the steps are not necessarily performed in sequence as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least a part of the steps in the above flowcharts may include a plurality of steps or a plurality of stages, which are not necessarily performed at the same time, but may be performed at different times, and the order of performing the steps or the stages is not necessarily performed in sequence, but may be performed alternately or alternately with other steps or at least a part of the steps or the stages in other steps.
In one embodiment, as shown in fig. 3, there is provided an apparatus for constructing a graphic code extraction model, where the apparatus 300 may include:
the sample acquisition module 301 is used for acquiring a graphic code original image sample and a material background image sample;
the sample generation module 302 is configured to obtain a corresponding graphic code standard image sample according to the graphic code original image sample;
a sample fusion module 303, configured to obtain an augmented image sample based on fusion of the graphic code standard image sample and the material background image sample;
and the model construction module 304 is configured to construct a graphic code extraction model by using the augmented image sample, the graphic code original image sample and the graphic code standard image sample.
In an embodiment, the sample generating module 302 is configured to generate a graphic code standard image initial sample according to the graphic code information carried by the graphic code original image sample; carrying out morphological transformation processing on graphic code points of the initial sample of the graphic code standard image to obtain a graphic code standard image sample; the morphological transformation process includes at least one of dilation, erosion, or random noise.
In one embodiment, the number of the material background image samples is multiple; the sample fusion module 303 is configured to perform contrast preservation fusion on the graphic code standard image sample and the multiple material background image samples to obtain an augmented image initial sample; and screening the initial sample of the augmented image according to the semantic distance between the initial sample of the augmented image and the original image sample of the graphic code to obtain the sample of the augmented image.
In an embodiment, the model building module 304 is configured to input the augmented image sample and the original image sample of the graphical code into a to-be-trained graphical code extraction model, and obtain a graphical code extraction result sample output by the to-be-trained graphical code extraction model for the augmented image sample and the original image sample of the graphical code; performing loss function calculation by using the graphic code extraction result sample and the graphic code standard image sample to obtain a loss calculation result; and training the graphic code extraction model to be trained by using the loss calculation result to construct and obtain the graphic code extraction model.
In one embodiment, as shown in fig. 4, there is provided a pattern code recognition apparatus, and the apparatus 400 may include:
a model obtaining module 401, configured to obtain a graphic code extraction model constructed according to the method described above;
an image input module 402, configured to input a to-be-identified graph code image to the graph code extraction model;
the rough positioning module 403 is configured to obtain a pattern code candidate region in the pattern code image to be recognized according to a pattern code recognition result output by the pattern code extraction model for the pattern code image to be recognized;
and the fine positioning module 404 is configured to perform edge fitting processing on the candidate region of the graphic code, and determine a graphic code region in the graphic code image to be identified.
In an embodiment, the fine positioning module 404 is configured to extract at least one layer of outer layer edge points of the candidate region of the graphic code, so as to obtain an outer layer edge point set; performing robust regression fitting on the outer layer edge point set to obtain a graphic code region edge fitting result in the graphic code image to be identified; and determining the graphic code area in the graphic code image to be identified according to the edge fitting result of the graphic code area.
For specific limitations of the apparatus for constructing the pattern code extraction model and the pattern code recognition apparatus, reference may be made to the above limitations of the method for constructing the pattern code extraction model and the pattern code recognition method, which are not described herein again. The modules in the device for constructing the graphic code extraction model and the graphic code identification device can be wholly or partially realized by software, hardware and a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
In one embodiment, a computer device is provided, which may be a server, the internal structure of which may be as shown in fig. 5. The computer device includes a processor, a memory, and a network interface connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The database of the computer device is used for storing image sample data. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a method of constructing a graphical code extraction model.
In one embodiment, a computer device is provided, which may be a terminal, and its internal structure diagram may be as shown in fig. 6. The computer device includes a processor, a memory, a communication interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless communication can be realized through WIFI, an operator network, NFC (near field communication) or other technologies. The computer program is executed by a processor to implement a pattern code recognition method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
It will be appreciated by those skilled in the art that the configurations shown in fig. 5 and 6 are block diagrams of only some of the configurations relevant to the present disclosure, and do not constitute a limitation on the computing devices to which the present disclosure may be applied, and that a particular computing device may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, a computer device is further provided, which includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of the above method embodiments when executing the computer program.
In an embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when being executed by a processor, carries out the steps of the above-mentioned method embodiments.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database or other medium used in the embodiments provided herein can include at least one of non-volatile and volatile memory. Non-volatile memory may include Read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical storage, or the like. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM can take many forms, such as Static Random Access Memory (SRAM) or Dynamic Random Access Memory (DRAM), among others.
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.