Methods, apparatus, and storage media for item classification and counting based on image recognition
Through the gray transformation, filtering and feature extraction of items, combining the OSTU threshold segmentation method and defect filling and repair, the problem of blurring and statistical rates after the processing of the items is solved, and the accurate counting and recognition of the items are realized.
Patent Information
- Application Number
- CN202011146495.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-10-23
- Publication Date
- 2025-01-28
- Estimated Expiration
- 2040-10-23
AI Technical Summary
In the prior art, the image processing function is insufficient, resulting in the item becoming blurred after the item photo is processed and the statistical rate is inaccurate.
By obtaining the photos of items, perform gray transformation and filtering, extract color characteristics and geometric shape characteristics, use the OSTU threshold segmentation method to improve the quality of the image, fill in the defects of the target area image, and finally realize the accurate count of items.
It improves the visual effect of the image, reduces the judgment of the program's border, improves the recognition speed and accuracy, and reduces the error rate.
Smart Images

Figure CN112365450B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of object recognition statistics, and in particular to a method, device and storage medium for object classification and counting based on image recognition. Background Art
[0002] In production lines or places where items are mixed, items need to be classified and counted. Currently, classification and counting generally adopts manual counting methods. This method is labor-intensive, time-consuming and inefficient.
[0003] Image recognition is a basic technical means of artificial intelligence. At present, image recognition is done by extracting the features of each pixel in the image to be recognized, and comparing them with the features of each pixel in the existing image. When the similarity of the features of the compared pixels is within the set range, the object in the existing image is output as the object in the image to be recognized. However, the problem is that the image processing function is insufficient: the object becomes blurred after the photo of the object is processed, and the processing of the photo of the object is missing, resulting in inaccurate statistics. Summary of the invention
[0004] The purpose of the present invention is to provide a method, device and storage medium for object classification and counting based on image recognition to solve the problems raised in the above background technology.
[0005] To achieve the above object, the present invention provides the following technical solutions:
[0006] A method for classifying and counting objects based on image recognition, comprising:
[0007] Image acquisition: Get photos of objects;
[0008] Image preprocessing: select the photo of the object, transform the grayscale of the photo, and then filter it to obtain a binary image;
[0009] Object feature extraction: Extract color features from binary images, then grayscale the image, extract the object contour and geometric shape features, and then obtain the target area image by subtracting the original image from the binary image.
[0010] Image quality improvement: fill and repair defects in the target area image to obtain an optimized binary image;
[0011] Object counting: The optimized binary image is scanned and identified in sequence up and down and left and right to obtain the number of objects.
[0012] Preferably, the grayscale transformation uses a weighted average method to grayscale the leaves, and converts the 32-bit RGB image into a 256-bit grayscale image through the formula: G=0.299r+0.587g+0.114b, where: G is the grayscale value, r, g, and b are the values of the red, green, and blue components in the RGB image, respectively, and the filtering process is a median filter.
[0013] Preferably, the color feature is extracted by using a color histogram; the image grayscale processing includes: reading 24-bit values of three primary colors, defining a proportional transformation matrix Determine the grayscale value: M max =255; Mmin=0 to get the gray to inverse function, determine the transformation function and equalization coefficient: Pr=0.3, Pg=0.59, Pb=0.11, realize equalization, gray and frequency adjustment, and complete the purpose of gray image processing, where: gray value gray=r=g=b, r=r*S r , g=g*S g , b=b*S b , S r , S g , S b are the grayscale values of the transformed image R, G, and B, respectively, and M max 、M min Corresponding to the white grayscale value and the black grayscale value respectively; the extracting of the object contour includes: using the OSTU threshold segmentation method to first remove most of the background grayscale from the histogram, and then using the OSTU threshold segmentation method to perform a secondary segmentation on the remaining object and shadow parts after removing the background; the extracting of the geometric shape feature includes: calculating several area-based geometric parameters of the object according to the extracted object contour, including the area, major axis, minor axis, average distance from the center of gravity of the area to the boundary of the object, and the mean square error of the distance from the center of gravity of the area to each point on the boundary.
[0014] Preferably, the OSTU threshold segmentation method includes: setting the threshold value obtained by the first OSTU threshold segmentation as q0, and performing the second OSTU threshold segmentation on the gray levels 0 to q based on this threshold value: first calculating the average grayscale of the pixels between the gray levels 0 to q Then calculate the variance with 1, 2, 3…k…q-1 as the threshold:
[0015] The k corresponding to the maximum variance is the threshold obtained by two OSTU threshold segmentations.
[0016] Preferably, the defect filling and repair of the target area image adopts the method of taking the target pixel as the center point, and when at least one pixel in the four neighborhoods above, below, left and right has a different grayscale from the target pixel, the grayscale of the center point is replaced by a grayscale of 255 (black), so as to achieve the purpose of eliminating white point noise.
[0017] Preferably, the ratio of the area of the region to the product of the major axis and the minor axis is the rectangularity of the object, and the ratio of the average distance from the center of gravity of the region to the boundary of the object and the mean square deviation of the distances from the center of gravity of the region to each point on the boundary is the roundness of the object.
[0018] To achieve the above object, the present invention also provides the following technical solutions:
[0019] A device for classifying and counting objects based on image recognition, comprising:
[0020] The acquisition module is used to obtain photos of items;
[0021] The preprocessing module is used to transform the grayscale of the object photo and then filter it to obtain a binary image;
[0022] The feature extraction module is used to extract color features based on the binary image, then grayscale the image, and then extract the contour and geometric shape features of the object in sequence, and then obtain the target area image by subtracting the original image from the binary image;
[0023] A quality improvement module fills and repairs defects in the target area image to obtain an optimized binary image; and
[0024] The counting module scans and identifies the optimized binary image in top-bottom and left-right order to obtain the number of objects.
[0025] To achieve the above object, the present invention also provides the following technical solutions:
[0026] A computer device comprises a memory and a processor, wherein the memory stores a computer program, and wherein the processor implements the steps of any of the above methods when executing the computer program.
[0027] To achieve the above object, the present invention also provides the following technical solutions:
[0028] A computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps of any of the methods described above.
[0029] Compared with the prior art, the present invention has the following beneficial effects:
[0030] The present invention can filter out smaller impurities in the object image through the first grayscale processing, reduce the area of larger impurities and lighten the color. While removing the impurities, the object part does not become very blurred. The second grayscale processing can make the details of the image clear and improve the visual effect of the image. The OSTU threshold segmentation method is used to improve the image quality and make the image area complete. This can reduce the program's judgment on the border and improve the speed. At the same time, the geometric shape features are extracted to reduce the error rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 A block diagram of a method for classifying and counting objects based on image recognition according to the present invention;
[0032] Figure 2 It is a schematic diagram of a grayscaled object of the present invention;
[0033] Figure 3 This is a schematic diagram of the median filtering method of the present invention to reduce white spots and impurities on an object;
[0034] Figure 4 A schematic diagram of a binary image obtained by secondary OSTU threshold segmentation of the present invention;
[0035] Figure 5 A block diagram of a device for classifying and counting objects based on image recognition according to the present invention;
[0036] Figure 6 is an internal structural diagram of a computer device of the present invention;
[0037] Figure 7 It is a schematic diagram of the object piece image feature extraction, recognition method and counting method of the present invention. DETAILED DESCRIPTION
[0038] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0039] See also Figures 1 to 7 , the present invention provides a technical solution:
[0040] A method for classifying and counting objects based on image recognition, comprising:
[0041] S101, image acquisition: acquiring a photo of an object;
[0042] S102, image preprocessing: select a photo of the object, transform the grayscale of the photo, and then perform filtering to obtain a binary image;
[0043] S103, feature extraction of the object: extract color features from the binary image, then grayscale the image, extract the contour and geometric shape features of the object in sequence, and then obtain the target area image by subtracting the original image from the binary image;
[0044] S104, improving the quality of the image: filling and repairing the defects in the target area image to obtain an optimized binary image;
[0045] S105, object counting: scanning and identifying the optimized binary image in top-bottom and left-right order to obtain the number of objects.
[0046] Specifically, the grayscale transformation uses a weighted average method to grayscale the leaves, converting the image from the RGB color space to the grayscale space. First, the 32-bit RGB image is converted to a 256-bit grayscale image through the formula: G = 0.299r + 0.587g + 0.114b, where G is the grayscale value, r, g, and b are the values of the red, green, and blue components of the RGB image, respectively. The filtering process is median filtering. In order to reduce the interference of noise on the image processing link, the median filtering method is used to reduce the noise of the image, that is, a window with an odd number of points is used, and the value of the center point of the window is replaced by the median of each point in the window. By Figure 2-3 It can be seen that the smaller impurities have been basically filtered out, and the larger impurities have become smaller in area and lighter in color, making them easy to process in the subsequent binarization. While removing impurities, the object part does not become very blurred, and the result is good.
[0047] Specifically, the color feature is extracted by using a color histogram; the image grayscale processing includes: reading the 24-bit values of the three primary colors, defining a proportional transformation matrix Determine the grayscale value: M max =255; Mmin=0 to get the gray to inverse function, determine the transformation function and equalization coefficient: Pr=0.3, Pg=0.59, Pb=0.11, realize equalization, gray and frequency adjustment, and complete the purpose of gray image processing, where: gray value gray=r=g=b, r=r*S r , g=g*S g , b=b*S b , S r , S g , S b are the grayscale values of the transformed image R, G, and B, respectively, and M max 、M min They correspond to white grayscale value and black grayscale value respectively, such as Figure 3As shown, a better image grayscale processing effect is achieved, making the details of the image clear and improving the visual effect of the image.
[0048] The object contour extraction includes: first removing most of the background grayscale from the histogram using the OSTU threshold segmentation method, and then performing a secondary segmentation of the remaining object and shadow parts using the OSTU threshold segmentation method after removing the background. Specifically, the OSTU threshold segmentation method includes: setting the threshold value obtained by the first OSTU threshold segmentation as q0, and performing a second OSTU threshold segmentation on the grayscale 0 to q based on this: first calculating the average grayscale of the pixels between the grayscale 0 to q Then calculate the variance with 1, 2, 3...k...q-1 as thresholds:
[0049] The k corresponding to the maximum variance is the threshold value obtained by two OSTU threshold segmentations, dw gray: image grayscale (value). The defect filling and repairing of the target area image adopts the method of taking the target pixel as the center point, and replacing the grayscale of the center point with the grayscale of 255 when at least one pixel in the four neighboring areas above, below, left and right is different from the grayscale of the target pixel, so as to achieve the purpose of eliminating white point noise. Figure 4 As shown in the figure, after the feature extraction of the object, the image of the object still has some defects, such as many burrs on the edge of the object, white pixels in some areas, or being cut or missing. The OSTU threshold segmentation method is used to improve the image quality and make the image area complete, which can reduce the program's judgment on the border, increase the speed, and reduce the error rate.
[0050] The extraction of geometric shape features includes: calculating several region-based geometric parameters of the object based on the extracted object contour, including the area of the region, the major axis, the minor axis, the average distance from the center of gravity of the region to the boundary of the object, and the mean square error of the distance from the center of gravity of the region to each point on the boundary. The ratio of the product of the area of the region to the major axis and the minor axis is the rectangularity of the object, and the ratio of the average distance from the center of gravity of the region to the boundary of the object and the mean square error of the distance from the center of gravity of the region to each point on the boundary is the roundness of the object. By extracting geometric shape features, the recognition rate can be effectively improved, and automatic classification of objects can be achieved.
[0051] The present invention can filter out smaller impurities in the object image through the first grayscale processing, reduce the area of larger impurities and lighten the color. While removing the impurities, the object part does not become very blurred. The second grayscale processing can make the details of the image clear and improve the visual effect of the image. The OSTU threshold segmentation method is used to improve the image quality and make the image area complete. This can reduce the program's judgment on the border and improve the speed. At the same time, the geometric shape features are extracted to reduce the error rate.
[0052] Although embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions and variations may be made to the embodiments without departing from the principles and spirit of the present invention, and that the scope of the present invention is defined by the appended claims and their equivalents.
Claims
1. A method for object classification and counting based on image recognition, characterized in that: include: Image acquisition: Get photos of objects; Image preprocessing: select the photo of the object, transform the grayscale of the photo, and then filter it to obtain a binary image; Object feature extraction: Extract color features from binary images, then grayscale the image, extract the object contour and geometric shape features, and then obtain the target area image by subtracting the original image from the binary image. Image quality improvement: fill and repair defects in the target area image to obtain an optimized binary image; Object counting: Scan and identify the optimized binary image in top-bottom and left-right order to obtain the number of objects; The color feature is extracted by using a color histogram; the image grayscale processing includes: reading the 24-bit values of the three primary colors, defining a proportional transformation matrix Determine the grayscale value: M max =255; Mmin=0 to get the gray to inverse function, determine the transformation function and equalization coefficient: Pr=0.3, Pg=0.59, Pb=0.11, achieve equalization, gray and frequency adjustment, and complete the purpose of gray image processing, where: gray value gray=r=g=b, r=r*S r , g=g*S g , b=b*S b , S r , S g , S b are the grayscale values of the transformed image R, G, and B, respectively, and M max 、M min Corresponding to the white grayscale value and the black grayscale value respectively; extracting the object contour includes: using the OSTU threshold segmentation method to first remove most of the background grayscale from the histogram, and then using the OSTU threshold segmentation method to perform secondary segmentation on the remaining object and shadow parts after removing the background; extracting the geometric shape features includes: calculating several area-based geometric parameters of the object according to the extracted object contour, including area, major axis, minor axis, average distance from the center of gravity of the area to the boundary of the object, and mean square error of the distance from the center of gravity of the area to each point on the boundary; The OSTU threshold segmentation method includes: setting the threshold value obtained by the first OSTU threshold segmentation as q0, and performing the second OSTU threshold segmentation on the gray levels 0 to q based on this threshold value: firstly calculating the average gray level of the pixels between the gray levels 0 to q Then calculate the variance with 1, 2, 3...k...q-1 as thresholds: The k corresponding to the maximum variance is the threshold obtained by two OSTU threshold segmentations.
2. The method for classifying and counting objects based on image recognition according to claim 1, characterized in that: The grayscale transformation uses a weighted average method to grayscale the leaves, and converts the 32-bit RGB image into a 256-bit grayscale image through the formula: G=0.299r+0.587g+0.114b, where: G is the grayscale value, r, g, and b are the values of the red, green, and blue components in the RGB image, respectively, and the filtering process is a median filter.
3. The method for classifying and counting objects based on image recognition according to claim 1, characterized in that: The defect filling and repair of the target area image adopts the target pixel as the center point. When at least one pixel in the four neighboring areas above, below, left and right has a different grayscale from the target pixel, the grayscale of the center point is replaced by a grayscale of 255, so as to achieve the purpose of eliminating white point noise.
4. The method for classifying and counting objects based on image recognition according to claim 3, characterized in that: The ratio of the area of the region to the product of the major axis and the minor axis is the rectangularity of the object, and the ratio of the average distance from the center of gravity of the region to the boundary of the object and the mean square deviation of the distance from the center of gravity of the region to each point on the boundary is the roundness of the object.
5. A device for classifying and counting objects based on image recognition, characterized in that: include: The acquisition module is used to obtain photos of items; The preprocessing module is used to transform the grayscale of the object photo and then filter it to obtain a binary image; The feature extraction module is used to extract color features based on the binary image, then grayscale the image, and then extract the contour and geometric shape features of the object in sequence, and then obtain the target area image by subtracting the original image from the binary image; A quality improvement module fills and repairs defects in the target area image to obtain an optimized binary image; and A counting module scans and identifies the optimized binary image in top-bottom and left-right order to obtain the number of objects; The color feature is extracted by using a color histogram; the image grayscale processing includes: reading the 24-bit values of the three primary colors, defining a proportional transformation matrix Determine the grayscale value: M max =255; Mmin=0 to get the gray to inverse function, determine the transformation function and equalization coefficient: Pr=0.3, Pg=0.59, Pb=0.11, achieve equalization, gray and frequency adjustment, and complete the purpose of gray image processing, where: gray value gray=r=g=b, r=r*S r , g=g*S g , b=b*S b , S r , S g , S b are the grayscale values of the transformed image R, G, and B, respectively, and M max 、M min Corresponding to the white grayscale value and the black grayscale value respectively; extracting the object contour includes: using the OSTU threshold segmentation method to first remove most of the background grayscale from the histogram, and then using the OSTU threshold segmentation method to perform secondary segmentation on the remaining object and shadow parts after removing the background; extracting the geometric shape features includes: calculating several area-based geometric parameters of the object according to the extracted object contour, including area, major axis, minor axis, average distance from the center of gravity of the area to the boundary of the object, and mean square error of the distance from the center of gravity of the area to each point on the boundary; The OSTU threshold segmentation method includes: setting the threshold value obtained by the first OSTU threshold segmentation as q0, and performing the second OSTU threshold segmentation on the gray levels 0 to q based on this threshold value: firstly calculating the average gray level of the pixels between the gray levels 0 to q Then calculate the variance with 1, 2, 3...k...q-1 as thresholds: The k corresponding to the maximum variance is the threshold obtained by two OSTU threshold segmentations.
6. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
7. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Detection method for vehicle license plate real-time positioning character segmentation
CN101789080A
Quantitative core stereo microscopic image description method
CN108830877A
