A label printing positioning method, device, equipment and storage medium
By acquiring and adjusting the binary image of the label and using the contour features to calculate the offset parameters, the positioning error problem caused by noise during the printing process was solved, and the accuracy of label positioning and detection precision were improved.
Patent Information
- Application Number
- CN202310539141.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-11
- Publication Date
- 2025-09-12
- Estimated Expiration
- 2043-05-11
AI Technical Summary
In the printing inspection of packaging products, due to the dust-free production environment and the noise generated during the printing process, positioning errors occur when comparing the product to be inspected with the design template, affecting the inspection accuracy, especially the insufficient label positioning accuracy.
By obtaining the initial binary image of the label to be detected, determining the difference image with the template image, extracting contour features, calculating the offset parameters, and adjusting the label image to improve positioning accuracy, including the calculation of contour moment, length, area and center of gravity coordinates and the application of translation matrix.
It improves label positioning accuracy, reduces false detection rate, and improves the accuracy of printing detection.
Smart Images

Figure CN116681913B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field of visual inspection, and in particular to a positioning method, device, equipment and storage medium for label printing. Background Art
[0002] The application of machine vision technology in packaging product printing inspection has improved the accuracy of printed packaging. However, since packaging production environments are not always dust-free, and the printing process is prone to defects such as ink spillage, which in turn introduces noise, leading to positioning errors when comparing the inspected product to the design template, affecting inspection accuracy. Locating the inspected label within the packaging product image is a key technology in packaging product printing inspection. Therefore, it is necessary to improve the positioning accuracy of label printing and improve label inspection accuracy. Summary of the Invention
[0003] The present disclosure provides a positioning method, device, equipment and storage medium for label printing, so as to at least solve the above technical problems existing in the prior art.
[0004] According to a first aspect of the present disclosure, a positioning method for label printing is provided, the method comprising:
[0005] Get the initial binary image of the label to be detected;
[0006] Determining a difference image between the initial binarized image and the binarized image of the template image;
[0007] Determine all contours in the difference image to obtain a contour set; and determine contour features of each contour in the contour set;
[0008] Determine the offset parameter of the tag to be detected according to all contour features;
[0009] The initial binary image of the tag to be detected is adjusted according to the offset parameter.
[0010] In one embodiment, obtaining an initial binary image of the tag to be detected includes:
[0011] Get the original image of the label to be detected;
[0012] After the initial template matching between the original image and the template image, an initial binary image of the label to be detected is obtained.
[0013] In one embodiment, the contour features include contour moment, contour length, contour area, and center of gravity coordinates.
[0014] In one embodiment, determining the offset parameter of the tag to be detected based on all contour features includes:
[0015] determining the contour corresponding to the longest contour length, and determining the width and direction of the contour at the center of gravity;
[0016] offsetting the initial binary image multiple times in the width direction according to the width of the contour to obtain multiple binary images to be detected;
[0017] Determine a difference image between each binary image to be detected and the binary image of the template image;
[0018] Determine whether the minimum value of the total contour area of all difference maps meets the threshold condition. If so, there is a deviation in the initial binary image; and determine the offset parameter of the tag to be detected based on the difference map corresponding to the minimum value.
[0019] In one possible implementation manner, determining the offset parameter of the tag to be detected based on the difference map corresponding to the minimum value includes:
[0020] A translation matrix is determined according to the width and direction of the contour, and each element in the translation matrix is the translation parameter.
[0021] According to a second aspect of the present disclosure, a positioning device for label printing is provided, the device comprising:
[0022] An acquisition module is used to obtain an initial binary image of the label to be detected;
[0023] a difference image determination module, configured to determine a difference image between the initial binarized image and the binarized image of the template image;
[0024] A contour feature determination module is used to determine all contours in the difference image to obtain a contour set; and determine the contour feature of each contour in the contour set;
[0025] An offset parameter determination module, configured to determine the offset parameter of the tag to be detected based on all contour features;
[0026] An adjustment module is used to adjust the initial binary image of the tag to be detected according to the offset parameter.
[0027] In one embodiment, the acquisition module is specifically configured to:
[0028] Get the original image of the label to be detected;
[0029] After the initial template matching between the original image and the template image, an initial binary image of the label to be detected is obtained.
[0030] In one embodiment, the offset parameter determination module is specifically configured to:
[0031] determining the contour corresponding to the longest contour length, and determining the width and direction of the contour at the center of gravity;
[0032] offsetting the initial binary image multiple times in the width direction according to the width of the contour to obtain multiple binary images to be detected;
[0033] Determine a difference image between each binary image to be detected and the binary image of the template image;
[0034] Determine whether the minimum value of the total contour area of all difference maps meets the threshold condition. If so, there is a deviation in the initial binary image; and determine the offset parameter of the tag to be detected based on the difference map corresponding to the minimum value.
[0035] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0036] at least one processor; and
[0037] a memory communicatively connected to the at least one processor; wherein,
[0038] The memory stores instructions that can be executed by the at least one processor. The instructions are executed by the at least one processor to enable the at least one processor to perform the method described in the present disclosure.
[0039] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method described in the present disclosure.
[0040] The present disclosure provides a positioning method, device, equipment and storage medium for label printing, which first obtains an initial binary image of the label to be detected; then determines a difference image between the initial binary image and the binary image of the template image; determines all contours in the difference image to obtain a contour set; and determines the contour features of each contour in the contour set; further determines the offset parameters of the label to be detected based on all contour features; and finally adjusts the initial binary image of the label to be detected based on the offset parameters. The technical solution of the present invention avoids positioning offsets caused by noise and other reasons by adjusting the binary image of the label to be detected, improves label positioning accuracy, and thereby reduces the false detection rate.
[0041] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present disclosure, nor are they intended to limit the scope of the present disclosure. Other features of the present disclosure will become readily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will become readily understood by reading the detailed description below with reference to the accompanying drawings, in which several embodiments of the present disclosure are shown by way of example and not limitation, wherein:
[0043] In the drawings, the same or corresponding reference numerals denote the same or corresponding parts.
[0044] Figure 1 A schematic diagram showing a flow chart of a positioning method for label printing according to an embodiment of the present disclosure is shown;
[0045] Figure 2 A schematic diagram illustrating an implementation flow of a positioning method for label printing according to an embodiment of the present disclosure is shown;
[0046] Figure 3 A schematic diagram of obtaining an initial binary image of a tag to be detected according to an embodiment of the present disclosure is shown;
[0047] Figure 4 A schematic diagram illustrating an embodiment of the present disclosure for determining an offset parameter of a tag to be detected is shown;
[0048] Figure 5 A schematic structural diagram of a positioning device for label printing according to an embodiment of the present disclosure is shown;
[0049] Figure 6 A schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0050] To make the purposes, features, and advantages of the present disclosure more apparent and understandable, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of them. All other embodiments obtained by those skilled in the art based on the embodiments of the present disclosure without creative work shall fall within the scope of protection of the present disclosure.
[0051] like Figure 1-2 FIG. 1 is a flow chart of a positioning method for label printing provided by an embodiment of the present invention, the method comprising:
[0052] S1, obtain the initial binary image of the label to be detected;
[0053] In one example, obtaining an initial binary image of a label to be detected includes:
[0054] S11, obtaining the original image of the label to be detected;
[0055] S12: After performing initial template matching on the original image and the template image, an initial binary image of the label to be detected is obtained.
[0056] The original image of the label to be inspected can be a printed sample of the label processed by a staff member, or it can be an original image captured by a capture device, without limitation. The template image is a template captured by the capture device. After an initial template matching between the original image and the template image, conventional image processing operations such as grayscale conversion, Gaussian filtering, and binarization are performed to obtain an initial binary image of the label to be inspected.
[0057] S2, determining a difference image between the initial binarized image and the binarized image of the template image;
[0058] Subtract the initial binary image of the tag to be detected from the binary image of the template image, that is, perform a difference operation to obtain the difference image between the two binary images. The calculation formula is as follows:
[0059] dst(I)=abs(src1(I)-src2(I))#(1)
[0060] Wherein, I in formula (1) is the pixel traversal, src1 is the binary image of the label to be detected, src2 is the binary image of the template image, and dst is the difference image.
[0061] S3, determining all contours in the difference image to obtain a contour set; and determining contour features of each contour in the contour set;
[0062] Perform contour search on the difference image to determine all contours and obtain a contour set; further determine the contour features of each contour, where the contour features include contour moment, contour length, contour area and centroid coordinates.
[0063] Calculate the contour moment, contour length, and contour area of each contour, and further calculate the center coordinates of the contour through the contour moment. The calculation method of the center of gravity coordinates is as follows:
[0064] G x =m 10 ÷m 00 #(2)
[0065] G y =m 01 ÷m 00 #(3)
[0066] In formulas (2) and (3), Gx and Gy are the x and y coordinates of the contour center of gravity, m 00 is the contour 0th order moment, m 10 、m 01 is the first moment of the contour.
[0067] S4, determining the offset parameter of the tag to be detected according to all contour features;
[0068] In one example, determining the offset parameter of the tag to be detected according to all contour features includes:
[0069] S41, determining the contour corresponding to the longest contour length, and determining the width and direction of the contour at the center of gravity;
[0070] S42, shifting the initial binary image multiple times in the width direction according to the width of the contour to obtain multiple binary images to be detected;
[0071] S43, determining a difference image between each binary image to be detected and the binary image of the template image;
[0072] S44. Determine whether the minimum value of the total contour area of all difference maps meets the threshold condition. If so, the initial binary image has a deviation; and determine the offset parameter of the tag to be detected based on the difference map corresponding to the minimum value.
[0073] Based on the contour lengths of all contour features, determine the contour corresponding to the longest line in the contour set, calculate the contour width w and width direction θ of the contour at its center of gravity, and shift the label binary map multiple times in the range (-w, w) along the width direction to obtain multiple binary maps to be detected to form the set of binary maps to be detected. For example, divide the range (-w, w) into 5 equal parts, shift the label binary map 5 times, and obtain 5 binary maps to be detected to form the set of binary maps to be detected.
[0074] These binary images to be detected are then compared with the binary image of the template image to calculate the difference image. The minimum value of the total contour area of the difference image is calculated to see if it is less than the threshold. The threshold is set to the original value, which is the sum of all contour areas determined in step S3. If the minimum value is less than the original value, it means that there is a deviation in the initial positioning. Positioning adjustment is performed according to the minimum value state. Otherwise, the original binary image is still used. The formula for translation in the width direction is as follows:
[0075] dst(x,y)=src(M 11 x+M 12 y+M 13 ,M 21 x+M 22 y+M 23 )#(4)
[0076]
[0077] In formulas (4)-(5), dst is the image after translation, src is the image before translation, M is the translation matrix, w is the width of the contour line, and θ is the width direction.
[0078] S5. Adjust the initial binary image of the tag to be detected according to the offset parameter.
[0079] In one example, determining the offset parameter of the tag to be detected according to the difference map corresponding to the minimum value includes:
[0080] A translation matrix is determined according to the width and direction of the contour, and each element in the translation matrix is the translation parameter.
[0081] The present invention first obtains an initial binary image of the tag to be detected; then determines a difference image between the initial binary image and the binary image of a template image; determines all contours in the difference image to obtain a contour set; and determines the contour features of each contour in the contour set; further determines the offset parameters of the tag to be detected based on all contour features; and finally adjusts the initial binary image of the tag to be detected based on the offset parameters. The technical solution of the present invention avoids positioning offsets caused by noise and other reasons by adjusting the binary image of the tag to be detected, improves the tag positioning accuracy, and thereby reduces the false detection rate.
[0082] like Figure 3 FIG. 1 is a schematic structural diagram of a positioning device for label printing provided by the present invention, the device comprising:
[0083] An acquisition module 10 is used to acquire an initial binary image of the tag to be detected;
[0084] A difference image determination module 20 is used to determine a difference image between the initial binarized image and the binarized image of the template image;
[0085] A contour feature determination module 30 is configured to determine all contours in the difference image to obtain a contour set; and determine contour features of each contour in the contour set;
[0086] An offset parameter determination module 40 is used to determine the offset parameter of the tag to be detected based on all contour features;
[0087] The adjustment module 50 is configured to adjust the initial binary image of the tag to be detected according to the offset parameter.
[0088] In one example, the acquisition module 10 is specifically configured to:
[0089] Get the original image of the label to be detected;
[0090] After the initial template matching between the original image and the template image, an initial binary image of the label to be detected is obtained.
[0091] In one example, the contour features include contour moment, contour length, contour area, and center of gravity coordinates.
[0092] In one example, the offset parameter determination module 40 is specifically configured to:
[0093] determining the contour corresponding to the longest contour length, and determining the width and direction of the contour at the center of gravity;
[0094] offsetting the initial binary image multiple times in the width direction according to the width of the contour to obtain multiple binary images to be detected;
[0095] Determine a difference image between each binary image to be detected and the binary image of the template image;
[0096] Determine whether the minimum value of the total contour area of all difference maps meets the threshold condition. If so, there is a deviation in the initial binary image; and determine the offset parameter of the tag to be detected based on the difference map corresponding to the minimum value.
[0097] In one example, the adjustment module 50 is specifically configured to:
[0098] A translation matrix is determined according to the width and direction of the contour, and each element in the translation matrix is the translation parameter.
[0099] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.
[0100] Figure 6 A schematic block diagram of an example electronic device 800 that can be used to implement embodiments of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital assistants, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are provided as examples only and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0101] like Figure 6As shown, the device 800 includes a computing unit 801, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 802 or a computer program loaded from a storage unit 808 into a random access memory (RAM) 803. Various programs and data required for the operation of the device 800 can also be stored in the RAM 803. The computing unit 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.
[0102] Various components in device 800 are connected to I / O interface 805, including an input unit 806, such as a keyboard, mouse, etc.; an output unit 807, such as various types of displays, speakers, etc.; a storage unit 808, such as a magnetic disk, optical disk, etc.; and a communication unit 809, such as a network card, modem, wireless communication transceiver, etc. The communication unit 809 allows device 800 to exchange information / data with other devices via a computer network such as the Internet and / or various telecommunication networks.
[0103] The computing unit 801 can be various general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 801 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units that run machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The computing unit 801 performs the various methods and processes described above, such as a positioning method for label printing. For example, in some embodiments, the positioning method for label printing can be implemented as a computer software program that is tangibly contained in a machine-readable medium, such as a storage unit 808. In some embodiments, part or all of the computer program can be loaded and / or installed on the device 800 via the ROM 802 and / or the communication unit 809. When the computer program is loaded into the RAM 803 and executed by the computing unit 801, one or more steps of the positioning method for label printing described above can be performed. Alternatively, in other embodiments, the computing unit 801 can be configured to perform the positioning method for label printing by any other appropriate means (e.g., by means of firmware).
[0104] Various embodiments of the systems and techniques described herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), system-on-chip systems (SOCs), programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments can include being implemented in one or more computer programs that are executable and / or interpreted on a programmable system that includes at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0105] The program code for implementing the method of the present disclosure can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device so that when the program code is executed by the processor or controller, the functions / operations specified in the flow chart and / or block diagram are implemented. The program code can be executed entirely on the machine, partially on the machine, as a stand-alone software package, partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0106] In the context of the present disclosure, a machine-readable medium can be a tangible medium that can contain or store a program for use by or in conjunction with an instruction execution system, device or equipment. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or equipment, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium can include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0107] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0108] The systems and techniques described herein can be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include a local area network (LAN), a wide area network (WAN), and the Internet.
[0109] A computer system may include a client and a server. The client and server are generally remote from each other and typically interact through a communication network. The client-server relationship arises through computer programs running on the respective computers and having a client-server relationship with each other. The server may be a cloud server, a server in a distributed system, or a server integrated with a blockchain.
[0110] It should be understood that the various forms of the processes shown above can be used to reorder, add, or delete steps. For example, the steps described in this disclosure can be performed in parallel, sequentially, or in a different order, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved. This is not a limitation herein.
[0111] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one such feature. Throughout the present disclosure, "plurality" means two or more, unless otherwise specifically defined.
[0112] The above description is merely a specific embodiment of the present disclosure, but the scope of protection of the present disclosure is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this disclosure should be included in the scope of protection of the present disclosure. Therefore, the scope of protection of the present disclosure should be based on the scope of protection of the claims.
Claims
1. A positioning method for label printing, characterized in that: The method comprises: Get the initial binary image of the label to be detected; Determining a difference image between the initial binarized image and the binarized image of the template image; Determine all contours in the difference image to obtain a contour set; and determine contour features of each contour in the contour set, wherein the contour features include contour moment, contour length, contour area, and centroid coordinates; Determining the offset parameters of the tag to be detected based on all contour features, including: determining the contour corresponding to the longest contour length, and determining the width w and width direction of the contour at the center of gravity; based on the width w and width direction of the contour, shifting the initial binary image multiple times in the range of (-w, w) at preset intervals in the width direction to obtain multiple binary images to be detected; determining a difference image between each binary image to be detected and the binary image of the template image; determining whether the minimum value of the total contour area of all difference images meets a threshold condition, and if so, the initial binary image has a deviation; determining a translation matrix based on the width and width direction of the contour of the difference image corresponding to the minimum value, each element in the translation matrix is the offset parameter; The initial binary image of the tag to be detected is adjusted according to the offset parameter.
2. The method according to claim 1, characterized in that The step of obtaining an initial binary image of the tag to be detected includes: Get the original image of the label to be detected; After the initial template matching between the original image and the template image, an initial binary image of the label to be detected is obtained.
3. A positioning device for label printing, characterized in that: The device comprises: An acquisition module is used to obtain an initial binary image of the label to be detected; a difference image determination module, configured to determine a difference image between the initial binarized image and the binarized image of the template image; a contour feature determination module, configured to determine all contours in the difference image to obtain a contour set; and determine contour features of each contour in the contour set, wherein the contour features include contour moment, contour length, contour area, and centroid coordinates; An offset parameter determination module is used to determine the offset parameters of the tag to be detected based on all contour features, including: determining the contour corresponding to the longest contour length, and determining the width w and width direction of the contour at the center of gravity; based on the width w and width direction of the contour, shifting the initial binary image multiple times in the range of (-w, w) at preset intervals in the width direction to obtain multiple binary images to be detected; determining a difference image between each binary image to be detected and the binary image of the template image; determining whether the minimum value of the total contour area of all difference images meets a threshold condition, and if so, the initial binary image has a deviation; determining a translation matrix based on the width and width direction of the contour of the difference image corresponding to the minimum value, each element in the translation matrix is the offset parameter; An adjustment module is used to adjust the initial binary image of the tag to be detected according to the offset parameter.
4. The device according to claim 3, characterized in that The acquisition module is specifically used to: Get the original image of the label to be detected; After the initial template matching between the original image and the template image, an initial binary image of the label to be detected is obtained.
5. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 2.
6. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to cause the computer to execute the method according to any one of claims 1-2.
Citation Information
Patent Citations
Bridge pavement crack classification and recognition method based on width learning neural network
CN110197203A
Label parameter extraction method and device, storage medium and electronic device
CN112183540A