Intelligent measuring and calculating method for length of high-density fish body in culture pond
By improving YOLO network and binocular camera technology, and combining fish morphology constraints and dynamic confidence threshold filtering, parallax matching is optimized to achieve automated, non-contact, and accurate measurement of fish length in high-density fish farming environments. This solves the problems of large measurement errors and low efficiency in existing technologies and provides highly reliable length data support.
Patent Information
- Application Number
- CN202510992172.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-18
- Publication Date
- 2025-11-14
AI Technical Summary
Existing technologies struggle to achieve accurate, reliable, and efficient automatic measurement of fish length in high-density fish farming environments, especially when fish are densely packed and swimming rapidly. Existing methods suffer from large measurement errors, low efficiency, and poor reliability.
By employing an improved YOLO network combined with binocular camera technology, and through fish detection models and camera parameter calibration, multi-level filtering is performed using fish morphology constraints and dynamic confidence thresholds. Combined with the SGBM algorithm to optimize disparity matching, automated and non-contact measurement of fish length is achieved.
It significantly improves the accuracy, efficiency, and reliability of fish length measurement, and can stably output length data that meets the precision requirements of aquaculture management in complex scenarios, reducing the need for manual intervention and making it suitable for continuous monitoring of high-density fish populations.
Smart Images

Figure CN120953346A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of fish length measurement technology, and in particular to an intelligent method for measuring the length of fish in high-density aquaculture ponds. Background Technology
[0002] In factory-style high-density fish farming, accurate measurement of fish body length is a core element for monitoring growth status, optimizing feed delivery, preventing diseases, and improving production efficiency. With the development of the global aquaculture industry, high-density models such as recirculating aquaculture systems (RAS) and cage culture have become mainstream, characterized by high fish carrying capacity per unit water volume (often reaching 100–200 fish / m³). 3 Furthermore, the complex behaviors of fish (such as high-speed swimming and clustering) present significant technical challenges to body length measurement. Accurate body length data can not only be used for individual growth curve analysis, but also guide water quality control and the prevention of stress-related diseases (such as bacterial infections and weakened immunity), thereby effectively improving aquaculture efficiency and economic benefits.
[0003] However, existing measurement technologies face many limitations in large-scale, high-density aquaculture practices, resulting in insufficient accuracy and poor reliability, making it difficult to meet actual needs. Specifically:
[0004] 1. Manual Measurement Method: While low-cost and easy to implement, this method suffers from serious drawbacks in high-density environments. Operators must frequently catch individual fish and perform contact measurements using calipers, a time-consuming process (each measurement > 10 seconds) and inefficient, failing to meet the requirements of high-frequency monitoring (ideally, an interval of approximately 30 minutes). Repeated operations can easily induce severe stress responses in the fish population (manifested as elevated cortisol levels), leading to abnormal behavior, decreased feed intake, and even mass mortality. In high-density environments, overlapping fish bodies interfere with manual identification of individual boundaries, resulting in measurement errors as high as ±(5%–10%), far exceeding the acceptable ±2% threshold for aquaculture management. Therefore, the manual measurement method is no longer suitable for modern large-scale aquaculture, and an automated, non-contact alternative is urgently needed.
[0005] 2. Methods based on general object detection algorithms (such as YOLO): These methods aim to automate measurements using computer vision, but their accuracy drops significantly in environments with severe occlusion caused by densely packed fish. Algorithms like YOLO rely on convolutional neural networks (CNNs) to process images and use anchor boxes to locate objects. In high-density conditions where fish outlines overlap, the model's feature extraction is prone to losing key boundary information, leading to a surge in false positives and false negatives.
[0006] 3. Monocular Vision Method: This method, relying solely on a single RGB camera, is simple in structure and low in cost. However, due to the lack of depth data, it struggles to effectively handle fish overlap issues, severely impacting measurement accuracy. Its measurement principle is based on estimating actual size using pixel coordinates and calibration parameters. However, visual confusion caused by dense fish schools (such as fish stacking) prevents the algorithm from segmenting individuals and accurately locating key points (such as head and tail positions). Furthermore, two-dimensional imaging cannot compensate for distance perception distortion caused by changes in fish posture (such as tilting while swimming) and is easily affected by ambient lighting (such as strong reflections and shadows), resulting in low applicability in aquaculture ponds with multiple light sources.
[0007] 4. Binocular Vision Method: This method uses dual cameras to acquire parallax for depth calculation, partially addressing the shortcomings of monocular methods. However, significant problems remain in high-density scenes. This technique utilizes stereo matching algorithms (such as semi-global matching) to generate point cloud data to provide 3D coordinate support for measurement. However, the blurred boundaries of high-density fish schools, synchronization errors caused by rapid movement, and low-texture fish surfaces (such as scaleless areas) severely reduce feature point stability and exacerbate matching errors at occluded locations. These issues lead to poor depth map quality (e.g., generating false depth values), ultimately amplifying length calculation errors.
[0008] In summary, existing technologies are insufficient to effectively solve the challenge of accurately and automatically measuring the body length of fish in high-density aquaculture. Therefore, providing an intelligent method for calculating the body length of fish in high-density aquaculture ponds, thereby improving the accuracy, efficiency, and reliability of fish length measurement, has become an urgent technical problem to be solved. Summary of the Invention
[0009] The technical problem to be solved by this invention is to provide an intelligent method for calculating the body length of fish in high-density aquaculture ponds, thereby improving the accuracy, efficiency and reliability of fish body length calculation.
[0010] This invention is implemented as follows: A method for intelligently calculating the body length of fish in high-density aquaculture ponds, comprising the following steps:
[0011] Step S1: Create a fish detection model based on the YOLO network and set the loss function of the fish detection model;
[0012] Step S2: Obtain a large number of historical fish school images, preprocess and label each of the historical fish school images to construct a dataset, train the fish detection model using the dataset and loss function, and deploy the trained fish detection model.
[0013] Step S3: Set fish morphology constraint parameters, calibrate the camera parameters of the binocular camera, collect video of the breeding pond through the binocular camera, and analyze the video of the breeding pond to obtain the left eye image and the right eye image.
[0014] Step S4: Input the left and right eye images into the deployed fish detection model to obtain fish body bounding boxes with confidence scores. Filter the fish body bounding boxes using the fish species morphology constraint parameters and confidence scores.
[0015] Step S5: Perform stereo matching on the fish body bounding boxes based on the left and right eye images to calculate the depth value of the fish body corresponding to each fish body bounding box;
[0016] Step S6: Using the camera parameters and depth values, convert the pixel coordinates of the fish body bounding box into physical dimensions, and obtain the initial fish body length based on the physical dimensions;
[0017] Step S7: Take the average of the initial fish lengths calculated within the preset time period to obtain the optimized fish length, and output the optimized fish length.
[0018] Furthermore, in step S1, the backbone network of the YOLO network adopts CSPDarknet, the neck adopts PAN-FPN, and both the backbone network and the neck introduce SPPF and C2f modules.
[0019] The attention module, which is guided by prior knowledge embedded in the neck, is calculated as follows:
[0020]
[0021] Among them, Att out The attention value of the fish is represented by Q; the query matrix is represented by K; the key matrix is represented by T; and d represents the transpose of the query matrix. k M represents the dimension of the key vector, i.e., the scaling factor; prior V represents the prior matrix indicating the location of key points on the fish's body; V represents the value matrix.
[0022] The output of the fish detection model is:
[0023] P∈R H×W×C ;
[0024] Where P represents a 3D tensor; R represents a real number; H represents the height of the detection grid in the input image, which is obtained by the YOLO network dividing the input image based on a preset grid size; W represents the width of the detection grid in the input image; C represents the number of channels predicted by each detection grid, C = 4 + 1 + K, where 4 represents the fish body bounding box parameters, 1 represents the confidence level, and K represents the fish body category probability; the fish body bounding box parameters include the x-coordinate b of the bounding box center point. x , the ordinate of the center point of the bounding box b y , bounding box width b w , bounding box height b h .
[0025] Furthermore, in step S1, the formula for the loss function is:
[0026]
[0027] in, This represents the loss value of the loss function; The bounding box loss is represented by CIoU Loss; The confidence loss is represented by the binary cross-entropy loss. Represents classification loss; λ box , λ obj , λ cls All of these represent weighting coefficients.
[0028] Furthermore, step S2 specifically includes:
[0029] A large number of historical fish school images are acquired, and each of the historical fish school images is preprocessed with image enhancement. After labeling the fish positions and fish lengths of the preprocessed historical fish school images, a dataset is constructed. The dataset is divided into a training set, a validation set, and a test set based on a preset ratio.
[0030] The fish detection model is trained using the training set until the loss value of the loss function is less than a preset loss threshold. The trained fish detection model is then validated using the validation set. The validated fish detection model is tested using the test set, and the tested fish detection model is then deployed.
[0031] Furthermore, in step S2, during the training of the fish detection model, the predicted fish body bounding boxes and the labeled fish body positions are dynamically matched by a task alignment allocator, and redundant fish body bounding boxes are filtered out by nonmaximum suppression.
[0032] Furthermore, step S3 specifically includes:
[0033] Fish morphological constraint parameters, including fish species, length range, width range, aspect ratio threshold range, and anatomical structure proportions, are set. Camera parameters of the binocular camera, including at least focal length, principal point coordinates, and baseline distance, are calibrated. Video of the aquaculture pond is acquired through the binocular camera, and the video of the aquaculture pond is analyzed to obtain the left eye image and the right eye image. The focal length includes horizontal focal length and vertical focal length.
[0034] Furthermore, step S4 specifically includes:
[0035] The left and right eye images are input into the deployed fish detection model to obtain fish body bounding boxes with confidence scores. The fish body bounding boxes are filtered firstly using the fish species morphology constraint parameters. The confidence scores are then verified using a preset dynamic confidence threshold to perform secondary filtering on each fish body bounding box. The dynamic confidence threshold is dynamically adjusted based on image sharpness and fish body occlusion rate.
[0036] Furthermore, step S5 specifically includes:
[0037] From the left and right eye images respectively, the left and right target regions of each fish body bounding box are identified. Based on a preset disparity search range, the SGBM algorithm is used to slide and search for the best matching block of the left target region within the right target region. The best matching block is then subjected to occlusion processing and filtering smoothing to obtain the disparity. Based on the disparity and camera parameters, the depth value of the fish body corresponding to the fish body bounding box is calculated.
[0038] Z = (f × B) / d;
[0039] Where Z represents the depth value; f represents the focal length; B represents the baseline distance; and d represents the parallax.
[0040] Furthermore, in step S6, the formula for converting the pixel coordinates of the fish body bounding box into physical dimensions is as follows:
[0041]
[0042] Where W represents the actual width of the fish; H represents the actual height of the fish; Z represents the depth value; w px The width of the fish's bounding box in pixels; h px f represents the pixel height of the fish's bounding box; x Indicates the horizontal focal length; f y Indicates the vertical focal length.
[0043] The advantages of this invention are:
[0044] 1. A fish detection model is created using a YOLO network, and its loss function is defined. A large dataset of historical fish images is then acquired and used to train the fish detection model using the dataset and the loss function. The trained model is then deployed. Next, fish morphology constraint parameters are set, and the camera parameters of the binocular camera are calibrated. Video from the aquaculture pond is captured using the binocular camera, and the left and right eye images are obtained by analyzing the video. These images are then input into the deployed fish detection model to obtain fish bounding boxes with confidence scores. The bounding boxes are filtered using the fish morphology constraint parameters and confidence scores. Stereo matching is performed on the bounding boxes based on the left and right eye images to calculate the depth value of each bounding box. Finally, the pixel coordinates of the fish bounding boxes are converted to physical dimensions using the camera parameters and depth values. The initial fish length is obtained based on these physical dimensions, and the average of the initial fish lengths calculated over a preset time period is taken. The system optimizes and outputs fish length measurements. Specifically, it incorporates an attention module with prior knowledge of fish key points to enhance the recognition of occluded targets. Dual filtering, combining fish morphology constraints and dynamic confidence thresholds, effectively eliminates false detections. Simultaneously, based on precisely calibrated binocular camera parameters, the SGBM algorithm optimizes disparity matching and calculates depth values. A physical size conversion formula eliminates attitude tilt errors, significantly improving the accuracy of fish length measurement. A fully automated process replaces manual operation. An improved fish detection model, combined with a task alignment allocator, accelerates dense target processing. High-frequency real-time output is achieved through multi-frame averaging within a preset timeframe, greatly improving the efficiency of fish length measurement. Occlusion processing and filtering after stereo matching improve depth map quality, while temporal averaging suppresses transient interference, ensuring stable output of length data that meets aquaculture management accuracy requirements even in complex scenarios such as fish stacking and rapid swimming, thus significantly improving the reliability of fish length measurement.
[0045] 2. By adopting an improved YOLO network, the backbone network uses CSPDarknet, the neck uses PAN-FPN, and SPPF and C2f modules are introduced. These modules enhance the feature extraction capability. At the same time, a prior knowledge-guided attention module is embedded. This module uses the prior matrix of the fish body key point position to guide attention, making the model more focused on the fish body related regions. This design significantly improves the accuracy of fish detection, especially in high-density fish groups with overlapping or occluded fish bodies. The attention module integrates domain knowledge (such as fish body anatomy), reduces background interference, and improves the accuracy of bounding box localization. This is more adaptable to the complexity of the aquaculture environment than the traditional YOLO model, reduces the false detection rate, and enhances the model's generalization ability to different fish species and postures.
[0046] 3. Multi-level filtering is performed using fish morphology constraint parameters (such as length range, aspect ratio threshold, etc.) and dynamic confidence thresholds (first-level filtering is based on morphology parameters, and second-level filtering dynamically adjusts confidence based on image sharpness and occlusion rate). Combined with binocular stereo matching, the initial fish length within a preset time period is averaged to achieve optimization. This method effectively addresses the challenges posed by high-density fish populations in aquaculture ponds, such as fish overlap, motion blur, or occlusion. The multi-level filtering mechanism reduces false detections and false negatives. The SGBM algorithm (Semi-Global Block Matching) optimizes matching within the disparity search range, improving the stability of depth calculation. Finally, length optimization (average processing) smooths out instantaneous noise, ensuring more reliable output results. Overall, it maintains high robustness in complex environments and reduces the need for manual intervention.
[0047] 4. Because the YOLO model itself is known for its high efficiency (faster than traditional detection models), the training process uses a task alignment allocator to dynamically match predicted boxes and non-maximum suppression to filter redundant bounding boxes, reducing computational overhead. Stereo matching and coordinate transformation are based on calibrated camera parameters, optimizing the algorithm implementation. The entire process is compactly designed. YOLO's lightweight structure and efficient training strategies (such as dataset partitioning and image augmentation) ensure rapid model deployment and inference. The use of binocular cameras allows for parallel processing of left and right eye images. Depth calculation and coordinate transformation formulas simplify physical size estimation, enabling the system to process video streams in real time. This is suitable for continuous monitoring of aquaculture ponds, saving a significant amount of time compared to traditional manual measurement or monocular camera methods.
[0048] 5. The composite loss function optimizes the balance between bounding box regression, confidence, and classification; CloU Loss improves the localization accuracy of the bounding boxes and reduces training instability; the task alignment allocator dynamically matches predictions and annotations, improving learning efficiency; image enhancement (such as rotation or cropping) enhances data diversity and makes the model more robust. These mechanisms ensure high detection accuracy while reducing the risk of overfitting.
[0049] 6. By integrating an improved YOLO deep learning model (introducing an attention module guided by prior knowledge and a CSPDarknet backbone network) with binocular stereo vision technology, automated, non-contact, and accurate measurement of fish length in high-density aquaculture ponds was achieved. The core advantages are: significantly improving the robustness of detection in overlapping and occluded fish scenarios through multi-level morphological constraints and dynamic confidence threshold filtering mechanisms; effectively reducing length measurement errors by optimizing the formulaic process of disparity calculation and depth value conversion to physical dimensions using the binocular SGBM algorithm; and balancing real-time processing efficiency with cross-species adaptability through temporal mean optimization and camera parameter calibration, effectively solving the problems of low efficiency and poor monocular vision accuracy in traditional manual measurement, providing highly reliable data support for intelligent aquaculture management. Attached Figure Description
[0050] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0051] Figure 1 This is a flowchart of an intelligent method for calculating the body length of high-density fish in aquaculture ponds, according to the present invention.
[0052] Figure 2 This is a schematic diagram of the fish body boundary frame for both valid and invalid aspects of the present invention. Detailed Implementation
[0053] The overall approach of the technical solution in this application is as follows: An attention module incorporating prior knowledge of key fish points enhances the ability to identify occluded targets. Dual filtering, combining fish morphology constraints and dynamic confidence thresholds, effectively eliminates false detections. Simultaneously, based on precisely calibrated binocular camera parameters, the SGBM algorithm optimizes disparity matching and calculates depth values. A physical size conversion formula eliminates attitude tilt errors, thereby improving the accuracy of fish length measurement. A fully automated process replaces manual operation. An improved fish detection model, combined with a task alignment allocator, accelerates dense target processing. High-frequency real-time output is achieved through multi-frame mean calculation within a preset timeframe, improving the efficiency of fish length measurement. Occlusion processing and filtering after stereo matching improve the quality of the depth map. Temporal mean optimization suppresses transient interference, ensuring stable output of length data that meets the accuracy requirements of aquaculture management in complex scenarios such as fish stacking and rapid swimming, thus enhancing the reliability of fish length measurement.
[0054] Please refer to Figures 1 to 2 As shown, a preferred embodiment of the intelligent method for calculating the body length of high-density fish in aquaculture ponds according to the present invention includes the following steps:
[0055] Step S1: Create a fish detection model based on the YOLO network and set the loss function of the fish detection model; the fish detection model performs real-time detection based on the morphological features of farmed fish (such as typical aspect ratio, body color and texture, etc.);
[0056] Step S2: Obtain a large number of historical fish school images, preprocess and label each of the historical fish school images to construct a dataset, train the fish detection model using the dataset and loss function, and deploy the trained fish detection model.
[0057] Step S3: Set the fish morphology constraint parameters, calibrate the camera parameters of the binocular camera, and collect the aquaculture pond video through the binocular camera (which has been stereo-corrected to an epipolar alignment state). Analyze the aquaculture pond video to obtain the left and right eye images. Before the binocular camera takes pictures, stereo correction is also performed, that is, aligning the left and right images to the same plane, making the epipolar lines horizontal, and simplifying the parallax calculation.
[0058] Step S4: Input the left and right eye images into the deployed fish detection model to obtain fish body bounding boxes with confidence scores. Filter the fish body bounding boxes using the fish species morphology constraint parameters and confidence scores.
[0059] Step S5: Perform stereo matching on the fish body bounding boxes based on the left and right eye images to calculate the depth value of the fish body corresponding to each fish body bounding box;
[0060] Step S6: Using the camera parameters and depth values, and with the help of geometric projection, convert the pixel coordinates of the fish body bounding box into physical dimensions, and obtain the initial fish body length based on the physical dimensions;
[0061] Step S7: Take the average of the initial fish lengths calculated within a preset time period to obtain the optimized fish length, and output the optimized fish length. For example, take the average of the initial fish lengths within 10 minutes. In specific implementation, a weighted average can be performed based on confidence level, and outliers can also be eliminated by combining a fish school behavior model.
[0062] This invention significantly improves detection accuracy in high-density aquaculture scenarios by implanting fish-specific features (fish morphological constraint parameters), effectively solving the problems of missed and false detections caused by fish occlusion. Combining motion trajectory prediction and stereo matching optimization, it can stably calculate depth values even in severely occluded environments, overcoming the shortcomings of traditional monocular vision (lack of depth information) or the susceptibility to failure in binocular matching. By introducing a temporal fusion algorithm and outlier filtering mechanism, it ensures the continuity and stability of long-term monitoring data, avoiding interference from instantaneous errors in aquaculture management. Employing a general-purpose binocular camera, high-precision measurement is achieved through algorithm optimization rather than hardware upgrades, making it suitable for large-scale deployment needs in factory farming.
[0063] In step S1, the backbone of the YOLO network adopts CSPDarknet, the neck adopts PAN-FPN, and both the backbone and the neck introduce SPPF (Spatial Pyramid Pooling Fast Version) and C2f module (Bottleneck structure with cross-stage partial fusion).
[0064] The attention module, which is guided by prior knowledge embedded in the neck, is calculated as follows:
[0065]
[0066] Among them, Att out The attention value of the fish is represented by Q; the query matrix is represented by K; the key matrix is represented by T; and d represents the transpose of the query matrix. k M represents the dimension of the key vector, i.e., the scaling factor;prior The prior matrix representing the location of key points on the fish body (an attention-guided matrix constructed based on the biological characteristics of the fish species, reflecting the spatial distribution pattern of key parts of the fish body (such as the head and trunk); V represents the value matrix;
[0067] The output of the fish detection model is:
[0068] P∈R H×W×C ;
[0069] Where P represents a 3D tensor; R represents a real number; H represents the height of the detection grid in the input image, which is obtained by the YOLO network dividing the input image based on a preset grid size; W represents the width of the detection grid in the input image; C represents the number of channels predicted by each detection grid, C = 4 + 1 + K, where 4 represents the fish body bounding box parameters, 1 represents the confidence level, and K represents the probability of the fish body's class (there are K classes in total, which can be simplified to 1 for a single fish scene); the fish body bounding box parameters include the x-coordinate b of the bounding box center point. x , the ordinate of the center point of the bounding box b y , bounding box width b w , bounding box height b h The grid size for detection is determined by the input image size and the downsampling rate.
[0070] b x =σ(t) x )·s x +c x ;
[0071] b y =σ(t) y )·s y +c y ;
[0072]
[0073] Where σ() represents the Sigmoid function, used to constrain the center point coordinates within the current detection grid (value range 0 to 1); (t x ,t y ,) represents the offset of the center point of the model output; (t w ,t h ,) represents the dimensional offset of the model output; (c x ,c y (s) represents the coordinates of the top-left corner of the current detection grid; x ,s y ) represents the scaling factor for the width and height of the detection grid (usually set to 1).
[0074] In step S1, the formula for the loss function is:
[0075]
[0076] in, This represents the loss value of the loss function; The bounding box loss is represented by CIoU Loss, which comprehensively considers overlapping areas, center point distance, and aspect ratio. The confidence loss is represented by the binary cross-entropy loss. The classification loss is represented by multi-class cross-entropy or Focal Loss; λ box , λ obj , λ cls All of these represent weighting coefficients.
[0077]
[0078] Among them, b pred Represents the bounding box of the fish body; b gt ρ represents the labeled fish body location, i.e., the ground truth bounding box; ρ represents the Euclidean distance between the initial detection result and the labeled data center point; c represents the diagonal length of the minimum bounding box; α box Indicates the aspect ratio penalty weight; v represents the aspect ratio difference penalty term;
[0079]
[0080] Among them, w gt Indicates the width of the labeled data; h gt Indicates the height of the labeled data; w pred Indicates the width of the fish's bounding box; h pred Indicates the height of the fish's bounding box;
[0081]
[0082] Where y represents the true label (1 for foreground, 0 for background); p represents the confidence level of the model prediction;
[0083]
[0084] Among them, y k Represents the true label (one-hot encoded) of category k; p k This represents the class probability predicted by the model.
[0085] Step S2 specifically involves:
[0086] A large number of historical fish school images are acquired, and each of the historical fish school images is preprocessed with image enhancement. After labeling the fish positions and fish lengths of the preprocessed historical fish school images, a dataset is constructed. The dataset is divided into a training set, a validation set, and a test set based on a preset ratio.
[0087] The fish detection model is trained using the training set until the loss value of the loss function is less than a preset loss threshold. The trained fish detection model is then validated using the validation set. The validated fish detection model is tested using the test set, and the tested fish detection model is then deployed.
[0088] In step S2, during the training of the fish detection model, the predicted fish bounding boxes and the labeled fish positions are dynamically matched by a task-aligned assigner, and redundant fish bounding boxes are filtered out by nonmaximum suppression.
[0089] The formula for the task alignment allocator is:
[0090]
[0091] Where s represents the alignment score, and the initial detection result with the highest s is selected as the positive sample; α assign The IoU() represents the classification-localization balance coefficient; IoU() represents the intersection-union ratio between the fish body bounding box and the labeled data.
[0092] The formula for nonmaximum suppression (NMS) is:
[0093] NMS: Preserve argmax(score) i ), Delete IoU(b i ,b j )>τ;
[0094] Where τ represents the IoU threshold (default 0.5); score i b represents the overall score of the bounding box of the i-th fish body; i b represents the coordinates of the bounding box of the i-th fish body; j This represents the coordinates of the bounding box of the j-th fish body (and b). i (Comparison of candidate boxes).
[0095] Step S3 specifically involves:
[0096] Fish morphological constraint parameters are set, including fish species, length range, width range, aspect ratio threshold range (set according to the biological characteristics of the target fish species), and anatomical structure proportions (length ratio range of head / body / tail). For example, for rainbow trout, the ratio is 3.5:1 to 6:1. Camera parameters for the binocular camera, including at least focal length, principal point coordinates, and baseline distance, are calibrated. Video from the aquaculture pond is acquired using the binocular camera, and the video is analyzed to obtain left and right eye images. The focal length includes both horizontal and vertical focal lengths. These fish morphological constraint parameters are used to filter out valid fish body bounding boxes that meet the requirements, excluding invalid detection results caused by fish body bending or occlusion.
[0097] If the horizontal field of view θ of the binocular camera is known... x It can be achieved through the image width W img Calculate focal length:
[0098]
[0099] The same applies to the vertical direction.
[0100] Step S4 specifically involves:
[0101] The left and right eye images are input into the deployed fish detection model to obtain fish body bounding boxes with confidence scores. The fish body bounding boxes are filtered firstly using the fish species morphology constraint parameters. The confidence scores are then verified using a preset dynamic confidence threshold to perform secondary filtering on each fish body bounding box. The dynamic confidence threshold is dynamically adjusted based on image sharpness and fish body occlusion rate.
[0102] The dynamic confidence threshold is used to control the retention threshold of fish bounding boxes, with a value range of [0.6, 0.8]. The adjustment logic is as follows: the higher the image sharpness, the lower the threshold can be (allowing more candidate boxes to enter the screening); the higher the occlusion rate, the higher the threshold needs to be (avoiding false detections). Image sharpness (IC) is the average gradient magnitude of the fish edge region (unit: pixel intensity difference); occlusion rate (OR) is the area ratio of the occluded region in a single fish bounding box, and the judgment criterion is: calculated by matching the difference through prior texture templates (difference > 50% is considered occlusion).
[0103] The formula for calculating the dynamic confidence threshold is:
[0104]
[0105] Where IC represents image sharpness; OR represents fish occlusion rate; OR max Indicates the maximum fish body occlusion rate; IC max Indicates the maximum image sharpness; represents the pixel gradient (edge intensity) calculated by the Sobel operator; N represents the number of valid pixels within the fish body bounding box (excluding occluded areas); the valid texture area is the pixel area within the fish body bounding box that has a similarity of ≥0.5 with the prior texture template.
[0106] Step S5 specifically involves:
[0107] From the left and right images respectively, the left and right target regions of each fish body bounding box are identified. Based on a preset disparity search range (adapted to the typical depth range of the aquaculture pond) and a maximum inter-frame displacement threshold (fish motion constraint), the SGBM algorithm is used to slide and search for the best matching block of the left target region within the right target region. The best matching block is then subjected to occlusion processing (marking areas where the left and right images do not match as invalid and completing them through motion trajectory prediction from adjacent frames) and filtering and smoothing processing (using WLS filtering to eliminate noise and retain stable disparity values of fish body key points) to obtain the disparity. Based on the disparity and camera parameters, the depth value of the fish body corresponding to the fish body bounding box is calculated.
[0108] Z = (f × B) / d;
[0109] Where Z represents the depth value (meters), i.e., the vertical depth from the target point to the camera; f represents the focal length (pixels); B represents the baseline distance (meters), i.e., the baseline distance between the optical centers of the two cameras. The longer the baseline, the higher the accuracy at long distances, but it will reduce the effective measurement range (the field of view may not overlap at close range); d represents the parallax (pixels), i.e., the difference in the horizontal coordinates of the same target point in the left and right images, d = x left -x right The smaller the parallax, the deeper the depth. There is a non-linear relationship between parallax and depth: depth is inversely proportional to parallax. At close range, parallax changes are sensitive, while at long range, the depth estimation error is larger.
[0110] The formula for handling occlusion is:
[0111]
[0112] in, σ represents the predicted depth based on the motion trajectory; σ represents the standard deviation threshold of the depth estimate.
[0113] In step S6, the formula for converting the pixel coordinates of the fish body bounding box into physical dimensions is as follows:
[0114]
[0115] Where W represents the actual width of the fish; H represents the actual height of the fish; Z represents the depth value; w px The width of the fish's bounding box in pixels; h pxf represents the pixel height of the fish's bounding box; x Indicates the horizontal focal length; f y Indicates the vertical focal length.
[0116] In summary, the advantages of this invention are:
[0117] 1. A fish detection model is created using a YOLO network, and its loss function is defined. A large dataset of historical fish images is then acquired and used to train the fish detection model using the dataset and the loss function. The trained model is then deployed. Next, fish morphology constraint parameters are set, and the camera parameters of the binocular camera are calibrated. Video from the aquaculture pond is captured using the binocular camera, and the left and right eye images are obtained by analyzing the video. These images are then input into the deployed fish detection model to obtain fish bounding boxes with confidence scores. The bounding boxes are filtered using the fish morphology constraint parameters and confidence scores. Stereo matching is performed on the bounding boxes based on the left and right eye images to calculate the depth value of each bounding box. Finally, the pixel coordinates of the fish bounding boxes are converted to physical dimensions using the camera parameters and depth values. The initial fish length is obtained based on these physical dimensions, and the average of the initial fish lengths calculated over a preset time period is taken. The system optimizes and outputs fish length measurements. Specifically, it incorporates an attention module with prior knowledge of fish key points to enhance the recognition of occluded targets. Dual filtering, combining fish morphology constraints and dynamic confidence thresholds, effectively eliminates false detections. Simultaneously, based on precisely calibrated binocular camera parameters, the SGBM algorithm optimizes disparity matching and calculates depth values. A physical size conversion formula eliminates attitude tilt errors, significantly improving the accuracy of fish length measurement. A fully automated process replaces manual operation. An improved fish detection model, combined with a task alignment allocator, accelerates dense target processing. High-frequency real-time output is achieved through multi-frame averaging within a preset timeframe, greatly improving the efficiency of fish length measurement. Occlusion processing and filtering after stereo matching improve depth map quality, while temporal averaging suppresses transient interference, ensuring stable output of length data that meets aquaculture management accuracy requirements even in complex scenarios such as fish stacking and rapid swimming, thus significantly improving the reliability of fish length measurement.
[0118] 2. By adopting an improved YOLO network, the backbone network uses CSPDarknet, the neck uses PAN-FPN, and SPPF and C2f modules are introduced. These modules enhance the feature extraction capability. At the same time, a prior knowledge-guided attention module is embedded. This module uses the prior matrix of the fish body key point position to guide attention, making the model more focused on the fish body related regions. This design significantly improves the accuracy of fish detection, especially in high-density fish groups with overlapping or occluded fish bodies. The attention module integrates domain knowledge (such as fish body anatomy), reduces background interference, and improves the accuracy of bounding box localization. This is more adaptable to the complexity of the aquaculture environment than the traditional YOLO model, reduces the false detection rate, and enhances the model's generalization ability to different fish species and postures.
[0119] 3. Multi-level filtering is performed using fish morphology constraint parameters (such as length range, aspect ratio threshold, etc.) and dynamic confidence thresholds (first-level filtering is based on morphology parameters, and second-level filtering dynamically adjusts confidence based on image sharpness and occlusion rate). Combined with binocular stereo matching, the initial fish length within a preset time period is averaged to achieve optimization. This method effectively addresses the challenges posed by high-density fish populations in aquaculture ponds, such as fish overlap, motion blur, or occlusion. The multi-level filtering mechanism reduces false detections and false negatives. The SGBM algorithm (Semi-Global Block Matching) optimizes matching within the disparity search range, improving the stability of depth calculation. Finally, length optimization (average processing) smooths out instantaneous noise, ensuring more reliable output results. Overall, it maintains high robustness in complex environments and reduces the need for manual intervention.
[0120] 4. Because the YOLO model itself is known for its high efficiency (faster than traditional detection models), the training process uses a task alignment allocator to dynamically match predicted boxes and non-maximum suppression to filter redundant bounding boxes, reducing computational overhead. Stereo matching and coordinate transformation are based on calibrated camera parameters, optimizing the algorithm implementation. The entire process is compactly designed. YOLO's lightweight structure and efficient training strategies (such as dataset partitioning and image augmentation) ensure rapid model deployment and inference. The use of binocular cameras allows for parallel processing of left and right eye images. Depth calculation and coordinate transformation formulas simplify physical size estimation, enabling the system to process video streams in real time. This is suitable for continuous monitoring of aquaculture ponds, saving a significant amount of time compared to traditional manual measurement or monocular camera methods.
[0121] 5. The composite loss function optimizes the balance between bounding box regression, confidence, and classification; CloU Loss improves the localization accuracy of the bounding boxes and reduces training instability; the task alignment allocator dynamically matches predictions and annotations, improving learning efficiency; image enhancement (such as rotation or cropping) enhances data diversity and makes the model more robust. These mechanisms ensure high detection accuracy while reducing the risk of overfitting.
[0122] 6. By integrating an improved YOLO deep learning model (introducing an attention module guided by prior knowledge and a CSPDarknet backbone network) with binocular stereo vision technology, automated, non-contact, and accurate measurement of fish length in high-density aquaculture ponds was achieved. The core advantages are: significantly improving the robustness of detection in overlapping and occluded fish scenarios through multi-level morphological constraints and dynamic confidence threshold filtering mechanisms; effectively reducing length measurement errors by optimizing the formulaic process of disparity calculation and depth value conversion to physical dimensions using the binocular SGBM algorithm; and balancing real-time processing efficiency with cross-species adaptability through temporal mean optimization and camera parameter calibration, effectively solving the problems of low efficiency and poor monocular vision accuracy in traditional manual measurement, providing highly reliable data support for intelligent aquaculture management.
[0123] While specific embodiments of the present invention have been described above, those skilled in the art should understand that the specific embodiments described are merely illustrative and not intended to limit the scope of the present invention. Equivalent modifications and variations made by those skilled in the art in accordance with the spirit of the present invention should be covered within the scope of protection of the claims of the present invention.
Claims
1. A method for intelligently calculating the body length of high-density fish in aquaculture ponds, characterized in that: Includes the following steps: Step S1: Create a fish detection model based on the YOLO network and set the loss function of the fish detection model; Step S2: Obtain a large number of historical fish school images, preprocess and label each of the historical fish school images to construct a dataset, train the fish detection model using the dataset and loss function, and deploy the trained fish detection model. Step S3: Set fish morphology constraint parameters, calibrate the camera parameters of the binocular camera, collect video of the breeding pond through the binocular camera, and analyze the video of the breeding pond to obtain the left eye image and the right eye image. Step S4: Input the left and right eye images into the deployed fish detection model to obtain fish body bounding boxes with confidence scores. Filter the fish body bounding boxes using the fish species morphology constraint parameters and confidence scores. Step S5: Perform stereo matching on the fish body bounding boxes based on the left and right eye images to calculate the depth value of the fish body corresponding to each fish body bounding box; Step S6: Using the camera parameters and depth values, convert the pixel coordinates of the fish body bounding box into physical dimensions, and obtain the initial fish body length based on the physical dimensions; Step S7: Take the average of the initial fish lengths calculated within the preset time period to obtain the optimized fish length, and output the optimized fish length.
2. The intelligent method for calculating the body length of high-density fish in aquaculture ponds as described in claim 1, characterized in that: In step S1, the backbone network of the YOLO network adopts CSPDarknet, the neck adopts PAN-FPN, and both the backbone network and the neck introduce SPPF and C2f modules. The attention module, which is guided by prior knowledge embedded in the neck, is calculated as follows: Among them, Att out The attention value of the fish is represented by Q; the query matrix is represented by K; the key matrix is represented by T; and d represents the transpose of the query matrix. k M represents the dimension of the key vector, i.e., the scaling factor; prior V represents the prior matrix indicating the location of key points on the fish's body; V represents the value matrix. The output of the fish detection model is: P∈R H×W×C ; Where P represents a 3D tensor; R represents a real number; H represents the height of the detection grid in the input image, which is obtained by the YOLO network dividing the input image based on a preset grid size; W represents the width of the detection grid in the input image; C represents the number of channels predicted by each detection grid, C = 4 + 1 + K, where 4 represents the fish body bounding box parameters, 1 represents the confidence level, and K represents the fish body category probability; the fish body bounding box parameters include the x-coordinate b of the bounding box center point. x , the ordinate of the center point of the bounding box b y , bounding box width b w , bounding box height b h .
3. The intelligent method for calculating the body length of high-density fish in aquaculture ponds as described in claim 1, characterized in that: In step S1, the formula for the loss function is: in, This represents the loss value of the loss function; The bounding box loss is represented by CIoU Loss; The confidence loss is expressed using binary cross-entropy loss. Represents classification loss; λ box , λ obj , λ cls All of these represent weighting coefficients.
4. The intelligent method for calculating the body length of high-density fish in aquaculture ponds as described in claim 1, characterized in that: Step S2 specifically involves: A large number of historical fish school images are acquired, and each of the historical fish school images is preprocessed with image enhancement. After labeling the fish positions and fish lengths of the preprocessed historical fish school images, a dataset is constructed. The dataset is divided into a training set, a validation set, and a test set based on a preset ratio. The fish detection model is trained using the training set until the loss value of the loss function is less than a preset loss threshold. The trained fish detection model is then validated using the validation set. The validated fish detection model is tested using the test set, and the tested fish detection model is then deployed.
5. The intelligent method for calculating the body length of high-density fish in aquaculture ponds as described in claim 1, characterized in that: In step S2, during the training of the fish detection model, the predicted fish body bounding boxes and the labeled fish body positions are dynamically matched by a task alignment allocator, and redundant fish body bounding boxes are filtered out by nonmaximum suppression.
6. The intelligent method for calculating the body length of high-density fish in aquaculture ponds as described in claim 1, characterized in that: Step S3 specifically involves: Fish morphological constraint parameters, including fish species, length range, width range, aspect ratio threshold range, and anatomical structure proportions, are set. Camera parameters of the binocular camera, including at least focal length, principal point coordinates, and baseline distance, are calibrated. Video of the aquaculture pond is acquired through the binocular camera, and the video of the aquaculture pond is analyzed to obtain the left eye image and the right eye image. The focal length includes horizontal focal length and vertical focal length.
7. The intelligent method for calculating the body length of high-density fish in aquaculture ponds as described in claim 1, characterized in that: Step S4 specifically involves: The left and right eye images are input into the deployed fish detection model to obtain fish body bounding boxes with confidence scores. The fish body bounding boxes are filtered firstly using the fish species morphology constraint parameters. The confidence scores are then verified using a preset dynamic confidence threshold to perform secondary filtering on each fish body bounding box. The dynamic confidence threshold is dynamically adjusted based on image sharpness and fish body occlusion rate.
8. The intelligent method for calculating the body length of high-density fish in aquaculture ponds as described in claim 1, characterized in that: Step S5 specifically involves: From the left and right eye images respectively, the left and right target regions of each fish body bounding box are identified. Based on a preset disparity search range, the SGBM algorithm is used to slide and search for the best matching block of the left target region within the right target region. The best matching block is then subjected to occlusion processing and filtering smoothing to obtain the disparity. Based on the disparity and camera parameters, the depth value of the fish body corresponding to the fish body bounding box is calculated. Z = (f × B) / d; Where Z represents the depth value; f represents the focal length; B represents the baseline distance; and d represents the parallax.
9. The intelligent method for calculating the body length of high-density fish in aquaculture ponds as described in claim 1, characterized in that: In step S6, the formula for converting the pixel coordinates of the fish body bounding box into physical dimensions is as follows: Where W represents the actual width of the fish; H represents the actual height of the fish; Z represents the depth value; w px The width of the fish's bounding box in pixels; h px f represents the pixel height of the fish's bounding box; x Indicates the horizontal focal length; f y Indicates the vertical focal length.
Citation Information
Cited By
Fish body mass non-contact estimation method based on binocular vision
CN121810695A
Non-contact fish length measurement method based on multi-scale anti-occlusion dynamic optimization
CN122368518A