Method for automatically extracting surface crack characteristics of breeding duck eggs based on image recognition
By using the duck frame selection method and the round-like value acquisition method in the automatic extraction technology of crack features on the surface of breeding duck eggs, combined with the threshold acquisition method, the problem of indistinguishable light spots and cracks is solved, and the accuracy of identification is improved.
Patent Information
- Application Number
- CN202510517246.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-05-30
- Estimated Expiration
- 2045-04-23
AI Technical Summary
The existing automatic extraction technology for surface crack features of breeding duck eggs is difficult to distinguish light spots from cracks, resulting in misjudgment of identification.
The width-length ratio and circle-like value of the binarization map of the duck egg are obtained by obtaining the width-length ratio threshold and circle-like threshold respectively based on the duck frame selection method and the circle-like value acquisition method, and the crack signal and the crack characteristics of the duck egg surface are generated.
Effectively distinguish light spots and cracks, improving the accuracy of crack recognition on the surface of breeding duck eggs.
Smart Images

Figure CN120070415A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of automatic extraction of surface crack characteristics of breeding duck eggs, and specifically to an automatic extraction method for surface crack characteristics of breeding duck eggs based on image recognition. Background Art
[0002] The eggshells of breeding duck eggs are relatively fragile and prone to cracks. Cracks will provide a channel for microorganisms to invade, resulting in damage to the interior of the breeding duck eggs, and further causing the breeding duck eggs to be unable to breed normally. Therefore, it is necessary to identify the surface cracks of breeding duck eggs.
[0003] The existing crack identifications include acoustic wave identification and image recognition. Image recognition is based on the transmissive image of the breeding duck egg for recognition. However, because the thickness of the duck eggshell itself is uneven, for example, light spots will appear in the transmissive image of the thin part. The light spots and cracks have similar colors, making it difficult to distinguish the light spots and cracks based on color. When extracting the crack binary image, the light spots are easily regarded as cracks. For example, in the patent application with the publication number CN119359731A, a method and system for detecting surface cracks of duck eggs based on image analysis are disclosed. This scheme classifies and identifies green duck eggs and white duck eggs without considering the light spots of the duck eggs themselves, resulting in misjudgment of cracks. That is, in the existing automatic extraction technology for surface crack characteristics of breeding duck eggs, the light spots and cracks of the eggs themselves cannot be distinguished, leading to misjudgment in the identification of surface cracks of breeding duck eggs. Summary of the Invention
[0004] The present invention aims to solve at least one of the technical problems in the existing technology to some extent. By respectively obtaining the width-to-length ratio and circularity value of the binary image of the duck egg through the duck frame selection method and the circularity value acquisition method, and obtaining the width-to-length ratio threshold and circularity threshold through the threshold acquisition method, crack signals and surface crack characteristics of the duck egg are generated based on the width-to-length ratio threshold, circularity threshold, width-to-length ratio, and circularity value, so as to solve the problem that in the existing automatic extraction technology for surface crack characteristics of breeding duck eggs, the light spots and cracks of the eggs themselves cannot be distinguished, resulting in misjudgment in the identification of surface cracks of breeding duck eggs.
[0005] To achieve the above object, the present application provides an automatic extraction method for surface crack characteristics of breeding duck eggs based on image recognition, including the following steps: Obtain the transmissive image of the breeding duck egg based on an image acquisition device, and mark it as the duck egg transmissive image; Perform grayscale processing on the duck egg transmissive image to obtain the duck egg grayscale image; Perform binary processing on the duck egg grayscale image to obtain the duck egg binary image; Respectively obtain the width-to-length ratio and circularity value of the duck egg binary image through the duck frame selection method and the circularity value acquisition method; Obtain the width-to-length ratio threshold and circularity threshold through the threshold acquisition method; Generate crack signals and duck egg surface crack characteristics based on the aspect ratio threshold, circularity threshold, aspect ratio value, and circularity value.
[0006] Further, the graying processing of the duck egg transmission image to obtain the duck egg grayscale image includes the following sub-steps: Obtain the RGB value of each pixel point in the duck egg transmission image, marked as the duck egg RGB value; Use the gray conversion formula to convert all the duck egg RGB values in the duck egg transmission image into gray values to obtain the duck egg grayscale image.
[0007] Further, the binarization processing of the duck egg grayscale image to obtain the duck egg binary image includes the following sub-steps: Obtain the gray value of each pixel point in the duck egg grayscale image, marked as the duck egg gray value; Divide the gray values from 0 to 255 into a1 equal-interval range intervals, marked as the divided range intervals; Count the frequency of the duck egg gray values in each divided range interval, marked as the divided range frequency; Taking the duck egg gray value as the X-axis, the divided range frequency as the Y-axis, and the divided range interval as the histogram interval, draw a histogram, marked as the duck egg gray histogram.
[0008] Further, the binarization processing of the duck egg grayscale image to obtain the duck egg binary image also includes the following sub-steps: Obtain the divided range interval in the duck egg gray histogram where the divided range frequency is greater than the divided range frequencies on both the left and right sides, marked as the candidate peak interval; obtain the median of the candidate peak interval, marked as the candidate peak median; Mark the candidate peak interval where the interval between two adjacent candidate peak medians is greater than the adjacent gray interval threshold as the selected peak interval, and select three selected peak intervals; Sort the three selected peak intervals in ascending order according to the candidate peak median, and mark them as the first peak interval, the second peak interval, and the third peak interval respectively; Obtain the divided range interval between the second peak interval and the third peak interval, marked as the middle preselection interval, and obtain the middle preselection interval with the smallest divided range frequency, marked as the middle final interval; Obtain the median of the middle final interval, marked as the binarization threshold; Set the duck egg gray values greater than or equal to the binarization threshold in the duck egg grayscale image to 0, and set the duck egg gray values less than the binarization threshold in the duck egg grayscale image to 255 to obtain the duck egg binary image.
[0009] Further, obtain the aspect ratio and circularity value of the duck egg binary image based on the duck frame selection method and the circularity value acquisition method respectively, including the following sub-steps: Obtain the pixel points with a gray value of 0 adjacent to the pixel points with a gray value of 255 in the binary image of the duck egg, and mark them as boundary pixel points; Mark the area of pixel points with a gray value of 0 in the binary image of the duck egg as the initial abnormal area; Use the box selection method to obtain the bounding rectangle of each initial abnormal area; Obtain the long side and the short side of the bounding rectangle, and mark them as Jc and Jk respectively; Calculate the width-to-length ratio as: Bck = Jk / Jc; where Bck is the width-to-length ratio; Use the method for obtaining the circularity value to obtain the circularity value of each initial abnormal area.
[0010] Further, the box selection method includes: Establish a rectangular coordinate system on the plane, marked as the box selection coordinate system; place the binary image of the duck egg in the first quadrant of the box selection coordinate system; Obtain the coordinates of a pixel point with the minimum abscissa in the initial abnormal area, marked as (Xmin, Y1), and obtain the coordinates of a pixel point with the maximum abscissa in the initial abnormal area, marked as (Xmax, Y2); draw a straight line parallel to the Y-axis through the point (Xmin, Y1), marked as the first straight line; draw a straight line parallel to the Y-axis through the point (Xmax, Y2), marked as the second straight line; obtain the midpoint of the point (Xmin, Y1) and the point (Xmax, Y2), marked as the reference midpoint; Rotate the first straight line and the second straight line clockwise n times by ds° with the reference midpoint as the rotation point, and the maximum rotation range is 180°; After each rotation of ds°, draw two straight lines perpendicular to the first straight line through the boundary pixel points of the initial abnormal area, marked as the third straight line and the fourth straight line respectively, and at the same time satisfy that the distance between the third straight line and the fourth straight line is the maximum value that can be drawn. The rectangle formed by the first straight line, the second straight line, the third straight line, and the fourth straight line is marked as the initial rectangle. Obtain the length and width of the initial rectangle, and multiply the length and width of the initial rectangle to calculate the area of the initial rectangle; When the rotation ends, obtain the initial rectangle with the minimum area, marked as the bounding rectangle.
[0011] Further, the method for obtaining the circularity value includes: Connect the midpoints of all adjacent boundary pixel points in the initial abnormal area to obtain the distance line segments, and calculate the sum of all distance line segments, marked as Lz; Obtain the number of pixel points in the initial abnormal area, marked as Gs; Obtain the area of each pixel point in the box selection coordinate system, marked as Sd; Calculate the circularity value as: Zz = (4 * Π * Sd * Gs) / (Lz 2 ) ; where Zz is the circularity value.
[0012] Further, obtaining the aspect ratio threshold and the circularity threshold by using the threshold obtaining method includes the following sub-steps: Obtain the first number of speckle transmissive images containing only normal breeding duck eggs, and mark them as normal speckle images; Obtain the aspect ratio value of each normal speckle image, and mark it as the normal aspect ratio value; Obtain the circularity value of each normal speckle image, and mark it as the normal circularity value; Use the threshold obtaining method to obtain the aspect ratio threshold of the normal aspect ratio value; Use the threshold obtaining method to obtain the circularity threshold of the normal circularity value.
[0013] Further, the threshold obtaining method further includes: Obtain the normal aspect ratio value range, divide the normal aspect ratio value range into a2 equal-interval range intervals, and mark them as aspect ratio division intervals; Count the frequency of each aspect ratio division interval, and mark it as the aspect ratio division frequency; Taking the normal aspect ratio value as the X-axis, the aspect ratio division frequency as the Y-axis, and the aspect ratio division interval as the histogram interval, draw a histogram, and mark it as the aspect ratio histogram; Obtain the sum of all aspect ratio division frequencies, and mark it as Lck; Calculate the abnormal aspect ratio frequency threshold as: Py = u * Lck / a2; where Py is the abnormal aspect ratio frequency threshold and u is the abnormal occupancy ratio; Mark the aspect ratio division frequencies less than or equal to the abnormal aspect ratio frequency threshold as abnormal aspect ratio frequencies; Judge whether the aspect ratio division frequency of the rightmost aspect ratio division interval of the aspect ratio histogram is an abnormal aspect ratio frequency. If so, delete the rightmost aspect ratio division interval and the corresponding aspect ratio division frequency in the aspect ratio histogram, and then repeat the above operation until it is not; Mark the aspect ratio histogram after stopping as the filtered aspect ratio histogram; Obtain the maximum value of the abscissa of the aspect ratio division interval in the filtered aspect ratio histogram, and mark it as the aspect ratio threshold.
[0014] Further, generating a crack signal and the surface crack characteristics of the duck egg based on the aspect ratio threshold, the circularity threshold, the aspect ratio value, and the circularity value includes the following sub-steps: If the aspect ratio value is less than the aspect ratio threshold and the circularity value is less than the circularity threshold, mark the initial abnormal area as a crack area; If the aspect ratio value is greater than or equal to the aspect ratio threshold or the circularity value is greater than or equal to the circularity threshold, determine that the initial abnormal area is marked as a speckle area; If the finally obtained area is a crack area, a crack signal is emitted, and the crack area is output as the surface crack feature of the duck egg.
[0015] Advantages of the present invention: By using the duck frame selection method and the circularity value acquisition method to respectively obtain the width-to-length ratio and the circularity value of the binary image of the duck egg, and using the threshold acquisition method to obtain the width-to-length ratio threshold and the circularity threshold, and generating a crack signal and the surface crack feature of the duck egg based on the width-to-length ratio threshold, the circularity threshold, the width-to-length ratio, and the circularity value. The advantage is that it can distinguish the light spot and the crack from the image features of the light spot and the crack, and improve the accuracy of identifying the crack. In the present invention, by using the duck frame selection method and the circularity value acquisition method to respectively obtain the width-to-length ratio and the circularity value of the binary image of the duck egg, the advantage is that although the crack and the light spot have similar colors after passing through light, their image shapes are different. For example, the light spot is close to a circle, while the crack is in a long shape. Therefore, the width-to-length ratio and the circularity value are set to comprehensively judge and distinguish the crack and the light spot, and the accuracy of identifying the crack is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] Figure 1 is a flowchart of the steps of the method of the present invention; Figure 2 is a schematic diagram of the binary threshold of the present invention; Figure 3 is a schematic diagram of the first straight line, the second straight line, the third straight line, and the fourth straight line of the present invention; Figure 4 is a schematic diagram of the rotation of the first straight line, the second straight line, the third straight line, and the fourth straight line of the present invention; Figure 5 is a schematic diagram of the selected rectangle of the present invention; Figure 6 is a schematic diagram of the width-to-length ratio histogram of the present invention; Figure 7 is a schematic diagram of the selected width-to-length ratio histogram of the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0017] 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 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.
[0018] Embodiment 1. Please refer to Figure 1 As shown, the present application provides an automatic extraction method for the surface crack feature of breeding duck eggs based on image recognition, including the following steps: Step S1: Obtain a transmissive image of a breeding duck egg using an image acquisition device, and label it as the duck egg transmissive image; Step S2: Perform grayscale processing on the duck egg transmissive image to obtain a duck egg grayscale image; Step S2 further includes the following sub-steps: Step S201: Obtain the RGB values of each pixel in the duck egg transmissive image, and label them as duck egg RGB values; Step S202: Use the grayscale conversion formula to convert all the duck egg RGB values in the duck egg transmissive image into grayscale values to obtain a duck egg grayscale image; In practical applications, the grayscale conversion formula is Hyd = (R + G + B) / 3, where Hyd is the grayscale value, and R, G, and B are the three channel values of the duck egg RGB value. For example, if the R, G, and B of a duck egg RGB value are 139, 128, and 0, then the grayscale value is Hyd = (139 + 128 + 0) / 3 = 134, and the calculation result is rounded to an integer.
[0019] Step S3: Perform binarization processing on the duck egg grayscale image to obtain a duck egg binarized image; Step S3 further includes the following sub-steps: Step S301: Obtain the grayscale value of each pixel in the duck egg grayscale image, and label it as the duck egg grayscale value; Step S302: Divide the grayscale values from 0 to 255 into a1 equal interval range intervals, and label them as the divided range intervals; Step S303: Count the frequency of the duck egg grayscale values in each divided range interval, and label it as the divided range frequency; Step S304: Draw a histogram with the duck egg grayscale value as the X-axis, the divided range frequency as the Y-axis, and the divided range interval as the histogram interval, and label it as the duck egg grayscale histogram; Step S305: Obtain the divided range interval in the duck egg grayscale histogram where the divided range frequency is greater than the divided range frequencies on both the left and right sides, and label it as the candidate peak interval; Obtain the median of the candidate peak interval, and label it as the candidate peak median; Step S306: Mark the candidate peak intervals where the interval between two adjacent candidate peak medians is greater than the adjacent grayscale interval threshold as the selected peak intervals, and select three selected peak intervals; The adjacent grayscale interval threshold is set based on the size of a1. If a1 is too large, the peak fluctuation is more obvious. For example, there will be multiple peaks in the background, so some need to be excluded. Since the obtained a1 is 8 in this case, which is a small data, it can be set to 0, and the peak fluctuation is more obvious. Because the duck egg transmissive image contains the background, the duck egg part, and the crack and light spot part, and the colors of these three parts are different, approaching black, light yellow, and bright yellow respectively, and mainly contain these three distributions, so there will be three selected peak intervals; Step S307: Sort the three screened peak intervals in ascending order according to the candidate peak medians, and label them as the first peak interval, the second peak interval, and the third peak interval respectively; Step S308: Obtain the division range interval between the second peak interval and the third peak interval, label it as the intermediate preselection interval, and obtain the intermediate preselection interval with the smallest division range frequency and label it as the intermediate final interval; Step S309: Obtain the median of the intermediate final interval and label it as the binarization threshold; Step S310: Set the duck egg gray values greater than or equal to the binarization threshold in the duck egg gray scale image to 0, and set the duck egg gray values less than the binarization threshold in the duck egg gray scale image to 255 to obtain the duck egg binarized image; In practical applications, please refer to Figure 2 As shown, divide the gray values from 0 to 255 into 8 division range intervals. The first peak interval, the second peak interval, and the third peak interval are 0 to 31, 159 to 191, and 223 to 255 respectively. The binarization threshold is (191 + 223) / 2 = 207. Set the duck egg gray values greater than or equal to 207 in the duck egg gray scale image to 0, and set the duck egg gray values less than 207 in the duck egg gray scale image to 255 to obtain the duck egg binarized image.
[0020] Step S4: Obtain the width-to-length ratio and the circularity value of the duck egg binarized image based on the duck frame selection method and the circularity value acquisition method respectively; Step S4 also includes the following sub-steps: Step S401: Obtain the pixel points with a gray value of 0 adjacent to the pixel points with a gray value of 255 in the duck egg binarized image, and label them as boundary pixel points; Step S402: Label the pixel point area with a gray value of 0 in the duck egg binarized image as the initial abnormal area; Step S403: Use the frame selection method to obtain the frame selection rectangle of each initial abnormal area; Step S403 also includes the following sub-steps: Step S40301: Establish a plane rectangular coordinate system and label it as the frame selection coordinate system; Place the duck egg binarized image in the first quadrant of the frame selection coordinate system; When placing the duck egg binarized image, scale the duck egg binarized image so that the actual size of the breeding duck egg is the same as the size of the plane rectangular coordinate system for convenient comparison; Step S40302: Obtain the coordinates of a pixel point with the smallest abscissa in the initial abnormal area, marked as (Xmin, Y1), and obtain the coordinates of a pixel point with the largest abscissa in the initial abnormal area, marked as (Xmax, Y2); draw a straight line parallel to the Y-axis through the point (Xmin, Y1), marked as the first straight line; draw a straight line parallel to the Y-axis through the point (Xmax, Y2), marked as the second straight line; obtain the midpoint of the point (Xmin, Y1) and the point (Xmax, Y2), marked as the reference midpoint. Step S40303: Rotate the first straight line and the second straight line clockwise n times by ds° with the reference midpoint as the rotation point, and the maximum rotation range is 180°. Step S40304: After each rotation of ds°, draw two straight lines perpendicular to the first straight line through the boundary pixel points of the initial abnormal area, respectively marked as the third straight line and the fourth straight line, and at the same time satisfy that the distance between the third straight line and the fourth straight line is the maximum value that can be drawn. The rectangle formed by the first straight line, the second straight line, the third straight line, and the fourth straight line is marked as the initial rectangle. Obtain the length and width of the initial rectangle, and multiply the length and width of the initial rectangle to calculate the area of the initial rectangle. Step S40305: When the rotation ends, obtain the initial rectangle with the smallest area, marked as the selected rectangle. In practical applications, please refer to Figure 3 、 Figure 4 and Figure 5 As shown, the coordinates of a pixel point with the smallest abscissa in the initial abnormal area are obtained as (1.32, 1.51), and the coordinates of a pixel point with the largest abscissa in the initial abnormal area are obtained and marked as (2.46, 1.98); draw the first straight line parallel to the Y-axis through the point (1.32, 1.51); draw the second straight line parallel to the Y-axis through the point (2.46, 1.98); the midpoint of the point (1.32, 1.51) and the point (2.46, 1.98) is (1.89, 1.745), so the reference midpoint is (1.89, 1.745). Rotate the first straight line and the second straight line clockwise 6 times by 30° with the reference midpoint as the rotation point. After each rotation of 30°, obtain an initial rectangle, for example Figure 5 As shown; Step S404: Obtain the long side and the short side of the selected rectangle, respectively marked as Jc and Jk. Step S405: Calculate the width-to-length ratio as: Bck = Jk / Jc; where Bck is the width-to-length ratio; because cracks are usually slender, and light spots are usually close to circular, so the width-to-length ratio of cracks is larger, and the width-to-length ratio of light spots is smaller. Step S406: Use the method for obtaining the circularity value to obtain the circularity value of each initial abnormal area; Step S406 also includes the following sub-steps: Step S40601: Connect the midpoints of all adjacent boundary pixels of the initial abnormal region to obtain distance line segments, calculate the sum of all distance line segments, and mark it as Lz; Step S40602: Obtain the number of pixels in the initial abnormal region, and mark it as Gs; Step S40603: Obtain the area of each pixel in the selected coordinate system, and mark it as Sd; Step S40604: Calculate the circularity value as: Zz = (4 * Π * Sd * Gs) / (Lz 2 ); where Zz is the circularity value. For some cracks with branches, the width-to-length ratio of the cracks may be close to that of the light spots, reducing the discrimination accuracy of the model. Therefore, it is necessary to determine whether the initial abnormal region is close to a circle. In the circularity calculation formula, Sd * Gs represents the area of the initial abnormal region, and Lz represents the perimeter of the initial abnormal region. If the initial abnormal region is a circle, the circularity value is 1. The closer it is to a circle, the closer the circularity value is to 1. Therefore, the circularity value can be used to determine whether it is close to a circle, and then determine whether it is a spot or a crack; In practical applications, please refer to Figure 5 As shown, the long side and short side of the selected rectangle are 1.17 cm and 0.15 cm respectively. The long side and short side of the selected rectangle are rounded to two decimal places, and the calculated width-to-length ratio is: Bck = 0.15 / 1.17 = 0.13, and the calculation result is rounded to two decimal places. Connect the midpoints of all adjacent boundary pixels of the initial abnormal region to obtain distance line segments, and the sum of all distance line segments is 2.98 cm. The number of pixels in the initial abnormal region is 2304, and the area of each pixel in the selected coordinate system is 3 * 10 -5 cm 2 , calculate the circularity value as: Zz = (4 * Π * 2304 * 3 * 10 -5 ) / (2.98 2 ) = 0.10, and the calculation result is rounded to two decimal places.
[0021] Step S5: Use the threshold acquisition method to obtain the width-to-length ratio threshold and the circularity threshold; Step S5 also includes the following sub-steps: Step S501: Obtain the first quantity of spot light-transmitting images containing only normal breeding duck eggs, and mark them as normal spot images; Step S502: Obtain the width-to-length ratio of each normal spot image, and mark it as the normal width-to-length ratio; Step S503: Obtain the circularity value of each normal spot image, and mark it as the normal circularity value; Step S504: Use the threshold acquisition method to obtain the width-to-length ratio threshold of the normal width-to-length ratio; Step S504 also includes the following sub-steps: Step S50401, the method for obtaining the aspect ratio threshold includes: obtaining the normal aspect ratio value range, dividing the normal aspect ratio value range into a2 equal-interval range intervals, marked as aspect ratio division intervals; Step S50402, counting the frequency of each aspect ratio division interval, marked as aspect ratio division frequency; Step S50403, taking the normal aspect ratio as the X-axis, the aspect ratio division frequency as the Y-axis, and the aspect ratio division interval as the histogram interval to draw a histogram, marked as aspect ratio histogram; Step S50404, obtaining the sum of all aspect ratio division frequencies, marked as Lck; Step S50405, calculating the abnormal aspect ratio frequency threshold as: Py = u * Lck / a2; where Py is the abnormal aspect ratio frequency threshold and u is the abnormal occupancy ratio; the abnormal aspect ratio frequency threshold is used to screen out data with a relatively small frequency of occurrence. For example, if the abnormal occupancy ratio is set to 1%, defects less than 1% are usually ignored in data analysis, and in high-precision fields, defects with a defect rate less than 0.1% are usually ignored. Since there are many noise points in image processing, it should not be set too small, such as setting the abnormal occupancy ratio to 1%; Step S50406, marking the aspect ratio division frequencies less than or equal to the abnormal aspect ratio frequency threshold as abnormal aspect ratio frequencies; Step S50407, determining whether the aspect ratio division frequency of the rightmost aspect ratio division interval in the aspect ratio histogram is an abnormal aspect ratio frequency. If so, deleting the rightmost aspect ratio division interval and the corresponding aspect ratio division frequency in the aspect ratio histogram, and then repeating the above operation until it is not; marking the aspect ratio histogram after stopping as the screened aspect ratio histogram; Step S50408, obtaining the maximum value of the abscissa of the aspect ratio division interval in the screened aspect ratio histogram, marked as the aspect ratio threshold; In practical applications, please refer to Figure 6 and Figure 7 As shown, the normal aspect ratio value range is obtained as 0.5 to 1.0, the normal aspect ratio value range is divided into 5 equal-interval range intervals, the sum of all aspect ratio division frequencies is 180, and the abnormal aspect ratio frequency threshold is calculated as: Py = 1% * 180 / 5 = 3.6. Marking the aspect ratio division frequencies less than or equal to 3.6 as abnormal aspect ratio frequencies. For example, the frequency of the aspect ratio division interval from 0.5 to 0.6 is 2, then 2 is the abnormal aspect ratio frequency. Obtaining the maximum value 0.60 of the abscissa of the aspect ratio division interval in the screened aspect ratio histogram, that is, the aspect ratio threshold 0.60; Step S505, using the threshold obtaining method to obtain the circularity threshold of normal circularity values; Step S505 further includes the following sub-steps: Step S50501, the threshold acquisition method for obtaining the circular-like threshold includes: obtaining the normal circular-like value range, dividing the normal wide circular-like range into a2 equal-interval range intervals, and marking them as circular-like division intervals; Step S50502, count the frequency of each circular-like division interval, and mark it as the circular-like division frequency; Step S50503, taking the normal circular-like value as the X-axis, the circular-like division frequency as the Y-axis, and the circular-like division interval as the histogram interval, draw a histogram, and mark it as the circular-like ratio histogram; Step S50504, obtain the sum of all circular-like division frequencies, and mark it as Lly; Step S50505, calculate the abnormal circular-like frequency threshold as: Plz = u * Lly / a2; where Plz is the abnormal circular-like frequency threshold and u is the abnormal occupancy ratio; Step S50506, mark the circular-like division frequencies less than or equal to the abnormal circular-like frequency threshold as abnormal circular-like frequencies; Step S50507, determine whether the circular-like division frequency in the rightmost circular-like division interval of the circular-like histogram is an abnormal circular-like frequency. If so, delete the rightmost circular-like ratio division interval and the corresponding circular-like division frequency in the circular-like histogram, and then repeat the above operation until it is not; mark the circular-like histogram after stopping as the screened circular-like histogram; Step S50508, obtain the maximum value of the abscissa of the circular-like division interval in the screened circular-like histogram, and mark it as the circular-like threshold; In practical applications, for example, the circular-like threshold obtained by the aspect ratio threshold acquisition method is 0.72.
[0022] Step S6, generate a crack signal and the duck egg surface crack characteristics based on the aspect ratio threshold, the circular-like threshold, the aspect ratio value, and the circular-like value; Step S6 also includes the following sub-steps: Step S601, if the aspect ratio value is less than the aspect ratio threshold and the circular-like value is less than the circular-like threshold, mark the initial abnormal area as the crack area; Step S602, if the aspect ratio value is greater than or equal to the aspect ratio threshold or the circular-like value is greater than or equal to the circular-like threshold, determine that the initial abnormal area is marked as the spot area; Step S603, if the crack area is finally obtained, send out a crack signal and output the crack area as the duck egg surface crack characteristics; In practical applications, the aspect ratio threshold, the near-circularity threshold, the aspect ratio value, and the near-circularity value are 0.60, 0.72, 0.13, and 0.10 respectively. If 0.10 is less than 0.60 and 0.10 is less than 0.72, the initial abnormal area is marked as a crack area, a crack signal is sent, and the crack area is output as the surface crack feature of the duck egg. Since cracks are usually slender, while light spots are close to circular, the aspect ratio of cracks is larger, and the aspect ratio of light spots is smaller. The closer to circular, the closer the near-circularity value is to 1. Therefore, the near-circularity value can be used to determine whether it is close to circular. When the near-circularity value is small, it is a crack. Therefore, the aspect ratio and the near-circularity value can be combined to determine whether it is a crack or a light spot.
[0023] Embodiment 2, the present application also provides an electronic device, which may include: a processor, a communication interface, a memory, and a communication bus. Among them, the processor, the communication interface, and the memory complete mutual communication through the communication bus. The memory stores computer-readable instructions, and the processor can call the instructions in the memory. When the computer-readable instructions are executed by the processor, the steps in the method for automatically extracting the surface crack features of breeding duck eggs based on image recognition are run to achieve the following functions: obtaining a light-transmitting image of the breeding duck egg based on an image acquisition device and marking it as a duck egg light-transmitting image; performing grayscale processing on the duck egg light-transmitting image to obtain a duck egg grayscale image; performing binarization processing on the duck egg grayscale image to obtain a duck egg binarized image; respectively obtaining the aspect ratio and the near-circularity value of the duck egg binarized image based on the duck frame selection method and the near-circularity value acquisition method; using the threshold acquisition method to obtain the aspect ratio threshold and the near-circularity threshold; generating a crack signal and the surface crack features of the duck egg based on the aspect ratio threshold, the near-circularity threshold, the aspect ratio value, and the near-circularity value.
[0024] In addition, when the logical instructions in the above-mentioned memory are implemented in the form of software function units and sold or used as an independent product, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, in essence, or the part that contributes to the prior art, or a part of this technical solution, can be embodied in the form of a software product. The 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 various embodiments of the present application. The foregoing storage medium includes: various media such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc that can store program codes.
[0025] Embodiment 3. The present application further provides a computer program product, which includes a computer program stored on a computer-readable storage medium. The computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the automatic extraction method for surface crack features of breeding duck eggs based on image recognition provided by the above-mentioned various methods. The method includes: obtaining a light-transmitting image of a breeding duck egg through an image acquisition device and marking it as a duck egg light-transmitting image; performing grayscale processing on the duck egg light-transmitting image to obtain a duck egg grayscale image; performing binarization processing on the duck egg grayscale image to obtain a duck egg binarized image; respectively obtaining the width-to-length ratio and the circularity value of the duck egg binarized image based on the duck frame selection method and the circularity value acquisition method; using the threshold acquisition method to obtain the width-to-length ratio threshold and the circularity threshold; generating a crack signal and the surface crack features of the duck egg based on the width-to-length ratio threshold, the circularity threshold, the width-to-length ratio, and the circularity value.
[0026] Embodiment 4. The present application further provides a computer-readable storage medium. The present application provides a storage medium on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned automatic extraction method for surface crack features of breeding duck eggs based on image recognition are run to achieve the following functions: obtaining a light-transmitting image of a breeding duck egg through an image acquisition device and marking it as a duck egg light-transmitting image; performing grayscale processing on the duck egg light-transmitting image to obtain a duck egg grayscale image; performing binarization processing on the duck egg grayscale image to obtain a duck egg binarized image; respectively obtaining the width-to-length ratio and the circularity value of the duck egg binarized image based on the duck frame selection method and the circularity value acquisition method; using the threshold acquisition method to obtain the width-to-length ratio threshold and the circularity threshold; generating a crack signal and the surface crack features of the duck egg based on the width-to-length ratio threshold, the circularity threshold, the width-to-length ratio, and the circularity value.
[0027] Through the description of the above embodiments, the embodiments of the present invention can be provided as a method, a system, or a computer program product. Based on such an understanding, the above technical solution, in essence, or the part that contributes to the prior art can be embodied in the form of a software product. The computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disc, etc., and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0028] In the embodiments provided in the present application, it should be understood that the disclosed system or method can be implemented in other ways. The embodiments described above are merely illustrative. For example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation. For another example, multiple modules or units can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed coupling or direct coupling or communication connection between each other can be through some communication interfaces. The indirect coupling or communication connection of systems, modules, and units can be electrical, mechanical, or other forms.
[0029] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application and are not intended to limit them. Although the present application 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 equivalently replace 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 embodiments of the present application.
Claims
1. A method for automatically extracting surface crack features of breeding duck eggs based on image recognition, characterized in that: The steps include: A light transmission image of a breeding duck egg is obtained based on an image acquisition device, and is marked as a light transmission image of a duck egg; Grayscale processing is performed on the duck egg transmittance image to obtain a duck egg grayscale image; Binarization processing is performed on the duck egg grayscale image to obtain a duck egg binary image; Based on the duck frame selection method and the circular value acquisition method, the width-to-length ratio and the circular value of the duck egg binary image are obtained respectively; The width-to-length ratio threshold and the circle-like threshold are obtained by using the threshold acquisition method; Crack signals and crack features on the surface of duck eggs are generated based on the width-to-length ratio threshold, the circular threshold, the width-to-length ratio value and the circular value.
2. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 1, characterized in that: Grayscale processing of the duck egg transmittance image to obtain a duck egg grayscale image includes the following sub-steps: Get the RGB value of each pixel in the duck egg transmittance image and mark it as the duck egg RGB value; The grayscale conversion formula is used to convert all the RGB values of the duck eggs in the duck egg transmittance image into grayscale values to obtain the duck egg grayscale image.
3. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 2, characterized in that: Binarization of the duck egg grayscale image to obtain a duck egg binary image includes the following sub-steps: Get the gray value of each pixel in the duck egg grayscale image and mark it as the duck egg grayscale value; Divide the grayscale values from 0 to 255 into a1 equally spaced range intervals, marked as divided range intervals; Count the frequency of the grayscale value of duck eggs in each divided range, and mark it as the divided range frequency; A histogram is drawn with the duck egg grayscale value as the X-axis, the division range frequency as the Y-axis, and the division range interval as the histogram interval, and is marked as a duck egg grayscale histogram.
4. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 3, characterized in that: The process of binarizing the duck egg grayscale image to obtain a duck egg binary image also includes the following sub-steps: Obtain the division range interval in the duck egg grayscale histogram whose division range frequency is greater than the division range frequency on both sides, and mark it as the candidate peak interval; obtain the median of the candidate peak interval, and mark it as the candidate peak median; The candidate peak intervals whose median intervals between two adjacent candidate peaks are greater than the threshold of the adjacent grayscale interval are marked as screening peak intervals, and three screening peak intervals are selected; Sort the three screened peak intervals according to the candidate peak median values from small to large, and mark them as the first peak interval, the second peak interval, and the third peak interval respectively; Obtain the division range interval between the second peak interval and the third peak interval, mark it as the middle pre-selected interval, obtain the middle pre-selected interval with the smallest division range frequency and mark it as the middle final interval; Get the median of the final interval and mark it as the binarization threshold; The grayscale values of the duck eggs in the duck egg grayscale image that are greater than or equal to the binarization threshold are set to 0, and the grayscale values of the duck eggs in the duck egg grayscale image that are less than the binarization threshold are set to 255, so as to obtain a duck egg binarization image.
5. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 4, characterized in that: The method for obtaining the width-to-length ratio and the circular value of the duck egg binary image based on the duck frame selection method and the circular value acquisition method includes the following sub-steps: Get the pixel points with gray value of 0 adjacent to the pixel points with gray value of 255 in the binary image of duck egg, and mark them as boundary pixels; The pixel area with gray value of 0 in the duck egg binary image is marked as the initial abnormal area; A frame selection method is used to obtain a frame selection rectangle for each initial abnormal area; Get the long side and wide side of the selection rectangle, marked as Jc and Jk respectively; The calculated width-to-length ratio is: Bck=Jk / Jc; Where Bck is the width-to-length ratio; The circular value of each initial abnormal area is obtained by using the circular value obtaining method.
6. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 5, characterized in that: The frame selection methods include: Establish a plane rectangular coordinate system, marked as the frame selection coordinate system; place the duck egg binary image in the first quadrant of the frame selection coordinate system; Get the coordinates of the pixel with the smallest horizontal coordinate in the initial abnormal area, marked as (Xmin, Y1), get the coordinates of the pixel with the largest horizontal coordinate in the initial abnormal area, marked as (Xmax, Y2); draw a straight line parallel to the Y axis through the point (Xmin, Y1), marked as the first straight line; draw a straight line parallel to the Y axis through the point (Xmax, Y2), marked as the second straight line; get the midpoint of the point (Xmin, Y1) and the point (Xmax, Y2), marked as the reference midpoint; Rotate the first straight line and the second straight line clockwise n times ds° with the reference midpoint as the rotation point, and the maximum rotation range is 180°; After each rotation of ds°, two straight lines perpendicular to the first straight line are drawn through the boundary pixels of the initial abnormal area, and are marked as the third straight line and the fourth straight line respectively, and the distance between the third straight line and the fourth straight line is the maximum value that can be drawn. The rectangle formed by the first straight line, the second straight line, the third straight line and the fourth straight line is marked as the initial rectangle, and the length and width of the initial rectangle are obtained, and the length and width of the initial rectangle are multiplied to calculate the area of the initial rectangle; When the rotation is completed, the initial rectangle with the smallest area is obtained and marked as the selection rectangle.
7. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 6, characterized in that: The methods for obtaining circular values include: Connect the midpoints of all adjacent boundary pixels in the initial abnormal area to obtain distance segments, and calculate the sum of all distance segments, marked as Lz; Get the number of pixels in the initial abnormal area, marked as Gs; Get the area of each pixel in the frame selection coordinate system, marked as Sd; The circular value is: Zz=(4*Π*Sd*Gs) / (Lz 2 ); where Zz is a quasi-circular value.
8. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 7, characterized in that: The method for obtaining the aspect ratio threshold and the circle-like threshold by using the threshold obtaining method includes the following sub-steps: Acquire a first number of spot light transmission images containing only normal duck eggs, and mark them as normal spot images; Obtain the width-to-length ratio of each normal spot image, and mark it as the normal width-to-length ratio; Obtain the circular value of each normal spot image and mark it as the normal circular value; Using a threshold value acquisition method to acquire a width-to-length ratio threshold value of a normal width-to-length ratio; The threshold value acquisition method is used to obtain the circle-like threshold of the normal circle-like value.
9. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 8, characterized in that: The threshold acquisition methods include: Obtain a normal width-to-length ratio range, and divide the normal width-to-length ratio range into a2 equally spaced range intervals, marked as width-to-length ratio division intervals; Count the frequency of each width-to-length ratio division interval and mark it as the width-to-length ratio division frequency; Draw a histogram with the normal width-to-length ratio as the X-axis, the width-to-length ratio division frequency as the Y-axis, and the width-to-length ratio division interval as the histogram interval, and mark it as the width-to-length ratio histogram; Get the sum of all aspect ratio division frequencies, marked as Lck; The abnormal width-to-length ratio frequency threshold is calculated as: Py=u*Lck / a2; where Py is the abnormal width-to-length ratio frequency threshold, and u is the abnormal proportion value; Mark the width-to-length ratio frequency that is less than or equal to the abnormal width-to-length ratio frequency threshold as the abnormal width-to-length ratio frequency; Determine whether the width-to-length ratio division frequency of the rightmost width-to-length ratio division interval of the width-to-length ratio histogram is an abnormal width-to-length ratio frequency. If so, delete the rightmost width-to-length ratio division interval and the corresponding width-to-length ratio division frequency in the width-to-length ratio histogram, and then repeat the above operation until it is not abnormal; mark the stopped width-to-length ratio histogram as a screened width-to-length ratio histogram; Get the maximum value of the horizontal coordinate of the width-to-length ratio partition interval in the filtered width-to-length ratio histogram, marked as the width-to-length ratio threshold.
10. The method for automatically extracting surface crack features of breeding duck eggs based on image recognition according to claim 9, characterized in that: Generating crack signals and crack features on the surface of duck eggs based on the width-to-length ratio threshold, the circular threshold, the width-to-length ratio value, and the circular value includes the following sub-steps: If the width-to-length ratio is less than the width-to-length ratio threshold and the circular value is less than the circular threshold, the initial abnormal area is marked as a crack area; If the width-to-length ratio is greater than or equal to the width-to-length ratio threshold or the circular value is greater than or equal to the circular threshold, the initial abnormal area is determined to be marked as a spot area; If the final result is a crack region, a crack signal is issued, and the crack region is output as the crack feature of the duck egg surface.
Citation Information
Patent Citations
A visual detection method for fine cracks on the surface of an egg shell
CN108986055A
A nondestructive testing and automatic grading method for poultry egg surface cracks
CN109685786A
Egg crack detection method and device
CN113686876A
Device and method for measuring multiple qualities of hatching eggs
CN119245745A
Duck egg surface crack detection method and system based on image analysis
CN119359731A
Cited By
Machine visual quality detection method for semiconductor equipment part production
CN120997175A
A machine vision quality inspection method for semiconductor equipment component manufacturing
CN120997175B