Disclosure of Invention
In view of the foregoing, it is desirable to provide a method of constructing a pattern code extraction model, a pattern code recognition method, apparatus, computer device, and storage medium.
A method of constructing a graphic code extraction model, the method comprising:
obtaining an original image sample of a graphic code and a background image sample of a material;
obtaining a corresponding graphic code standard image sample according to the graphic code original image sample;
obtaining an augmented image sample based on 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 of identifying a graphic code, the method comprising:
obtaining 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 region in the graphic code image to be identified according to the graphic code identification result output by the graphic code extraction model aiming at the graphic code image to be identified;
and carrying out graphic code edge fitting processing on the graphic code candidate areas, and determining the graphic code areas in the graphic code images 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 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 using the augmented image sample, the graphic code original image sample and the graphic code standard image sample.
A graphic code recognition apparatus comprising:
the model acquisition module is used for acquiring a graphic code extraction model constructed according to the method;
the image input module is used for inputting the graphic code image to be identified into the graphic code extraction model;
the coarse positioning module is used for obtaining a graphic code candidate region in the graphic code image to be identified according to the 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 carrying out graphic code edge fitting processing on the graphic code candidate areas and determining the graphic code areas in the graphic code images to be identified.
A computer device comprising a memory storing a computer program and a processor which when executing the computer program performs the steps of:
obtaining an original image sample of a graphic code and a background image sample of a material; obtaining a corresponding graphic code standard image sample according to the graphic code original image sample; obtaining an augmented image sample based on 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 storing a computer program and a processor which when executing the computer program performs the steps of:
obtaining 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 region in the graphic code image to be identified according to the graphic code identification result output by the graphic code extraction model aiming at the graphic code image to be identified; and carrying out graphic code edge fitting processing on the graphic code candidate areas, and determining the graphic code areas in the graphic code images to be identified.
A computer readable storage medium having stored thereon a computer program which when executed by a processor performs the steps of:
obtaining an original image sample of a graphic code and a background image sample of a material; obtaining a corresponding graphic code standard image sample according to the graphic code original image sample; obtaining an augmented image sample based on 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 having stored thereon a computer program which when executed by a processor performs the steps of:
obtaining 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 region in the graphic code image to be identified according to the graphic code identification result output by the graphic code extraction model aiming at the graphic code image to be identified; and carrying out graphic code edge fitting processing on the graphic code candidate areas, and determining the graphic code areas in the graphic code images to be identified.
The method, the device, the computer equipment and the storage medium are used for acquiring the graphic code original image sample and the material background image sample, obtaining the corresponding graphic code standard image sample according to the graphic code original image sample, obtaining the augmented image sample based on 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, standard graphic codes and various material backgrounds can be fused in a model training stage to form the augmented image samples with various material backgrounds, the original image samples of the graphic codes and the standard image samples of the graphic codes are used as model training data for model training, a graphic code extraction model suitable for various application scenes can be constructed and obtained, and the accuracy of the model in identifying the graphic codes is improved.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be further described in detail with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the present application.
The following section first describes the method for constructing the graphic code extraction model provided in the present application, and then describes the graphic code recognition method provided in the present application. The method for constructing the graphic code extraction model can be mainly executed by a server, and the server can be realized by an independent server or a server cluster formed by a plurality of servers; the graphic code recognition 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, a method of constructing a graphic code extraction model is provided, which may include the steps of:
step S101, obtaining a graphic code original image sample and a material background image sample;
the description of related features such as images in the model construction stage is uniformly described in a mode such as image samples, so that the description is distinguished from the model application, namely the graphic code recognition stage. In this step, the original image sample of the graphic code and the background image sample of the material may be obtained by data collection and web crawler technology, where the original image sample of the graphic code is an image containing graphic codes such as two-dimensional codes, and the background image sample of the material is a background image containing multiple materials, and the materials may include various materials that may be used for printing the graphic code, such as various colors of paper, various types of wood 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 the application scenario 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 step mainly generates a graphic code standard image sample corresponding to the graphic code standard image sample according to the graphic code information contained in the graphic code original image sample, that is, performs certain conversion on the original image sample on the basis of basically retaining the original graphic code information to form a new graphic code image for subsequent fusion processing, wherein the new graphic code image is called a graphic code standard image sample, and the conversion can be used for, for example, changing the position, direction or 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 an initial sample of a graphic code standard image according to graphic code information carried by an original graphic code sample of the graphic code; and carrying out 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 embodiment mainly generates a corresponding initial sample of the graphic code standard image according to graphic code information carried by an original image sample of the graphic code, specifically, the graphic code information (text information) carried by the original image sample of the graphic code can be extracted first, then the text information is changed into standard graphic code picture information through a code system of the graphic code such as a two-dimensional code, and then a quadrilateral area is set for affine transformation, so that the initial sample of the graphic code standard image can be obtained. On the basis, in order to enrich the morphology of the graphic code so as to enable the model to adapt to more various and changeable application scenes, the graphic code points of the initial sample of the graphic code standard image are subjected to morphological transformation processing to obtain the graphic code standard image sample, 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, corrosion, random noise, etc.) on the shape of the graphic code point in the graphic code standard image initial sample, so as to obtain the graphic code standard image sample.
Step S103, obtaining an augmented image sample based on fusion of a graphic code standard image sample and a 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 texture background image samples may be plural, and for this purpose, in one embodiment, step S103 may include:
carrying out contrast preservation fusion on the standard image sample of the graphic code and the background image samples of a plurality of materials to obtain an initial sample of the enhanced image; and screening the initial sample of the enhanced image according to the semantic distance between the initial sample of the enhanced image and the initial sample of the graphic code to obtain the sample of the enhanced image.
The contrast preserving fusion (histocompatibility fusion) is an algorithm for carrying out contrast preserving fusion on two pictures by calculating the color distribution of the pictures. In this embodiment, the contrast preserving and fusing of the standard image sample of the graphic code and the background image samples of the plurality of materials may include the contrast preserving and fusing of the standard image sample of the graphic code and each background image sample of the plurality of materials respectively, and may further include the contrast preserving and fusing of the standard image sample of the graphic code and two or more background image samples of the plurality of materials respectively, so as to obtain the initial sample of the enhanced image in a rich sample form, and the number of the initial samples of the enhanced image is also a plurality of. Then, the image sample as the augmented image sample that meets the condition needs to be screened from the initial sample of the augmented image, the embodiment can screen according to the semantic distance (D (i_aug) -D (i_dm)) between the initial sample of the augmented image (i_aug) and the initial sample of the image (i_dm) of the graphic code, and if the semantic distance is lower than or equal to the semantic distance threshold, the initial sample of the augmented image can be screened as the sample of the augmented image.
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, a decoder can be composed through a skip-connection between layers using the image net 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 model training, and the graphic code extraction model is constructed by using the input data and the label data. The graphic code standard image sample is mainly a graphic code standard image sample generated according to graphic code information carried by the graphic code original image sample, and in the above part of embodiments or referred to as a graphic code standard image initial sample, i.e. a graphic code standard image sample without morphological transformation.
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 obtaining 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; carrying out 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, the augmented image sample and the original image sample of the graphic code as input data of the model training are input into the 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 original image sample of the graphic code, the standard image sample of the graphic code as the label data of the model training is subjected to loss function calculation with the graphic code extraction result sample to obtain a loss calculation result or a loss function calculation result, and then the loss calculation result can be used for adjusting the 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 and obtain the graphic code extraction model. In a specific application, after the augmented image sample and the 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 line loss function in a graphic code standard image sample can be calculated, a loss weight is added to a graphic code dead zone (quick zone) part, and the graphic code extraction model is constructed after a certain iteration.
According to the method for constructing the graphic code extraction model, the graphic code original image sample and the material background image sample are obtained, then the corresponding graphic code standard image sample is obtained according to the graphic code original image sample, then the enhanced image sample is obtained based on fusion of the graphic code standard image sample and the material background image sample, and the graphic code extraction model is constructed by utilizing the enhanced image sample, the graphic code original image sample and the graphic code standard image sample. According to the scheme, standard graphic codes and various material backgrounds can be fused in a model training stage to form the augmented image samples with various material backgrounds, the original image samples of the graphic codes and the standard image samples of the graphic codes are used as model training data for model training, a graphic code extraction model suitable for various application scenes can be constructed and obtained, and the accuracy of the model in identifying the graphic codes is improved.
In one embodiment, as shown in fig. 2, a method for identifying a graphic code is provided, which may include the steps of:
step S201, obtaining a graphic code extraction model constructed according to the method described in the embodiment;
step S202, inputting a graphic code image to be identified into a graphic code extraction model;
in this step, after the graphic code image to be identified is obtained, the graphic code image to be identified may be scaled to a set scale space, or a series of basic preprocessing operations such as graying, sharpening, denoising may be performed, and then input into the graphic code extraction model.
Step S203, a graphic code candidate region in the graphic code image to be identified is obtained according to the graphic code identification result output by the graphic code extraction model aiming at the graphic code image to be identified;
the method mainly comprises the step of coarsely positioning the region where the graphic code in the graphic code image to be identified is located by the graphic code extraction model. After the graphic code image to be identified is input into the graphic code extraction model, the graphic code extraction model outputs a corresponding graphic code identification result, so that a graphic code candidate region in the graphic code image to be identified is obtained according to the graphic code identification result, namely, a region where the graphic code located on the graphic code image to be identified by the graphic code extraction model is used as the graphic code candidate region.
Step S204, performing graphic code edge fitting processing on the graphic code candidate areas to determine the graphic code areas in the graphic code images to be identified.
The method comprises the step of performing edge fitting processing on the candidate region of the graphic code on the basis of rough positioning of a graphic code extraction model so as to accurately position the graphic code region in the 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 graphic code candidate region to obtain an outer layer edge point set; performing robust regression fit on the outer layer edge point set to obtain a graph code region edge fitting result in a graph code image to be identified; and determining the graphic code region in the graphic code image to be identified according to the graphic code region edge fitting result.
The method mainly comprises the steps of extracting at least one layer of outer layer edge points from a graphic code candidate region roughly positioned by a graphic code extraction model to form an outer layer edge point set, then carrying out robust regression fitting processing on the outer layer edge point set, determining the edge of the graphic code region according to the result of the edge fitting of the graphic code region, and accurately positioning the graphic code region in a graphic code image to be identified according to the edge. The robust regression fit refers to a statistical robust regression theory, such as Theil-Sen estimation, for example, to complete the fit of edges of the graphic code region. In a specific application, for the extraction of outer edge points, an edge extraction algorithm such as a canny operator can be applied to extract edge points of a candidate region of the graphic code, and edge points (corresponding to outer edge points) of a layer are extracted from the outer side of the region into the region to serve as an outer edge point set for fitting the boundary of the graphic code region, then the outer edge point set can be estimated by using Theil-Sen to perform fitting to obtain an edge fitting result of the graphic code region, the graphic code region in the graphic code image to be identified is positioned according to the edge fitting result, and image data corresponding to the graphic code region can be output to a graphic code decoding module after the graphic code region is positioned to finish decoding processing.
According to the graphic code identification method, the edge extraction and robust regression statistical method is used on the basis of the rough positioning of the model to realize the high-precision optimization of the rough positioning of the graphic code candidate region, the graphic code identification accuracy is improved, the method can adapt to continuously changing application scenes, has stronger robustness, and is beneficial to improving the readability and decoding rate of graphic codes such as two-dimensional codes (QR, DM codes) and the like.
It should be understood that, although the steps in the flowcharts are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited to the order of execution unless explicitly recited herein, and the steps may be executed in other orders. Moreover, at least a portion of the steps in the flowcharts above may include a plurality of steps or stages that are not necessarily performed at the same time, but may be performed at different times, and the order of execution of the steps or stages is not necessarily sequential, but may be performed in rotation or alternately with at least a portion of the steps or stages in other steps or other steps.
In one embodiment, as shown in FIG. 3, an apparatus for constructing a graphic code extraction model is provided, the apparatus 300 may include:
the sample acquisition module 301 is configured to acquire 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;
the sample fusion module 303 is configured to obtain an augmented image sample based on fusion of the graphic code standard image sample and the material background image sample;
the model construction module 304 is configured to construct a graphics code extraction model using the augmented image sample and the graphics code original image sample and the graphics code standard image sample.
In one embodiment, the sample generating module 302 is configured to generate a graphic code standard image initial sample according to graphic code information carried by the graphic code original image sample; performing morphological transformation on the graphic code points of the graphic code standard image initial sample to obtain the graphic code standard image sample; the morphological transformation process includes at least one of swelling, erosion, or random noise.
In one embodiment, the number of the texture background image samples is a plurality; the sample fusion module 303 is configured to perform contrast preserving fusion on the graphic code standard image sample and a plurality of material background image samples, so as to obtain an amplified image initial sample; and screening the initial sample of the enhanced image according to the semantic distance between the initial sample of the enhanced image and the original image sample of the graphic code to obtain the sample of the enhanced image.
In one embodiment, the model building module 304 is configured to input the augmented image sample and the graphic code original image sample into a graphic code extraction model to be trained, and obtain a graphic code extraction result sample output by the graphic code extraction model to be trained for 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 one embodiment, as shown in fig. 4, a graphic code recognition apparatus is provided, and the apparatus 400 may include:
a model acquisition module 401 for acquiring a graphic code extraction model constructed according to the method described above;
an image input module 402, configured to input a graphic code image to be identified into the graphic code extraction model;
the coarse positioning module 403 is configured to obtain a candidate region of the graphic code in the graphic code image to be identified according to the graphic code recognition result output by the graphic code extraction model for the graphic code image to be identified;
and the fine positioning module 404 is configured to perform a graphic code edge fitting process on the graphic code candidate region, and determine a graphic code region in the graphic code image to be identified.
In one embodiment, the fine positioning module 404 is configured to extract at least one layer of outer edge points of the candidate region of the graphic code to obtain a set of outer edge points; performing robust regression fit on the outer layer edge point set to obtain a graphic code region edge fit result in the graphic code image to be identified; and determining the graphic code region in the graphic code image to be identified according to the graphic code region edge fitting result.
The specific limitations of the device for constructing the graphic code extraction model and the graphic code recognition device can be referred to as the limitations of the method for constructing the graphic code extraction model and the graphic code recognition method, respectively, and are not repeated herein. The above-described means for constructing a graphic code extraction model and the respective modules in the graphic code recognition means may be implemented in whole or in part by software, hardware, and combinations thereof. The above modules may be embedded in hardware or may be independent of a processor in the computer device, or may be stored in software in a memory in the computer device, so that the processor may call and execute operations corresponding to the above 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 includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, computer programs, and a database. The internal memory provides an environment for the operation of the operating system and computer programs in the non-volatile storage media. The database of the computer device is 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 graphic code extraction model.
In one embodiment, a computer device is provided, which may be a terminal, and the internal structure of which 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 includes a non-volatile 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 the operating system and computer programs in the non-volatile storage media. The communication interface of the computer device is used for carrying out wired or wireless communication with an external terminal, and the wireless mode 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 method of identifying a graphic code. 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, can also be keys, a track ball or a touch pad arranged on the shell of the computer equipment, and can also be an external keyboard, a touch pad or a mouse and the like.
Those skilled in the art will appreciate that the structures shown in fig. 5 and 6 are block diagrams of only portions of structures that are relevant to the present application and are not intended to limit the computer device on which the present application may be implemented, and that a particular computer device may include more or fewer components than shown, or may combine certain components, or have a different arrangement of components.
In an embodiment, there is also provided a computer device comprising a memory and a processor, the memory having stored therein a computer program, the processor implementing the steps of the method embodiments described above when the computer program is executed.
In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored which, when executed by a processor, carries out the steps of the method embodiments described above.
Those skilled in the art will appreciate that implementing all or part of the above described methods may be accomplished by way of a computer program stored on a non-transitory computer readable storage medium, which when executed, may comprise the steps of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in embodiments provided herein may include at least one of non-volatile and volatile memory. The nonvolatile memory may include Read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, or the like. Volatile memory can include Random access memory (Random AccessMemory, RAM) or external cache memory. By way of illustration, and not limitation, RAM can take many forms, such as static random access memory (StaticRandomAccessMemory, SRAM) or dynamic random access memory (DynamicRandomAccessMemory, DRAM), among others.
The technical features of the above embodiments may be arbitrarily combined, and all possible combinations of the technical features in the above embodiments are not described for brevity of description, however, as long as there is no contradiction between the combinations of the technical features, they should be considered as the scope of the description.
The above examples merely represent a few embodiments of the present application, which are described in more detail and are not to be construed as limiting the scope of the invention. It should be noted that it would be apparent to those skilled in the art that various modifications and improvements could be made without departing from the spirit of the present application, which would be within the scope of the present application. Accordingly, the scope of protection of the present application is to be determined by the claims appended hereto.