Automatic large yellow croaker body length measuring method
Through the automated measurement method of large yellow croaker body length, image processing and machine vision technology are used to solve the problems of low efficiency and uncertainty in traditional manual measurement, and efficient and accurate measurement of fish body length is achieved.
Patent Information
- Application Number
- CN202510032430.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-09
- Publication Date
- 2025-04-25
AI Technical Summary
In the prior art, the measurement of fish body length depends on manual operation, which takes a long time and is inefficient, and the accuracy and consistency of the measurement results are difficult to ensure.
The automated large yellow croaker body length measurement method is used to detect reference lines and perspective transformation through image acquisition and processing, instance segmentation, and the Hough transformation algorithm is used to detect fish body length detection standards based on quadratic function fitting to calculate the complete body length of the fish.
Automatic detection of the body length of the big yellow croaker is realized, which significantly improves measurement efficiency, reduces human resource investment and time consumption, and improves measurement accuracy and data objectivity and repeatability.
Smart Images

Figure CN119888715A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the technical field of automated measurement of aquaculture, in particular to an automated method for measuring the body length of large yellow croaker. Background Art
[0002] In the field of automated measurement technology, with the rapid development of artificial intelligence and machine learning, computer vision has become one of the core technologies in industrial automation. Image recognition, as an important branch of computer vision, can identify, classify or detect objects by analyzing and understanding image or video data. In industrial automation, image recognition has a wide range of applications, helping to improve production efficiency, reduce error rates, and reduce dependence on manual inspection. It has been widely used in human and some animal and plant research, but less in fish research applications.
[0003] At present, the traditional method of measuring fish body length mainly relies on manual operation, using tools such as vernier calipers and weight meters to evaluate the body length and weight of live fish. This method is not only time-consuming, labor-intensive, inefficient, and prone to omissions; but also due to human factors, the accuracy and consistency of the measurement results are difficult to guarantee. Summary of the invention
[0004] In order to overcome the above problems existing in the prior art, the present invention proposes an automated method for measuring the body length of large yellow croaker.
[0005] The technical solution adopted by the present invention to solve the technical problem is: an automated method for measuring the body length of large yellow croaker, comprising: Step 1, image acquisition and processing: a large yellow croaker image is completely acquired through an image acquisition device, and a reference straight line of known length is set in the large yellow croaker image, and an image segmentation model is used to perform instance segmentation on the acquired large yellow croaker image to obtain a mask image, and the size of the obtained mask image is adjusted to be consistent with the original image size; Step 2, establishment of fish body length detection standard: fish body length detection standard is established by fitting a quadratic function, and the relationship between fish body length and image pixel value is modeled; Step 3, using the Hough transform algorithm to detect the reference straight line in the image of step 1, and determine the position and pixel length of the reference straight line; Step 4, performing perspective transformation on the image obtained in step 1, and projecting the fish body in the three-dimensional space onto a two-dimensional plane; Step 5, measuring the pixel distance between the fish head and the fish handle after the perspective transformation in step 4, and determining the actual length between the fish head and the fish handle according to the relationship between the pixel length of the reference straight line obtained in step 3 and the real length of the reference straight line; Step 6, analyzing the multiple relationship between the actual length between the fish head and the fish handle obtained in step 5 and the complete body length of the fish, drawing a box plot and a scatter plot, and selecting a suitable multiple relationship according to the analysis results; Step 7, calculate the complete body length of the fish based on the multiple relationship obtained in step 6.
[0006] In the above-mentioned automated method for measuring the body length of large yellow croaker, the instance segmentation in step 1 is specifically as follows: locating the target object in the image according to the text prompt provided by the user to obtain a bounding box; passing the bounding box information to a general image segmentation model, and the image segmentation model performs accurate instance segmentation within the bounding box; using an image generation tool to generate an image according to the text description; the system fuses the detection and segmentation results to generate a final visual output.
[0007] In the above-mentioned automated method for measuring the body length of large yellow croaker, step 2 specifically comprises: Step 2.1, according to the mask of the fish obtained in step 1, obtain the coordinates of all the pixels where the fish is located, use the nonlinear least squares fitting method to fit the quadratic function model with the pixel coordinates, and obtain a preliminary fitting curve; Step 2.2, evaluating the fitting result obtained in step 2.1, assigning weight m to the pixel points above the fitting curve, and assigning weight n to the pixel points below the fitting curve; refitting the quadratic function to obtain a quadratic fitting curve close to the actual fish body shape; Step 2.3, based on the quadratic fitting curve obtained in step 2.2 and the fish mask, the positions of the fish head and fish handle are obtained.
[0008] In the above-mentioned automated method for measuring the body length of large yellow croaker, in step 2.2, m is greater than n.
[0009] The above-mentioned automated method for measuring the body length of large yellow croaker, wherein step 3 is specifically as follows: converting the image in step 1 from the BGR color space to the HSV color space, and performing dilation and erosion operations on the image; setting the distance resolution i and the angle resolution j; stipulating that the minimum detection length of a straight line is p pixels; setting the maximum gap between straight lines to q pixels, if the gap between two straight lines is less than q pixels, they are regarded as belonging to the same straight line; setting the accumulator threshold to w, and only when the accumulator value of a straight line exceeds w, the straight line will be confirmed as a valid straight line.
[0010] The above-mentioned automated method for measuring the body length of large yellow croaker, the step 4 specifically comprises: finding the source point position from the image obtained in step 1, and the new position to which the source point is mapped after perspective transformation, i.e., the target point position, obtaining a perspective transformation matrix according to the positions of the source point and the target point, and performing perspective transformation on the image obtained in step 1 through the perspective transformation matrix.
[0011] The beneficial effects of the present invention are as follows: (1) Automation and efficiency improvement: The present invention realizes automatic detection of the body length of large yellow croaker by combining machine vision technology. This automated detection method significantly improves the measurement efficiency and reduces the input of human resources and time consumption compared with the traditional manual measurement method.
[0012] (2) Improved measurement accuracy: The average error in size measurement of the present invention is 3%. This improvement in accuracy helps to better classify the grades of large yellow croaker.
[0013] (3) Objectivity and repeatability of data: The application of machine vision technology makes the measurement process more objective, reduces the interference of human factors, and improves the repeatability of data. This is of great significance for scientific research and data statistical analysis.
[0014] (4) Enhanced data analysis capabilities: The present invention also includes the ability to perform box plot and scatter plot analysis on the measurement results, which helps to gain a deeper understanding of the distribution of data and the relationship between variables. Through data analysis, the reliability and outliers of the measurement results can be more accurately evaluated, thereby improving the scientific nature of decision-making. BRIEF DESCRIPTION OF THE DRAWINGS
[0015] Figure 1 It is a schematic diagram of the process of the present invention; Figure 2 is a schematic diagram of an original picture in an embodiment of the present invention; Figure 3 is a schematic diagram for explaining fish parts in an embodiment of the present invention; Figure 4 is a mask image of a fish obtained after instance segmentation in an embodiment of the present invention; Figure 5 is a mask image of a plate obtained after instance segmentation in an embodiment of the present invention; Figure 6 Schematic diagram of the initial fitting result in an embodiment of the present invention; Figure 7 is a schematic diagram of a quadratic fitting result in an embodiment of the present invention; Figure 8 is a schematic diagram of the position of the fish handle in an embodiment of the present invention; Fig. 9 It is a box plot of the proportional relationship between the body length of the fish and the distance from the fish head to the fish handle in an embodiment of the present invention. DETAILED DESCRIPTION
[0016] In order to enable those skilled in the art to better understand the technical solution of the present invention, the present invention is described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0017] First, let’s explain the parts of the big yellow croaker. Figure 3 As shown, Figure 3 The shorter blue vertical line at the tail of the fish is the position of the fish's handle. The two red points and the curve between them are the length from the fish's head to the fish's handle. The distance between the two longer vertical blue lines is the complete body length of the fish given at the end of the experiment.
[0018] like Figure 1 As shown, this embodiment discloses an automated method for measuring the body length of large yellow croaker, comprising: Step 1, image acquisition and processing: The image of the large yellow croaker is completely acquired through an image acquisition device, and a reference straight line of known length is set in the large yellow croaker image. The acquired large yellow croaker image is segmented by an image segmentation model to obtain a mask image, and the size of the obtained mask image is adjusted to be consistent with the original image size.
[0019] In this embodiment, the large yellow croaker is laid flat on a plate with its back facing upward, and a 5 cm straight line (i.e., a reference straight line) is drawn on the plate. Figure 2 As shown, place the plate with the large yellow croaker and the reference line under the image acquisition device to ensure that the fish body is completely within the field of view of the camera. This step is crucial because only when the fish body is completely captured by the camera can the accuracy of subsequent measurements be ensured. Adjust the position and angle of the camera to ensure that all parts of the fish body can be clearly captured. In this process, the shape and size of the fish body and the field of view of the camera need to be taken into account to obtain the best image effect.
[0020] Adjust the light source to ensure that there is enough light during image acquisition, and avoid overexposure or underexposure. Also avoid direct light exposure on the black line to reduce reflections at the black line. Prevent overexposure of the black line due to excessive light source, which may affect the detection of the black line and the accuracy of body length measurement.
[0021] Start the camera and start capturing images of large yellow croakers. Check the image quality to ensure that the image is clear and has no obvious noise. Monitor the image in real time to ensure that there are no problems during the image acquisition process. Image quality checks include contrast, brightness, clarity, and other aspects. Any failure to meet the requirements may lead to inaccurate measurement results.
[0022] The specific process of instance segmentation is as follows: Using the Grounded-Segment-Anything segmentation algorithm, the image is segmented according to the prompt words, so as to achieve accurate segmentation of the large yellow croaker and the plate. The model can identify the features of the fish body and the plate, thereby identifying their contours in the image. First, use GroundingDINO to locate the target object in the image according to the text prompts provided by the user to obtain the bounding box. Then, the bounding box information is passed to the general image segmentation model SAM model, which will perform accurate instance segmentation within these areas. Use the StableDiffusion image generation tool to generate an image based on the text description. Finally, the system fuses the detection and segmentation results to generate the final visual output. Through the segmentation results output by the algorithm, we can obtain the masks of the large yellow croaker and the plate. These masks clearly identify the contours of the fish body and the plate, providing accurate areas for subsequent geometric transformations and data analysis. Figure 2 Perform instance segmentation and obtain the mask image of the fish as follows Figure 4 As shown, the mask image of the plate is Figure 5 shown.
[0023] Step 2, establishment of fish length detection standard: fish length detection standard is established by fitting a quadratic function, and the relationship between fish length and image pixel value is modeled.
[0024] Step 2 specifically includes: Step 2.1: Detect the outer contour of the fish based on the mask of the fish obtained in step 1, and obtain the set of all pixel points in the fish body. These pixel points represent the edge features of the fish body and are the basis for shape analysis.
[0025] The first quadratic function fitting is performed using the pixel set in the fish. The quadratic function, i.e., a parabola, is used to describe the horizontal position and overall direction of the fish. Based on the mask of the fish, the coordinates of all the pixel points where the fish is located can be obtained, and the quadratic function model is fitted to the data points using the nonlinear least squares fitting method curve_fit function. During the fitting process, the curve_fit function will try to adjust the coefficients required by the quadratic function: the values of a, b, and c to minimize the difference between the y value predicted by the model and the y value of the actual data point. After the fitting is completed, the curve_fit function will return an array of the best fitting parameters to obtain a preliminary fitting curve.
[0026] Figure 6 This is the result of the first fitting, and the fitting curve is biased downward.
[0027] The formula of the curve at this time is: .
[0028] Step 2.2, evaluate the fitting results obtained in step 2.1. For the pixels above the fitting curve, it is considered that they may represent the upper edge of the fish body, so a higher weight of 1.2 is assigned to enhance the influence of these points in the fitting process. For the pixels below the fitting curve, a standard weight of 1 is assigned because they are closer to the actual fish body contour. Using the new weight 1:1.2, the quadratic function is refitted using the nonlinear least squares fitting method curve_fit function to obtain a more accurate fitting result. After assigning the new weight, the quadratic function is refitted. This time, the fitting will pay more attention to the pixels on the upper edge of the fish body, so as to obtain a curve that is closer to the actual fish body shape.
[0029] Figure 7 The red line in the figure is the fitted quadratic curve, which serves as a reference for measuring the length of the fish.
[0030] The formula of the curve at this time is: .
[0031] Step 2.3, based on the quadratic fitting curve obtained in step 2.2 and the fish mask, the positions of the fish head and fish handle are obtained.
[0032] In the process of determining the intersection of the quadratic curve and the straight line, we first need to determine the equations of the two lines. The quadratic function is a curve used to describe the horizontal position and overall direction of the fish, that is, Figure 7 The red curve. The straight line is the normal to each pixel in the quadratic function. Then, substitute the equation of the line into the equation of the quadratic curve to form a system of equations. By solving this system of equations, you can find the coordinates of the intersection in the horizontal direction. Next, substitute these coordinates into the equation of the line and calculate the corresponding vertical coordinates. In this way, you can get the specific location of the intersection. Finally, these intersections are verified to ensure that they satisfy the equations of both lines at the same time, thereby determining the accuracy of the intersection. This process will eventually give all valid intersection locations, which are the exact locations where the two curves intersect.
[0033] In this embodiment, the quadratic function equation representing the overall position of the fish is: ; The area near the fish head can be divided into some very small straight lines. The straight lines that intersect the quadratic function equation are the straight lines determined by the two points (615, 712) and (619, 716): ; Finding the intersection of the two gives the point at the fish head: (617, 714).
[0034] Fish handle position detection: In the automated measurement technology solution, first of all, for each point in the quadratic curve fitted in the area from the belly to the tail of the fish, the normal of this point in the quadratic function is made, and the normal intersects with the fish body contour to form a line segment. By measuring the line segment formed by the normal of the quadratic function at each point and the fish contour, this length is recorded. Whenever it is found that the new length value is less than the shortest length recorded before, the record of the shortest length will be updated and the corresponding intersection position will be marked. This process ensures that the shortest distance in the direction perpendicular to the fish can be found, that is, the position of the fish handle. Figure 8 The vertical blue line in the middle of the fish tail is the position of the fish handle. The intersection points of the blue line and the fish are: (1620,722) (1627, 655). The equation of the line is: ; Curve equation: ; The point where the fish handle is located is: (1624, 687).
[0035] Step 3: Use the Hough transform algorithm to detect the reference straight line in the image of step 1 to determine the position and pixel length of the reference straight line.
[0036] The Hough transform algorithm is used in this technical solution to detect black lines in the image and determine their position and pixel length. The detection of black lines is a key step in the measurement process, and it is necessary to ensure the accurate measurement of black lines. As a reference, the accurate measurement of black lines is crucial for the subsequent calculation of the length of the fish. Therefore, the parameters of the Hough transform algorithm need to be adjusted and optimized to improve the accuracy of detection. We adjusted the threshold of the HSV color space to capture specific black tones and saturation intervals. Since the HSV color space is more efficient in color recognition and processing, we converted the input image from the BGR color space to the HSV color space. Subsequently, we performed a dilation operation on the image, which helped to bridge the broken black areas in the image. Next, we performed an erosion operation to eliminate noise and small black areas. In the Hough transform, we set the distance resolution to 1 and the angle resolution to Π / 180. We set the minimum detection length of a straight line to 130 pixels, and only straight lines exceeding this length will be recognized. At the same time, we set the maximum gap between straight lines to 8 pixels. If the gap between two straight lines is less than this value, they will be considered to belong to the same straight line. In addition, we have set the accumulator threshold to 50, which means that only when the accumulator value of a line exceeds this threshold will the line be confirmed as a valid line.
[0037] Step 4, perform perspective transformation on the image obtained in step 1, and project the fish body in the three-dimensional space onto a two-dimensional plane.
[0038] Perspective transformation is a geometric transformation that maps the three-dimensional structure in the image onto a two-dimensional plane while maintaining the linearity of the lines. This step requires first calculating a perspective transformation matrix, which is based on two sets of points: source points and destination points. The source points are the set of points in the original position in the image, that is, the four corner points of the plate, and the destination points are the new positions that these points should be mapped to after the perspective transformation, that is, the four vertices of the original rectangular image. After the perspective transformation matrix is calculated, the original image is transformed using this matrix to generate a new image. This new image is the result of the original image after the perspective transformation, only the image of the inside of the plate is shown, and its size is specified to be the same as the original image. The purpose of the perspective transformation is to remove the perspective distortion in the image to obtain accurate measurement results. This step involves the technique of orthogonally projecting points in a three-dimensional coordinate system onto a two-dimensional plane, which is achieved through matrix operations. The matrix parameters need to be accurately calculated to ensure the accuracy of the transformation. This may include calculating the intrinsic and extrinsic parameters of the camera, as well as the position of the fish in three-dimensional space.
[0039] The detection process of the four corner points of the plate is as follows: after obtaining the mask of the plate, the four corner points of the plate are detected, which is usually achieved by a corner point detection algorithm. The algorithm can identify the intersection points of straight lines in the image, and these intersection points are the corner points of the plate. Figure 5 The four corner points are: [354, 549], [2030, 499], [2203, 1731], [222, 1723]. Perspective transformation matrix:
[0040] .
[0041] Step 5, measure the pixel distance between the fish head and the fish handle after the perspective transformation in step 4, and determine the actual length between the fish head and the fish handle based on the relationship between the pixel length of the reference straight line obtained in step 3 and the true length of the reference straight line.
[0042] Since the ratio of the pixel length to the real length of all objects in the image is consistent, the ratio of the real length of the reference line to the pixel length is consistent with the ratio of the pixel length of the distance from the fish head to the fish handle to the complete length of the fish. Knowing the actual length of the reference line and obtaining the pixel lengths of the two after perspective transformation, the actual length of the distance from the fish head to the fish handle can be calculated based on the ratio mentioned above. The purpose of body length calculation is to convert the measurement results in the image into actual physical length. This step requires precise measurement and calculation of the proportional relationship, and considers possible sources of error, such as measurement error of the black line, error of perspective transformation, etc. Appropriate correction measures need to be taken to improve the accuracy of the measurement.
[0043] The calculation method is as follows: the pixel distance of the black line is L1=324.94; the real length of the black line is L2=5cm; the pixel length from the fish head to the fish handle is Y1=1369.64; the real length from the fish head to the fish handle is Y2. L1 / L2= Y1 / Y2,
[0044] The actual length from the fish head to the fish handle is Y2=21.07cm.
[0045] Step 6, analyze the multiple relationship between the actual length between the fish head and the fish handle obtained in step 5 and the complete body length of the fish, draw a box plot and a scatter plot, and select an appropriate multiple relationship based on the analysis results.
[0046] Step 7, calculate the complete body length of the fish based on the multiple relationship obtained in step 6.
[0047] After measuring the distance from the fish head to the handle, it is necessary to further analyze the proportional relationship between the fish's body length and this distance. After statistical analysis, it was found that the median of this ratio was 1.09, while the mean was slightly higher, at 1.10. Given that the median can better reflect the central tendency of the data and is not easily affected by extreme values, the median was chosen as the basis for determining the multiple. Therefore, the distance from the fish head to the handle was multiplied by this median multiple to obtain the true predicted body length of the fish. This method improves the accuracy and reliability of the prediction.
[0048] Fig. 9 This is a box plot of the proportional relationship between the body length of the fish and the distance from the fish head to the fish handle. Most of the values are concentrated between 1.08 and 1.11, with a median of 1.09.
[0049] The measured body length of the fish is output to a text file for users to view and analyze the measurement results. The body length is the distance between the two blue lines in the numerical direction. That is, the actual length from the head to the handle of the fish is 21.07cm×1.09=22.97cm.
[0050] The above embodiments are only exemplary embodiments of the present invention and are not intended to limit the present invention. Those skilled in the art may make various modifications or equivalent substitutions to the present invention within the essence and protection scope of the present invention, and such modifications or equivalent substitutions shall also be deemed to fall within the protection scope of the present invention.
Claims
1. An automated method for measuring the body length of large yellow croaker, characterized in that: include: Step 1, image acquisition and processing: a large yellow croaker image is completely acquired through an image acquisition device, and a reference straight line of known length is set in the large yellow croaker image, and an image segmentation model is used to perform instance segmentation on the acquired large yellow croaker image to obtain a mask image, and the size of the obtained mask image is adjusted to be consistent with the original image size; Step 2, establishment of fish body length detection standard: fish body length detection standard is established by fitting a quadratic function, and the relationship between fish body length and image pixel value is modeled; Step 3, using the Hough transform algorithm to detect the reference straight line in the image of step 1, and determine the position and pixel length of the reference straight line; Step 4, performing perspective transformation on the image obtained in step 1, and projecting the fish body in the three-dimensional space onto a two-dimensional plane; Step 5, measuring the pixel distance between the fish head and the fish handle after the perspective transformation in step 4, and determining the actual length between the fish head and the fish handle according to the relationship between the pixel length of the reference straight line obtained in step 3 and the real length of the reference straight line; Step 6, analyzing the multiple relationship between the actual length between the fish head and the fish handle obtained in step 5 and the complete body length of the fish, drawing a box plot and a scatter plot, and selecting a suitable multiple relationship according to the analysis results; Step 7, calculate the complete body length of the fish based on the multiple relationship obtained in step 6.
2. An automated method for measuring the body length of large yellow croaker according to claim 1, characterized in that: The instance segmentation in step 1 specifically includes: locating the target object in the image according to the text prompt provided by the user to obtain a bounding box; passing the bounding box information to the general image segmentation model, and the image segmentation model performs accurate instance segmentation within the bounding box; Use image generation tools to generate images based on text descriptions; the system fuses detection and segmentation results to generate the final visual output.
3. An automated method for measuring the body length of large yellow croaker according to claim 1, characterized in that: The step 2 specifically includes: Step 2.1, according to the mask of the fish obtained in step 1, obtain the coordinates of all the pixels where the fish is located, use the nonlinear least squares fitting method to fit the quadratic function model with the pixel coordinates, and obtain a preliminary fitting curve; Step 2.2, evaluating the fitting result obtained in step 2.1, assigning weight m to the pixel points above the fitting curve, and assigning weight n to the pixel points below the fitting curve; refitting the quadratic function to obtain a quadratic fitting curve close to the actual fish body shape; Step 2.3, based on the quadratic fitting curve obtained in step 2.2 and the fish mask, the positions of the fish head and fish handle are obtained.
4. An automated method for measuring the body length of large yellow croaker according to claim 3, characterized in that: In the step 2.2, m is greater than n.
5. An automated method for measuring the body length of large yellow croaker according to claim 1, characterized in that: The step 3 is specifically as follows: converting the image in step 1 from the BGR color space to the HSV color space, and performing dilation and erosion operations on the image; setting the distance resolution i and the angle resolution j; stipulating that the minimum detection length of a straight line is p pixels; setting the maximum gap between straight lines to q pixels, if the gap between two straight lines is less than q pixels, they are considered to belong to the same straight line; setting the accumulator threshold to w, and only when the accumulator value of a straight line exceeds w, the straight line will be confirmed as a valid straight line.
6. An automated method for measuring the body length of large yellow croaker according to claim 1, characterized in that: The step 4 specifically includes: finding the source point position from the image obtained in step 1, and the new position to which the source point is mapped after perspective transformation, namely, the target point position, obtaining a perspective transformation matrix according to the source point and target point positions, and performing perspective transformation on the image obtained in step 1 through the perspective transformation matrix.