Product quantity detection method and device, storage medium and program product

By obtaining gradient information of metal rod images, eliminating background interference and adjusting image posture, the environmental interference and recognition accuracy problems in machine vision detection are solved, and efficient and low-cost rod quantity detection is achieved.

CN120339193APending Publication Date: 2025-07-18MCC CAPITAL ENGINEERING & RESEARCH INC LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510340867.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-07-18

AI Technical Summary

Technical Problem

The existing machine vision detection methods are susceptible to background environment interference during the production process of metal rods, with low recognition accuracy, slow recognition speed, and high deployment cost, so they cannot effectively handle bar counting in tilted state.

Method used

By acquiring multiple images of the product to be detected, determining the edge profile using gradient amplitude and gradient direction, eliminating background interference, stitching the image, and adjusting the product to a horizontal or vertical state according to the average inclination, for accurate detection.

Benefits of technology

It reduces false alarm rate, improves recognition accuracy, reduces single-frame processing time, and reduces hardware deployment costs, achieving accurate detection of the number of metal rods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120339193A_ABST
    Figure CN120339193A_ABST
Patent Text Reader

Abstract

The invention relates to the field of image processing, and discloses a product number detection method and device, a storage medium and a program product, and the method comprises the steps: obtaining at least two first images of a to-be-detected product after a plurality of to-be-detected products enter a detection region; preprocessing each first image to obtain a gradient magnitude and a gradient direction of the first image; based on the gradient magnitude and the gradient direction, determining an edge contour of the first image, and obtaining a second image with the edge contour as a boundary; splicing at least two frames of adjacent second images into a third image; based on the average gradient of the to-be-detected product in the third image, rotating the third image, so that the to-be-detected product in the third image is in a horizontal state or a vertical state, and forming a corrected image; and calculating the number of the to-be-detected products in the corrected image based on the corrected image, and generating a number detection result. According to the method provided by the embodiment of the invention, the number of the to-be-detected products can be accurately detected.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing, and in particular, to a method, device, storage medium and program product for detecting the quantity of products. Background Art

[0002] With the development of the automation level in the industrial field, machine vision processing technology is increasingly widely used in the metal processing industry. For example, in the production process of metal bars, machine vision processing technology is used to detect the quantity of bars to replace the traditional manual detection method. However, the existing vision detection methods still have the following problems:

[0003] 1. Prone to be interfered by the background environment: The environment of the production line is complex. When the machine processes visual images, various background interferences (such as metal reflection, environmental reflection, etc.) are easily misidentified as target bars, resulting in a too high false alarm rate.

[0004] 2. Low recognition accuracy: The existing vision detection methods can only detect straight bars in the image. When the bars in the image are in an inclined state, the endpoints of the bars cannot be accurately located, resulting in missed detections. Or overlapping bars are identified as one bar, resulting in counting errors.

[0005] 3. Slow recognition speed: When the existing vision detection methods process each frame of image, the processing time of each frame of image is greater than 50 milliseconds. When the production line is in rapid production, the detection speed cannot meet the rapid detection requirements of the production line.

[0006] 4. High deployment cost: The existing vision detection methods can improve the recognition accuracy and recognition speed by deploying more advanced hardware, but this will lead to a significant increase in the deployment cost. For example, the existing vision detection methods use deep learning models for target detection, but this method generally requires the use of professional NVIDIA graphics cards to run the learning model, with extremely high costs. Summary of the Invention

[0007] Embodiments of the present invention provide a method, device, storage medium and program product for detecting the quantity of products to solve at least one of the above problems.

[0008] In a first aspect, an embodiment of the present invention provides a method for detecting the quantity of products, including: after a plurality of products to be detected enter a detection area, obtaining at least two first images of the products to be detected; preprocessing each first image to obtain the gradient magnitude and gradient direction of the first image; based on the gradient magnitude and gradient direction, determining the edge contour of the first image and obtaining a second image bounded by the edge contour; stitching at least two adjacent second images into a third image; rotating the third image based on the average inclination of the products to be detected in the third image so that the products to be detected in the third image are in a horizontal state or a vertical state, forming a corrected image; calculating the quantity of the products to be detected in the corrected image based on the corrected image, and generating a quantity detection result of the products to be detected in the horizontal state or the vertical state.

[0009] The method for detecting the quantity of products provided by the embodiment of the present invention can determine the edge contour of the first image according to the gradient magnitude and gradient direction of the first image, eliminate the interference of the background ambient light, extract the second image, and then stitch to obtain the third image. Finally, according to the average inclination of the products to be detected in the third image, the products to be detected in the third image are adjusted to a horizontal state or a vertical state to form a corrected image, realizing the accurate detection of the quantity of the products to be detected, reducing the false alarm rate, and improving the recognition accuracy.

[0010] Optionally, the step of preprocessing each first image to obtain the gradient magnitude and gradient direction of the first image includes: converting the first image into a first grayscale image; performing a filtering process on the first grayscale image to form a filtered image; calculating the horizontal gradient value of the filtered image in the horizontal direction and the vertical gradient value in the vertical direction; and obtaining the gradient magnitude and gradient direction based on the horizontal gradient value and the vertical gradient value.

[0011] Optionally, the step of determining the edge contour of the first image based on the gradient magnitude and gradient direction and obtaining a second image bounded by the edge contour includes: calculating the pixel direction of each pixel in the first image based on the gradient magnitude; comparing the gradient magnitude of each pixel in the first image with the gradient magnitudes of the two adjacent pixels in the gradient direction, and retaining the pixels whose gradient magnitudes are greater than the gradient magnitudes of the two adjacent pixels in the gradient direction; and determining the edge contour of the first image based on all the retained pixels in the first image and obtaining a second image bounded by the edge contour.

[0012] Optionally, based on all the pixels retained in the first image, determining the edge contour of the first image, and the steps of obtaining the second image bounded by the edge contour include: screening strong edge pixels with a gradient magnitude greater than a first threshold among all the pixels retained in the first image, and weak edge pixels with a gradient magnitude less than the first threshold and greater than a second threshold among all the pixels retained in the first image; determining the edge contour of the first image based on the strong edge pixels and the weak edge pixels; screening the boundary pixels with the maximum gradient magnitude among all the strong edge pixels and all the weak edge pixels; determining the bounding box of the edge contour based on the boundary pixels; and extracting the second image bounded by the bounding box from the first image based on the bounding box of the edge contour.

[0013] Optionally, the steps of stitching at least two adjacent second images into a third image include: obtaining the stable points and the direction vector of each stable point of at least two adjacent second images; and stitching at least two adjacent second images into a third image based on the stable points of the second images and the direction vector of each stable point.

[0014] Optionally, the steps of obtaining the stable points and the direction vector of each stable point of at least two adjacent second images include: obtaining at least two adjacent second images; converting each second image into a second grayscale image; detecting the stable points in each second grayscale image, and generating the direction vector corresponding to each stable point.

[0015] Optionally, the steps of stitching at least two adjacent second images into a third image based on the stable points of the second images and the direction vector of each stable point include: performing matching among all the stable points of at least two adjacent second images to obtain similar matching point pairs, where the similar matching point pairs are the two most similar stable points in at least two adjacent second images; generating the corresponding homography matrix based on the similar matching point pairs; filtering the outliers in the homography matrix based on the random sample consensus algorithm to obtain the optimal homography matrix; mapping one of the two adjacent second images to the other second image based on the optimal homography matrix to crop the overlapping part of one of the second images and the other second image; and stitching the cropped one of the second images and the other second image into a third image.

[0016] Optionally, the step of obtaining similar matching point pairs by matching all stable points of at least two second images adjacent in frames includes: matching at least one other second image adjacent to the second image frame, and matching at least one other second image with a frame interval distance from the second image. Among all stable points of the two matched second images, determine the nearest neighbor similar matching point pair and the second nearest neighbor similar matching point pair; calculate the nearest neighbor distance between the stable points in the nearest neighbor similar matching point pair and the second nearest neighbor distance between the stable points in the second nearest neighbor similar matching point pair; calculate the distance ratio of the nearest neighbor distance to the second nearest neighbor distance; compare the distance ratio with the ratio threshold. If the distance ratio is less than the ratio threshold, retain the corresponding nearest neighbor similar matching point pair. If the distance ratio is greater than the ratio threshold, eliminate the corresponding nearest neighbor similar matching point pair, and use the retained nearest neighbor similar matching point pair as the similar matching point pair.

[0017] Optionally, the average inclination of the product to be detected in the third image is obtained based on the following steps: obtaining the initial annotation information of the third image; based on the initial annotation information, obtaining the segmentation boundary points in the third image; based on the segmentation boundary points, calculating the minimum bounding rectangle of each product to be detected; based on the minimum bounding rectangle, calculating the corresponding average inclination of each product to be detected.

[0018] Optionally, the step of calculating the corresponding average inclination of each product to be detected based on the minimum bounding rectangle includes: calculating the rotation angle of each product to be detected based on the minimum bounding rectangle of each product to be detected; calculating the average inclination of each product to be detected based on the rotation angles of all products to be detected.

[0019] Optionally, after forming the corrected image, the method further includes: obtaining the corrected annotation information based on the corrected image, where the corrected annotation information includes the minimum bounding rectangle and the segmentation boundary points of each product to be detected in a horizontal or vertical state; updating the initial annotation information to the corrected annotation information.

[0020] Optionally, the step of rotating the third image based on the average inclination of the product to be detected in the third image so that the product to be detected in the third image is in a horizontal or vertical state to form a corrected image includes: generating a rotation matrix based on the average inclination; calculating the rotation angle of the third image based on the rotation matrix; rotating the third image based on the rotation angle of the third image so that all products to be detected in the third image are in a horizontal or vertical state to form a corrected image.

[0021] In a second aspect, an embodiment of the present invention provides a detection device for the number of products, including: a processor and a memory, where instructions are stored in the memory; the processor calls the instructions in the memory so that the processor executes the method for detecting the number of products according to any one of the foregoing embodiments in the first aspect of the present invention.

[0022] The processor of the detection device for the number of products provided by the embodiments of the present invention executes the method for detecting the number of products according to any one of the foregoing embodiments of the first aspect of the present invention by calling instructions in the memory. It can determine the edge contour of the first image based on the gradient magnitude and gradient direction of the first image, eliminate the interference of the background ambient light, extract the second image, and then splice to obtain the third image. Finally, according to the average inclination of the product to be detected in the third image, the product to be detected in the third image is adjusted to a horizontal state or a vertical state to form a corrected image, realizing the accurate detection of the number of products to be detected, reducing the false alarm rate, and improving the recognition accuracy.

[0023] In a third aspect, the embodiments of the present invention provide a computer-readable storage medium, in which instructions are stored, and when the instructions are executed by a processor, the method for detecting the number of products according to any one of the foregoing embodiments of the first aspect of the present invention is implemented.

[0024] The instructions stored in the computer-readable storage medium provided by the embodiments of the present invention can be called by the processor and execute the method for detecting the number of products according to any one of the foregoing embodiments of the first aspect of the present invention, so as to determine the edge contour of the first image according to the gradient magnitude and gradient direction of the first image, eliminate the interference of the background ambient light, extract the second image, and then splice to obtain the third image. Finally, according to the average inclination of the product to be detected in the third image, the product to be detected in the third image is adjusted to a horizontal state or a vertical state to form a corrected image, realizing the accurate detection of the number of products to be detected, reducing the false alarm rate, and improving the recognition accuracy.

[0025] In a fourth aspect, the embodiments of the present invention provide a computer program product, the computer program product includes a computer program, and when the computer program is executed by a processor, the method for detecting the number of products according to any one of the foregoing embodiments of the first aspect of the present invention is implemented.

[0026] The computer program in the computer program product provided by the embodiments of the present invention can implement the method for detecting the number of products according to any one of the foregoing embodiments of the first aspect of the present invention when executed by a processor, so that the computer program product can determine the edge contour of the first image according to the gradient magnitude and gradient direction of the first image, eliminate the interference of the background ambient light, extract the second image, and then splice to obtain the third image. Finally, according to the average inclination of the product to be detected in the third image, the product to be detected in the third image is adjusted to a horizontal state or a vertical state to form a corrected image, realizing the accurate detection of the number of products to be detected, reducing the false alarm rate, and improving the recognition accuracy. Description of the Drawings

[0027] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the accompanying drawings required for use in the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can be obtained based on the structures shown in these drawings.

[0028] Figure 1 Flow chart of the first embodiment of the detection method for the quantity of products of the present invention;

[0029] Figure 2 Flow chart of step S120 in the first embodiment of the detection method for the quantity of products of the present invention;

[0030] Figure 3 Flow chart of step S130 in the first embodiment of the detection method for the quantity of products of the present invention;

[0031] Figure 4 Flow chart of step S133 in the first embodiment of the detection method for the quantity of products of the present invention;

[0032] Figure 5 Flow chart block diagram from the first image to the second image in the first embodiment of the detection method for the quantity of products of the present invention;

[0033] Figure 6 Flow chart of step S140 in the first embodiment of the detection method for the quantity of products of the present invention;

[0034] Figure 7 Flow chart of step S141 in the first embodiment of the detection method for the quantity of products of the present invention;

[0035] Figure 8 Flow chart of step S142 in the first embodiment of the detection method for the quantity of products of the present invention;

[0036] Figure 9 Flow chart of step S1421 in the first embodiment of the detection method for the quantity of products of the present invention;

[0037] Figure 10 Flow chart block diagram from the second image to the third image in the first embodiment of the detection method for the quantity of products of the present invention;

[0038] Figure 11 Flow chart of step S150 in the first embodiment of the detection method for the quantity of products of the present invention;

[0039] Figure 12 Flow chart of step S154 in the first embodiment of the detection method for the quantity of products of the present invention;

[0040] Figure 13 Another flowchart of step S150 in the first embodiment of the detection method for the number of products of the present invention;

[0041] Figure 14 A comparative curve graph of the convergence results between the detection method for the number of products of the present invention and the prior art;

[0042] Figure 15 A comparative curve graph of the accuracy results between the detection method for the number of products of the present invention and the prior art;

[0043] Figure 16 An image recognition screen in the prior art;

[0044] Figure 17 A corrected image recognition screen in the first embodiment of the detection method for the number of products of the present invention;

[0045] Figure 18 A flowchart of the second embodiment of the detection method for the number of products of the present invention;

[0046] Figure 19 A flowchart from the third image to the corrected image in the first embodiment of the detection method for the number of products of the present invention;

[0047] Figure 20 A structural block diagram of an embodiment of the detection device for the number of products of the present invention. Detailed implementation manners

[0048] Next, the technical solutions in the embodiments of the present invention will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only a part of the embodiments of the present invention, rather than all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present invention.

[0049] It should be noted that all directional indications such as up, down, left, right, front, back... in the embodiments of the present invention are only used to explain the relative position relationship and movement conditions between components in a specific posture as shown in the accompanying drawings. If the specific posture changes, the directional indications will also change accordingly.

[0050] In addition, the descriptions involving "first", "second", etc. in the present invention are only for descriptive purposes and should not be construed as indicating or implying their relative importance or implicitly specifying the quantity of the indicated technical features. Thus, the features defined with "first" and "second" may explicitly or implicitly include at least one of such features. In addition, the technical solutions between various embodiments may be combined with each other, but it must be based on the ability of those of ordinary skill in the art to implement. When the combination of technical solutions results in contradictions or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present invention.

[0051] For the sake of easy understanding, the method for detecting the quantity of products in the embodiments of the present invention will be described below. As Figure 1 shown, the method for detecting the quantity of products in the embodiments of the present invention includes steps S110 to S160.

[0052] In step S110, after multiple products to be detected enter the detection area, at least two first images of the products to be detected are acquired.

[0053] Among them, the multiple products to be detected can be any batch of products. In the present invention, bars are used as an example for description, which does not mean that this method can only be used for detecting the quantity of bars.

[0054] In this embodiment, since the processed bars still have residual heat themselves, a thermal sensor is set in the detection area. After the bars on the production line completely enter the detection area, the thermal sensor is triggered, indicating that the bars have completely entered the detection area, and then the vision module for shooting images of the detection area is controlled to start, and the first images of the bars located in the detection area are taken for subsequent processing and recognition.

[0055] In step S120, each first image is preprocessed to obtain the gradient magnitude and gradient direction of the first image.

[0056] As Figure 2 shown, in some optional embodiments, step S120 includes steps S121 to S124.

[0057] In step S121, the first image is converted into a first grayscale image.

[0058] In step S122, the first grayscale image is filtered to form a filtered image.

[0059] In step S123, the horizontal gradient value of the filtered image in the horizontal direction and the vertical gradient value in the vertical direction are calculated.

[0060] In step S124, based on the horizontal gradient value and the vertical gradient value, the gradient magnitude and gradient direction are obtained.

[0061] As Figure 5 shown, after the first image in this embodiment is grayscaled and filtered, and then subjected to differential processing, the gradient magnitude and gradient direction are calculated to determine the bounding box, obtaining the second image.

[0062] In this embodiment, based on the following formula, the first image is converted into the first grayscale image:

[0063] I(x, y) = 0.299R + 0.587G + 0.114B;

[0064] where R, G, and B are the red, green, and blue component values of each pixel in the first image, 0.299, 0.587, and 0.114 are the corresponding coefficients, and x, y are the coordinates of each pixel in the first image.

[0065] After obtaining the first grayscale image, it is filtered (for example, filtered by the Gaussian filtering algorithm, bilateral filtering algorithm, or other filtering algorithms) to obtain the filtered image, so as to avoid misidentifying image noise as the edge contour of the image when performing differential calculation on the image subsequently.

[0066] After obtaining the filtered image, the horizontal gradient value of each pixel in the filtered image with its adjacent right or left pixel in the horizontal direction, and the vertical gradient value of each pixel with its adjacent lower or upper pixel in the vertical direction are calculated.

[0067] In this embodiment, taking the horizontal gradient value of each pixel in the filtered image with its adjacent right pixel in the horizontal direction as an example, the horizontal gradient value is calculated based on the following formula:

[0068] G x (x, y) = I(x + 1, y) - I(x, y);

[0069] Taking the vertical gradient value of each pixel in the filtered image with its adjacent lower pixel in the vertical direction as an example, the vertical gradient value is calculated based on the following formula:

[0070] G y (x, y) = I(x + 1, y) - I(x, y);

[0071] where G x (x, y) is the horizontal gradient value, G y (x, y) is the vertical gradient value, and I(x, y) is the pixel value of the pixel at the corresponding coordinate.

[0072] After obtaining the horizontal gradient value and the vertical gradient value, according to the following formula, the horizontal gradient value and the vertical gradient value are combined to calculate the gradient magnitude and gradient direction.

[0073]

[0074] Among them, G(x, y) is the gradient magnitude and θ(x, y) is the gradient direction.

[0075] In the embodiment of the present invention, through the edge cutting algorithm based on the difference method, the product to be detected is accurately separated from the image background, the anti-interference performance is improved, and the false detection rate is reduced.

[0076] In step S130, based on the gradient magnitude and the gradient direction, the edge contour of the first image is determined, and a second image with the edge contour as the boundary is obtained.

[0077] As Figure 3 and Figure 5 shown, in some optional embodiments, step S130 includes steps S131 to S133.

[0078] In step S131, based on the gradient magnitude, the pixel direction of each pixel in the first image is calculated.

[0079] In step S132, the gradient magnitude of each pixel in the first image is compared with the gradient magnitudes of two adjacent pixels in the gradient direction, and the pixels with the gradient magnitude greater than the gradient magnitudes of the two adjacent pixels in the gradient direction are retained.

[0080] In step S133, based on all the pixels retained in the first image, the edge contour of the first image is determined, and a second image with the edge contour as the boundary is obtained.

[0081] In this embodiment, through the non-maximum suppression method, the pixels with the maximum gradient magnitude in the gradient direction in the first image are retained to reduce the width of the edge contour of the first image. The non-maximum suppression method in this embodiment can be implemented by a numpy function, and then according to the gradient magnitude of each pixel, the edge contour in the first image is refined to obtain an accurate boundary.

[0082] The pixel direction of each pixel in the first image is calculated according to the gradient magnitude of each pixel. Check the two adjacent pixels before and after the current pixel in this direction. If the gradient magnitude of the current pixel is greater than the gradient magnitudes of these two adjacent pixels, the current pixel is retained; if the gradient magnitude of the current pixel is less than the gradient magnitudes of these two adjacent pixels, the current pixel magnitude is set to 0 (i.e., it is suppressed). The steps to determine the edge contour of the first image are as follows.

[0083] Furthermore, step S133 includes steps S1331 to S1335.

[0084] As Figure 4As shown, in step S1331, strong edge pixels with gradient magnitudes greater than the first threshold among all the pixels retained in the first image, and weak edge pixels with gradient magnitudes less than the first threshold and greater than the second threshold among all the pixels retained in the first image are screened out.

[0085] In step S1332, based on the strong edge pixels and the weak edge pixels, the edge contour of the first image is determined.

[0086] In step S1333, the boundary pixels with the maximum gradient magnitude among all the strong edge pixels and all the weak edge pixels are screened out.

[0087] In step S1334, based on the boundary pixels, the bounding box of the edge contour is determined.

[0088] In step S1335, based on the bounding box of the edge contour, a second image bounded by the bounding box is extracted from the first image.

[0089] As Figure 5 shown, in this embodiment, the gradient magnitude of the first threshold is 255, and the gradient magnitude of the second threshold is 75. By setting a first threshold with a higher value and a second threshold with a lower value, pixels with gradient magnitudes higher than the first threshold are classified as strong edge pixels in the first image, pixels with gradient magnitudes between the first threshold and the second threshold are classified as weak edge pixels in the first image, and pixels with gradient magnitudes less than the second threshold in the first image are suppressed.

[0090] After that, according to the obtained strong edge pixels and weak edge pixels, the find Contours function is used to extract the complete edge contour from the first image. Furthermore, the boundary pixels with the maximum gradient magnitude among all the strong edge pixels and all the weak edge pixels are screened out, and the boundary pixels with the maximum gradient magnitude are used as pixel mutation points and determined as the boundary of the edge contour to obtain the bounding box of the first image.

[0091] Finally, according to the bounding box, the part of the first image outside the bounding box is removed, and the image within the bounding box is retained to obtain the second image.

[0092] In step S140, at least two adjacent second images are stitched together to form a third image.

[0093] As Figure 6 shown, in some alternative embodiments, step S140 includes steps S141 to S142.

[0094] In step S141, the stable points of at least two adjacent second images and the direction vectors of each stable point are obtained.

[0095] As Figure 7As shown, further, step S141 includes steps S1411 to S1413.

[0096] In step S1411, at least two second images with adjacent frames are obtained.

[0097] In step S1412, each second image is converted into a second grayscale image.

[0098] In step S1413, stable points in each second grayscale image are detected, and a direction vector corresponding to each stable point is generated.

[0099] In this embodiment, by converting each second image into a second grayscale image, the amount of calculation is reduced, and the calculation speed of the direction vector corresponding to each stable point is accelerated.

[0100] In this embodiment, edge detection is performed on the second grayscale image at different scales through the ORB (Oriented FAST and Rotated BRIEF) algorithm and the Gaussian pyramid, stable points are screened from the second grayscale image, and a direction vector corresponding to each stable point is generated to describe the local characteristics of each stable point for subsequent image stitching.

[0101] In step S142, based on the stable points of the second image and the direction vector of each stable point, at least two second images with adjacent frames are stitched into a third image.

[0102] As Figure 8 shown, further, step S142 includes steps S1421 to S1425.

[0103] In step S1421, matching is performed among all the stable points of at least two second images with adjacent frames to obtain similar matching point pairs. Among them, a similar matching point pair is the two most similar stable points in at least two second images with adjacent frames.

[0104] In step S1422, a corresponding homography matrix is generated based on the similar matching point pairs.

[0105] In step S1423, based on the random sample consensus algorithm, the outlier points in the homography matrix are filtered to obtain an optimal homography matrix.

[0106] In step S1424, based on the optimal homography matrix, one of the two second images with adjacent frames is mapped to the other second image to crop the overlapping part of one second image and the other second image.

[0107] In step S1425, one of the cropped second images is spliced with the other second image to form a third image.

[0108] As Figure 10 shown, the second image in this embodiment is grayscaled to obtain a second grayscale image. Stable points are obtained according to the ORB algorithm, similar matching point pairs are matched according to the FLANN algorithm to obtain a homography matrix, and then the optimal homography matrix is calculated according to the RACSAC algorithm. Finally, according to the optimal homography matrix, two adjacent-frame second images are spliced to obtain a third image.

[0109] Specifically, in this embodiment, FLANN (Fast Library for Approximate Nearest Neighbors) is used to match similar matching point pairs. According to the KD-Tree algorithm in FLANN, the two most similar stable points in two adjacent-frame second images are matched to obtain similar matching point pairs, and then the corresponding homography matrix is generated. Then, according to RANSAC (Random Sample Consensus algorithm), the outliers in the homography matrix are filtered to obtain the optimal homography matrix.

[0110] Finally, according to the obtained optimal homography matrix, one of the two adjacent-frame second images is mapped to the other second image, the overlapping part of one second image and the other second image is cropped, and the third image is formed by splicing.

[0111] As Figure 9 shown, further, in step S1421, the steps of obtaining similar matching point pairs by matching among all the stable points of at least two adjacent-frame second images include steps S1421A to S1421D.

[0112] In step S1421A, at least one other second image adjacent to the second image frame and at least one other second image with a frame interval distance of one frame from the second image are matched, and the nearest-neighbor similar matching point pair and the second-nearest-neighbor similar matching point pair are determined among all the stable points of the two matched second images.

[0113] In step S1421B, the nearest-neighbor distance between the stable points in the nearest-neighbor similar matching point pair and the second-nearest-neighbor distance between the stable points in the second-nearest-neighbor similar matching point pair are calculated.

[0114] In step S1421C, the distance ratio of the nearest-neighbor distance to the second-nearest-neighbor distance is calculated.

[0115] In step S1421D, the distance ratio is compared with the ratio threshold. If the distance ratio is less than the ratio threshold, the corresponding nearest neighbor similar matching point pair is retained. If the distance ratio is greater than the ratio threshold, the corresponding nearest neighbor similar matching point pair is excluded, and the retained nearest neighbor similar matching point pairs are used as the similar matching point pairs.

[0116] In this embodiment, the nearest neighbor similar matching point pairs are the similar matching point pairs formed by two adjacent stable points, and the next-nearest neighbor similar matching point pairs are the similar matching point pairs formed by two stable points with one stable point in between. When matching the similar matching point pairs, according to the distances between the two stable points in the nearest neighbor similar matching point pairs and the next-nearest neighbor similar matching point pairs respectively, it is detected whether the similar matching point pairs are reliable, and the unreliable similar matching point pairs are excluded, while the reliable similar matching point pairs are retained.

[0117] The ratio threshold in this embodiment is 0.7, that is, if the distance ratio between the nearest neighbor distance and the next-nearest neighbor distance is less than 0.7, it proves that the corresponding nearest neighbor similar matching point pair has high reliability. If the distance ratio between the nearest neighbor distance and the next-nearest neighbor distance is greater than 0.7, it proves that the corresponding nearest neighbor similar matching point pair has low reliability.

[0118] Furthermore, the nearest neighbor similar matching point pairs with high reliability are retained to obtain the similar matching point pairs that can be used to generate the homography matrix. Among them, the specific value of the ratio threshold can be freely set and is not limited in this application.

[0119] In step S150, based on the average inclination of the product to be detected in the third image, the third image is rotated so that the product to be detected in the third image is in a horizontal state or a vertical state, forming a corrected image.

[0120] As Figure 11 shown, in some alternative embodiments, the average inclination of the product to be detected in step S150 is obtained based on steps S151 to S154.

[0121] In step S151, the initial annotation information of the third image is obtained.

[0122] In step S152, based on the initial annotation information, the segmentation boundary points in the third image are obtained.

[0123] In step S153, based on the segmentation boundary points, the minimum bounding rectangles of each product to be detected are calculated.

[0124] In step S154, based on the minimum bounding rectangles, the corresponding average inclinations of each product to be detected are calculated.

[0125] In this embodiment, the initial annotation information includes the bounding box information and the rotation angle information of the third image. According to the initial annotation information, the segmentation boundary points in the third image are determined. Furthermore, based on the segmentation boundary points in the third image, the minimum bounding rectangle and the average inclination of each product to be detected in the third image are calculated for subsequent rotation of the third image.

[0126] As Figure 12 shown, further, step S154 includes steps S1541 to S1542.

[0127] In step S1541, based on the minimum bounding rectangle of each product to be detected, the rotation angle of each product to be detected is calculated.

[0128] In step S1542, based on the rotation angles of all products to be detected, the average inclination of each product to be detected is calculated.

[0129] In this embodiment, according to the rotation angle of each product to be detected, the average inclination of the product to be detected is calculated, so that when the third image is rotated subsequently, it can be ensured that the whole of all products to be detected in the third image is in a horizontal state or a vertical state, which is convenient for quantity detection.

[0130] As Figure 13 shown, further, after step S154, step S150 further includes steps S155 to S157.

[0131] In step S155, based on the average inclination, a rotation matrix is generated.

[0132] In step S156, based on the rotation matrix, the rotation angle of the third image is calculated.

[0133] In step S157, based on the rotation angle of the third image, the third image is rotated so that all products to be detected in the third image are in a horizontal state or a vertical state, forming a corrected image.

[0134] In this embodiment, after the third image is rotated according to the rotation angle, according to the rotation matrix, an affine transformation is performed on the third image, and the same rotation operation is performed on the segmentation boundary points in the third image to keep the geometric relationship between the segmentation boundary points and the rotated third image consistent, so that all products to be detected in the third image are in a horizontal state or a vertical state, forming a corrected image.

[0135] The method in the embodiment of the present invention improves the image recognition accuracy through adaptive rotation correction, realizes the accurate recognition and positioning of the products to be detected, and at the same time, there is no need to further process the image later, reducing the calculation amount and accelerating the recognition speed.

[0136] In step S160, based on the corrected image, calculate the number of products to be detected in the corrected image, and generate a detection result of the number of products to be detected in the horizontal state or the vertical state.

[0137] In this embodiment, based on the finally obtained corrected image, accurate recognition of the product to be detected can be achieved, interference from the image background environment can be avoided, and the accuracy of the detection result of the number of products to be detected can be improved.

[0138] The image processing and recognition method of the first prior art in Table 1 is to process the picture using a fixed threshold segmentation or edge detection algorithm, and combine template matching or Hough transform to count the products to be detected. As Figure 16 shown, the first prior art does not solve the recognition problem and the target overlapping problem in the case of a complex image background. In the case of a complex image background, the background environment will be misrecognized as bars, and it is impossible to accurately distinguish closely arranged bars, and multiple bars are easily recognized as one.

[0139] The second prior art is an image processing and recognition method that uses a deep learning model (such as the YOLO model, the Faster R-CNN model) for target detection. The second prior art does not optimize the model for the bar tilt characteristics, and subsequent further processing is required to correct the calculation results, resulting in a large amount of calculation and an overly long single-frame processing time. When the model recognizes an image, it is easily interfered by the background environment, and the hardware cost required to deploy the model is also extremely high.

[0140] Table 1 is a result comparison table of the detection result indicators of the image of the product to be detected by the method of the first prior art, the detection result indicators of the image of the product to be detected by the second prior art, and the detection result indicators of the image of the product to be detected by the product quantity detection method of the embodiment of the present invention.

[0141] Table 1

[0142] Index Prior Art 1 Prior Art 2 The Present Invention Detection Accuracy Rate 82% 88% ≥98% Single Frame Processing Time 50ms 100ms ≤33ms False Detection Rate due to Background Interference 20% 12% <2% Hardware Cost Low High Medium

[0143] In this embodiment, a learning model can be trained, and the product quantity detection method in the embodiment of the present invention can be implemented according to the trained learning model.

[0144] As shown in Table 1, although the detection accuracy of the second prior art is higher than that of the first prior art and the false detection rate of background interference is lower than that of the second prior art, the hardware cost required to deploy the model of the second prior art is too high. For example, a professional computing card of model H100 is required to smoothly run the model.

[0145] The method of the embodiment of the present invention has greatly improved detection accuracy compared with the prior art 1 and the prior art 2. The single-frame processing time has been reduced to less than 33 ms, and the false detection rate caused by background interference has also been reduced to less than 2%. Moreover, the hardware cost required to deploy the model has also been greatly reduced. For example, the learning model can run smoothly using an RTX 3090 graphics card, and the cost has been significantly reduced compared with professional computing cards.

[0146] As Figure 14 , Figure 15 and Figure 17 shown, Figure 14 the dotted line in Figure 15 represents the convergence result curve graph of the image processing algorithm in the prior art, and the solid line represents the convergence result curve graph of the method in the embodiment of the present invention. Figure 17 The dotted line in

[0147] represents the accuracy result curve graph of the image processing algorithm in the prior art, and the solid line represents the accuracy result curve graph of the method in the embodiment of the present invention. Figure 17 This is the corrected image recognition screen in the embodiment of the present invention.

[0147] From Figure 14 and Figure 15 comparison, it can be obtained that the convergence (corresponding to Total loss) speed of the method of the embodiment of the present invention is faster than that of the prior art, and the convergence speed has been increased by an average of 103.8%, proving that the method of the embodiment of the present invention is more efficient and has less computational complexity. The accuracy (corresponding to mAP) of the method of the embodiment of the present invention is higher than that of the prior method, and the accuracy has been increased by an average of 41.4%, proving that the method of the embodiment of the present invention is more accurate for image recognition.

[0148] Figure 18 This is the flowchart of the second embodiment of the method for detecting the quantity of products of the present invention. Some steps of the second embodiment are the same as those of the first embodiment. The following will explain the differences between the two, and the same parts will not be elaborated.

[0149] As Figure 18 shown, in the second embodiment of the present invention, the method for detecting the quantity of products includes steps S210 to S260.

[0150] In step S210, after multiple products to be detected enter the detection area, at least two first images of the products to be detected are obtained.

[0151] In step S220, each of the first images is preprocessed to obtain the gradient magnitude and gradient direction of the first image.

[0152] In step S230, based on the gradient magnitude and the gradient direction, the edge contour of the first image is determined, and a second image with the edge contour as the boundary is obtained.

[0153] In step S240, at least two adjacent frames of the second images are stitched together to form a third image.

[0154] In step S250, based on the average inclination of the product to be detected in the third image, the third image is rotated so that the product to be detected in the third image is in a horizontal state or a vertical state, forming a corrected image.

[0155] In step S260, based on the corrected image, the number of products to be detected in the corrected image is calculated, generating a detection result of the number of products to be detected in a horizontal state or a vertical state.

[0156] After the corrected image is formed, the method for detecting the number of products in the second embodiment of the present invention further includes steps S270 to S280.

[0157] In step S270, based on the corrected image, corrected annotation information is obtained. The corrected annotation information includes the minimum bounding rectangle and the segmentation boundary points of each product to be detected in a horizontal state or a vertical state.

[0158] In step S280, the initial annotation information is updated to the corrected annotation information.

[0159] In this embodiment, the method for detecting the number of products in the embodiment of the present invention can be implemented by training a learning model and according to the trained learning model.

[0160] As Figure 19 shown, after processing the third image into a corrected image, the initial annotation information is updated to the corrected annotation information of the corrected image and saved. Then, the first image of the product to be detected is processed again to form a corrected image to identify the number of products to be detected. When processing the image according to the updated corrected annotation information, the calculation speed and recognition accuracy of the learning model can be improved.

[0161] The method for detecting the quantity of products provided by the embodiments of the present invention includes: after multiple products to be detected enter the detection area, acquiring at least two first images of the products to be detected; preprocessing each of the first images to obtain the gradient magnitude and gradient direction of the first image; based on the gradient magnitude and the gradient direction, determining the edge contour of the first image, and acquiring a second image with the edge contour as the boundary; stitching at least two adjacent frames of the second images into a third image; based on the average inclination of the products to be detected in the third image, rotating the third image so that the products to be detected in the third image are in a horizontal state or a vertical state, forming a corrected image; based on the corrected image, calculating the quantity of the products to be detected in the corrected image, and generating a quantity detection result of the products to be detected in the horizontal state or the vertical state.

[0162] The method provided by the embodiments of the present invention can determine the edge contour of the first image according to the gradient magnitude and gradient direction of the first image, eliminate the interference of the background ambient light, extract the second image, and then stitch to obtain the third image. Finally, according to the average inclination of the products to be detected in the third image, the products to be detected in the third image are adjusted to a horizontal state or a vertical state to form a corrected image, realizing the accurate detection of the quantity of the products to be detected, reducing the false alarm rate, and improving the recognition accuracy.

[0163] For the above method embodiments, the embodiments of the present invention also provide a Figure 20 product quantity detection device as shown, including: a processor 101 and a memory 102, and instructions are stored in the memory 102; the processor 101 calls the instructions in the memory 102 so that the processor 101 executes the product quantity detection method of any of the foregoing embodiments of the present invention.

[0164] The product quantity detection method of the foregoing of the present invention includes: after multiple products to be detected enter the detection area, acquiring at least two first images of the products to be detected; preprocessing each of the first images to obtain the gradient magnitude and gradient direction of the first image; based on the gradient magnitude and the gradient direction, determining the edge contour of the first image, and acquiring a second image with the edge contour as the boundary; stitching at least two adjacent frames of the second images into a third image; based on the average inclination of the products to be detected in the third image, rotating the third image so that the products to be detected in the third image are in a horizontal state or a vertical state, forming a corrected image; based on the corrected image, calculating the quantity of the products to be detected in the corrected image, and generating a quantity detection result of the products to be detected in the horizontal state or the vertical state.

[0165] The detection device for the number of products provided by the embodiments of the present invention can, by implementing the above method, determine the edge contour of the first image according to the gradient amplitude and gradient direction of the first image, eliminate the interference of background ambient light, extract the second image, and then splice the third image. Finally, according to the average inclination of the product to be detected in the third image, the product to be detected in the third image is adjusted to a horizontal state or a vertical state to form a corrected image, achieving accurate detection of the number of products to be detected, reducing the false alarm rate, and improving the recognition accuracy.

[0166] Further, the detection device for the number of products provided by the embodiments of the present invention may further include a communication interface 103 and a bus 104. The processor 101, the memory 102, and the communication interface 103 are electrically connected through the bus 104.

[0167] Among them, the memory 102 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory. Through at least one communication interface 103 (which can be wired or wireless), a communication connection between this system network element and at least one other network element can be realized. The Internet, wide area network, local area network, metropolitan area network, etc. can be used. The bus 104 can be an ISA bus, a PCI bus, an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of simplicity of representation, Figure 20 only a single bidirectional arrow is used in the figure, but it does not mean that there is only one bus or one type of bus.

[0168] The processor 101 may be an integrated circuit chip with the ability to process signals. In the implementation process, each step of the above method can be completed by the integrated logic circuit of the hardware in the processor 101 or the instructions in the form of software. The above-mentioned processor 101 may be a general-purpose processor, including a central processing unit (CPU for short), a network processor (NP for short), etc.; it may also be a digital signal processor (DSP for short), an application specific integrated circuit (ASIC for short), a field-programmable gate array (FPGA for short), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. It can implement or execute the various methods, steps, and logic block diagrams disclosed in the embodiments of the present invention. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. The steps of the method disclosed in combination with the embodiments of the present invention can be directly embodied as being executed and completed by the hardware decoding processor, or can be executed and completed by the combination of the hardware and software modules in the decoding processor. The software module may be located in a mature storage medium in the art such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. This storage medium is located in the memory 102, and the processor 101 reads the information in the memory 102 and combines its hardware to complete the steps of the method in the foregoing embodiments.

[0169] Embodiments of the present invention also provide a computer-readable storage medium. The computer-readable storage medium may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are run on a computer, the computer is caused to execute the steps of the method for detecting the quantity of the above product.

[0170] The computer-readable storage medium provided by an embodiment of the present invention stores data and computer-executable instructions of the above-mentioned method for detecting the quantity of products. The method for detecting the quantity of products includes: after a plurality of products to be detected enter a detection area, acquiring at least two first images of the products to be detected; preprocessing each of the first images to obtain the gradient magnitude and gradient direction of the first image; based on the gradient magnitude and the gradient direction, determining the edge contour of the first image, and acquiring a second image bounded by the edge contour; splicing at least two adjacent frames of the second images into a third image; based on the average inclination of the products to be detected in the third image, rotating the third image so that the products to be detected in the third image are in a horizontal state or a vertical state, forming a corrected image; based on the corrected image, calculating the quantity of the products to be detected in the corrected image, and generating a quantity detection result of the products to be detected in the horizontal state or the vertical state.

[0171] By implementing the above method, the computer-readable storage medium provided by an embodiment of the present invention can determine the edge contour of the first image according to the gradient magnitude and gradient direction of the first image, so as to eliminate the interference of background ambient light, extract the second image, and then splice the third image. Finally, according to the average inclination of the products to be detected in the third image, the products to be detected in the third image are adjusted to a horizontal state or a vertical state to form a corrected image, realizing the accurate detection of the quantity of the products to be detected, reducing the false alarm rate, and improving the recognition accuracy.

[0172] The present application also provides a computer program product, which is adapted to execute a program initialized with the following method steps when executed on a data processing device:

[0173] After a plurality of products to be detected enter a detection area, acquiring at least two first images of the products to be detected; preprocessing each of the first images to obtain the gradient magnitude and gradient direction of the first image; based on the gradient magnitude and the gradient direction, determining the edge contour of the first image, and acquiring a second image bounded by the edge contour; splicing at least two adjacent frames of the second images into a third image; based on the average inclination of the products to be detected in the third image, rotating the third image so that the products to be detected in the third image are in a horizontal state or a vertical state, forming a corrected image; based on the corrected image, calculating the quantity of the products to be detected in the corrected image, and generating a quantity detection result of the products to be detected in the horizontal state or the vertical state.

[0174] When the computer program in the computer program product provided by the embodiment of the present invention is executed by a processor, it can determine the edge contour of the first image according to the gradient amplitude and gradient direction of the first image, eliminate the interference of the background ambient light, extract the second image, and then splice the third image. Finally, according to the average inclination of the product to be detected in the third image, the product to be detected in the third image is adjusted to a horizontal state or a vertical state to form a corrected image, realizing the accurate detection of the quantity of the product to be detected, reducing the false alarm rate, and improving the recognition accuracy.

[0175] Those skilled in the art can clearly understand that for the convenience and conciseness of description, the specific working processes of the above-described systems, devices, and units can refer to the corresponding processes in the foregoing method embodiments, and will not be described herein again.

[0176] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The foregoing storage medium includes: various media such as USB flash drives, mobile hard disks, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical discs that can store program codes.

[0177] As described above, the above embodiments are only used to illustrate the technical solutions of the present invention, and are not intended to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the various embodiments of the present invention.

Claims

1. A method for detecting the quantity of products, characterized in that, Including: After multiple products to be detected enter the detection area, obtain at least two first images of the products to be detected; Preprocess each of the first images to obtain the gradient magnitude and gradient direction of the first image; Based on the gradient magnitude and the gradient direction, determine the edge contour of the first image, and obtain a second image bounded by the edge contour; Stitch at least two adjacent frames of the second images into a third image; Based on the average inclination of the products to be detected in the third image, rotate the third image so that the products to be detected in the third image are in a horizontal state or a vertical state, forming a corrected image; Based on the corrected image, calculate the number of the products to be detected in the corrected image, and generate a detection result of the number of the products to be detected in the horizontal state or the vertical state.

2. The method for detecting the quantity of products according to claim 1, wherein The step of preprocessing each of the first images to obtain the gradient magnitude and gradient direction of the first image includes: Convert the first image into a first grayscale image; Perform filtering processing on the first grayscale image to form a filtered image; Calculate the horizontal gradient value of the filtered image in the horizontal direction and the vertical gradient value in the vertical direction; Based on the horizontal gradient value and the vertical gradient value, obtain the gradient magnitude and the gradient direction.

3. The detection method of the product quantity according to claim 1, characterized in that, The step of determining the edge contour of the first image based on the gradient magnitude and the gradient direction, and obtaining a second image bounded by the edge contour includes: Based on the gradient magnitude, calculate the pixel direction of each pixel in the first image; Compare the gradient magnitude of each pixel in the first image with the gradient magnitudes of two adjacent pixels in the gradient direction, and retain the pixels whose gradient magnitude is greater than the gradient magnitudes of the two adjacent pixels in the gradient direction; Based on all the pixels retained in the first image, determine the edge contour of the first image, and obtain a second image bounded by the edge contour.

4. The method for detecting the quantity of products according to claim 3, characterized in that, The step of determining the edge contour of the first image based on all the pixels retained in the first image, and obtaining a second image bounded by the edge contour includes: Screen out the strong edge pixels whose gradient magnitude in all the pixels retained in the first image is greater than a first threshold, and the weak edge pixels whose gradient magnitude in all the pixels retained in the first image is less than the first threshold and greater than a second threshold; Based on the strong edge pixels and the weak edge pixels, determine the edge contour of the first image; Screen out the boundary pixels with the largest gradient magnitude among all the strong edge pixels and all the weak edge pixels; Based on the boundary pixels, determine the bounding box of the edge contour; Based on the bounding box of the edge contour, extract the second image bounded by the bounding box from the first image.

5. The detection method of the product quantity according to claim 1, characterized in that, The step of stitching at least two adjacent frames of the second images into a third image includes: Obtain the stable points of at least two adjacent frames of the second images and the direction vectors of each stable point; Based on the stable points of the second image and the direction vectors of each stable point, at least two adjacent frames of the second image are stitched into a third image.

6. The method for detecting the quantity of products according to claim 5, characterized in that, The step of obtaining the stable points of at least two adjacent frames of the second image and the direction vector of each stable point includes: Obtaining at least two adjacent frames of the second image; Converting each second image into a second grayscale image; Detecting the stable points in each second grayscale image and generating a direction vector corresponding to each stable point.

7. The method for detecting the quantity of products according to claim 5, characterized in that, The step of stitching at least two adjacent frames of the second image into a third image based on the stable points of the second image and the direction vector of each stable point includes: Performing matching among all the stable points of at least two adjacent frames of the second image to obtain similar matching point pairs, where the similar matching point pairs are the two most similar stable points in at least two adjacent frames of the second image; Generating a corresponding homography matrix based on the similar matching point pairs; Filtering the outliers in the homography matrix based on the Random Sample Consensus (RANSAC) algorithm to obtain an optimal homography matrix; Mapping one of the two adjacent frames of the second image to the other second image based on the optimal homography matrix to crop the overlapping part of one second image and the other second image; Stitching the cropped one second image and the other second image into the third image.

8. The method for detecting the quantity of products according to claim 7, wherein The step of performing matching among all the stable points of at least two adjacent frames of the second image to obtain similar matching point pairs includes: Matching at least one other second image adjacent to the second image frame and matching at least one other second image with a frame interval of one frame from the second image. Among all the stable points of the two matched second images, determining the nearest neighbor similar matching point pair and the next nearest neighbor similar matching point pair; Calculating the nearest neighbor distance between the stable points in the nearest neighbor similar matching point pair and the next nearest neighbor distance between the stable points in the next nearest neighbor similar matching point pair; Calculating the distance ratio of the nearest neighbor distance to the next nearest neighbor distance; Comparing the distance ratio with a ratio threshold. If the distance ratio is less than the ratio threshold, retaining the corresponding nearest neighbor similar matching point pair. If the distance ratio is greater than the ratio threshold, rejecting the corresponding nearest neighbor similar matching point pair, and taking the retained nearest neighbor similar matching point pairs as the similar matching point pairs.

9. The detection method of the product quantity according to claim 1, characterized in that, The average inclination of the product to be detected in the third image is obtained based on the following steps: Obtaining the initial annotation information of the third image; Obtaining the segmentation boundary points in the third image based on the initial annotation information; Calculating the minimum bounding rectangle of each product to be detected based on the segmentation boundary points; Calculating the corresponding average inclination of each product to be detected based on the minimum bounding rectangle.

10. The method for detecting the quantity of products according to claim 9, wherein, The step of calculating the corresponding average inclination of each product to be detected based on the minimum bounding rectangle includes: Calculate the rotation angle of each of the products to be detected based on the minimum bounding rectangle of each of the products to be detected; Calculate the average inclination of each of the products to be detected based on the rotation angles of all the products to be detected.

11. The method for detecting the quantity of products according to claim 9, wherein After forming the corrected image, the method further includes: Based on the corrected image, obtain corrected annotation information, where the corrected annotation information includes the minimum bounding rectangle and the segmentation boundary points of each of the products to be detected in a horizontal state or a vertical state; Update the initial annotation information to the corrected annotation information.

12. The detection method of the product quantity according to claim 1, characterized in that The step of rotating the third image based on the average inclination of the products to be detected in the third image so that the products to be detected in the third image are in a horizontal state or a vertical state to form a corrected image includes: Generate a rotation matrix based on the average inclination; Calculate the rotation angle of the third image based on the rotation matrix; Rotate the third image based on the rotation angle of the third image so that all the products to be detected in the third image are in a horizontal state or a vertical state to form the corrected image.

13. A detection device for the quantity of products, characterized in that, The detection device for the number of products includes: a processor and a memory, and instructions are stored in the memory; The processor calls the instructions in the memory so that the detection device for the number of products implements the method for detecting the number of products according to any one of claims 1 to 12.

14. A computer-readable storage medium having instructions stored thereon, characterized in that, When the instructions are executed by the processor, the method for detecting the number of products according to any one of claims 1 to 12 is implemented.

15. A computer program product, characterized in that, Including a computer program, when the computer program is executed by the processor, the method for detecting the number of products according to any one of claims 1 to 12 is implemented.