CN-122024224-A - Fruit and vegetable shape sorting method and system
Abstract
The application discloses a fruit and vegetable shape sorting method and system, which relate to machine identification, wherein foreground and background segmentation is carried out on image data, and long half shafts respectively corresponding to N angle images are calculated through an ellipse fitting algorithm according to external contour coordinates of fruits and vegetables in foreground images To Short half shaft To Calculating the eccentricity of each of the N angle images To To long half axle To Sorting, namely judging the difference value between the rest long half shafts and the maximum half shafts by taking the sorted maximum half shafts as a reference, acquiring images with the difference value smaller than a preset first threshold value to obtain an effective image set, acquiring the maximum eccentricity and the minimum eccentricity corresponding to the long half shafts in the effective image set when the number of the images in the effective image set is larger than the preset number threshold value, and judging the corresponding fruits and vegetables as flat fruits when the difference value between the maximum eccentricity and the minimum eccentricity is larger than a preset second threshold value, otherwise judging the fruits and vegetables as non-flat fruits. The application aims to improve the recognition accuracy of the flat fruits.
Inventors
- WANG HAIBIN
- WANG YANG
- GONG LE
- WANG ZHENG
Assignees
- 安徽唯嵩光电科技有限公司
Dates
- Publication Date
- 20260512
- Application Date
- 20251224
Claims (9)
- 1. A method for sorting fruit and vegetable shapes, which is characterized by comprising the following steps: S1, acquiring image data of N angles of a target fruit and vegetable; S2, performing foreground and background segmentation on the image data to obtain a foreground image only containing fruits and vegetables; S3, calculating long half shafts corresponding to the N angle images respectively through an ellipse fitting algorithm according to external contour coordinates of fruits and vegetables in the foreground images To the point of Short half shaft To the point of ; According to the long half shaft To the point of Short half shaft To the point of Calculating the eccentricity of each of the N angle images To the point of ; S4, for a long half shaft To the point of Sequencing, namely judging the difference value between the rest of the long half shafts and the maximum half shaft by taking the sequenced maximum half shaft as a reference, and acquiring images with the difference value smaller than a preset first threshold value to obtain an effective image set; S5, when the number of images in the effective image set is larger than a preset number threshold, obtaining a maximum eccentricity and a minimum eccentricity corresponding to a long half axis in the effective image set; And when the difference between the maximum eccentricity and the minimum eccentricity is larger than a preset second threshold, judging the corresponding fruits and vegetables as flat fruits, and otherwise judging the fruits and vegetables as non-flat fruits.
- 2. The fruit and vegetable shape sorting method according to claim 1, characterized in that: Performing foreground and background segmentation on image data, comprising: Converting the image data into a gray scale image; Edge detection is carried out on the gray level image through a Sobel operator, and gradient information in the directions of the x axis and the y axis is calculated And Obtaining a gradient image; performing binarization segmentation on the gradient image by adopting an Ojin binarization method to obtain a binarized edge image, and performing closing treatment on the binarized edge image through morphological closing operation to obtain a closed region; extracting the outline of the fruits and vegetables according to the closed region to obtain a mask image of the fruits and vegetables region; And performing AND operation on the image data and the fruit and vegetable area mask image to obtain a foreground image only containing fruits and vegetables.
- 3. The fruit and vegetable shape sorting method according to claim 2, characterized in that: Calculating long half shafts respectively corresponding to the N angle images through an ellipse fitting algorithm To the point of Short half shaft To the point of Comprising: extracting external contours of fruits and vegetables from the foreground image to obtain coordinate data of the contours; Carrying out ellipse fitting on the coordinate data of the contour by adopting Taubin weighting method to obtain an ellipse equation; According to an elliptic equation, respectively calculating long half shafts corresponding to the N angle images To the point of Short half shaft To the point of 。
- 4. A fruit and vegetable shape sorting method according to claim 3, characterized in that: According to the long half shaft To the point of Short half shaft To the point of Calculating the eccentricity of each of the N angle images To the point of Comprising: ; Wherein, the A short half shaft which is the ith angle; is the long half shaft of the ith angle.
- 5. The fruit and vegetable shape sorting method according to claim 3 or 4, characterized in that: The second threshold value is 。
- 6. The fruit and vegetable shape sorting method according to claim 5, wherein: computing gradient information in x-axis and y-axis directions And Obtaining a gradient image, comprising: Wherein, the Representing the gray value at the image (x, y).
- 7. The fruit and vegetable shape sorting method according to claim 6, wherein: performing AND operation on the image data and the fruit and vegetable area mask image, wherein the AND operation comprises the following steps: performing AND operation on the RGB value of each pixel point in the image data and the mask value of the pixel point at the corresponding position in the mask image of the fruit and vegetable area; When the mask value of the pixel point in the fruit and vegetable area mask image is 0, setting the RGB value of the pixel point at the corresponding position in the image data to be 0; and obtaining a foreground image only containing fruits and vegetables.
- 8. The fruit and vegetable shape sorting method of claim 7, wherein: after extracting the fruit and vegetable outline according to the closed area and before obtaining the fruit and vegetable area mask image, the method further comprises the following steps: performing morphological corrosion operation on the closed region, setting the corrosion times to be M times, and eliminating the pedicel region of the outer boundary of the fruits and vegetables through the M corrosion operations; morphological expansion operation is carried out on the closed area after the corrosion operation, wherein the expansion times are M times which are the same as the corrosion times, so that boundary information of the fruit and vegetable main body is recovered; and extracting the outline of the fruits and vegetables based on the closed area after the expansion operation, and obtaining the mask image of the fruits and vegetables area after the influence of the pedicel is eliminated.
- 9. A fruit and vegetable shape sorting system implementing the method of any one of claims 1 to 8, comprising: the image acquisition module is used for acquiring image data of N angles of the target fruits and vegetables; The foreground and background segmentation module is used for carrying out foreground and background segmentation on the image data to obtain a foreground image only containing fruits and vegetables; The feature extraction module calculates long half shafts corresponding to the N angle images respectively through an ellipse fitting algorithm according to the external contour coordinates of fruits and vegetables in the foreground images To the point of Short half shaft To the point of And according to the long half shaft To the point of Short half shaft To the point of Calculating the eccentricity of each of the N angle images To the point of ; Image screening module for long half shaft To the point of Sequencing, namely judging the difference value between the rest of the long half shafts and the maximum half shaft by taking the sequenced maximum half shaft as a reference, and acquiring images with the difference value smaller than a preset first threshold value to obtain an effective image set; The flat fruit judging module is used for acquiring the maximum eccentricity and the minimum eccentricity corresponding to the long half shafts in the effective image set when the number of the images in the effective image set is larger than a preset number threshold value, judging the corresponding fruits and vegetables as flat fruits when the difference between the maximum eccentricity and the minimum eccentricity is larger than a preset second threshold value, and otherwise judging the fruits and vegetables as non-flat fruits.
Description
Fruit and vegetable shape sorting method and system Technical Field The application relates to the field of machine vision, in particular to a fruit and vegetable shape sorting method and system. Background Early fruit quality detection and classification mainly rely on the manual work to accomplish, have intensity of labour big, work efficiency low problem, and receive the influence of inspector subjective factor easily, are difficult to guarantee classification standard's uniformity. With the rapid increase of fruit market sales and the continuous improvement of consumer demand for fruit quality, traditional manual sorting methods have failed to meet market demands. In recent years, with the rapid development of camera technology and machine learning technology, automated fruit sorting equipment has been widely used. The existing fruit sorting machine usually utilizes a camera to shoot a plurality of images of fruits on a conveyor belt, identifies appearance flaw features of the fruits through an image processing technology and a machine learning algorithm, sorts and grades the fruits by combining weight information acquired by a sensor, and remarkably improves sorting efficiency and accuracy. With the increasing refinement of fruit grading market standards, in addition to identifying the type and extent of appearance defects, precise differentiation of the shape characteristics of the fruit is also required. Taking kiwi fruits as an example, different varieties have typical differences in fruit shapes and are mainly divided into flat fruit kiwi fruits and non-flat fruit kiwi fruits. In the actual production process, the flat fruit kiwi fruits are required to be accurately screened out so as to achieve the purpose of fine grading, and meanwhile, the quality of the fruits and vegetables is not easy to damage in the sorting process. However, when the existing fruit and vegetable shape sorting method is used for carrying out ellipse fitting to extract shape characteristics, the shape sorting method is easy to be interfered by auxiliary structures such as pedicles and the like, so that the major axis of the fitted ellipse is abnormally increased, the recognition accuracy of flat fruits is reduced, and the actual requirements of fine classification cannot be met. Disclosure of Invention Aiming at the problem that auxiliary structures such as pedicles and the like interfere with ellipse fitting precision in the fruit and vegetable shape sorting process in the prior art, the application provides a fruit and vegetable shape sorting method and system, which are used for screening an effective image set according to a long-half-shaft difference value and judging flat fruits based on an eccentricity difference value, so that the aims of accurately eliminating pedicel interference and improving the recognition accuracy of the flat fruits are fulfilled. The application provides a fruit and vegetable shape sorting method, which comprises the steps of S1, obtaining image data of N angles of a target fruit and vegetable, S2, performing foreground and background segmentation on the image data to obtain a foreground image only containing the fruit and vegetable, S3, calculating long half shafts corresponding to the N angle images respectively through an ellipse fitting algorithm according to external contour coordinates of the fruit and vegetable in the foreground imageTo the point ofShort half shaftTo the point ofAccording to the long half shaftTo the point ofShort half shaftTo the point ofCalculating the eccentricity of each of the N angle imagesTo the point ofS4, for the long half shaftTo the point ofThe method comprises the steps of sorting, namely judging the difference value between the rest long half shafts and the maximum half shafts by taking the sorted maximum half shafts as a reference, obtaining images with the difference value smaller than a preset first threshold value to obtain an effective image set, S5, obtaining the maximum eccentricity and the minimum eccentricity corresponding to the long half shafts in the effective image set when the number of the images in the effective image set is larger than a preset number threshold value, and judging the corresponding fruits and vegetables as flat fruits when the difference value between the maximum eccentricity and the minimum eccentricity is larger than a preset second threshold value, otherwise judging the fruits and vegetables as non-flat fruits. Wherein, the the second threshold is more than or equal to 0.10 and less than or equal to 0.25. In particular, in the present application, the fruit and vegetable is preferably kiwi fruit. The posture of the kiwi fruit on the conveyor belt is random, and the real shape characteristics of the kiwi fruit cannot be comprehensively reflected by the single-angle image. According to the application, the image data of N angles of the target fruits and vegetables are obtained, and the effective image set is constructed bas