Non-contact fish length measurement method based on multi-scale anti-occlusion dynamic optimization

By employing a multi-scale anti-occlusion dynamic optimization method, combined with multi-target tracking and high-precision mask extraction, the problems of high cost, stringent equipment requirements, and environmental interference in underwater fish length measurement were solved, achieving low-cost and high-precision fish length measurement.

CN122368518APending Publication Date: 2026-07-10HUAZHONG AGRI UNIV

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
HUAZHONG AGRI UNIV
Filing Date
2026-06-10
Publication Date
2026-07-10

AI Technical Summary

Technical Problem

Existing technologies for measuring the body length of underwater fish suffer from problems such as high cost, demanding equipment requirements, susceptibility to interference from complex underwater environments, and difficulty in achieving high-precision measurements. In particular, traditional methods struggle to achieve stable detection and accurate length measurement under conditions of high-density obstruction and changes in the swimming posture of fish.

Method used

A non-contact fish body length measurement method with multi-scale anti-occlusion dynamic optimization is adopted. Through multi-scale feature enhancement, multi-target tracking and temporal morphology optimization, combined with high-precision mask extraction and scale mapping, fish body length measurement can be achieved under low-cost conditions using a common monocular camera.

Benefits of technology

Without adding expensive equipment, the accuracy and engineering applicability of fish body length measurement have been improved, the computing power cost has been reduced, and stable detection and high-precision measurement have been achieved under ordinary monocular imaging conditions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122368518A_ABST
    Figure CN122368518A_ABST
Patent Text Reader

Abstract

This invention discloses a non-contact fish length measurement method and system based on multi-scale anti-occlusion dynamic optimization. First, it captures video streams from an aquaculture pond in real time and automatically extracts frames at preset intervals to obtain non-redundant underwater images. Then, it uses a feature detection and enhancement network to detect and enhance fish features. Next, it optimizes the optimal morphology of swimming fish schools based on a multi-target tracking algorithm, including modeling the kinematic state of the fish school and anti-drift tracking matching, constructing a target temporal feature archive, and performing multi-constraint optimization to output the optimal morphology frame. Finally, it performs high-precision mask extraction and physical length conversion on the optimal morphology frame to obtain the fish length. This invention enables low-cost, non-contact, and automated fish length measurement in turbid water and fish occlusion scenarios, while balancing measurement accuracy and computational efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer vision technology and relates to a method and system for measuring the body length of fish, specifically a non-contact method and system for measuring the body length of fish based on multi-scale anti-occlusion dynamic optimization. Background Technology

[0002] In modern precision aquaculture systems, fish length information can assess the production performance of fish during the rearing period, reflect the efficiency of feeding management, and is a key basis for accurately evaluating the biomass and individual growth status of farmed fish populations, enabling scientific feeding, and optimizing harvesting plans. However, traditional methods for obtaining fish size mainly rely on contact methods (such as manual sampling), which are not only time-consuming, labor-intensive, and costly, but also easily induce strong stress reactions and even mechanical damage in fish. Furthermore, keeping live fish stationary on the water surface for physical measurement presents significant challenges. Therefore, there is an urgent need to research non-contact, automated detection methods for measuring fish length.

[0003] Computer vision technology can acquire target information through image analysis. Its non-contact and fast characteristics have led to its widespread application in underwater quality grading, species identification, counting, and behavior analysis. In early studies on estimating fish length using images, most methods were based on the two-dimensional image plane. That is, the length of the fish in the image plane was first obtained, and then the actual length was estimated based on the transformation relationship between image coordinates and physical coordinates. For example, early studies used Hough transform and projection transform to correct fish images, or used traditional image processing techniques such as histogram backprojection and dilation-erosion for contour segmentation. In addition, some studies trained artificial neural networks or used keypoint detection technology to obtain the endpoints of the fish's head and tail, using the line segment between the two points as the fish's length, and even attempted to measure the fish's body in a bent state by obtaining the fish's centerline. However, compared with terrestrial scenes, the underwater optical environment has a high degree of complexity and uncontrollability (such as light absorption and scattering leading to image blurring and color shift). In practical applications, this traditional vision method based solely on two-dimensional images is not only less robust, but also highly susceptible to image quality degradation and occlusion by fish, leading to a significant decrease in the accuracy of key point detection or contour segmentation.

[0004] In recent years, with the continuous optimization of neural network architecture, deep learning technology has been able to effectively overcome some interference factors such as uneven underwater lighting and water turbidity, achieving high-precision positioning of target bounding boxes. However, more importantly, simply achieving high-precision "target positioning (bounding box)" is not equivalent to completing accurate "fish length measurement." Because underwater fish are constantly turning, pitching, and swimming, their projected length in the two-dimensional monitoring image changes drastically due to perspective contraction. A single frame of two-dimensional image is insufficient to determine whether the fish is in a fully extended state, resulting in a serious systematic negative bias.

[0005] To overcome perspective and distortion errors in two-dimensional images, some advanced measurement methods are shifting towards three-dimensional space. Since traditional monocular cameras cannot directly convert image coordinates to world coordinates to obtain depth information, researchers often use binocular cameras or lidar, which can acquire three-dimensional information, as hardware. For example, binocular cameras can be used to acquire three-dimensional point cloud data of fish, and the fish's body length can be estimated through ellipsoidal fitting or a three-dimensional pose model of the point cloud. While these methods leverage stereo vision and improve accuracy compared to two-dimensional single-frame measurements, they also introduce new technical challenges: First, lidar and underwater binocular camera equipment are expensive and have stringent installation and deployment requirements; second, these three-dimensional devices are highly susceptible to severe interference from suspended noise points in turbid aquaculture water; and finally, binocular cameras are prone to significant calibration errors in complex underwater environments and under varying refractive indices, leading to insufficient long-term reliability of the system.

[0006] On the other hand, large vision models such as SAM and SAM 2 have recently demonstrated amazing zero-sample high-fidelity segmentation capabilities. However, attempting to extract length contours by performing full instance segmentation frame by frame on high frame rate (such as 30fps) underwater video streams would directly lead to the collapse of the computing power of existing edge computing devices, resulting in an engineering deadlock where high accuracy and real-time performance cannot be achieved simultaneously.

[0007] In summary, how to achieve stable detection, effective tracking, and accurate length measurement of underwater fish using only ordinary monocular monitoring cameras without adding expensive binocular cameras or lidar and other 3D underwater hardware, while reducing the impact of high-density obstruction, water turbidity, changes in fish swimming posture, and the computational cost of high-precision segmentation models on the measurement results, has become an urgent technical problem to be solved in the field of smart aquaculture. Summary of the Invention

[0008] This invention provides a non-contact fish length measurement method and system based on multi-scale anti-occlusion dynamic optimization. It improves the stability of fish detection in complex underwater environments by enhancing multi-scale features, selects suitable target frames for length measurement through multi-target tracking and temporal morphology optimization, and realizes fish length estimation by using high-precision mask extraction and scale mapping. Thus, it improves the accuracy and engineering applicability of fish length measurement under low-cost monocular imaging conditions.

[0009] The technical solution adopted by the present invention is: a non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization, comprising the following steps: Step 1: Capture the video stream inside the aquaculture pond in real time and automatically extract frames at preset times to obtain non-redundant underwater images; Step 2: Use a feature detection and enhancement network to detect and enhance the fish's body features; Step 3: Optimize the optimal form of swimming fish based on multi-target tracking algorithm, including kinematic state modeling and anti-drift tracking matching of fish, constructing target temporal feature archive and multi-constraint optimization, and outputting the target optimal form frame; Step 4: For the optimal shape frame, perform high-precision mask extraction and physical length conversion to obtain the fish body length.

[0010] Preferably, in step 1, an underwater light source is installed at the bottom of the aquaculture pond, and an underwater camera is fixedly installed on the side wall of the aquaculture pond near the bottom to monitor the fish in the aquaculture pond for a long time at the optimal elevation / horizontal angle.

[0011] Preferably, in step 2, the feature detection and enhancement network processes the input image sequentially through a first Conv layer, a second Conv layer, a first C2f layer, a third Conv layer, a second C2f layer, a fourth Conv layer, a third C2f layer, a fifth Conv layer, a fourth C2f layer, and an SPPF layer. The first C2f layer outputs B5, the third C2f layer outputs B4, and the SPPF layer outputs B3. After passing through the first Unsample layer, B3 is either fused with B4 through the first Concat layer before being input to the fifth C2f layer, or directly input to the fourth Concat layer. The fifth C2f layer outputs... After passing through the second Unsample layer, B5 is merged with B5 through the second Concat layer and then input into the sixth C2f layer. Simultaneously, it is directly input into the third Concat layer. The sixth C2f layer outputs B5', which, after processing through the sixth Conv layer, is merged with the output of the fifth C2f layer through the third Concat layer and then input into the seventh C2f layer. The seventh C2f layer outputs B4', which, after processing through the seventh Conv layer, is merged with the output of the first Unsample layer through the fourth Concat layer and then input into the eighth C2f layer. The eighth C2f layer outputs B3'. After passing through the first multi-scale spatial enhancement attention module, the second multi-scale spatial enhancement attention module, and the third multi-scale spatial enhancement attention module, respectively, B5', B4', and B3' are input into the first detection head, the second detection head, and the third detection head, respectively, to predict the fish target and output the fish bounding box coordinates, category confidence, and detection confidence. The first, second, and third multi-scale spatial enhancement attention modules have the same structure, differing only in the feature block size of their multi-branch scale aggregation layers. The multi-branch scale aggregation layer comprises three parallel branches, each employing a depthwise separable convolution with the same kernel size but different feature block sizes on the original feature map. Large-span downsampling is performed, followed by GAP processing before output, and then compared with the original feature map after GAP processing. After processing by the summation and averaging layer, the output sequentially passes through the first Linear layer, ReLU layer, second Linear layer, Sigmoid layer, and nonlinear amplification layer, and is then compared with the original feature map. After element-wise multiplication, the enhanced output is obtained. .

[0012] Preferably, in step 2, the feature detection and enhancement network is a pre-trained network; during training, the bounding box regression loss function of the detection head is: ; ; ; ; in, and The hyperparameters for fish swarm interference are used to adjust the repulsion intensity; parameters This represents the target total number of fish within the batch. This represents the predicted fish body bounding box currently undergoing regression. The true bounding boxes of non-matching adjacent fish bodies that are too close together and cause interference. This refers to the smoothness coefficient applied to the edges of the fish body. The intersection-union loss function is... This is the set of positive candidate boxes, where the subscript "+" represents the positive class. This indicates that all positive sample prediction boxes are traversed; IoG() represents the ratio of the overlap area between the predicted fish body box and the non-matching real fish body box to the area of ​​the real fish body box. : Represents two different predicted fish body boxes; The intersection-union ratio function is the area of ​​the intersection of two predicted fish body boxes divided by the area of ​​their union. This is a smooth logarithmic penalty function used to continuously penalize the overlap between the predicted bounding box and adjacent targets. A tiny constant added to prevent numerical anomalies in logarithmic operations.

[0013] Preferably, in step 3, the kinematic state modeling and anti-drift tracking matching of the fish swarm first uses Kalman filtering to establish a continuous state space vector for each detected target, and then performs state transition prediction: ; The center coordinates, area scale, aspect ratio, and corresponding rate of change of velocity of the fish body frame at time t-1 are included. This is the state transition matrix based on the physiomechanics of fish swimming; Let t be the predicted ideal position of the fish in the current frame at time t. When the fish swims behind aquatic plants or is occluded, causing the detection box to disappear, a time buffer is used to utilize... Maintain the target tracking identification Track ID of the fish without interruption; In the box matching process between consecutive frames, the Hungarian algorithm is used to perform bipartite graph matching by combining Mahalanobis distance with the appearance features of fish ReID (Recognition ID) numbers, thus limiting false matches.

[0014] in, This represents the Mahalanobis distance between the current fish detection bounding box and the predicted target trajectory. The detection bounding box for the new fish body actually observed in the current frame; The observation matrix is ​​pre-defined by the Kalman filter state-space model and is used to extract the observable components directly corresponding to the detection box from the target state vector. The covariance matrix characterizes the uncertainty in predicting fish swimming trajectories; if the spatial jumps of the frame generate... If the swimming speed exceeds a reasonable threshold, matching will be blocked directly to ensure that the same fish is not matched with other fish.

[0015] As a preferred embodiment, in step 3, the construction of the target temporal feature archive and multi-constraint optimization first establishes an independent temporal feature archive for each fish that has been successfully assigned a target tracking identity recognition Track ID. As long as the target survives in the picture, the timestamp / frame number of the frame, the full image memory pointer and the detection confidence, as well as the diagonal pixel length of the bounding box calculated in real time are written into its temporal feature archive frame by frame. When the Track ID of a target continues to exist, under the constraints of edge integrity and detection stability, the frame with the largest diagonal pixel length of the bounding box is the optimal shape frame. When the Track ID of a target is determined to be missing, the optimal form frame search algorithm for that Track ID is triggered:

[0016] in, It refers to the set of valid frames that meet the safety constraints (i.e., truncated frames that are close to the 10% edge region of the image and unstable frames with a detection confidence of less than 0.8). This represents the unique optimal morphological frame within the life cycle of this fish, identified through an optimization algorithm. According to the physical laws of 3D object projection, when... When the maximum value is reached, the fish is considered to be in the optimal length-measuring posture with its body fully extended and straight, and its side completely parallel to the camera's image sensor. This represents the diagonal pixel length of the target fish detection bounding box at time t.

[0017] Preferably, the optimal form frame search algorithm uses multi-constraint cascade filtering to extract valid frames with security constraints. ,include: Constraint A: Edge truncation prevention constraint, which removes frames whose bounding box center coordinates are located in the M% edge region around the entire image, to prevent the selection of invalid frames where only half of the fish body is in the picture. M is a preset value. Constraint B: High confidence constraint for the state, remove frames whose YOLO output detection confidence is below the threshold, or whose Kalman filter state is not "acknowledgment state"; Constraint C: Geometric projection optimal, traversing the diagonal length field in the remaining frame set filtered by constraints A and B. The argmax algorithm is used to extract the frame with the largest diagonal value, which is then used as the optimal frame.

[0018] As a preferred embodiment, step 4 includes the following sub-steps: Step 4.1: Based on the high-definition original image of the optimal shape frame, and combined with the corresponding two-dimensional bounding box coordinates, construct a joint prompt word, and use the mask decoder of the SAM 2 large vision model to generate a high-fidelity binary pixel mask mask of the target fish body that is stripped of the interference of aquatic plants and mud. Step 4.2: Extract the outer contour of the mask and fit it to obtain the maximum number of pixels along the major axis of the smallest bounding rectangle of the outer contour; Step 4.3: Multiply the number of pixels on the major axis by the spatial mapping coefficient matrix pre-calibrated based on the underwater camera's intrinsic and extrinsic parameters and depth of field to calculate the physical length of the target fish.

[0019] Preferably, in step 4.3, the physical length conversion formula for the target fish is: ; in, The number of pixels along the major axis calculated for the image mask; To the depth of the water where the fish is located The "physical-pixel" scaling factor that exhibits a dynamic mapping relationship.

[0020] This invention also provides a non-contact fish body length measurement system based on multi-scale anti-occlusion dynamic optimization, comprising: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, enable the one or more processors to implement the non-contact fish length measurement method based on multi-scale anti-occlusion dynamic optimization.

[0021] Compared with the prior art, the beneficial effects of the present invention include: (1) This invention solves the problem of detecting severe degradation of underwater images and dense occlusion by fish schools from the underlying network architecture. Existing technologies often attempt to preprocess images through image dehazing or color restoration algorithms, which not only increases latency but also introduces artifacts. The MultiSEAM of this invention directly performs multi-receptive field feature aggregation and exponential enhancement at the feature layer; moreover, it breaks the traditional "non-rejection" boundary box and creates a dual penalty mechanism of RepGT and RepBox based on the underwater three-dimensional overlap characteristics.

[0022] This invention fundamentally eliminates the "frame adhesion" and "frame jumping" phenomena caused by fish clustering in high-density aquaculture environments. Even in extremely turbid conditions and with incomplete fish bodies, the constructed feature detection and enhancement network can still maintain a high single-unit detection recall rate, providing extremely pure and stable prior data for subsequent accurate tracking and statistics.

[0023] (2) This invention pioneers an asymmetric asynchronous processing architecture of "detection and tracking (light) + extreme value optimization (filtering) + single-frame large model segmentation (heavy)". The current mainstream approach is to perform dense segmentation of the video frame by frame or simple frame-by-frame segmentation. The former requires astronomical computing power, while the latter misses the opportunity for measurement. This invention cleverly uses the tracker to establish a "life cycle profile", allowing the algorithm to "wait" and "filter" the best posture of the fish, and only performs large model attack on a single frame.

[0024] This invention solves the problem of deploying large-scale models on edge devices, significantly reducing the overall system's computing power and memory usage. Even on industrial control equipment equipped with only a standard Jetson platform, the system can still smoothly process 30fps multi-target high-definition monitoring streams, enabling high-concurrency, real-time engineering applications of large-scale models in smart fisheries.

[0025] (3) This invention uses morphological extremum screening in the time domain to replace three-dimensional measurement in the spatial domain. To solve the perspective error of two-dimensional projection, existing technologies mostly use expensive binocular cameras or lidar for three-dimensional point cloud fitting, which is not only costly, but also easily affected by noise interference and refraction calibration errors in murky water. This invention innovatively introduces the time axis dimension and uses the maximum value of the diagonal of the bounding box as the judgment index of "the fish body is fully stretched out and parallel to the lens".

[0026] This invention eliminates the reliance on high-cost 3D underwater hardware, achieving accurate length measurement using only a standard monocular camera. This transforms the measurement mechanism from a "random blind box" to one that is "inevitably optimal." By optimizing the temporal sequence to eliminate perspective shrinkage errors caused by fish pitch and distortion, the final output of the fish's physical length measurement accuracy far surpasses the level of traditional single-frame images or frame-by-frame measurements, providing a low-cost solution for subsequent accurate calculation of the bait coefficient. Attached Figure Description

[0027] The technical solutions of the present invention will be further illustrated below using embodiments and specific implementation methods. In addition, some accompanying drawings are used in the description of the technical solutions. Those skilled in the art can obtain other drawings and the intent of the present invention from these drawings without any creative effort.

[0028] Figure 1 This is a schematic diagram of the method according to an embodiment of the present invention; Figure 2 This is a schematic diagram illustrating the data acquisition principle of an aquaculture pond according to an embodiment of the present invention. Figure 3 This is a diagram of the feature detection and enhancement network structure according to an embodiment of the present invention; Figure 4 This is a structural diagram of the multi-scale spatial enhanced attention module according to an embodiment of the present invention; Figure 5 This is a schematic diagram illustrating the principle of optimal morphology optimization and fish length calculation in an embodiment of the present invention. Figure 6 This is a scene diagram of experimental data collection in an aquaculture pond according to an embodiment of the present invention; Figure 7 The figures show comparative experimental results of embodiments of the present invention, where the left figure shows the results obtained by YOLOv8 and the right figure shows the results obtained by the present invention. Figure 8 The figures show the comparison results of body length prediction in the experiment of this invention, where the left figure is the result obtained by the original YOLOv8 and the right figure is the result obtained by this invention. Detailed Implementation

[0029] To facilitate understanding and implementation of the present invention by those skilled in the art, the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.

[0030] Existing technologies face the following four technical shortcomings when dealing with highly turbid, high-density, and highly dynamic underwater video streams: (1) Fixed receptive field leads to failure of local feature extraction in turbid water.

[0031] Traditional single-stage object detection networks (such as the standard YOLOv8) mostly use fixed-size convolutional kernels for feature extraction. In extremely turbid water conditions where high-frequency textures are masked, the model can only rely on macroscopic low-frequency geometric contours (such as the shape of a fish's torso) for recognition. Due to the lack of multi-scale adaptive feature capture mechanisms, existing networks are prone to missing detections when only a portion of the fish body is visible (such as only the tail or dorsal fin), and the feature extraction networks lack resilience to degradation in poor underwater images.

[0032] (2) The interference of neighboring targets in the traditional bounding box regression loss function leads to detection box drift and false suppression under dense occlusion.

[0033] Existing object detection loss functions (such as CIoU and GIoU) ​​only include the positive "attraction" constraint between the predicted box and the matching ground truth bounding box when calculating the bounding box regression loss. In a high-density fish swarm, there is a large overlap of 2D projection surfaces. In this case, the predicted box is easily attracted by the strong attraction of adjacent non-target ground truth bounding boxes (i.e., another fish next to it) that are spatially close and have similar visual features, thus deviating from the correct target and "drifting"; or, multiple predicted boxes may converge to the same most salient target at the same time, causing real overlapping fish to be incorrectly removed as redundant predicted boxes in the subsequent non-maximum suppression (NMS) stage, resulting in serious missed detections.

[0034] (3) Two-dimensional morphological distortion and cross-frame identity confusion caused by three-dimensional movement.

[0035] Fish do not always swim in a straight line and sideways to the camera. Turning or bending movements cause the long axis of pixels in a 2D image to not represent the true body length. Existing simple length measurement algorithms, which calculate by cropping frames or sampling frames at a fixed frequency, cannot determine whether the fish is in a "fully extended" state. In addition, existing target tracking algorithms (such as DeepSORT) are prone to identity drift or trajectory breaks when fish are obscured by aquatic plants or when fish are densely intertwined, resulting in the same fish being recorded and measured repeatedly, causing serious distortion in population statistics and biomass distribution.

[0036] (4) The conflict between high-precision segmentation and the computing power bottleneck of edge computing devices; While high-fidelity large-scale vision models such as SAM2 offer extremely high segmentation accuracy, their massive number of network parameters and the resulting inference process consume enormous amounts of GPU memory and computing power. Attempting to perform frame-by-frame full instance segmentation and mask extraction on a 30fps high-definition surveillance video stream would directly cause the computing power of existing edge computing devices to collapse, resulting in huge latency and making it impossible to meet the real-time monitoring needs of smart aquaculture sites.

[0037] To systematically solve the above-mentioned technical problems, this embodiment proposes a non-contact fish body length measurement method and system based on multi-scale anti-occlusion dynamic optimization, which integrates feature-enhanced lightweight detection, kinematic temporal tracking, morphological extreme keyframe optimization and single zero-shot segmentation technology.

[0038] Please see Figure 1 This embodiment provides a non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization, which can be executed by a GPU-equipped computing device (such as an edge industrial control computer or cloud server). The specific implementation includes the following steps: Step 1: Capture video streams from aquaculture ponds in real time and automatically extract frames at preset times to obtain high-value underwater images that are not redundant. In one implementation, please see Figure 2 The bottom of the aquaculture pond is equipped with an underwater light source, and an underwater camera is fixedly installed on the side wall of the aquaculture pond near the bottom to monitor the fish in the aquaculture pond for a long time at the optimal elevation / horizontal angle.

[0039] Step 2: Use a feature detection and enhancement network to detect and enhance the fish's body features; In one implementation, please see Figure 3In this embodiment, the feature detection and enhancement network processes the input image sequentially through a first Conv layer, a second Conv layer, a first C2f layer, a third Conv layer, a second C2f layer, a fourth Conv layer, a third C2f layer, a fifth Conv layer, a fourth C2f layer, and an SPPF layer. The first C2f layer outputs B5, the third C2f layer outputs B4, and the SPPF layer outputs B3. After passing through the first Unsample layer, B3 is either fused with B4 through the first Concat layer before being input to the fifth C2f layer, or directly input to the fourth Concat layer. The output of the fifth C2f layer is processed by... After passing through the second Unsample layer, B5 is merged with B5 through the second Concat layer and then input into the sixth C2f layer. Simultaneously, it is directly input into the third Concat layer. The sixth C2f layer outputs B5', which, after processing through the sixth Conv layer, is merged with the output of the fifth C2f layer through the third Concat layer and then input into the seventh C2f layer. The seventh C2f layer outputs B4', which, after processing through the seventh Conv layer, is merged with the output of the first Unsample layer through the fourth Concat layer and then input into the eighth C2f layer. The eighth C2f layer outputs B3'. After passing through the first multi-scale spatial enhancement attention module, the second multi-scale spatial enhancement attention module, and the third multi-scale spatial enhancement attention module, respectively, B5', B4', and B3' are input into the first detection head, the second detection head, and the third detection head, respectively, to predict the fish target. The fish bounding box coordinates, category confidence, and detection confidence are output, and the final fish detection result is obtained after post-processing.

[0040] In this embodiment, the Conv layer is a convolutional layer used to extract edge and texture features of the base image; the C2f layer is a cross-stage local fusion network module used to extract and fuse deep semantic features while ensuring lightweight operation; the SPPF layer is a fast spatial pyramid pooling layer used to fuse local and global features through different pooling kernels; the Conv layer, C2f layer and SPPF layer are all existing standard backbone network components. In this embodiment, the first, second, and third multi-scale spatial enhancement attention modules have the same structure, differing only in the feature block size of their multi-branch scale aggregation layers. The multi-branch scale aggregation layer includes three parallel branches, each employing a depthwise separable convolution with the same kernel size but different feature block sizes on the original feature map. Large-span downsampling is performed, followed by GAP processing before output, and then compared with the original feature map after GAP processing. After processing by the summation and averaging layer, the output sequentially passes through the first Linear layer, ReLU layer, second Linear layer, Sigmoid layer, and nonlinear amplification layer, and is then compared with the original feature map. After element-wise multiplication, the enhanced output is obtained. .

[0041] The Linear layer provided in this embodiment is a fully connected layer. The first fully connected layer is used to linearly map the fused channel descriptions, generally serving as a dimensionality reduction and compression layer, learning the correlation between channels with fewer parameters. The second fully connected layer is used to map the compressed features back to the original channel dimension, generating the attention response value corresponding to each channel. The Sigmoid layer is an activation function layer used to compress the output of the second fully connected layer to the range of 0 to 1, forming normalized channel weights to represent the importance of different channels. The GAP processing is a global average pooling process used to compress the spatial feature map output of each branch into a channel-level description vector, summarizing the spatial information into the global response value of each channel, providing a basis for subsequent channel weight allocation.

[0042] The Multi-Scale Spatial Enhancement Attention Module (MultiSEAM) provided in this embodiment overcomes feature degradation to address the problem of high-frequency texture loss in turbid water. Given an input feature map... (Where B is the batch size, C is the number of channels, and H and W are the spatial dimensions), the processing flow is as follows: Multi-branch scale aggregation: Construct three parallel branches, each with a kernel size of 3 but different feature patch sizes. The depthwise separable convolutions are used for large-span downsampling. This forces the network to extract low-frequency structural features of fish at multiple scales (such as trunk curves and large areas of color) through different receptive fields when high-frequency textures are lacking.

[0043] Spatial compression and feature merging: The outputs of the three branches are passed through a global adaptive average pooling layer (GAP) to compress the spatial dimension information into channel descriptors, which are then combined with the original feature map after GAP processing. By summing and averaging, we obtain the fused composite fish body feature vector. : ; in, The input is the fish body feature tensor; () represents depth-separable convolution operations with different receptive fields; This is a comprehensive fish body feature descriptor that incorporates multi-scale receptive fields.

[0044] Exponential nonlinear channel activation: This involves activating the vector... The input consists of a multilayer perceptron with two fully connected layers (dimensionality reduction ratio set to reduction=16), and the fused channel description vector is... The input is a multilayer perceptron consisting of a first fully connected layer, a ReLU activation layer, and a second fully connected layer. The channel dimensions are first compressed and nonlinearly mapped before being restored to their original dimensions. The ReLU activation layer introduces nonlinear expressive power, enabling the module to learn more complex dependencies between different channels, rather than performing simple linear transformations. The Sigmoid function is used to generate normalized channel weights, representing the importance of different channels for fish target recognition.

[0045] This embodiment innovatively introduces the natural exponential operation exp() to nonlinearly amplify the output of the Sigmoid: ; The MLP layer consists of a first fully connected layer, a ReLU activation layer, and a second fully connected layer. The first fully connected layer compresses the dimensionality of the fused channel description vectors to reduce the number of parameters and extract a compact representation. The ReLU activation layer introduces non-linear mapping capabilities to enhance the modeling of inter-channel dependencies. The second fully connected layer restores the feature dimension. Subsequently, the sigmoid activation function maps the output to the range of 0 to 1, generating basic channel weights. These weights are then non-linearly amplified using an exponential function to obtain the final attention weights.

[0046] The amplified channel weights Expand to the original input feature dimension and combine with the original feature map Element-wise multiplication yields the enhanced output. This mechanism greatly enhances the network's response to weak visual signals, such as blurred fish fins in muddy water.

[0047] In one implementation, the feature detection and enhancement network is a pre-trained network. During training, a bidirectional repulsion loss mechanism is introduced to address occlusion adhesion. To address bounding box drift and NMS (Non-Maximum Suppression) deletion issues caused by high-density overlap, an additional penalty term for repelling erroneous targets is added to the bounding box regression loss of the detection head. After the network generates predicted boxes, when calculating the loss function, in addition to retaining the original target intersection-union (IUU) attraction loss, a 3D occlusion projection repulsion mechanism based on RepGT and RepBox is constructed. RepGT (Rejecting Non-Target Grounded Boxes): This method calculates the overlap ratio between the predicted box tensor and all grounded boxes. After excluding self-matches using a diagonal mask, it filters out non-target grounded boxes with an IoG greater than a set threshold (e.g., gtnms=0.4). A smooth logarithmic penalty (smooth_ln) is applied to these non-target grounded boxes, generating a repulsive gradient that pushes the predicted box away from its incorrect neighbors. Its core principle is based on the calculation of the overlap ratio with grounded boxes. ; Among them, parameters The target total number of fish in the batch; This represents the predicted fish body bounding box currently undergoing regression. The true bounding boxes of non-matching adjacent fish bodies that are too close together and cause interference. This is the smoothing coefficient for the edges of the fish. The formula is designed to generate a reverse gradient that "pushes" the predicted box away from incorrect neighboring fish.

[0048] RepBox (Reject Neighboring Predicted Boxes): Calculates the cross-union ratio (CUI) between different predicted boxes within the same batch. It penalizes neighboring predicted boxes with CUI values ​​greater than a set threshold (e.g., pnms=0.4), forcing predicted boxes assigned to different targets to move further apart. This prevents multiple predicted boxes from being incorrectly suppressed during the NMS stage.

[0049] ; Although both RepGT and RepBox use a smoothed logarithmic function to penalize overlap, their calculation metrics and exclusion targets are quite different: RepGT excludes "other non-target real fish bodies" (calculated based on IoG intersection ratio), preventing predicted boxes from being attracted to adjacent real fish bodies during regression and causing "positional drift"; RepBox excludes "other predicted boxes" (calculated based on IoU intersection-union ratio), forcing predicted boxes assigned to different targets to be far apart, preventing multiple predicted boxes from clustering on the same prominent fish body in high-density situations, thus avoiding erroneous removal of similar boxes during the NMS (non-maximum suppression) stage. The combination of these two approaches, one external and one internal, completely solves the pain points of "inaccurate boxes" and "easy missed detections" in densely overlapping fish groups.

[0050] Finally, combining the original Bbox loss and repulsion loss of YOLOv8, the final bounding box regression loss is defined as: ; in, and To adjust the fish swarm interference hyperparameter for repulsion intensity, it was experimentally verified that it was fixed at [value missing]. and At that time, the individual recall rate under the occlusion of complex fish schools reached the global optimum; The Complete Intersection over Union Loss (IoU) is a commonly used basic loss for bounding box regression in object detection. It measures the difference between the predicted bounding box and the ground truth bounding box and penalizes three geometric factors: area of ​​overlap (IoU), Euclidean distance of the center point, and consistency of aspect ratio. This is the set of positive candidate boxes, where the subscript "+" indicates a positive class. Here, it refers to the set of all predicted fish body boxes that successfully match the ground truth bounding box. The formula... This indicates that all positive sample predicted bounding boxes are traversed. IoG() represents the ratio of the overlap area between the predicted fish body bounding box and the non-matching real fish body bounding box to the area of ​​the real fish body bounding box; : Represents two different predicted fish body bounding boxes. In the calculation When using the (predicted bounding box exclusion loss) method, it is necessary to calculate the overlap between different predicted bounding boxes within the same batch (under the condition that...). The goal is to enable the network to output independent prediction boxes for different targets, preventing fish that are too close together in the same group of fish from being predicted as an overlapping box. It is the intersection-union ratio, which is the area of ​​the intersection of two boxes divided by the area of ​​their union. The loss term is used to directly measure two different predicted boxes. and The degree of spatial overlap between them. () The smoothed logarithmic penalty function is used to continuously penalize the overlap between the predicted bounding box and its adjacent objects. Let x represent the overlap ratio between boxes. Logarithmic penalty form is used at times ;when When using linear extension form This is to avoid a sharp increase in loss value and gradient when the overlap ratio is too high, thereby improving training stability. The default value is 0.5; The extremely small constant added to prevent numerical anomalies in logarithmic operations is taken as... .

[0051] Step 3: Optimize the optimal form of swimming fish based on multi-target tracking algorithm, including kinematic state modeling and anti-drift tracking matching of fish, constructing target temporal feature archive and multi-constraint optimization, and outputting the target optimal form frame; In one implementation, the fish swarm kinematics state modeling and anti-drift tracking matching involves inputting the aforementioned feature detection and the highly robust bounding box output of the enhancement network into a multi-target tracker (preferably using BoT-SORT or ByteTrack algorithms with camera motion compensation). Internally, the tracker uses a Kalman filter to establish a continuous state space vector for each detected target and performs state transition prediction. ; Includes the center coordinates of the fish's body frame, area scale, aspect ratio, and corresponding rate of velocity change; This is the state transition matrix based on the physiomechanics of fish swimming; This is the predicted ideal position of the fish in the current frame. When the fish swims behind aquatic plants or is occluded, causing the detection box to disappear, a time buffer (e.g., track_buffer=60 frames) is used to... Maintain the target tracking identification Track ID of the fish without interruption.

[0052] In the box matching stage between consecutive frames, the Hungarian algorithm is used to perform bipartite graph matching by combining Mahalanobis distance (spatial physical distance) with the appearance features of fish appearance re-identification numbers (ReIDs), thus limiting outrageous "move" false matches. ; The detection bounding box for the new fish body actually observed in the current frame; The observation matrix; The covariance matrix characterizes the uncertainty in predicting fish swimming trajectories. This is based on the spatial jumps within the bounding box. If the swimming speed exceeds a reasonable threshold, matching is directly blocked to ensure that the same fish is not mistakenly identified. ReID, which relies solely on physical distance (Mahaviron distance) for matching, is prone to errors, such as when two fish swim very close together. ReID, on the other hand, matches fish by comparing their "appearance" (texture, color, body shape, etc.). When the object detection network (such as YOLO) outlines a fish in the current frame, the system crops the image within that outline and feeds it into the feature extraction network. The network outputs a high-dimensional feature vector. The system determines whether they are the same fish by calculating the cosine similarity between the "feature vector saved from historical trajectories" and the "feature vector of the current newly detected bounding box". , representing the Mahalanobis distance between the current fish detection bounding box and the predicted target trajectory, is used to measure the consistency between the observed and predicted results. A smaller value indicates that the current detection result matches the trajectory prediction more closely; a larger value indicates that it is more likely to belong to another fish or that an abnormal jump has occurred.

[0053] The observation matrix is ​​used to map the predicted state in the state space to the measurement space that the detector can directly observe; it is pre-defined by the Kalman filter state space model and is used to extract the observable components that directly correspond to the detection box from the target state vector.

[0054] The construction of the target temporal feature archive and multi-constraint optimization involves creating an independent temporal feature archive in memory for each fish that has been successfully assigned a Track ID. As long as the target survives in the image, its archive is written frame by frame to include: the timestamp / frame number of that frame, the full-image memory pointer, the detection confidence, and the diagonal pixel length of the bounding box calculated in real time.

[0055] When the Track ID of a target continues to exist, under the constraints of edge integrity and detection stability, the frame with the largest diagonal pixel length of the bounding box is the optimal shape frame. When the Track ID of a target is determined to be lost (wandered out of the view boundary or lost due to occlusion timeout), the optimal shape frame search algorithm for that ID is triggered: ; in, It refers to the set of valid frames that meet the safety constraints (i.e., truncated frames that are close to the 10% edge region of the image and unstable frames with a detection confidence of less than 0.8). This represents the unique optimal morphological frame within the life cycle of this fish, identified through an optimization algorithm. According to the physical laws of 3D object projection, when... When the maximum value is reached, the fish is considered to be in the optimal length measurement posture with its body fully extended and straight, and its side completely parallel to the camera's photosensitive element. This represents the diagonal pixel length of the target fish detection bounding box at time t.

[0056] In one implementation, the optimal morphological frame for the final fish length calculation is selected, and a multi-constraint cascade filtering method is used to extract the valid frames with safety constraints. : A. Edge Truncation Prevention Constraint: Remove frames whose bounding box center coordinates are located in the 10% edge area around the entire image to prevent the selection of invalid frames where only half of the fish body is in the picture.

[0057] B-state high confidence constraint: Remove frames with a YOLO output detection confidence of less than 0.8, or frames whose Kalman filter state is not "acknowledgment state".

[0058] C-geometric projection optimality: In the set of remaining frames filtered by A and B, traverse the diagonal length field. The argmax algorithm is used to extract the frame with the largest diagonal value. According to the physical laws of projecting a three-dimensional object onto a two-dimensional plane, the diagonal length of the two-dimensional bounding box in the image reaches its maximum value if and only if the fish's body is fully extended and straight, and its sides are completely parallel to the camera's photosensitive element. This frame is defined as the optimal form frame in the fish's life cycle.

[0059] Step 4: For the optimal shape frame, perform high-precision mask extraction and physical length conversion to obtain the fish body length.

[0060] In one implementation, asynchronous joint cue generation and SAM 2 mask decoding are first performed. The high-resolution original image of the single optimal shape frame obtained in the optimization stage is input into the SAM 2 (Segment Anything Model 2) encoder residing in independent video memory to generate image feature embedding. The precise two-dimensional bounding box coordinates corresponding to the frame recorded in the archive are converted into a box prompt tensor and input into the SAM 2 mask decoder.

[0061] Thanks to the zero-shot generalization ability learned by the massive pre-training of large models, the SAM 2 model can accurately extract the binary contour mask of a fish in a complex background of aquatic plants and murky water without any pixel-level fine-tuning for any specific fish species, based on the cues within the bounding box.

[0062] With this design, regardless of whether the fish swims for 100 or 1000 frames in the video, the computationally intensive SAM 2 model only performs one inference on the fish, perfectly avoiding the computational disaster of frame-by-frame segmentation of real-time video streams.

[0063] Then, OpenCV topological morphology calculations and spatial calibration mapping are performed. The OpenCV computer vision library (such as the `cv2.findContours` function) is called, and a topological structure retrieval algorithm is used to extract the outer contour of the largest connected component of the mask. Using either the rotating caliper algorithm or the least squares method, the minimum bounding rectangle is fitted to the irregular polygonal contour to obtain the pixel length of the rectangle's major axis.

[0064] In one implementation, please see Figure 5 In this embodiment, the intrinsic distortion matrix of the camera is obtained in advance using an underwater checkerboard calibration plate, and dynamic calibration coefficients for underwater depth are established. The final formula for converting the actual length of the fish is: ; This refers to the final output of the absolute biological physical body length of the fish. The pixel extremum length calculated for the image mask; To the depth of the water where the fish is located The physical-pixel scaling factor (mm / pixel) with a dynamic mapping relationship.

[0065] The physical length The Track ID is bound to the aquaculture database as a historical biomass record. Subsequently, the system completely destroys the time-series archive dictionary of this ID in memory, freeing up memory for the calculation of new fish swarm targets.

[0066] The invention will be further illustrated below through specific experiments.

[0067] Please see Figure 6 The experiment began with the deployment of the data acquisition system: a system was built including an underwater light source, an underwater camera, a cloud platform, a laptop computer, and image processing software. In a real aquaculture base, several standardized rearing tanks (approximately 1 meter in radius and 2 meters deep) were selected for raising different species of fish. The underwater light source and underwater camera were fixedly installed on the side wall of the rearing tank near the bottom (approximately 1.5 meters from the water surface) to monitor the fish in the tanks over a long period at the optimal elevation / horizontal viewing angle.

[0068] The surveillance video stream captured by the underwater camera is transmitted to the cloud platform in real time. An automated script runs on a laptop to capture the video stream in real time at a high-definition resolution of 1920×1080 and a frame rate of 30fps. Furthermore, the system strictly adheres to an automatic frame extraction strategy of capturing a video frame every 10 seconds to obtain high-value underwater images without redundancy.

[0069] In the experiment, data collection was conducted continuously from 9:00 AM to 10:00 PM daily for seven days. This long-term, day-night collection method captured the densely packed (fish blocking fish) images of farmed fish under different feeding conditions and light intensities, as well as the high-frequency, poorly formatted images caused by turbid water and light scattering. This provided a "dense occlusion data base" with extremely high generalization value for the subsequent training of the detection model.

[0070] In the experiment, the monitoring video streams acquired from the breeding tanks were cleaned to remove erroneous images that clearly exceeded physiological patterns or were caused by sensor noise. This resulted in a raw image sample set containing severe physical characteristics such as occlusion, turbid water, and uneven lighting. The annotation software was then used to accurately annotate the bounding boxes of real fish targets for use in feature detection and training data for the augmentation network.

[0071] The cleaned image is input into the feature detection and enhancement network. As the feature data flows through the MultiSEAM (Multi-Scale Spatial Enhancement Attention) node, the program calls three DcovN functions with different configurations in parallel, using depthwise separable convolutions with kernel_size=3 but feature block strides of 3, 5, and 7 to complete large-span spatial downsampling. Subsequently, the features from the three branches undergo global adaptive pooling and mean mixing. Next, the mixture vector y is sequentially processed through linear dimensionality reduction, ReLU activation, linear dimensionality increase, and the Sigmoid function, finally executing the core algorithm instruction y = exp(y). Finally, the channel attention weights y, amplified non-linearly by natural exponential amplification, are applied back to the original input features, completing the adaptive recalibration and enhancement of the incomplete features.

[0072] During the backpropagation phase of feature detection and augmentation network training, the system receives the predicted bounding box tensor pbox and the ground truth bounding box tensor gtbox from the detection head network output. A custom loss function is then invoked. Perform target IoU calculation and predictive bounding box cross-computation. Generate a diagonal mask to exclude self-matching of targets; then filter out overlapping portions with an intersection-union ratio / intersection ratio greater than a set threshold, and calculate their smoothness. ln () Penalty value (i.e., generating RepGT and RepBox loss terms). Finally, based on the selected hyperparameter ratio (e.g., α=0.005 and β=0.05), the calculated repulsion loss is summarized into the total regression loss, and the network gradient is decreased and the weights are iteratively updated.

[0073] After the feature detection and augmentation network training converges, the optimal weight file is deployed on the front-end monitoring device for real-time inference. When the real-time video stream is input into the feature detection and augmentation network, the network outputs target bounding box coordinates and class confidence scores with high occlusion robustness. The system then feeds these detection boxes into a multi-target tracking algorithm (such as BoT-SORT), using an internal Kalman filter to build a velocity and acceleration state-space model for each dynamic target to cope with short-term occlusion; simultaneously, by calculating the Mahalanobis distance and visual feature similarity matrix of adjacent frame boxes, Hungarian matching is performed to assign and maintain a unique cross-frame identity label for each visible fish in the video, avoiding frequent ID drift and concatenation in high-density swimming conditions.

[0074] In the system's memory space, an independent feature archive dictionary is established for each target successfully assigned a Track ID. As long as the target survives in the field of view, the program appends its full-image memory pointer, bounding box coordinates, and pixel length L_diag calculated using the diagonal formula frame by frame. When a Track ID is detected to have not been updated for several consecutive frames (e.g., swimming out of the edge or completely lost due to occlusion), an asynchronous optimization filtering mechanism is triggered: the algorithm first removes "potentially truncated frames" whose bounding box center coordinates are close to the image edge region (e.g., the surrounding 10%), and filters out frames with insufficient detection confidence (e.g., below 0.8); then, in the remaining safety archive records, the max() function is called to retrieve the record where the diagonal pixel length L_diag reaches its maximum value. The original single image and precise bounding box corresponding to this record are locked as the optimal form frame in the fish's life cycle (at this point, the fish body is considered to be in the most straight and stretched, and parallel to the lens, optimal for length measurement).

[0075] Finally, the high-resolution original image of the locked optimal shape frame is extracted and combined with its corresponding two-dimensional bounding box coordinates to construct a joint prompt, which is asynchronously passed to the mask decoder of the SAM 2 large-scale vision model residing in the system's video memory. Leveraging SAM 2's powerful zero-shot generalization capability, the model directly generates a high-fidelity binary pixel mask of the target fish body, stripped of weeds and sediment interference. The system then calls vision libraries such as OpenCV to execute `cv2.findContours` to extract the outer contour of the mask, and uses the `cv2.minAreaRect` function to fit and obtain the maximum number of pixels along the major axis of the smallest bounding rectangle of the irregular shape. Finally, this number of pixels along the major axis is multiplied by a spatial mapping coefficient matrix pre-calibrated based on the underwater camera's intrinsic and extrinsic parameters and depth of field to calculate the absolute physical length of the fish.

[0076] The system will push the physical body length data with a unique Track ID, timestamp, and corresponding confidence information obtained from step 6 to the remote aquaculture management database in a structured manner. Based on the collected continuous length measurement data, the management backend will statistically analyze and output the average body length distribution of fish in the pond, the survival trajectory of individual fish, and the overall biological density assessment report, providing scientific data support for the precise feeding and harvesting decisions in aquaculture production.

[0077] The experimental results comparing this invention with YOLOv5, YOLOv8, YOLOv10, YOLOv12 and YOLO26 are shown in Table 1 below: Table 1

[0078] As shown in Table 1, this invention achieves the best overall performance. Specifically, the precision of this invention reaches 90.74%, higher than YOLOv5, YOLOv8, YOLOv10, YOLOv12, and YOLO26. This indicates that the method can effectively reduce false detections caused by aquatic plants, bubbles, fish shadows, and partial occlusion in complex underwater backgrounds. Meanwhile, the recall of this invention reaches 78.78%, 6.65 percentage points higher than YOLOv8 and 2.63 percentage points higher than YOLOv5. This demonstrates that this invention has stronger real-world fish target detection capabilities and can effectively reduce missed detections in high-density and occluded scenes.

[0079] In terms of comprehensive evaluation metrics, the F1 score of this invention reached 84.34%, ranking highest among all comparison models. This indicates that the invention achieves a better balance between precision and recall. On the mAP@0.5 metric, the invention achieved 88.10%, slightly higher than YOLOv5 (88.00%), and significantly better than YOLOv8, YOLOv10, YOLOv12, and YOLO26. Furthermore, under the more stringent mAP@0.5:0.95 metric, the invention achieved 60.04%, again achieving the best result. This demonstrates that the invention not only effectively detects fish targets but also provides more stable and accurate bounding box localization.

[0080] Overall, by introducing an improved loss function and the MultiSEAM multi-scale feature enhancement module, this invention effectively improves the ability to identify fish targets in complex underwater scenes. Compared with the traditional YOLO model, this invention significantly improves recall and F1 score while maintaining high precision, indicating that it is more suitable for recirculating aquaculture detection scenarios with fish occlusion, target overlap, and strong background interference.

[0081] The ablation study results of this invention and different improvement strategies are shown in Table 2 below; Table 2

[0082] As shown in Table 2, the baseline YOLOv8 model achieved 89.95% precision, 72.13% recall, 80.06% F1 score, 86.31% mAP@0.5, and 59.16% mAP@0.5:0.95. After introducing only the improved loss function, precision increased to 90.72%, recall to 75.57%, F1 score to 82.45%, and mAP@0.5 to 87.94%. Compared to the baseline model, mAP@0.5 improved by 1.63 percentage points, and the F1 score improved by 2.39 percentage points. This indicates that the improved loss function enhances the model's ability to constrain dense and overlapping targets during training, alleviates bounding box offsets between adjacent fish targets, and thus improves overall detection performance.

[0083] After further introducing the MultiSEAM module, the recall rate improved to 78.78%, the F1 score to 84.34%, and the mAP@0.5:0.95 to 60.04%. Compared with the model using only the improved loss function, the recall rate further improved by 3.21 percentage points, the F1 score by 1.89 percentage points, and the mAP@0.5:0.95 by 0.54 percentage points. This indicates that the MultiSEAM module can enhance the representation of fish features through multi-scale receptive field branching and channel reweighting. It is particularly helpful in capturing texture, structure, and contour information at different scales, thereby improving the target detection capability under conditions of occlusion, overlap, and blurred boundaries.

[0084] In summary, the improved loss function primarily enhances the ability to localize dense fish targets, while the MultiSEAM module further strengthens the model's multi-scale feature extraction capabilities. Combining these two strategies, the model achieves optimal results in precision, recall, F1 score, mAP@0.5, and mAP@0.5:0.95. This demonstrates that the proposed improved strategies are complementary and can effectively enhance fish detection performance in complex underwater scenarios.

[0085] Please see Figure 7 The results obtained in this experiment are shown in the left image, which is the result obtained by YOLOv8, and the right image is the result obtained by the present invention. It can be seen that the occluded fish are effectively detected in the solution of the present invention.

[0086] To demonstrate the effectiveness of the improved body length measurement strategy, this experiment employed both the original YOLO v8 detection bounding box scaling method and the improved YOLO detection, SAM segmentation, pose correction, and scaling factor conversion method proposed in this invention. The former primarily estimates the fish length based on the relationship between the pixel values ​​of the longer side of the detection bounding box and the calibrated scale, while the latter further utilizes SAM segmentation to extract the fish contour based on target detection and combines scaling factors to convert pixel length to actual length.

[0087] Depend on Figure 8 As can be seen, compared with the original method, the method proposed in this invention has a more concentrated scatter distribution, and the main sample points are more closely aligned with the ideal prediction line. This indicates that the improved method has improved prediction stability on most samples and can better reflect the correspondence between the actual body length and the predicted body length. However, there are still a few obvious outliers in the figure, mainly manifested in the significant underestimation of some samples with an actual body length of about 25-27 cm. This phenomenon may be related to objective factors in underwater image acquisition, including fish body posture curvature, local occlusion, failure of the detection box or segmentation mask to completely cover the long axis of the fish body, inconsistency in the spatial position of the calibrated fish and the fish to be tested, and proportional conversion errors caused by monocular perspective.

[0088] Based on the test set metrics, the method of this invention exhibits superior error results. The original method's MAE, RMSE, and MAPE were 5.1791 cm, 7.5618 cm, and 19.6680%, respectively, while the method of this invention reduced these to 4.4170 cm, 6.4715 cm, and 16.5029%, indicating that the improved method can effectively reduce the body length prediction error under the basic scaling factor. Under linear pixel mapping and position-aware correction conditions, the overall errors of the two methods are at similar levels, and the scatter points of the improved method are more compact in the main sample area, indicating that its prediction results have better stability. Overall, the improved YOLO+SAM+scale factor correction method proposed in this invention can obtain more refined fish body contours, providing more complete target area information for subsequent body length measurement and morphological analysis. Experimental results also show that underwater monocular image body length measurement is still affected by objective factors such as calibration position, perspective changes, and fish posture. Further improvements in measurement accuracy are needed by combining depth estimation, multi-point calibration, or fish key point detection.

[0089] It should be understood that the embodiments described above are only some, not all, of the embodiments of the present invention. Furthermore, the technical features of the various embodiments or individual embodiments provided by the present invention can be arbitrarily combined to form feasible technical solutions. Such combinations are not constrained by the order of steps and / or structural composition patterns, but must be based on the ability of those skilled in the art to implement them. When the combination of technical solutions is contradictory or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection claimed by the present invention.

[0090] It should be understood that the above description of the preferred embodiments is quite detailed, but it should not be considered as a limitation on the scope of protection of this invention. Those skilled in the art, under the guidance of this invention, can make substitutions or modifications without departing from the scope of protection of the claims of this invention, and all such substitutions or modifications fall within the scope of protection of this invention. The scope of protection of this invention should be determined by the appended claims.

Claims

1. A non-contact method for measuring fish body length based on multi-scale anti-occlusion dynamic optimization, characterized in that, Includes the following steps: Step 1: Capture the video stream inside the aquaculture pond in real time and automatically extract frames at preset times to obtain non-redundant underwater images; Step 2: Use a feature detection and enhancement network to detect and enhance the fish's body features; Step 3: Optimize the optimal form of swimming fish based on multi-target tracking algorithm, including kinematic state modeling and anti-drift tracking matching of fish, constructing target temporal feature archive and multi-constraint optimization, and outputting the target optimal form frame; Step 4: For the optimal shape frame, perform high-precision mask extraction and physical length conversion to obtain the fish body length.

2. The non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization according to claim 1, characterized in that: In step 1, an underwater light source is installed at the bottom of the aquaculture pond, and an underwater camera is fixedly installed on the side wall of the aquaculture pond near the bottom to obtain images of the fish in the aquaculture pond at the optimal elevation angle or level view.

3. The non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization according to claim 1, characterized in that: In step 2, the feature detection and enhancement network processes the input image sequentially through the first Conv layer, the second Conv layer, the first C2f layer, the third Conv layer, the second C2f layer, the fourth Conv layer, the third C2f layer, the fifth Conv layer, the fourth C2f layer, and the SPPF layer. The first C2f layer outputs B5, the third C2f layer outputs B4, and the SPPF layer outputs B3. After passing through the first Unsample layer, B3 is either fused with B4 through the first Concat layer before being input to the fifth C2f layer, or directly input to the fourth Concat layer. The output of the fifth C2f layer is processed by... After passing through the second Unsample layer, B5 is merged with B5 through the second Concat layer and then input into the sixth C2f layer. Simultaneously, it is directly input into the third Concat layer. The sixth C2f layer outputs B5', which, after processing through the sixth Conv layer, is merged with the output of the fifth C2f layer through the third Concat layer and then input into the seventh C2f layer. The seventh C2f layer outputs B4', which, after processing through the seventh Conv layer, is merged with the output of the first Unsample layer through the fourth Concat layer and then input into the eighth C2f layer. The eighth C2f layer outputs B3'. After passing through the first multi-scale spatial enhancement attention module, the second multi-scale spatial enhancement attention module, and the third multi-scale spatial enhancement attention module, respectively, B5', B4', and B3' are input into the first detection head, the second detection head, and the third detection head, respectively, to predict the fish target and output the fish bounding box coordinates, category confidence, and detection confidence. The first, second, and third multi-scale spatial enhancement attention modules have the same structure, differing only in the feature block size of their multi-branch scale aggregation layers. The multi-branch scale aggregation layer comprises three parallel branches, each employing a depthwise separable convolution with the same kernel size but different feature block sizes on the original feature map. Large-span downsampling is performed, followed by GAP processing before output, and then compared with the original feature map after GAP processing. After processing by the summation and averaging layer, the output sequentially passes through the first Linear layer, ReLU layer, second Linear layer, Sigmoid layer, and nonlinear amplification layer, and is then compared with the original feature map. After element-wise multiplication, the enhanced output is obtained. .

4. The non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization according to claim 1, characterized in that: In step 2, the feature detection and enhancement network is a pre-trained network; during training, the bounding box regression loss function of the detection head is: ; ; ; ; in, and The hyperparameters for fish swarm interference are used to adjust the repulsion intensity; parameters This represents the target total number of fish within the batch. This represents the predicted fish body bounding box currently undergoing regression. The true bounding boxes of non-matching adjacent fish bodies that are too close together and cause interference. This refers to the smoothness coefficient applied to the edges of the fish body. The intersection-union loss function is... This is the set of positive candidate boxes, where the subscript "+" represents the positive class. This indicates that all positive sample prediction boxes are traversed; IoG() represents the ratio of the overlap area between the predicted fish body box and the non-matching real fish body box to the area of ​​the real fish body box. : Represents two different predicted fish body boxes; The intersection-union ratio function is the area of ​​the intersection of two predicted fish body boxes divided by the area of ​​their union. This is a smooth logarithmic penalty function used to continuously penalize the overlap between the predicted bounding box and adjacent targets. A tiny constant added to prevent numerical anomalies in logarithmic operations.

5. The non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization according to claim 1, characterized in that: In step 3, the kinematic state modeling and anti-drift tracking matching of the fish swarm first uses Kalman filtering to establish a continuous state space vector for each detected target, and then performs state transition prediction: ; The center coordinates of the fish body frame contained at time t-1 ( ), area scale Aspect Ratio and the corresponding rate of change of velocity ; This is the state transition matrix based on the physiomechanics of fish swimming; The ideal position of the fish predicted in the current frame at time t; when the fish swims behind aquatic plants or is occluded, causing the detection box to disappear, a time buffer is set to utilize... Maintain uninterrupted target tracking and identification of fish using Track ID; In the box matching process between consecutive frames, the Hungarian algorithm is used to perform bipartite graph matching by combining Mahalanobis distance with the appearance features of fish ReID (Recognition ID) numbers, thus limiting false matches. ; in, This represents the Mahalanobis distance between the current fish detection bounding box and the predicted target trajectory. The detection bounding box for the new fish body actually observed in the current frame; The observation matrix is ​​pre-defined by the Kalman filter state-space model and is used to extract the observable components directly corresponding to the detection box from the target state vector. The covariance matrix characterizes the uncertainty in predicting fish swimming trajectories; if the spatial jumps of the frame generate... If the swimming speed exceeds a reasonable threshold, matching will be blocked directly to ensure that the same fish is not matched with other fish.

6. The non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization according to claim 1, characterized in that: In step 3, the construction of the target temporal feature archive and multi-constraint optimization first establishes an independent temporal feature archive for each fish that has been successfully assigned a target tracking identity recognition Track ID. As long as the target survives in the picture, the frame timestamp / frame number, full image memory pointer and detection confidence, as well as the real-time calculated bounding box diagonal pixel length are written into its temporal feature archive frame by frame. When the Track ID of a target continues to exist, under the constraints of edge integrity and detection stability, the frame with the largest diagonal pixel length of the bounding box is the optimal shape frame. When the Track ID of a target is determined to be missing, the optimal form frame search algorithm for that Track ID is triggered: ; in, It refers to the set of valid frames that satisfy security constraints. This represents the unique optimal morphological frame within the life cycle of this fish, identified through an optimization algorithm. According to the physical laws of projection of three-dimensional objects, when When the maximum value is reached, the fish is considered to be in the optimal length-measuring posture with its body fully extended and straight, and its side completely parallel to the camera's image sensor. This represents the diagonal pixel length of the target fish detection bounding box at time t.

7. The non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization according to claim 6, characterized in that: The optimal form frame search algorithm uses multi-constraint cascade filtering to extract valid frames with safety constraints. ,include: Constraint A: Edge truncation prevention constraint, which removes frames whose bounding box center coordinates are located in the M% edge region around the entire image, to prevent the selection of invalid frames where only half of the fish body is in the picture. M is a preset value. Constraint B: High confidence constraint for the state, remove frames whose YOLO output detection confidence is below the threshold, or whose Kalman filter state is not "acknowledgment state"; Constraint C: Geometric projection optimal, traversing the diagonal length field in the remaining frame set filtered by constraints A and B. The argmax algorithm is used to extract the frame with the largest diagonal value, which is then used as the optimal frame.

8. The non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization according to claim 1, characterized in that: Step 4 includes the following sub-steps: Step 4.1: Based on the high-definition original image of the optimal shape frame, and combined with the corresponding two-dimensional bounding box coordinates, construct a joint prompt word, and use the mask decoder of the SAM 2 large vision model to generate a high-fidelity binary pixel mask mask of the target fish body that is stripped of the interference of aquatic plants and mud. Step 4.2: Extract the outer contour of the mask and fit it to obtain the maximum number of pixels along the major axis of the smallest bounding rectangle of the outer contour; Step 4.3: Multiply the number of pixels on the major axis by the spatial mapping coefficient matrix pre-calibrated based on the underwater camera's intrinsic and extrinsic parameters and depth of field to calculate the physical length of the target fish.

9. The non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization according to claim 8, characterized in that: In step 4.3, the formula for converting the physical length of the target fish is: ; in, The number of pixels along the major axis calculated for the image mask; To the depth of the water where the fish is located The "physical-pixel" scaling factor that exhibits a dynamic mapping relationship.

10. A non-contact fish body length measurement system based on multi-scale anti-occlusion dynamic optimization, characterized in that, include: One or more processors; A storage device for storing one or more programs, which, when executed by one or more processors, cause the one or more processors to implement the non-contact fish body length measurement method based on multi-scale anti-occlusion dynamic optimization as described in any one of claims 1 to 9.