Disclosure of Invention
The invention aims to provide a method, a device and equipment for detecting logistics packages and a readable storage medium, which are used for improving the position detection precision of the logistics packages on a sorting conveyor belt.
In order to achieve the above purpose, the embodiment of the present invention provides the following technical solutions:
a logistics package detection method comprises the following steps:
collecting images of packages on a sorting conveyor belt;
fusing a first data matrix formed by the X coordinate value and a second data matrix formed by the Y coordinate value of each coordinate in the image and the gray value of the image into image information of the image;
processing the image information through a preset detection model to obtain the types of the targets contained in the image information and the position information of a boundary frame covering each target; wherein the object contained in the image information at least comprises: a package and a piano plate.
Wherein the training step of the detection model comprises:
acquiring a training image, and extracting the characteristics of two scales of the training image through a convolution layer and a residual error network layer;
the extracted features are fused and analyzed through a feature processing layer to obtain an analysis result;
determining a detection result of the training image according to the analysis result, wherein the detection result is as follows: the training image comprises detection types of targets and detection position information of a boundary box covering each target;
judging whether the difference between the detection result and the labeling information of the training image meets a preset condition or not through a preset loss function, wherein the labeling information is the real category of each target contained in the training image and the real position information of a boundary box covering each target;
if so, finishing the training of the detection model;
the residual error network layer is formed by arranging a plurality of network sub-layers with different scales from large to small according to the scale size, and the last two network sub-layers in the residual error network layer respectively output the features of the training image with two scales.
The method for obtaining the analysis result by fusing and analyzing the extracted features through the feature processing layer comprises the following steps:
performing convolution and up-sampling on a first feature output by a first network sublayer in the residual error network layer to obtain a target feature with the same size as a second feature output by the second network sublayer in the residual error network layer;
connecting and convolving the target feature and the second feature to obtain a first vector;
performing convolution on the first characteristic, and representing a convolution result by using a vector to obtain a second vector;
and analyzing the first vector and the second vector to obtain the analysis result.
Wherein, still include:
presetting the loss function according to the difference between the detection result and the labeling information, wherein the difference between the detection result and the labeling information at least comprises: the position error of the bounding box covering the same target, the confidence error of whether the target exists in the bounding box covering the same target, and the category error of the same target.
After the training image is acquired, the method further includes:
and recording the marking information of the training image by using an xml file.
Before the fusing the first data matrix formed by the X coordinate values and the second data matrix formed by the Y coordinate values of each coordinate in the image and the gray level value of the image into the image information of the image, the method further comprises:
and preprocessing the image, and converting the preprocessed image into a gray image.
After the processing is performed on the image information through a preset detection model to obtain the categories of the targets included in the image information and the position information of the bounding box covering each target, the method further includes:
and determining whether the position of the parcel needs to be adjusted according to the position information of the bounding box covering the parcel in the image.
A logistics parcel detection apparatus comprising:
the acquisition module is used for acquiring the images of the packages on the package sorting conveyor belt;
the fusion module is used for fusing a first data matrix formed by X coordinate values of all coordinates in the image and a second data matrix formed by Y coordinate values, and the gray value of the image into image information of the image;
the detection module is used for processing the image information through a preset detection model to obtain the category of the targets contained in the image information and the position information of the boundary frame covering each target; wherein the object contained in the image information at least comprises: a package and a piano plate.
A logistics parcel detection apparatus comprising:
a memory for storing a computer program;
a processor, configured to implement the steps of the logistics package detection method according to any one of the above items when executing the computer program.
A readable storage medium, on which a computer program is stored, which when executed by a processor implements the steps of the logistics package detection method of any one of the above.
According to the scheme, the logistics package detection method provided by the embodiment of the invention comprises the following steps: collecting images of packages on a sorting conveyor belt; fusing a first data matrix formed by the X coordinate value and a second data matrix formed by the Y coordinate value of each coordinate in the image and the gray value of the image into image information of the image; processing the image information through a preset detection model to obtain the category of the targets contained in the image information and the position information of a boundary frame covering each target; wherein the object contained in the image information at least comprises: a package and a piano plate.
As can be seen, for the acquired images of the packages on the sorting conveyor belt, the method first fuses a first data matrix formed by X coordinate values and a second data matrix formed by Y coordinate values of each coordinate in the images, and the gray values of the images into image information of the images, that is: the position information of the image is embedded in the image information to facilitate determination of the position information of the object in the image. Further, processing image information containing coordinate information through a preset detection model to obtain the category of the targets contained in the image information and position information of a boundary frame covering each target; wherein the object contained in the image information at least comprises: a package and a piano plate. Therefore, the position information of the boundary frame of each target in the image, namely the position information of each target can be determined, namely the position information of the logistics packages on the sorting conveyor belt is obtained through detection, and the coordinate information of the image is added in the detection process, so that the detection precision of the positions of the logistics packages on the sorting conveyor belt is improved, and the package sorting accuracy can be improved.
Correspondingly, the logistics package detection device, the equipment and the readable storage medium provided by the embodiment of the invention also have the technical effects.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
The embodiment of the invention discloses a method, a device and equipment for detecting logistics packages and a readable storage medium, which are used for improving the position detection precision of the logistics packages on a sorting conveyor belt.
Referring to fig. 2, a method for detecting a logistics package according to an embodiment of the present invention includes:
s201, collecting an image of a package on a sorting conveyor belt;
s202, fusing a first data matrix formed by X coordinate values of all coordinates in the image, a second data matrix formed by Y coordinate values and gray values of the image into image information of the image;
before fusing a first data matrix formed by an X coordinate value and a second data matrix formed by a Y coordinate value of each coordinate in the image and the gray value of the image into image information of the image, the method further comprises the following steps: and preprocessing the image, and converting the preprocessed image into a gray image.
S203, processing the image information through a preset detection model, and obtaining the category of the targets contained in the image information and the position information of the boundary frame covering each target.
Wherein the object contained in the image information at least comprises: a package and a piano plate. The position information of the bounding box includes: the length, width, and center point coordinates of the bounding box, or the coordinates of the four vertices of the bounding box.
Based on the application scene of the invention, the invention only needs to detect whether the position of the parcel is convenient for the scanning of the bar code camera. When the package is positioned in the center of the trolley, the position is an ideal position, and the scanning angle is optimal; when the position of the parcel deviates from the center of the trolley but is still on the trolley, the parcel sorting system can control the trolley to roll so that the parcel is positioned in the center of the trolley; and when the parcel is located the edge of wind instrument board or letter sorting conveyer belt, just can't adjust the position of parcel to can make the parcel fall into wrong letter sorting mouth, or need the position of manual adjustment parcel.
Therefore, in the present embodiment, after the object category included in the image and the position information of the bounding box covering each object are determined, the number and position of each parcel and the number and position of the piano plates included in the current image can be determined. From the obtained location information, it can be determined whether and how the location of the package needs to be adjusted.
The method includes the steps of processing image information through a preset detection model, obtaining the types of targets contained in the image information and position information of a boundary frame covering each target, and further including: and determining whether the position of the parcel needs to be adjusted according to the position information of the bounding box covering the parcel in the image.
Specifically, determining whether the position of the package needs to be adjusted according to the position information of the bounding box covering the package in the image includes: calculating the area of a bounding box covering each target in the image; and determines whether a portion of the package is outside of the sorting conveyor.
When a part of the packages is not positioned outside the sorting conveyor belt, judging whether an overlapping area exists between a boundary frame covering the current package and a boundary frame covering the piano board or not for one package;
if so, calculating the overlapping area M of the boundary frame covering the current parcel and the boundary frame covering the piano plate, and the sum N of the area of the boundary frame covering the current parcel and the area of the boundary frame covering the piano plate; and calculating the ratio of M to N-M, and when the ratio is greater than a preset threshold value, considering that the position of the current parcel needs to be adjusted, and at the moment, generating corresponding adjustment information and sending the adjustment information to a management terminal for displaying so that a worker can perform manual intervention. Wherein N-M represents the difference between N and M.
Similarly, when a part of the parcel is positioned outside the sorting conveyor belt, judging whether an overlapping area exists between a boundary frame covering the current parcel and a boundary frame covering the outside of the sorting conveyor belt or not for one parcel;
if so, calculating the overlapping area M of the boundary frame covering the current package and the boundary frame covering the outside of the sorting conveyor belt, and the sum N of the area of the boundary frame covering the current package and the area of the boundary frame covering the outside of the sorting conveyor belt; and calculating the ratio of M to N-M, and when the ratio is greater than a preset threshold value, determining that the position of the current parcel needs to be adjusted, and controlling the trolley of the sorting conveyor belt to roll so as to enable the current parcel to be positioned on the trolley. Wherein, the outside of the sorting conveyor belt is the position of both sides of the sorting conveyor belt.
As can be seen, the present embodiment provides a method for detecting a logistics package, in which for an acquired image of a package on a sorting conveyor belt, a first data matrix formed by an X coordinate value and a second data matrix formed by a Y coordinate value of each coordinate in the image, and a gray value of the image are fused into image information of the image, that is: the position information of the image is embedded in the image information to facilitate determination of the position information of the object in the image. Further, processing image information containing coordinate information through a preset detection model to obtain the category of the targets contained in the image information and position information of a boundary frame covering each target; wherein the object contained in the image information at least comprises: a package and a piano plate. Therefore, the position information of the boundary frame of each target in the image, namely the position information of each target can be determined, namely the position information of the logistics packages on the sorting conveyor belt is obtained through detection, and the coordinate information of the image is added in the detection process, so that the detection precision of the positions of the logistics packages on the sorting conveyor belt is improved, and the package sorting accuracy can be improved.
Referring to fig. 3, the training step of the detection model includes:
s301, acquiring a training image, and extracting features of two scales of the training image through a convolutional layer and a residual network layer;
s302, fusing and analyzing the extracted features through a feature processing layer to obtain an analysis result;
s303, determining a detection result of the training image according to the analysis result;
wherein, the detection result is as follows: training the detection category of the target contained in the image, and the detection position information of the boundary box covering each target;
s304, judging whether the difference between the detection result and the labeling information of the training image meets a preset condition or not through a preset loss function; if yes, go to S305; if not, executing S306;
the labeling information is the real category of each target contained in the training image and the real position information of a boundary box covering each target;
s305, completing the training of the detection model;
s306, updating the parameters of the detection model by a random gradient descent method, and executing S301.
The residual error network layer is composed of a plurality of network sublayers with different scales from large to small according to the scale size, and the last two network sublayers in the residual error network layer respectively output the features of two scales of the training image.
The extracted features are fused and analyzed through the feature processing layer, and an analysis result is obtained, wherein the method comprises the following steps:
performing convolution and sampling on a first feature output by a first network sublayer in the residual error network layer to obtain a target feature with the same scale as a second feature output by the second network sublayer in the residual error network layer;
connecting and convolving the target feature and the second feature to obtain a first vector;
performing convolution on the first characteristic, and expressing a convolution result by using a vector to obtain a second vector;
and analyzing the first vector and the second vector to obtain an analysis result.
Wherein, still include:
presetting a loss function according to the difference between the detection result and the labeling information, wherein the difference between the detection result and the labeling information at least comprises the following steps: the position error of the bounding box covering the same target, the confidence error of whether the target exists in the bounding box covering the same target, and the category error of the same target.
Wherein, after obtaining the training image, still include: and recording the annotation information of the training image by using the xml file. Namely: the true category of each object in the image and the true position information of the bounding box covering each object are recorded.
In the following, a logistics package detection device provided by an embodiment of the present invention is introduced, and a logistics package detection device described below and a logistics package detection method described above may be referred to each other.
Referring to fig. 4, a logistics package detection apparatus provided in an embodiment of the present invention includes:
an acquisition module 401, configured to acquire an image of a package on a package sorting conveyor;
a fusion module 402, configured to fuse a first data matrix formed by an X coordinate value and a second data matrix formed by a Y coordinate value of each coordinate in the image, and a gray value of the image into image information of the image;
a detection module 403, configured to process the image information through a preset detection model, to obtain a category of an object included in the image information and position information of a bounding box covering each object; wherein the object contained in the image information at least comprises: a package and a piano plate.
Wherein, still include: a training module for training the detection model, comprising:
the acquisition unit is used for acquiring a training image and extracting the characteristics of two scales of the training image through a convolutional layer and a residual network layer;
the analysis unit is used for fusing and analyzing the extracted features through the feature processing layer to obtain an analysis result;
a determining unit, configured to determine a detection result of the training image according to the analysis result, where the detection result is: the detection type of the targets contained in the training image and the detection position information of the boundary box covering each target;
a judging unit, configured to judge, through a preset loss function, whether a difference between the detection result and annotation information of the training image meets a preset condition, where the annotation information is a real category of each target included in the training image and real position information of a bounding box covering each target;
the completion unit is used for completing the training of the detection model when the difference between the detection result and the labeling information of the training image meets the preset condition;
the residual error network layer is formed by arranging a plurality of network sub-layers with different scales from large to small according to the scale size, and the last two network sub-layers in the residual error network layer respectively output the features of the training image with two scales.
Wherein the parsing unit includes:
the sampling subunit is used for performing convolution and up-sampling on a first feature output by a first network sublayer to the last in the residual error network layer to obtain a target feature with the same scale as a second feature output by the second network sublayer to the last in the residual error network layer;
the first convolution subunit is used for connecting and convolving the target feature and the second feature to obtain a first vector;
the second convolution subunit is used for performing convolution on the first feature and expressing a convolution result by using a vector to obtain a second vector;
and the analysis subunit is used for analyzing the first vector and the second vector to obtain the analysis result.
Wherein the training module further comprises:
a presetting unit, configured to preset the loss function according to a difference between the detection result and the labeled information, where the difference between the detection result and the labeled information at least includes: the position error of the bounding box covering the same target, the confidence error of whether the target exists in the bounding box covering the same target, and the category error of the same target.
Wherein the training module further comprises:
and the recording unit is used for recording the marking information of the training image by using the xml file.
Wherein, still include:
and the preprocessing unit is used for preprocessing the image and converting the preprocessed image into a gray image.
Wherein, still include:
and the determining module is used for determining whether the position of the parcel needs to be adjusted according to the position information of the bounding box covering the parcel in the image.
It can be seen that this embodiment provides a commodity circulation parcel detection device, includes: the device comprises an acquisition module, a fusion module and a detection module. Firstly, an acquisition module acquires an image of a package on a package sorting conveyor belt; then a fusion module fuses a first data matrix formed by the X coordinate value and a second data matrix formed by the Y coordinate value of each coordinate in the image and the gray value of the image into image information of the image; finally, the detection module processes the image information through a preset detection model to obtain the category of the targets contained in the image information and the position information of the boundary frame covering each target; wherein the object contained in the image information at least comprises: a package and a piano plate. Therefore, all the modules work in a cooperative manner, and each module plays its own role, so that the detection precision of the position of the logistics packages on the sorting conveyor belt and the accuracy of package sorting are improved.
In the following, a logistics package detection device provided by an embodiment of the present invention is introduced, and a logistics package detection device described below and a logistics package detection method and device described above may be referred to each other.
Referring to fig. 5, a logistics package detection apparatus provided in an embodiment of the present invention includes:
a memory 501 for storing a computer program;
a processor 502, configured to implement the steps of the logistics package detection method according to any of the above embodiments when executing the computer program.
The following describes a readable storage medium provided by an embodiment of the present invention, and a readable storage medium described below and a logistics package detection method, apparatus, and device described above may be referred to each other.
A readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps of the logistics package detection method according to any of the above embodiments.
The following detection model can be designed based on the detection model training procedure provided by the present invention, please refer to fig. 6. The detection model shown in fig. 6 includes: the device comprises a feature extraction module, a feature fusion module and an analysis module, wherein:
the characteristic extraction module comprises a convolution layer and five residual error network blocks, and the characteristic scales extracted by the residual error network blocks are different;
the feature fusion module is used for performing convolution on the features output by the last residual network block, sampling the features to obtain the features with the scale of 26 × 256, connecting the features with the features output by the last residual network block to obtain the features with the scale of 26 × 768, and performing convolution on the features with the scale of 26 × 768 to obtain the features with the scale of 13 × 1024;
and the feature analysis module is used for respectively convolving the two features with the scales of 13 × 1024 and analyzing the two obtained convolution results so as to output the data block.
Wherein, the two obtained convolution results are analyzed, namely: the number and category of targets contained in the current image, the position information of the bounding box covering each target, and the like are determined.
The feature extraction module outputs the feature size of 13 × 1024 "at the end, and the previous layer outputs the feature size of 26 × 512", and the two features are input into the feature fusion module. Wherein, the characteristic of '13 × 1024' is divided into two paths, and one path is convoluted by 3x3 and 1x1 to obtain '13 × 21'; and the other path expands the data block into 26 × 256 through the upsampling layer, then fuses with the second reciprocal feature 26 × 512 to obtain 26 × 768 ", connects the upsampling result with 26 × 512 to obtain 26 × 768", and performs convolution on the feature of 26 × 768 to obtain a feature with the scale of 13 × 1024 ", and performs convolution on the feature of 13 × 1024" through 3 × 3 and 1 × 1 to obtain 26 × 21 ". In this way, two results are obtained: "26 × 21" and "13 × 21".
It should be noted that, because the sizes of the small package and the large package are different from each other, and the size of the gusset is much larger than that of the general package, there are two scales of outputs of the feature extraction module, namely, the 13x13 scale and the 26x26 scale. Wherein the 13x13 scale is used to detect large packages and piano plates, and the 26x26 scale is used to detect small packages.
The two features, 26 × 21 and 13 × 21, pass through a feature analysis module, which extracts category information, coordinate information, and a probability of the presence of a target in the bounding box from the data block. For example: three bounding boxes are obtained through prediction, namely box1, box2 and box3, and the information contained in each bounding box is as follows: x and y represent the abscissa and ordinate, respectively, of the center position of the bounding box, w and h represent the length and width, respectively, of the bounding box, p represents the probability that an object is present within the bounding box, and class1 and class2 represent the class of the object at that location. See FIG. 7 for the analysis results.
Before the image is input into the feature extraction module, a first data matrix composed of X coordinate values and a second data matrix composed of Y coordinate values of each coordinate in the image, and a gray scale value of the image are fused into image information of the image, so as to embed position information in the image information. The image information is shown in fig. 8.
In order to measure the error between the detection result and the real result contained in the output data block, namely: the error between the position information of the boundary frame covering the target A in the detection result and the position information of the boundary frame covering the target A in the real result; the confidence degree of whether the target exists in the boundary box covering the target A in the detection result and the error of the confidence degree of whether the target exists in the boundary box covering the target A in the real result are detected; the class of the object a determined in the detection result and the class of the object a in the real result. The invention presets a loss function according to the difference of the three aspects, and specifically comprises the following steps:
1. the error of the position information of the bounding box is represented by formula (1):
where S denotes the number of meshes divided in the image, B denotes the number of predicted bounding boxes,
indicating whether the jth bounding box in the ith grid covers the current target, wherein a bounding box with a maximum value of Iou from the real bounding box of the current target is a predicted bounding box covering the current target, please refer to fig. 9, where B is 3, the predicted position is the position information of the bounding box covering the target a in the detection result, x 'and y' are coordinates of a center point of the bounding box, w 'is the length of the bounding box, and h' is the width of the bounding box; the real position is the position information of the boundary box covering the target A in the marking information, x and y are the coordinates of the central point of the boundary box, w is the length of the boundary box, and h is the width of the boundary box.
2. The error of the confidence is represented by equation (2):
3. the error of the category is expressed by formula (3), and the category is two types: wrapping and piano plate:
the obtained loss function is the formula (4) by integrating 1, 2 and 3:
Loss=Losscoord+Lossconf+Lossclass(4)
in order to prove the superiority of the invention, different detection methods are adopted to detect the same batch of data, and the detection results are shown in table 1.
TABLE 1
As can be seen from Table 1, Faster R-CNN has higher accuracy but slower processing speed; SSD, Yolo v3, and tiny Yolo have slightly lower accuracy, but faster processing speeds. The accuracy of the invention is closest to that of fast R-CNN, and the processing speed is fastest, thus the invention can ensure the accuracy and improve the processing efficiency.
The present invention was also tested in a practical production environment. 28209 were randomly selected from all the test result graphs collected within one month, and only 3 of the result graphs were missed by manual inspection. That is, the false detection rate of the present invention is only one ten thousandth. The partial effect diagram of the production test is shown in fig. 10, and the pictures are respectively from three different sorting lines.
The embodiments in the present description are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments are referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.