Label detection method, device and equipment and computer readable storage medium
By generating a vertical histogram and performing standard squared difference matching, the problem of inaccurate label inspection results in existing technologies has been solved, enabling accurate detection of the label position and application direction on solar panels and ensuring correct label application.
Patent Information
- Application Number
- CN202110915512.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-10
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2041-08-10
AI Technical Summary
In existing technologies, the grayscale histogram of the label is used as a retrieval template to match the solar panel to be inspected, which results in low accuracy of label inspection results and makes it impossible to accurately identify the label application effect.
By preprocessing the target label according to the preset position information in the image to be detected, a vertical histogram based on pixel value is generated, the target grayscale image is obtained by cropping and conversion, and the actual position of the label is determined by standard squared difference matching to determine whether the label is correctly affixed.
It improves the accuracy of label position detection, ensures the label application effect, and can accurately identify whether the label is applied correctly or backwards, further improving the detection accuracy.
Smart Images

Figure CN114565551B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image processing, in particular to a label detection method, device and equipment and a computer readable storage medium. BACKGROUND
[0002] In order to distinguish each solar cell panel, a label capable of uniquely identifying the solar cell panel is attached at a fixed position of the solar cell panel. In order to avoid label attachment errors or label missing of the solar cell panel, the correctness of the label on the solar cell panel needs to be verified during the production process of the solar cell panel.
[0003] At present, the label on the solar cell panel is generally verified by using a gray histogram of the label as a retrieval template and matching with the solar cell panel to be verified. However, the accuracy of this verification method is not high, and in most cases, only the appearance defect of the label can be identified, and the label attachment effect cannot be accurately identified. SUMMARY
[0004] The present application provides a label detection method, device, equipment and computer readable storage medium, aiming at solving the problem that the gray histogram of the label is used as a retrieval template and matched with the solar cell panel to be verified in the prior art, resulting in low accuracy of the verification result and inability to accurately identify the label attachment effect.
[0005] In a first aspect, the present application provides a label detection method, which comprises:
[0006] According to the preset position information of the target label in the to-be-detected image, the to-be-detected image is preprocessed to obtain a vertical histogram based on pixel values; wherein the pixel value is the pixel value of the binary image corresponding to the to-be-detected image;
[0007] According to the vertical histogram, the binary image is intercepted and converted to obtain a target gray image; wherein the target gray image includes the target label;
[0008] According to the matching template of the target label, the target gray image is subjected to standard square difference matching processing to obtain the actual position of the target label in the to-be-detected image;
[0009] According to the actual position of the target label in the to-be-detected image, it is judged whether the target label is attached correctly.
[0010] In a possible implementation manner of the present application, according to the preset position information of the target label in the to-be-detected image, the to-be-detected image is preprocessed to obtain a vertical histogram based on pixel values, which comprises:
[0011] According to the preset position information of the target label in the to-be-detected image, the to-be-detected image is cropped to obtain a first local image;
[0012] The first local image is binarized to obtain a binary image; wherein the binary image includes white pixel points;
[0013] According to the pixel value of the binary image, a vertical histogram based on the pixel value is obtained; wherein the horizontal coordinate of the vertical histogram is the width of the binary image, and the vertical coordinate of the vertical histogram is the sum of the pixel values of all white pixel points corresponding to each width value in the binary image.
[0014] In a possible implementation of the present application, the binary image also includes black pixel points;
[0015] The first local image is binarized to obtain a binary image, including:
[0016] According to the pixel value of all pixel points in the first local image, an average pixel value of all pixel points in the first local image is obtained;
[0017] If the pixel value of the pixel point in the first local image is greater than the average pixel value, the pixel value of the pixel point in the first local image is modified to 255 to obtain a white pixel point;
[0018] If the pixel value of the pixel point in the first local image is less than the average pixel value, the pixel value of the pixel point in the first local image is modified to 0 to obtain a black pixel point.
[0019] In a possible implementation of the present application, the binary image is intercepted and converted according to the vertical histogram to obtain a target gray image, including:
[0020] The starting point of the interception is determined according to the vertical histogram; wherein the starting point of the interception is the first horizontal coordinate point in the vertical histogram, and the first horizontal coordinate point is the first horizontal coordinate point with a non-zero vertical coordinate value in the vertical histogram;
[0021] The ending point of the interception is determined according to the preset interception width; wherein the ending point of the interception is the second horizontal coordinate point in the vertical histogram;
[0022] The binary image is intercepted based on the starting point of the interception and the ending point of the interception to obtain a target image; wherein the target image includes a target label;
[0023] The target image is grayed to obtain a target gray image.
[0024] In a possible implementation of the present application, the actual position of the target label in the to-be-detected image includes the upper left corner position coordinate and the lower right corner position coordinate of the target label in the to-be-detected image.
[0025] According to the matching template of the target label, the target gray image is subjected to a standard square difference matching process to obtain an actual position of the target label in the image to be detected, comprising:
[0026] Based on the normalized square difference matching method, the matching template is used to traverse the target gray image to obtain a matching result; wherein the matching result comprises a normalized square difference value corresponding to each pixel point in the target gray image;
[0027] The pixel point corresponding to the smallest normalized square difference value in the matching result is selected as a reference point;
[0028] The reference point is subjected to a shift process according to the starting point of the interception to obtain a top-left position coordinate;
[0029] According to the size information of the matching template and the top-left position coordinate, a bottom-right position coordinate is obtained.
[0030] In a possible implementation manner of the present application, before the target gray image is subjected to a standard square difference matching process according to the matching template of the target label to obtain an actual position of the target label in the image to be detected, the method comprises:
[0031] Specific position information of the target label in the image to be detected is obtained, and a label image of the target label is obtained according to the specific position information;
[0032] The label image of the target label is subjected to a gray processing to obtain a label gray image, and the label gray image is taken as the matching template of the target label.
[0033] In a possible implementation manner of the present application, according to the actual position of the target label in the image to be detected, whether the target label is correctly pasted is judged, comprising:
[0034] The actual position of the target label in the image to be detected is compared with a preset position interval;
[0035] If the actual position of the target label in the image to be detected is within the position interval, it is determined that the target label is correctly pasted;
[0036] Otherwise, it is determined that the target label is incorrectly pasted.
[0037] In a possible implementation manner of the present application, after it is determined that the target label is incorrectly pasted, the method further comprises:
[0038] The matching template is rotated by 180° to obtain a second matching template, and the target gray image is subjected to a standard square difference matching process according to the second matching template to obtain a second position of the target label in the image to be detected;
[0039] If the second position of the target label in the image to be detected is within the position interval, it is determined that the target label is pasted reversely.
[0040] In a second aspect, the present application provides a label detection device, which comprises:
[0041] a preprocessing module, configured to perform preprocessing on the image to be detected according to preset position information of the target label in the image to be detected, to obtain a vertical histogram based on pixel values; wherein the pixel values are pixel values of a binary image corresponding to the image to be detected;
[0042] a clipping conversion module, configured to perform clipping conversion processing on the binary image according to the vertical histogram, to obtain a target gray image; wherein the target gray image comprises the target label;
[0043] a matching module, configured to perform standard square difference matching processing on the target gray image according to a matching template of the target label, to obtain an actual position of the target label in the image to be detected;
[0044] a judging module, configured to judge whether the target label is pasted correctly according to the actual position of the target label in the image to be detected.
[0045] In a possible implementation of the present application, the preprocessing module is specifically configured to:
[0046] perform clipping processing on the image to be detected according to the preset position information of the target label in the image to be detected, to obtain a first local image;
[0047] perform binary processing on the first local image, to obtain a binary image; wherein the binary image comprises white pixel points;
[0048] obtain a vertical histogram based on pixel values according to pixel values of the binary image; wherein the horizontal coordinate of the vertical histogram is the width of the binary image, and the vertical coordinate of the vertical histogram is the sum of the pixel values of all white pixel points corresponding to each width value in the binary image.
[0049] In a possible implementation of the present application, the binary image further comprises black pixel points, and the preprocessing module is specifically further configured to:
[0050] obtain an average pixel value of all pixel points in the first local image according to the pixel values of all pixel points in the first local image;
[0051] if the pixel value of the pixel point in the first local image is greater than the average pixel value, modify the pixel value of the pixel point in the first local image to 255, to obtain the white pixel point;
[0052] If the pixel value of the pixel point in the first local image is less than the average pixel value, the pixel value of the pixel point in the first local image is modified to 0 to obtain a black pixel point.
[0053] In a possible implementation of the present application, the intercepting and converting module is specifically configured to:
[0054] determine an intercept start point according to the vertical histogram; the intercept start point is a first horizontal coordinate point in the vertical histogram, and the first horizontal coordinate point is a horizontal coordinate point with a non-zero vertical coordinate value in the vertical histogram;
[0055] determine an intercept end point according to the preset intercept width; the intercept end point is a second horizontal coordinate point in the vertical histogram;
[0056] perform intercept processing on the binary image based on the intercept start point and the intercept end point to obtain a target image; the target image includes a target label;
[0057] perform grayscale processing on the target image to obtain a target grayscale image.
[0058] In a possible implementation of the present application, the actual position of the target label in the to-be-detected image includes an upper-left corner position coordinate and a lower-right corner position coordinate of the target label in the to-be-detected image, and the matching module is specifically configured to:
[0059] perform traversal on the target grayscale image by using the matching template based on a normalized square difference matching method to obtain a matching result; the matching result includes a normalized square difference value corresponding to each pixel point in the target grayscale image;
[0060] select a pixel point corresponding to a smallest normalized square difference value in the matching result as a reference point;
[0061] perform offset processing on the reference point according to the intercept start point to obtain the upper-left corner position coordinate;
[0062] obtain the lower-right corner position coordinate according to size information of the matching template and the upper-left corner position coordinate.
[0063] In a possible implementation of the present application, the label detection apparatus further includes:
[0064] a template obtaining module configured to obtain specific position information of the target label in the to-be-detected image, and obtain a label image of the target label according to the specific position information;
[0065] perform grayscale processing on the label image of the target label to obtain a label grayscale image, and use the label grayscale image as a matching template of the target label.
[0066] In a possible implementation of the present application, the judging module is specifically configured to:
[0067] comparing the actual position of the target label in the to-be-detected image with the preset position interval;
[0068] If the actual position of the target label in the to-be-detected image is within the position interval, it is determined that the target label is correctly attached.
[0069] Otherwise, it is determined that the target label is incorrectly attached.
[0070] In a possible implementation of the present application, after it is determined that the target label is incorrectly attached, the judging module is specifically further configured to:
[0071] rotating the matching template by 180° to obtain a second matching template, performing standard square difference matching processing on the target gray-scale image according to the second matching template, and obtaining a second position of the target label in the to-be-detected image;
[0072] If the second position of the target label in the to-be-detected image is within the position interval, it is determined that the target label is attached reversely.
[0073] In a third aspect, the present application further provides a label detection device, which comprises a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the steps in the label detection method of the first aspect.
[0074] In a fourth aspect, the present application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the steps in the label detection method of the first aspect.
[0075] From the above, the present application has the following beneficial effects:
[0076] 1. According to the present application, the binary image corresponding to the to-be-detected image is intercepted and converted according to the vertical histogram, to obtain a target gray-scale image including the target label, and then the target gray-scale image is subjected to standard square difference matching processing according to the matching template of the target label, to obtain the actual position of the target label in the to-be-detected image, and then it is determined whether the target label is correctly attached according to the actual position. Compared with the prior art in which the gray-scale histogram of the label is used as a retrieval template and matched with the to-be-inspected solar cell panel, the detection result after the standard square difference matching processing is more accurate, the detection accuracy of the label position is improved, and the attachment effect of the target label is ensured.
[0077] 2、The application determines whether the target label is correctly pasted by comparing the actual position of the target label in the to-be-detected image with the preset position interval, if the actual position of the target label in the to-be-detected image is not within the position interval, a second matching template is obtained by rotating the matching template by 180°, and then the standard square difference matching processing is performed on the target gray image according to the second matching template to obtain a second position of the target label in the to-be-detected image, and then the second position and the position interval are compared, if the second position is within the position interval, it can be determined that the target label is pasted reversely, through the method of the application, not only the actual position of the label can be determined, but also whether the label is pasted reversely can be determined, and the accuracy of label detection is further improved. BRIEF DESCRIPTION OF DRAWINGS
[0078] In order to more clearly illustrate the technical solutions in the present application, the drawings required to be used in the description of the present application will be briefly introduced as follows, obviously, the drawings in the following description are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor on the basis of these drawings.
[0079] Figure 1 is a scene schematic diagram of a label detection system provided in an embodiment of the present application;
[0080] Figure 2 is a flow schematic diagram of a label detection method provided in an embodiment of the present application;
[0081] Figure 3 is an image schematic diagram of a to-be-detected image in an embodiment of the present application;
[0082] Figure 4 is an image schematic diagram of a matching template in an embodiment of the present application;
[0083] Figure 5 is an image schematic diagram of a first local image in an embodiment of the present application;
[0084] Figure 6 is an image schematic diagram of a binary image in an embodiment of the present application;
[0085] Figure 7 is an image schematic diagram of a vertical histogram in an embodiment of the present application;
[0086] Figure 8 is an image schematic diagram of a target gray image in an embodiment of the present application;
[0087] Figure 9 is an image schematic diagram of a matching result in an embodiment of the present application;
[0088] Figure 10is a local enlarged image schematic view of obtaining the actual position of the target label in the to-be-detected image in an embodiment of the present application;
[0089] Figure 11 is an image schematic view of a second matching template in an embodiment of the present application;
[0090] Figure 12 is a structural schematic view of a label detection device provided in an embodiment of the present application;
[0091] Figure 13 is a structural schematic view of a label detection device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0092] The technical solutions in the present application will be described clearly and completely in the present application by combining with the drawings in the present application. Obviously, the described embodiments are only some of the embodiments of the present application, but not all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0093] In the description of the present application, it should be understood that the terms "center", "longitudinal", "transverse", "length", "width", "thickness", "upper", "lower", "front", "rear", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", "outer" and the like indicate the orientation or positional relationship shown in the drawings, and are only for the purpose of facilitating the description of the present application and simplifying the description, and do not indicate or imply that the device or element referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as a limitation of the present application. In addition, the terms "first", "second" are only for the purpose of description, and cannot be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Therefore, the features limited by "first", "second" can explicitly or implicitly include one or more features. In the description of the present application, the meaning of "multiple" is two or more, unless otherwise specifically limited.
[0094] In this application, the word "exemplary" is used to mean "serving as an example, instance, or illustration." Any implementation described as "exemplary" in this application is not necessarily to be construed as preferred or advantageous over other implementations. The following description is presented to enable any person skilled in the art to make and use the application. In the following description, for purposes of explanation, specific details are set forth. It is apparent to those skilled in the art that the present application can be practiced without using these specific details. In other instances, well-known structures and processes are not described in detail in order to avoid obscuring the description of the application. Thus, the present application is not intended to be limited by the embodiments shown, but is to be accorded the widest scope consistent with the principles and features disclosed herein.
[0095] The application provides a label detection method, device, equipment and computer readable storage medium, which are described in detail below respectively.
[0096] Please refer to Figure 1 , Figure 1 is a scene schematic diagram of a label detection system provided by an embodiment of the application. The label detection system can include a server 100 and a terminal device 200 in communication connection with the server 100. The terminal device 200 can be arranged on a production process line of a solar cell panel, and is configured to capture a front image of the solar cell panel 300 with a label attached, to obtain a to-be-detected image, and to upload the to-be-detected image to the server 100. Alternatively, the terminal device 200 can be in communication connection with a shooting device 400 such as a camera or a camera lens arranged on the production process line of the solar cell panel, to obtain a front image of the solar cell panel 300 with a label attached, which is captured by the shooting device 400, to obtain a to-be-detected image, and to forward the to-be-detected image to the server 100. The server 100 is integrated with a label detection device, and can be configured to perform label detection on the to-be-detected image uploaded by the terminal device 200, to determine whether the label attached on the solar cell panel 300 is correctly positioned and to detect the attachment effect of the label.
[0097] In the embodiment of the application, the server 100 is mainly configured to perform preprocessing on the to-be-detected image according to preset position information of a target label in the to-be-detected image, to obtain a vertical histogram based on pixel values. The pixel values are pixel values of a binary image corresponding to the to-be-detected image. The binary image is subjected to intercepting and converting processing according to the vertical histogram, to obtain a target gray image. The target gray image includes the target label. The target gray image is subjected to standard square difference matching processing according to a matching template of the target label, to obtain an actual position of the target label in the to-be-detected image. Whether the target label is correctly attached is determined according to the actual position of the target label in the to-be-detected image.
[0098] In this embodiment, the server 100 can be a standalone server, a server network, or a server cluster. For example, the server 100 described in this application includes, but is not limited to, a computer, a network host, a single network server, a set of multiple network servers, or a cloud server composed of multiple servers. The cloud server is composed of a large number of computers or network servers based on cloud computing.
[0099] In this embodiment, the server 100 and the terminal device 200 can communicate via network using any communication method, including but not limited to mobile communication based on the 3rd Generation Partnership Project (3GPP), Long Term Evolution (LTE), and Worldwide Interoperability for Microwave Access (WiMAX), or computer network communication based on the TCP / IP Protocol Suite (TCP / IP) and User Datagram Protocol (UDP). The terminal device 200 can interact with the server 100 through the above communication methods.
[0100] In this embodiment, the terminal device 200 can be a general-purpose computer device or a dedicated computer device. In specific implementations, the terminal device 200 can be a handheld computer, a personal digital assistant (PDA), a mobile phone, a tablet computer, a wireless terminal device, or other terminal devices with shooting functions, etc. This application does not limit the type of the terminal device 200.
[0101] Those skilled in the art will understand that Figure 1 The application environment shown is merely one application scenario adapted to the solution of this application, and does not constitute a limitation on the application scenario of the solution of this application. Other application scenarios may include more than one application scenario. Figure 1 More or fewer terminal devices 200 shown, for example Figure 1 Only two terminal devices are shown in the diagram. It is understood that the label detection system may include more or fewer terminal devices communicating with the server 100; this is not limited here. Furthermore, it should be noted that the solution presented in this application can also be used in image processing processes such as label detection and image matching in other application scenarios.
[0102] It should be noted that, Figure 1The scenario schematic diagram of the label detection system shown is only an example, the label detection system and the scenario described in the application are used to more clearly illustrate the technical solutions of the application, and do not constitute a limitation on the technical solutions provided by the application. Those skilled in the art can know that, as the label detection system evolves and new business scenarios appear, the technical solutions provided by the application are also applicable to similar technical problems.
[0103] Firstly, the application provides a label detection method, which is applied to a server, and the execution subject of the label detection method is a label detection device. The label detection method comprises the following steps of:
[0104] According to the preset position information of the target label in the to-be-detected image, the to-be-detected image is preprocessed to obtain a vertical histogram based on pixel values; wherein the pixel values are pixel values of a binary image corresponding to the to-be-detected image; the binary image is subjected to intercept conversion processing according to the vertical histogram to obtain a target gray image; wherein the target gray image comprises the target label; the target gray image is subjected to standard square difference matching processing according to a matching template of the target label to obtain an actual position of the target label in the to-be-detected image; and whether the target label is correctly attached is judged according to the actual position of the target label in the to-be-detected image.
[0105] As shown in Figure 2 , Figure 2 is a flowchart of the label detection method provided in the embodiments of the application. It should be noted that although the logical order is shown in the flowchart, in some cases, the steps shown or described herein can be executed in an order different from that shown herein. The label detection method is applied to a server, and the label detection method comprises the following steps of:
[0106] S201, according to the preset position information of the target label in the to-be-detected image, the to-be-detected image is preprocessed to obtain a vertical histogram based on pixel values; wherein the pixel values are pixel values of a binary image corresponding to the to-be-detected image.
[0107] In the application scenario, the to-be-detected image can be a front image of a solar panel or a solar photovoltaic module. It can be understood that a solar panel is a device that converts solar radiation energy into electric energy through photovoltaic effect or photochemical effect. Most solar panels are made of silicon. Compared with ordinary batteries and rechargeable batteries, solar cells are more energy-saving and environmentally friendly green products.
[0108] Generally, a solar panel includes a plurality of solar cell pieces arranged in rows and columns on a backboard of the solar panel, and a label of the solar panel is usually attached to the upper left corner of the solar panel and generally does not exceed the height of the solar cell piece in the first row and the first column.
[0109] The label of the solar panel can be used to uniquely identify the solar panel, and generally, the label of the solar panel can include a barcode and a serial code of the solar panel. By scanning the barcode on the solar panel, relevant parameter information of the solar panel can be obtained, which can include electrical performance parameter information and specification parameter information. The electrical performance parameter information can be product model, short-circuit current, short-circuit voltage, open-circuit voltage, optimal working current and voltage, power deviation, and the like. The specification parameter information can be weight, length, width, thickness, application level, and the like.
[0110] It can be understood that the front image obtained by photographing the front of the solar panel can be an image including all solar cell pieces of a solar panel, that is, the to-be-detected image can be a front image of a whole solar panel. Since the label of the solar panel is attached to a certain fixed area, the to-be-detected image can be preprocessed according to the preset position information of the target label in the to-be-detected image before detection.
[0111] For example, the to-be-detected image can be first cropped according to the preset position information to retain the image of the target label preset position and the surrounding pixel points. In order to facilitate subsequent image matching of the cropped image and reduce the amount of calculation, the cropped image can also be rendered as a black and white effect image to highlight the contour of the target, that is, the contour of the target label. The black and white effect image can be similar to the binaryzation of the to-be-detected image or the cropped image, and the binaryzation image obtained is a black and white effect image highlighting the contour of the target in the image. For the black and white effect image, that is, the binaryzation image, the pixel point situation in the binaryzation image can be counted to assist in finding the actual position of the target label subsequently. Therefore, a vertical histogram of the binaryzation image can be generated to count the pixel point situation in the binaryzation image.
[0112] It can be understood that the to-be-detected image in the embodiments of the present application can also be the image containing the target label preset position and the surrounding pixel points obtained after cropping. For this case, the preprocessing process of the to-be-detected image can reduce the step of cropping to speed up the detection.
[0113] S202, perform intercept conversion processing on the binary image according to the vertical histogram to obtain a target gray image; wherein the target gray image includes the target label.
[0114] Since the vertical histogram in S201 can be used to count the pixel points in the binary image, the horizontal coordinate of the vertical histogram can correspond to the width of the binary image, and the vertical coordinate can be used to count the pixel value of each column of pixel points in the binary image. For the pixel points with a pixel value of 0 in the binary image, it can be considered that they are not associated with the target label. Therefore, in order to further reduce the calculation amount and improve the detection accuracy, the binary image can be further cropped. For example, for each horizontal coordinate value in the vertical histogram, if the vertical coordinate value corresponding to the horizontal coordinate value is 0, it can be discarded. Since the position of the target label is a region, the first horizontal coordinate value when the vertical coordinate value is not 0 can be searched along the extension direction of the horizontal coordinate of the vertical histogram, and the binary image is intercepted based on the horizontal coordinate value.
[0115] In addition, since the captured image to be detected can be a three-channel image based on three color channels of red, green and blue (R, G, B), and the binary image obtained based on the image to be detected can also be another three-channel image based on three color channels of red, green and blue (R, G, B), if the other three-channel image is directly used for calculation, the calculation amount is three times that of a single-channel image. Therefore, the intercepted binary image can also be subjected to grayscale processing to obtain a target gray image including the target label.
[0116] S203, performing standard square difference matching processing on the target gray image according to the matching template of the target label to obtain the actual position of the target label in the image to be detected.
[0117] It can be understood that the matching template of the target label can be a template image including only the target label. Since the target gray image is a gray image, the matching module for performing standard square difference matching processing on the target gray image can also be a gray image.
[0118] In the embodiment of the application, the standard square difference matching processing on the target gray image according to the matching template of the target label is to traverse the target gray image using the matching template, compare the matching template with the image region covered by the matching template in the target gray image, find the best matching result when the traversal is completed, and find the region with the highest similarity to the matching template of the target label according to the best matching result. The region can be considered as the actual position of the target label in the image to be detected.
[0119] S204, judging whether the target label is correctly attached according to the actual position of the target label in the image to be detected.
[0120] It can be understood that the pasting position and direction of the target label on the solar cell panel are subject to certain regulations, which can be pasting requirements describing the pasting position and direction. The target label can be considered to be pasted correctly only when the pasting position and direction meet the pasting requirements. Therefore, in the embodiments of the present application, the actual position detected in S203 can be compared with the pasting requirements of the target label. When the actual position meets the pasting requirements, it can be determined that the target label is pasted correctly. When the actual position does not meet the pasting requirements, it can be determined that the target label is pasted incorrectly. Since there are various cases of pasting errors, such as position pasting errors, direction pasting errors (i.e., pasting upside down or skewing), etc., under the premise of determining that the target label is pasted incorrectly, the type of error can also be determined by the pasting requirements, so as to obtain the pasting effect of the target label on the solar cell panel.
[0121] In the embodiments of the present application, the binary image corresponding to the to-be-detected image is intercepted and converted according to the vertical histogram, to obtain a target gray image including the target label. Then, the target gray image is subjected to standard square difference matching processing according to the matching template of the target label, to obtain the actual position of the target label in the to-be-detected image. Then, whether the target label is pasted correctly is judged according to the actual position. Compared with the prior art of using the gray histogram of the label as a retrieval template to match the to-be-inspected solar cell panel, the detection result based on the standard square difference matching processing is more accurate, which improves the detection accuracy of the label position, and further ensures the pasting effect of the target label.
[0122] In some embodiments of the present application, before the target gray image is subjected to standard square difference matching processing according to the matching template of the target label to obtain the actual position of the target label in the to-be-detected image, the label detection method can further include:
[0123] Obtaining specific position information of the target label in the to-be-detected image, and obtaining a label image of the target label according to the specific position information; performing gray processing on the label image of the target label to obtain a label gray image, and taking the label gray image as the matching template of the target label.
[0124] Please refer to Figure 3 , Figure 3 is a schematic diagram of a to-be-detected image in the embodiments of the present application, Figure 3The shown to be detected image is a front image of a whole solar panel, and the specific position information of the target label in the to be detected image can be obtained by viewing the picture tool based on the Java public image processing software ImageJ, and since the target label can be framed by a rectangular frame, the specific position of the target label can be represented by the coordinates of the two top points of the diagonal line of the rectangular frame, that is, the specific position information in the embodiment of the application can be the upper left point coordinates (such as "(130, 273)") and the lower right point coordinates (such as "(201, 562)") of the rectangular frame, and the target label can be cut or cropped from the to be detected image according to the upper left point coordinates (130, 273) and the lower right point coordinates (201, 562). It can be understood that in the embodiment of the application, the upper left point coordinates of the to be detected image are taken as the origin coordinates (0, 0), the x-axis increases from left to right, and the y-axis increases from top to bottom.
[0125] In the embodiment of the application, the target label can be cut or cropped from the to be detected image by using the picture cutting method in the OpenCV open source library to obtain the label image. Specifically, the cropping frame can be set as box (130, 273, 201, 562), wherein 130 is the minimum value of the x-axis, 273 is the minimum value of the y-axis, 201 is the maximum value of the x-axis, and 562 is the maximum value of the y-axis. Based on the cropping frame box (130, 273, 201, 562), the target label can be cut from the to be detected image to obtain the label image.
[0126] Similarly, since the to be detected image obtained by shooting can be a three-channel image based on three color channels of red, green and blue (R, G, B), and the label image obtained based on the to be detected image can also be a three-channel image based on three color channels of red, green and blue (R, G, B), if the three-channel image is directly used for calculation, the calculation amount is three times that of a single-channel image. Therefore, in the embodiment of the application, the label image of the target label can also be subjected to grayscale processing to obtain a label grayscale image, and the label grayscale image can be used as a matching template of the target label, as shown in Figure 4 The matching template is composed of a barcode on the left and a sequence code on the right.
[0127] As shown in Figure 5 Figure 5 is an image schematic diagram of a first local image in the embodiment of the application. In some embodiments of the application, the to be detected image is preprocessed according to the preset position information of the target label in the to be detected image to obtain a vertical histogram based on pixel values, which can further include:
[0128] According to the preset position information of the target label in the to-be-detected image, the to-be-detected image is cropped to obtain a first local image; the first local image is binarized to obtain a binarized image; wherein the binarized image includes white pixel points; according to the pixel value of the binarized image, a vertical histogram based on the pixel value is obtained; wherein the horizontal coordinate of the vertical histogram is the width of the binarized image, and the vertical coordinate of the vertical histogram is the sum of the pixel values of all white pixel points corresponding to each width value in the binarized image.
[0129] In the embodiments of the present application, the position of the label is always at the upper left corner of the solar cell panel, and does not exceed the height of the first row and the first column of the solar cell, as shown in Figure 3 A whole solar cell panel includes 6 rows and 12 columns of solar cells, and assuming that the height of the to-be-detected image is H, according to the preset position information, that is, the target label is located at the upper left corner of the to-be-detected image and does not exceed the height of the first row and the first column of the solar cell, the to-be-detected image is cropped, and here the cropping height can be H / 6, so a first local image as shown in Figure 5 can be obtained, and here the width of the first local image is the same as the width of the to-be-detected image.
[0130] It should be noted that the cropping height H / 6 is only an example of the embodiments of the present application, and the cropping height of the first local image can also be H / 5 or H / 4 or other values related to the height H of the to-be-detected image. The cropping height of the first local image can be selected according to the preset position information of the target label and the actual application scenario, and the specific implementation is not limited here.
[0131] Further, in order to highlight the characteristics of the target label, in the embodiments of the present application, the first local image can also be binarized, and specifically, the binarization can be: according to the pixel value of all pixel points in the first local image, the average pixel value of all pixel points in the first local image is obtained, that is, the pixel values of all pixel points in the first local image are summed, and then the sum of the pixel values is divided by the total number of pixel points in the first local image to obtain the average pixel value of all pixel points in the first local image; then the average pixel value is taken as a comparison threshold and compared with the pixel value of the pixel point in the first local image, if the pixel value of the pixel point in the first local image is greater than the average pixel value, the pixel value of the pixel point in the first local image can be modified to 255 to obtain a white pixel point; if the pixel value of the pixel point in the first local image is less than or equal to the average pixel value, the pixel value of the pixel point in the first local image can be modified to 0 to obtain a black pixel point, so a binarized image as shown in Figure 6 can be obtained.
[0132] As shown in Figure 7 ,Figure 7 This is a schematic diagram of a vertical histogram in an embodiment of this application. Based on the binarized image obtained above, a vertical histogram associated with the pixel values of the binarized image can be drawn. Please continue reading. Figure 7 The horizontal axis of the vertical histogram can be the width of the binarized image, and the vertical axis can be the sum of the pixel values of all white pixels corresponding to each width value in the binarized image. In other words, the vertical axis can be the sum of the pixel values of white pixels in each column of pixels in the binarized image.
[0133] like Figure 8 As shown, Figure 8 This is a schematic diagram of a target grayscale image in an embodiment of this application. In some embodiments of this application, the target grayscale image is obtained by cropping and converting the binarized image according to the vertical histogram, which may further include:
[0134] The starting point for cropping is determined based on the vertical histogram; the starting point is the first abscissa point in the vertical histogram, which is the first abscissa point in the vertical histogram with a non-zero ordinate value. The ending point for cropping is determined based on the preset cropping width; the ending point is the second abscissa point in the vertical histogram. Based on the starting and ending points, the binarized image is cropped to obtain the target image; the target image includes the target label. The target image is then converted to grayscale to obtain the target grayscale image.
[0135] To further reduce the computational load and improve detection accuracy, in this embodiment, the binarized image can be further cropped. It is understood that a horizontal coordinate point with a ordinate value of 0 in the vertical histogram indicates that the column containing that horizontal coordinate point has little or no correlation with the target label. Therefore, the horizontal coordinate points in the vertical histogram can be searched from left to right to find the first horizontal coordinate point with a non-zero ordinate value as the cropping starting point x; Figure 8The distance from the intercept starting point x to the first column of solar cell pieces can be obtained as 230. Therefore, in order to be able to surround the target label completely, assuming that the width of the solar cell piece is W, the intercept width is set as W*80%, and therefore the intercept endpoint can be W*80%+x, that is, starting from the intercept starting point x, the width of W*80% pixels is intercepted as the width of the target image. Assuming that the intercept starting point x=52 and the width of the solar cell piece W is 1000, the intercept endpoint is 1000*80%+52=852. According to the intercept starting point and the intercept endpoint, the binaryzation image is subjected to intercept processing, and the target image with a width of the first horizontal coordinate 52 to the second horizontal coordinate 852 in the binaryzation image can be obtained. Then, the color space of the binaryzation image can be converted by using the cvtColor() function in the OpenCV open source library, for example, the binaryzation image is subjected to grayscale processing by using cvtColor(src, dst, CV_BGR2GRAY), and a target grayscale image as shown in Figure 8 is obtained.
[0136] As shown in Figure 9 , Figure 9 is an image schematic diagram of the matching result in the embodiment of the application. In some embodiments of the application, the actual position of the target label in the to-be-detected image includes the upper left corner position coordinate and the lower right corner position coordinate of the target label in the to-be-detected image. According to the matching template of the target label, the target grayscale image is subjected to standard square difference matching processing, and the actual position of the target label in the to-be-detected image is obtained, which can further include:
[0137] Based on the normalized square difference matching method, the target grayscale image is traversed by using the matching template, and the matching result is obtained. The matching result includes the normalized square difference value corresponding to each pixel point in the target grayscale image. The pixel point corresponding to the smallest normalized square difference value in the matching result is selected as the reference point. The upper left corner position coordinate is obtained by offset processing of the reference point according to the intercept starting point. The lower right corner position coordinate is obtained according to the size information of the matching template and the upper left corner position coordinate.
[0138] Specifically, the calculation formula of the normalized square difference matching method is as follows:
[0139]
[0140] Wherein, T(x', y') represents the pixel value of the matching template at the pixel point (x', y'), I(x+x', y+y') represents the pixel value of the target gray-scale image at the pixel point (x+x', y+y'), x' and y' represent the loop variable, representing the pixel points of the matching template traversed from left to right and from top to bottom, the value range of x' is the width of the matching template, the value range of y' is the height of the matching template, (x, y) represents the pixel point coordinates of the target gray-scale image, the value range of x is the width of the target gray-scale image, and the value range of y is the height of the target gray-scale image.
[0141] According to the calculation formula of the normalized square difference matching method, the matching template is traversed in the target gray-scale image, and an image schematic diagram of the matching result can be obtained as shown in Figure 9 The matching result can include the normalized square difference value corresponding to each pixel point in the target gray-scale image. According to the above formula, when the normalized square difference value is 0, it means that the matching template and the target gray-scale image are completely matched, that is, when the pixel value is 0, the matching result is the best. Since the pixel point with the minimum normalized square difference value represents the best match, in the embodiment of the application, the pixel point corresponding to the minimum normalized square difference value in the matching result can be selected as the reference point. Assuming that the coordinates of the reference point are (x_min, y_min), since the target image is obtained by intercepting the binary image, combining the starting point x of the interception with the reference point (x_min, y_min) for offset processing, the top-left corner position coordinates (x_min+x, y_min) of the target label in the image to be detected can be obtained. According to the size information of the matching template such as the width roi_w and the height roi_h of the matching template, the bottom-right corner position coordinates (x_min+x+roi_w, y_min+roi_h) of the target label in the image to be detected can be obtained, so that the actual position of the target label in the image to be detected can be obtained.
[0142] As shown in Figure 10 Figure 10 is a local enlarged image schematic diagram of obtaining the actual position of the target label in the to-be-detected image in the embodiment of the present application. In the embodiment of the present application, the width and height of the matching template, i.e., the target label, can be obtained according to the shape() function in the OpenCV open source library, for example, using image.shape(), the number of rows, the number of columns and the number of color channels of the matching template can be obtained, such as (289, 71, 1), that is, the width of the matching template is roi_w=71, the height is roi_h=289, the coordinates of the reference point are (x_min=108, y_min=278), the starting point x=52 is intercepted, and the top-left corner position coordinates of the target label in the to-be-detected image are (x_min+x=160, y_min=278), i.e., (160, 278), and the bottom-right corner position coordinates are (x_min+x+roi_w=231, y_min+roi_h=567), i.e., (231, 567), and the actual position of the target label in the to-be-detected image is Figure 10 the black box in
[0143] In some embodiments of the present application, judging whether the target label is correctly pasted according to the actual position of the target label in the to-be-detected image can further include:
[0144] comparing the actual position of the target label in the to-be-detected image with a preset position interval; if the actual position of the target label in the to-be-detected image is within the position interval, it is determined that the target label is correctly pasted; otherwise, it is determined that the target label is incorrectly pasted.
[0145] It can be understood that, in order to standardize the pasting position of the label in the solar cell panel, the pasting range of the label, i.e., the position interval, can be preset, and the position interval can include a lower threshold and an upper threshold. In the embodiment of the present application, the position interval is used to standardize the horizontal coordinate of the top-left corner position coordinates of the target label. For example, if the position interval is set to [100, 180], if the horizontal coordinate value of the top-left corner position coordinates of the target label is within the position interval [100, 180], it can be considered that the target label is correctly pasted; on the contrary, if the horizontal coordinate value of the top-left corner position coordinates of the target label is not within the position interval [100, 180], the target label is incorrectly pasted, such as being pasted incorrectly or missing.
[0146] Please refer to Figure 10 , Figure 10 the actual position of the target label in the to-be-detected image is the top-left corner position coordinates (160, 278) and the bottom-right corner position coordinates (231, 567). Since the horizontal coordinate value of the top-left corner position coordinates is 160, which is within the position interval [100, 180], it can be determined that the target label is correctly pasted.
[0147] In some embodiments of this application, after determining that the target label is misapplied, the label detection method may further include:
[0148] The matching template is rotated 180° to obtain the second matching template. The target grayscale image is then subjected to standard squared difference matching processing based on the second matching template to obtain the second position of the target label in the image to be detected. If the second position of the target label in the image to be detected is within the position range, it is determined that the target label is reversed.
[0149] like Figure 11 As shown, Figure 11 This is a schematic diagram of the second matching template in an embodiment of this application. When the x-coordinate value of the upper left corner of the target label is not within the position range, in order to further determine the application effect of the target label, such as the error type of application error, the matching template can be rotated 180° with its own center point as the origin to obtain the second matching template. It can be understood that, for... Figure 4 For the matching template shown, the corresponding second matching template should be as follows: Figure 11 The second matching template shown has a serial number on the left and a barcode on the right. After obtaining this second matching template, it can be used to match... Figure 8 The target grayscale image shown is subjected to standard squared difference matching processing to obtain the second position of the target label in the image to be detected. The calculation process of the second position can refer to the calculation process of the actual position of the target label in the above embodiment, which will not be repeated here.
[0150] Understandably, after obtaining the second position of the target label in the image to be detected, the second position can be compared with the position range again. Specifically, the second position can also include the coordinates of the second upper left corner. If the x-coordinate value of the second upper left corner is within the above position range [100, 180], it can be determined that the target label is pasted upside down. If the x-coordinate value of the second upper left corner is still not within the above position range [100, 180], it can be determined that the target label is missing or omitted.
[0151] In the embodiment of the present application, whether the target label is correctly pasted is determined by comparing the actual position of the target label in the to-be-detected image with the preset position interval. If the actual position of the target label in the to-be-detected image is not within the position interval, a second matching template is obtained by rotating the matching template by 180°, and then the standard square difference matching processing is performed on the target gray image according to the second matching template to obtain a second position of the target label in the to-be-detected image. Then, the second position and the position interval are compared. If the second position is within the position interval, it can be determined that the target label is pasted reversely. Through the method of the present application, not only the actual position of the label can be determined, but also whether the label is pasted reversely can be determined, thereby further improving the accuracy of label detection.
[0152] It should be noted that, in the above embodiment, the matching template is rotated by 180° to obtain the second matching template, which is only an example of the present application. It can be understood that, in some other application scenarios, the target gray image can also be rotated by 180° and then subjected to the standard square difference matching processing with the matching template. Therefore, the object of rotation can be selected according to the actual application scenario, and the specific implementation is not limited here.
[0153] In order to better implement the label detection method in the present application, the present application further provides a label detection device. As shown in Figure 12 The label detection device 1200 provided in the embodiment of the present application is a structure schematic diagram of the label detection device provided in the embodiment of the present application. The label detection device of the present application is applied to a server. The label detection device 1200 comprises:
[0154] A preprocessing module 1201 is configured to perform preprocessing on a to-be-detected image according to preset position information of a target label in the to-be-detected image to obtain a vertical histogram based on pixel values. The pixel values are pixel values of a binary image corresponding to the to-be-detected image.
[0155] A cutting conversion module 1202 is configured to perform cutting conversion processing on the binary image according to the vertical histogram to obtain a target gray image. The target gray image includes the target label.
[0156] A matching module 1203 is configured to perform standard square difference matching processing on the target gray image according to a matching template of the target label to obtain an actual position of the target label in the to-be-detected image.
[0157] A judgment module 1204 is configured to judge whether the target label is correctly pasted according to the actual position of the target label in the to-be-detected image.
[0158] In the embodiments of the present application, the intercepting and converting module 1202 performs intercepting and converting processing on the binary image corresponding to the to-be-detected image according to the vertical histogram to obtain a target grayscale image including a target label, then the matching module 1203 performs standard square difference matching processing on the target grayscale image according to the matching template of the target label to obtain the actual position of the target label in the to-be-detected image, and then the judging module 1204 judges whether the target label is correctly pasted according to the actual position. Compared with the prior art that uses the grayscale histogram of the label as a retrieval template and matches it with the to-be-inspected solar cell panel, the detection result after the standard square difference matching processing is more accurate, and the detection accuracy of the label position is improved.
[0159] In some embodiments of the present application, the preprocessing module 1201 can be specifically used for:
[0160] performing cropping processing on the to-be-detected image according to the preset position information of the target label in the to-be-detected image to obtain a first local image;
[0161] performing binaryzation processing on the first local image to obtain a binary image; wherein the binary image includes white pixel points;
[0162] obtaining a vertical histogram based on pixel values according to the pixel values of the binary image; wherein the horizontal coordinate of the vertical histogram is the width of the binary image, and the vertical coordinate of the vertical histogram is the sum of the pixel values of all white pixel points corresponding to each width value in the binary image.
[0163] In some embodiments of the present application, the binary image also includes black pixel points, and the preprocessing module 1201 can be specifically used for:
[0164] obtaining the average pixel value of all pixel points in the first local image according to the pixel values of all pixel points in the first local image;
[0165] if the pixel value of the pixel point in the first local image is greater than the average pixel value, modifying the pixel value of the pixel point in the first local image to 255 to obtain a white pixel point;
[0166] if the pixel value of the pixel point in the first local image is less than the average pixel value, modifying the pixel value of the pixel point in the first local image to 0 to obtain a black pixel point.
[0167] In some embodiments of the present application, the intercepting and converting module 1202 can be specifically used for:
[0168] determining an intercept starting point according to the vertical histogram; wherein the intercept starting point is a first horizontal coordinate point in the vertical histogram, and the first horizontal coordinate point is the first horizontal coordinate point with a non-zero vertical coordinate value in the vertical histogram;
[0169] The intercept end point is a second abscissa point in the vertical histogram, and the intercept end point is determined according to a preset intercept width;
[0170] The target image is obtained by performing intercept processing on the binary image based on the intercept start point and the intercept end point, and the target image includes the target label;
[0171] The target image is subjected to grayscale processing to obtain a target grayscale image.
[0172] In some embodiments of the present application, the actual position of the target label in the to-be-detected image includes an upper-left corner position coordinate and a lower-right corner position coordinate of the target label in the to-be-detected image, and the matching module 1203 can be specifically configured to:
[0173] The matching result is obtained by traversing the target grayscale image using the matching template based on a normalized square difference matching method, and the matching result includes a normalized square difference value corresponding to each pixel point in the target grayscale image;
[0174] The pixel point corresponding to the smallest normalized square difference value in the matching result is selected as a reference point;
[0175] The upper-left corner position coordinate is obtained by performing offset processing on the reference point according to the intercept start point;
[0176] The lower-right corner position coordinate is obtained according to the size information of the matching template and the upper-left corner position coordinate.
[0177] In some embodiments of the present application, the label detection device 1200 can further include:
[0178] The template acquisition module 1205 is configured to acquire specific position information of the target label in the to-be-detected image, and obtain a label image of the target label according to the specific position information;
[0179] The label image of the target label is subjected to grayscale processing to obtain a label grayscale image, and the label grayscale image is used as a matching template of the target label.
[0180] In some embodiments of the present application, the judgment module 1204 can be specifically configured to:
[0181] The actual position of the target label in the to-be-detected image is compared with a preset position interval;
[0182] If the actual position of the target label in the to-be-detected image is within the position interval, it is determined that the target label is correctly pasted;
[0183] Otherwise, it is determined that the target label is incorrectly pasted.
[0184] In some embodiments of the present application, after it is determined that the target label is incorrectly pasted, the judgment module 1204 can be specifically further configured to:
[0185] rotating the matching template by 180° to obtain a second matching template, performing standard square difference matching processing on the target gray image according to the second matching template to obtain a second position of the target label in the to-be-detected image;
[0186] If the second position of the target label in the to-be-detected image is within the position interval, it is determined that the target label is pasted reversely.
[0187] It should be noted that, in the present application, the related content of the preprocessing module 1201, the intercepting and converting module 1202, the matching module 1203, the judging module 1204 and the template obtaining module 1205 corresponds to the above one by one. As can be clearly understood by those skilled in the art, for the convenience and brevity of description, the specific working process of the label detection device and its corresponding modules described above can be referred to as Figure 2 to Figure 11 The description of the label detection method in any embodiment corresponds, and the specific description is not repeated here.
[0188] In order to better implement the label detection method of the present application, on the basis of the label detection method, the present application further provides a label detection device which integrates any one of the label detection devices provided by the present application. The label detection device comprises a processor 1301, a memory 1302, and a computer program stored in the memory 1302 and executable on the processor 1301. The processor 1301 executes the computer program to realize the steps in the label detection method of any one of the embodiments.
[0189] As shown in Figure 13 , it shows a structural schematic diagram of the label detection device related to the embodiments of the present application. Specifically:
[0190] The device can include a processor 1301 with one or more processing cores, a memory 1302 with one or more computer readable storage media, a power supply 1303 and an input unit 1304, etc. Those skilled in the art can understand that Figure 13 The device structure shown in the figure does not constitute a limitation on the device, and can include more or fewer components than shown, or combine certain components, or different component arrangements. Among them:
[0191] The processor 1301 is a control center of the device, which connects the whole device by using various interfaces and lines, and performs various functions and processes data of the device by running or executing software programs and / or modules stored in the memory 1302 and calling data stored in the memory 1302, thereby monitoring the whole device. Optionally, the processor 1301 can include one or more processing cores; the processor 1301 can be a central processing unit (CPU), and can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs) or other programmable logic devices, discrete gates or transistor logic components, discrete hardware components, etc. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor and the like, preferably, the processor 1301 can integrate an application processor and a modem processor, wherein the application processor mainly processes operating systems, user interfaces, application programs and the like, and the modem processor mainly processes wireless communication. It can be understood that the above-mentioned modem processor can also not be integrated into the processor 1301.
[0192] The memory 1302 can be used to store software programs and modules, and the processor 1301 executes various function applications and data processing by running the software programs and modules stored in the memory 1302. The memory 1302 can mainly include a program storage area and a data storage area, wherein the program storage area can store operating systems, application programs required by at least one function and the like; the data storage area can store data created according to the use of the device and the like. In addition, the memory 1302 can include a high-speed random access memory, and can also include a non-volatile memory, for example, at least one magnetic disk storage device, a flash memory device or other volatile solid-state memory device. Accordingly, the memory 1302 can also include a memory controller to provide the processor 1301 with access to the memory 1302.
[0193] The device also includes a power supply 1303 for supplying power to various components, and preferably, the power supply 1303 can be logically connected to the processor 1301 through a power management system, so as to realize functions such as management of charging, discharging and power consumption management through the power management system. The power supply 1303 can also include one or more direct or alternating current power supplies, recharging systems, power failure detection circuits, power converters or inverters, power state indicators and any other components.
[0194] The device can further include an input unit 1304, which can be used to receive inputted digital or character information, and generate keyboard, mouse, joystick, optical or trackball signal inputs related to user settings and function controls.
[0195] Although not shown, the device can further include a display unit, etc., which will not be described here. In particular in the present application, the processor 1301 in the device will load the executable file corresponding to the process of one or more application programs into the memory 1302 according to the following instructions, and run the application program stored in the memory 1302 by the processor 1301, thereby realizing various functions, as follows:
[0196] According to the preset position information of the target label in the to-be-detected image, the to-be-detected image is preprocessed to obtain a vertical histogram based on pixel values; wherein the pixel values are pixel values of a binary image corresponding to the to-be-detected image;
[0197] According to the vertical histogram, the binary image is intercepted and converted to obtain a target gray image; wherein the target gray image includes the target label;
[0198] According to the matching template of the target label, the target gray image is subjected to standard square difference matching processing to obtain the actual position of the target label in the to-be-detected image;
[0199] According to the actual position of the target label in the to-be-detected image, it is judged whether the target label is correctly pasted.
[0200] Those of ordinary skill in the art can understand that all or part of the steps in the above-mentioned various methods can be completed by instructions, or by related hardware controlled by instructions, which can be stored in a computer readable storage medium and loaded and executed by a processor.
[0201] To this end, the present application provides a computer readable storage medium, which can include a read only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc. The computer readable storage medium stores a computer program, which is executed by a processor to implement the steps in any label detection method provided by the present application. For example, the computer program is executed by the processor to implement the following steps:
[0202] According to the preset position information of the target label in the to-be-detected image, the to-be-detected image is preprocessed to obtain a vertical histogram based on pixel values; wherein the pixel values are pixel values of a binary image corresponding to the to-be-detected image;
[0203] The binary image is intercepted and converted according to the vertical histogram to obtain a target gray image; the target gray image includes a target label;
[0204] The target gray image is processed by standard square difference matching according to a matching template of the target label to obtain an actual position of the target label in the to-be-detected image;
[0205] Whether the target label is correctly pasted is determined according to the actual position of the target label in the to-be-detected image.
[0206] Due to the instructions stored in the computer readable storage medium, the method and device of the present application can be implemented. Figure 2 to Figure 11 According to the steps in the label detection method of any embodiment, the method and device of the present application can be implemented. Figure 2 to Figure 11 The beneficial effects of the label detection method of any embodiment can be achieved, as described above, and will not be repeated here.
[0207] In the above embodiments, the description of each embodiment has its own emphasis, and the parts not described in detail in a certain embodiment can be referred to the detailed description of other embodiments above, which will not be repeated here.
[0208] In the implementation, the above various units or structures can be implemented as independent entities, or can be combined as the same or several entities, and the specific implementation of the above various units or structures can be referred to the above embodiments, which will not be repeated here.
[0209] The above provides a label detection method, device, equipment and computer readable storage medium, and the principle and implementation mode of the present application are described by specific examples; the above description is only used to help understand the method and its core idea; meanwhile, for those skilled in the art, the specific implementation mode and application range will be changed according to the idea of the present application, and the above description should not be understood as the limitation of the present application.
Claims
1. A label detection method, characterized in that, The label detection method includes: Based on the preset position information of the target label in the image to be detected, the image to be detected is preprocessed to obtain a vertical histogram based on pixel values; wherein, the pixel values are the pixel values of the binarized image corresponding to the image to be detected. The binarized image is cropped and transformed according to the vertical histogram to obtain a target grayscale image; wherein the target grayscale image includes the target label; The target grayscale image is subjected to standard squared difference matching processing based on the matching template of the target label to obtain the actual position of the target label in the image to be detected; Based on the actual position of the target label in the image to be detected, determine whether the target label is correctly affixed; After determining that the target label is misplaced, the matching template is rotated 180° to obtain a second matching template. The target grayscale image is then subjected to standard squared difference matching processing based on the second matching template to obtain the second position of the target label in the image to be detected. If the target label is located at a second position within a position range in the image to be detected, then the target label is determined to be reversed; wherein, the second position includes the x-coordinate of the second upper left corner position coordinate, and the position range is [100, 180].
2. The method according to claim 1, characterized in that, The step of preprocessing the image to be detected based on the preset position information of the target label in the image to be detected to obtain a vertical histogram based on pixel values includes: Based on the preset position information of the target label in the image to be detected, the image to be detected is cropped to obtain a first partial image; The first local image is binarized to obtain the binarized image; wherein the binarized image includes white pixels; Based on the pixel values of the binarized image, a vertical histogram based on the pixel values is obtained; wherein, the horizontal axis of the vertical histogram is the width of the binarized image, and the vertical axis of the vertical histogram is the sum of the pixel values of all white pixels corresponding to each width value in the binarized image.
3. The method according to claim 2, characterized in that, The binarized image also includes black pixels; The step of binarizing the first local image to obtain the binarized image includes: The average pixel value of all pixels in the first local image is obtained based on the pixel values of all pixels in the first local image. If the pixel value of a pixel in the first local image is greater than the average pixel value, then the pixel value of the pixel in the first local image is modified to 255 to obtain the white pixel. If the pixel value of a pixel in the first local image is less than the average pixel value, then the pixel value of the pixel in the first local image is modified to 0 to obtain the black pixel.
4. The method according to claim 2, characterized in that, The step of cropping and converting the binarized image based on the vertical histogram to obtain the target grayscale image includes: The starting point for cutting is determined based on the vertical histogram; wherein, the starting point for cutting is the first horizontal coordinate point in the vertical histogram, and the first horizontal coordinate point is the first horizontal coordinate point in the vertical histogram with a non-zero vertical coordinate value; The cut-off endpoint is determined according to the preset cut-off width; wherein, the cut-off endpoint is the second horizontal coordinate point in the vertical histogram; Based on the cropping start point and the cropping end point, the binarized image is cropped to obtain a target image; wherein, the target image includes the target label; The target image is converted to grayscale to obtain the target grayscale image.
5. The method according to claim 4, characterized in that, The actual position of the target label in the image to be detected includes the coordinates of the upper left corner and the lower right corner of the target label in the image to be detected; The step of performing standard squared difference matching processing on the target grayscale image based on the matching template of the target label to obtain the actual position of the target label in the image to be detected includes: Based on the normalized squared difference matching method, the target grayscale image is traversed using the matching template to obtain the matching result; wherein, the matching result includes the normalized squared difference value corresponding to each pixel in the target grayscale image; The pixel corresponding to the smallest normalized squared difference in the matching results is selected as the reference point. The reference point is offset based on the starting point of the cut-off point to obtain the coordinates of the upper left corner. The coordinates of the lower right corner are obtained based on the size information of the matching template and the coordinates of the upper left corner.
6. The method according to claim 1, characterized in that, Before performing standard squared difference matching processing on the target grayscale image based on the matching template of the target label to obtain the actual position of the target label in the image to be detected, the method includes: Obtain the specific location information of the target label in the image to be detected, and obtain the label image of the target label based on the specific location information; The label image of the target label is converted to grayscale to obtain a grayscale label image, which is then used as a matching template for the target label.
7. The method according to any one of claims 1-6, characterized in that, The step of determining whether the target label is correctly affixed based on its actual position in the image to be detected includes: Compare the actual position of the target label in the image to be detected with a preset position range; If the actual position of the target label in the image to be detected is within the position range, then the target label is determined to be correctly applied; Otherwise, the target label is determined to be incorrectly applied.
8. A label detection device, characterized in that, The label detection device includes: The preprocessing module is used to preprocess the image to be detected based on the preset position information of the target label in the image to be detected, and obtain a vertical histogram based on pixel values; wherein, the pixel values are the pixel values of the binarized image corresponding to the image to be detected. The cropping and conversion module is used to perform cropping and conversion processing on the binarized image according to the vertical histogram to obtain a target grayscale image; wherein the target grayscale image includes the target label; The matching module is used to perform standard squared difference matching processing on the target grayscale image according to the matching template of the target label to obtain the actual position of the target label in the image to be detected; The judgment module is used to determine whether the target label is correctly affixed based on its actual position in the image to be detected. It is also used to, after determining that the target label is incorrectly affixed, rotate the matching template by 180° to obtain a second matching template, and perform standard squared difference matching processing on the target grayscale image based on the second matching template to obtain the second position of the target label in the image to be detected. If the second position of the target label in the image to be detected is within a position range, then it is determined that the target label is affixed backwards. The second position includes the abscissa of the second upper left corner position coordinate, and the position range is [100, 180].
9. A label inspection device, characterized in that, The label detection device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. The processor executes the computer program to implement the steps of the label detection method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that is executed by a processor to implement the steps of the tag detection method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Railway ticket character region segmentation method and device
CN109977959A
Icon detection method and device and computer readable storage medium
CN112329851A