Accurate counting method for fish passing through fishway
By combining the target extraction algorithm of background modeling and deep learning, combined with the tracking algorithm of key points and target areas, and adopting the double mixing line mechanism, the problems of low target detection rate and inaccurate counting in the fish passage method are solved. Efficient and accurate counting of fish passing through fish passages is achieved.
Patent Information
- Application Number
- CN202411040711.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-31
- Publication Date
- 2024-10-29
AI Technical Summary
The existing fish passage method based on video analysis has problems such as low target detection rate in underwater scenes, easy misdetection of targets, and low efficiency of tracking algorithms, resulting in inaccurate counting.
A target extraction algorithm based on background modeling and deep learning is used, combined with a tracking algorithm for key points and target areas, and a double line mechanism is used to improve counting accuracy and solve the tracking inaccuracy problems caused by fish occlusion and posture problems.
It achieves efficient extraction and counting of fish targets, improves the detection rate, reduces false detections, ensures counting accuracy, and avoids missed statistics caused by target trajectory loss.
Smart Images

Figure CN118865449A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of counting fish passing through a fishway, and in particular to a method for accurately counting fish passing through a fishway. Background Art
[0002] The number of fish passing through refers to the total number of fish passing through a fishway within a certain period of time; the number of fish refers to the number of fish in a single static picture; because the same target may persist for a period of time in a continuous video, it is impossible to obtain the number of fish passing through information based on a single detection result, and the problem of target matching and filtering duplicates needs to be considered. At present, the main process of the fish passing detection solution based on image processing is fish target detection + target tracking, among which the target detection methods mainly include background difference method, frame difference method, Vibe algorithm, deep learning target detection, etc., and the tracking algorithms include TLD tracking, particle filtering, KCF tracking, etc.
[0003] 1. The background difference method is a general method for motion segmentation of static scenes. It performs a difference operation between the currently acquired image frame and the background image to obtain a grayscale image of the target motion area. The grayscale image is thresholded to extract the motion area. In order to avoid the influence of ambient light changes, the background image is updated according to the currently acquired image frame.
[0004] 2. The inter-frame difference method is to subtract the pixel values of two adjacent frames or two images separated by several frames in the video stream, and threshold the subtracted image to extract the motion area in the image.
[0005] 3. The Vibe algorithm stores a sample set for all pixels. The sample values stored in the sample set are the past pixel values of the pixel and the pixel values of its neighbors. The new pixel value of each subsequent frame is compared with the sample history value in the sample set to determine whether it belongs to the background point.
[0006] 4. Deep learning target detection algorithm is a technology that realizes target detection and recognition by using a large amount of labeled sample data and learning the common features of the target. Commonly used ones include SSD, centernet, yolo, etc. These algorithms are based on convolutional neural networks, pooling layers, activation functions and loss functions to realize model training and reasoning.
[0007] 5. TLD tracking, its operating mechanism is: the detection module and the tracking module are processed in parallel with complementary interference. First, the tracking module assumes that the movement of objects between adjacent video frames is limited and the tracked target is visible, so as to estimate the movement of the target. If the target disappears from the camera's field of view, the tracking will fail. The detection module assumes that each visual frame is independent of each other, and based on the previously detected and learned target model, a full-image search is performed on each frame to locate the area where the target may appear. Like other target detection methods, the detection module in TLD may also have errors, and the errors are divided into two situations: wrong negative samples and wrong positive samples. The learning module evaluates the two errors of the detection module based on the results of the tracking module, and generates training samples based on the evaluation results to update the target model of the detection module, and at the same time updates the "key feature points" of the tracking module to avoid similar errors in the future.
[0008] 6. Particle filtering is a nonlinear filtering method based on Monte Carlo simulation. Its core idea is to express the probability density distribution with randomly sampled particles. The three important steps of particle filtering are: 1) Particle sampling, extracting a group of particles from the proposed distribution; 2) Particle weighting, calculating the weight of each particle according to the observed probability distribution, importance distribution and Bayesian formula; 3) Estimated output, outputting the mean covariance of the system state, etc. In addition, in order to deal with the particle degradation phenomenon, resampling and other strategies are also adopted.
[0009] 7. KCF is a discriminative tracking method. This type of method generally trains a target detector during the tracking process, uses the target detector to detect whether the predicted position of the next frame is the target, and then uses the new detection results to update the training set and then update the target detector. When training the target detector, the target area is generally selected as the positive sample, and the surrounding area of the target is the negative sample. Of course, the closer the area to the target is, the greater the possibility of being a positive sample.
[0010] However, the current fish pass method based on video analysis has low target detection rate and easy misdetection of targets in underwater scenes. It also has problems such as low efficiency of tracking algorithm and inaccurate counting. Summary of the invention
[0011] In view of this, the present invention proposes a method for accurately counting fish passing through a fishway. 1. It adopts a target extraction algorithm based on the combination of background modeling and deep learning. On the one hand, it can effectively and quickly extract moving targets in the scene, and on the other hand, it can accurately extract fish targets and eliminate non-fish targets; it can effectively detect all targets of interest while being relatively efficient. A tracking algorithm based on the combination of key points and target areas is adopted to solve the problem of inaccurate tracking caused by fish occlusion and posture problems. A double-interlaced line mechanism is adopted to solve the problem of target tracking loss or tracking interruption near the single-interlaced line, thereby improving counting accuracy.
[0012] The technical solution of the present invention is achieved in this way:
[0013] The present invention provides a method for accurately counting fish passing through a fishway, comprising the following steps:
[0014] S1 obtains a video sequence and extracts image frames, generates a background model based on the image frames, extracts the motion area using the background model, takes the motion area as the area to be classified, builds and trains a deep learning target classification model, and uses the deep learning target classification model to identify the area to be classified to obtain a fish image;
[0015] S2 builds and trains a key point recognition model, uses the key point recognition model to recognize fish images, and obtains key points of the fish images;
[0016] S3 uses the first matching method to perform rough matching on the fish image, and then uses the second matching method to perform precise matching on the key points of the fish image to obtain a target matching result, and implements target tracking to obtain a target motion trajectory;
[0017] S4 uses the double-line mechanism to determine the fish passing through the target movement trajectory and obtain the number of fish passing through.
[0018] Based on the above solution, preferably, step S1 includes:
[0019] S11 obtains a video sequence, extracts image frames, sums and averages selected multiple frames, and obtains an initial background model;
[0020] S12 updates the background model using the set learning rate in subsequent image frame processing, and obtains the updated background model when the image frame processing is completed;
[0021] S13 performs a difference operation between the current frame and the background model to extract a foreground mask;
[0022] S14 extracts a foreground target area, i.e., a motion area, from the foreground mask according to connected component analysis;
[0023] S15 repeats steps S13-S14, completes processing of all image frames, and obtains the area to be classified of each image frame;
[0024] S16 constructs and trains a deep learning target classification model, inputs the image frame into the deep learning target classification model, performs target classification and recognition on the classified area, and obtains a fish image.
[0025] Based on the above scheme, preferably, the deep learning target classification model uses the ResNet-50 network as the feature extraction backbone network, and the loss function used in the training of the deep learning target classification model is the cross entropy loss function.
[0026] Based on the above solution, preferably, the key points of the fish image include the fish head, dorsal fin, pelvic fin, pectoral fin, anal fin, and caudal fin.
[0027] Based on the above solution, preferably, the key point recognition model includes:
[0028] 5 convolutional layers, the first convolutional layer includes 128 convolutional kernels, each of which is 5*5 in size and has a step size of 2; the second convolutional layer includes 128 convolutional kernels, each of which is 5*5 in size and has a step size of 2; the third convolutional layer includes 96 convolutional kernels, each of which is 3*3 in size and has a step size of 2; the fourth convolutional layer includes 96 convolutional kernels, each of which is 3*3 in size and has a step size of 2; the fifth convolutional layer includes 100 convolutional kernels, each of which is 3*3 in size and has a step size of 2;
[0029] 5 pooling layers, each using average pooling;
[0030] 6 activation function layers, using ReLU activation function;
[0031] 2 fully connected layers.
[0032] Based on the above solution, preferably, when training the key point recognition model, the loss function used is Euclidean distance.
[0033] Based on the above solution, preferably, the first matching method is:
[0034] According to the recognition results of the deep learning target classification model, the target frame in the fish image is extracted to locate the position of the fish target in the image frame;
[0035] Set the IoU threshold, calculate the IoU between the target frames at the same position in the previous and next frames, and compare the IoU with the IoU threshold. If the IoU is greater than the IoU threshold, the two corresponding target frames are considered to be matched successfully, and they are taken as a matching pair and added to the initial matching result.
[0036] Select a target box in the initial matching result. If the target box only matches one target box, keep the corresponding matching pair in the initial matching result. If the target box matches multiple target boxes, use the target box as the source target box, and the multiple target boxes it matches as the target boxes to be matched, and add the corresponding matching pair to the first matching result.
[0037] Based on the above solution, preferably, the second matching method is:
[0038] Extract features from each target frame in the first matching result to obtain key points and corresponding descriptors;
[0039] For the descriptor of each key point, traverse all descriptors in the target frame to be matched, find the descriptor with the smallest distance, take the corresponding two descriptors as the first descriptor matching pair, and add them to the first candidate matching result;
[0040] The order of the source target frame and the target frame to be matched is swapped, the distance between the corresponding descriptors is calculated, and the two descriptors with the smallest distance are found as the second descriptor matching pair, and added to the second candidate matching result;
[0041] The first candidate matching result and the second candidate matching result are compared. If there is a first descriptor match that matches the second descriptor match, the corresponding two descriptors are taken as a final matching pair and added to the target matching result.
[0042] Based on the above solution, preferably, step S4 includes:
[0043] S41 sets a first virtual mixing line and a second virtual mixing line;
[0044] S42 calculates the position of the fish target in the current frame and the position of the fish target in the previous frame based on the target motion trajectory, and determines whether the two positions are located on both sides of the first virtual mixing line. If so, it is determined that the fish target has passed the first virtual mixing line, and the counter is incremented by 1 and the information of the fish target is recorded. If not, the count remains unchanged and step S43 is executed;
[0045] S43 calculates the position of the fish target in the current frame and the position of the fish target in the previous frame again, and determines whether the two positions are located on both sides of the second virtual mixing line. If so, it is determined that the fish target has passed the second virtual mixing line, and the counter is incremented by 1 and the information of the fish target is recorded;
[0046] S44 repeats steps S42-S43, and performs fish passing determination on the fish targets in the image frame to obtain the final number of fish passing.
[0047] On the basis of the above solution, preferably, for the target motion trajectory that is no longer updated, each point in the entire trajectory list is checked to ensure that all are located on the same side of the first virtual mixing line. If the condition is met, it is considered to be an invalid count.
[0048] The method of the present invention has the following beneficial effects compared with the prior art:
[0049] (1) Fast calculation can be achieved by extracting moving targets in images, because the average background modeling method is based on pixel-level operations, with less calculation and frame difference operations. Therefore, it is better than directly using deep learning target extraction algorithms, with higher detection rate, less false detection, and no particularly high requirements for hardware resources.
[0050] (2) The target tracking algorithm based on key point matching can achieve the optimal matching of key points by using a full matching algorithm based on a relatively small number of key points. Since the number of key points is small, the amount of calculation is very small. The key point matching algorithm solves the problem that the traditional target tracking algorithm cannot track the target due to posture problems and occlusion problems;
[0051] (3) Double-line mechanism: The fish passing situation is judged by two lines, avoiding the situation that the target track may be lost when using one line, thus causing missed statistics. This method can effectively solve the missed statistics caused by the loss of the target track and achieve accurate counting. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0053] Figure 1 The present invention is a flow chart of the method. DETAILED DESCRIPTION
[0054] The following will be combined with the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0055] See also Figure 1 The present invention provides a method for accurately counting fish passing through a fishway, comprising the following steps:
[0056] S1 obtains a video sequence and extracts image frames, generates a background model based on the image frames, extracts the motion area using the background model, takes the motion area as the area to be classified, builds and trains a deep learning target classification model, and uses the deep learning target classification model to identify the area to be classified to obtain a fish image;
[0057] S2 builds and trains a key point recognition model, uses the key point recognition model to recognize fish images, and obtains key points of the fish images;
[0058] S3 uses the first matching method to perform rough matching on the fish image, and then uses the second matching method to perform precise matching on the key points of the fish image to obtain a target matching result, and implements target tracking to obtain a target motion trajectory;
[0059] S4 uses the double-line mechanism to determine the fish passing through the target movement trajectory and obtain the number of fish passing through.
[0060] The technical implementation process of the present invention is as follows: first, background modeling is performed for the current video, and moving targets are extracted from the current video in real time, and deep learning fish and non-fish classification calculations are performed on the moving targets; secondly, deep learning target classification recognition is performed on the current image to identify the current fish target and type; secondly, fish target key points are extracted from the current image, and previous and next frame targets are matched according to the key points and target area information to achieve target tracking; finally, the target is judged to have crossed the line to achieve number statistics.
[0061] Specifically, in one embodiment of the present invention, step S1 includes:
[0062] Step S1 includes:
[0063] S11 obtains a video sequence, extracts image frames, sums and averages selected multiple frames, and obtains an initial background model;
[0064] S12 updates the background model using the set learning rate in subsequent image frame processing, and obtains the updated background model when the image frame processing is completed;
[0065] S13 performs a difference operation between the current frame and the background model to extract a foreground mask;
[0066] S14 extracts a foreground target area, i.e., a motion area, from the foreground mask according to connected component analysis;
[0067] S15 repeats steps S13-S14, completes processing of all image frames, and obtains the area to be classified of each image frame;
[0068] S16 constructs and trains a deep learning target classification model, inputs the image frame into the deep learning target classification model, performs target classification and recognition on the classified area, and obtains a fish image.
[0069] Background modeling refers to extracting background information by analyzing and processing each frame in the video sequence, thereby realizing the detection of foreground targets. The present invention adopts a more efficient average background modeling method, that is, summing and averaging multiple frames of image data to obtain the background, and then in the subsequent update process, the background is updated at a learning rate of 0.1, so as to realize continuous background update. Since the background model is constantly updated and learned during the whole process, this method has a certain robustness for extracting the background. Secondly, the current frame image data and the background model are subjected to difference calculation, and a threshold is set. The area with a difference less than the threshold is considered to be a non-moving area, and the area with a difference greater than the threshold is considered to be a moving target area, and the area is extracted as the area to be classified and identified.
[0070] Then, a deep learning target classification model is constructed and trained. The targets are classified into two categories, namely fish targets and non-fish targets. In order to train the model, the acquired image samples can be processed by the above-mentioned background modeling method to obtain the area to be identified in the sample, thereby reducing the amount of model calculation. The two types of data are placed in two folders respectively; ResNet-50 is used as the feature extraction backbone network, and the cross entropy loss function is used as the classification loss function. The parameters of the model can be effectively optimized by minimizing the cross entropy between the predicted probability distribution and the true probability distribution, so that the prediction results of the model are closer to the true label results; finally, a binary classification model of fish targets and non-fish targets is trained and generated, and the model is used in the inference process to classify and identify the types of moving targets.
[0071] The image frame is input into the deep learning target classification model, and the target classification and recognition are performed on the classified area to obtain the fish image.
[0072] Specifically, in one embodiment of the present invention, the target key point refers to the area in the target with significant features, key information and special content, which plays an important role in extracting the target's posture. In the present invention, while identifying the fish target, the target key point is further extracted. The present invention extracts a total of 6 key points, namely, the fish head, dorsal fin, pelvic fin, pectoral fin, anal fin and caudal fin. In order to extract the above 6 key points, the present invention constructs a key point recognition model, and its training process adopts the following steps:
[0073] First, perform data annotation and mark 6 key points in the fish target image;
[0074] Secondly, the network structure is designed. The following network structure model is designed in the present invention, which is divided into 5 conv layers, 5 pool layers, 6 Relu layers and 2 fully connected layers. The main function of the conv layer is to extract features with translation, rotation and scale invariance in the image, and at the same time complete the dimension reduction of the image feature dimension, prevent overfitting, and improve the generalization ability of the model. The characteristics of the convolution layer mainly include local perception, parameter sharing, and multi-core convolution. The first conv layer has 128 convolution kernels, each of which is 5*5 in size and has a step length of 2. The second conv layer has 128 convolution kernels, each of which is 5*5 in size and has a step length of 2. The third conv layer has 96 convolution kernels, each of which is 3*3 in size and has a step length of 2. The fourth conv layer has 96 convolution kernels, each of which is 3*3 in size and has a step length of 2. The fifth conv layer has 100 convolution kernels, each of which is 3*3 in size and has a step length of 2.
[0075] The convolution kernel of the pool layer uses average pooling to obtain the average value of the corresponding position, and the pooling layer only has forward calculations. The main function of the pool layer is to compress the image and reduce the spatial size of the data body. In this way, the number of parameters in the network can be reduced, which reduces the consumption of computing resources and effectively controls overfitting.
[0076] The Relu layer is a linear correction function layer and is a commonly used activation function in deep learning network models. The main function of this layer is to increase the nonlinearity of the neural network model. The advantages of the Relu activation function are that the gradient is not saturated and the calculation speed is fast.
[0077] The fully connected layer is a common layer type in convolutional neural networks. Its main function is to take the output of the previous layer as input and perform linear combination to generate new output. The fully connected layer connects each neuron in the previous layer to each neuron in the current layer, and calculates the corresponding weights and biases to generate the output of the current layer. This invention has two fully connected layers. The first fully connected layer mainly reduces the dimensionality of high-dimensional data, reducing the feature dimension of the data to 186 dimensions, and then it is processed by the second fully connected layer to output 12-dimensional result information. Each key point has two-dimensional data, which is the final output result information of the model.
[0078] The second step is to design a loss function. The present invention adopts Euclidean distance as the loss function, which has the characteristics of simple and fast calculation, and the accuracy meets the actual needs.
[0079] Finally, the model is trained. The main process of model training is to iterate a large amount of sample data and annotated label data to minimize the loss function value of the model's forward reasoning results and the annotated data. During the training process, the loss value of the forward training is calculated, and the reverse update training is performed until the loss value is stable. At this time, the values of all parameters in the model are saved to generate the optimal model.
[0080] After the key point recognition model is trained, the model is used to recognize fish images to obtain the key points of the fish images.
[0081] In actual scenes, there are often problems of occlusion and posture changes. It is easy to make tracking errors using traditional target tracking algorithms. Therefore, the present invention performs matching tracking based on key points. Feature matching requires calculating the distance between two descriptors, and the difference between them needs to be quantified and defined as a similarity measure.
[0082] Specifically, the first rough matching is performed first, and the target is matched according to the target frame. The intersection-over-union ratio of the target frame is used to determine whether the two targets are the same target. The higher the intersection-over-union ratio, the more overlap the two frames have, and they may be the same target. The intersection-over-union ratio is the intersection area of the two target frames divided by their union area, which is used to measure the degree of overlap between the two frames. The specific process of the first matching method is as follows:
[0083] According to the recognition results of the deep learning target classification model, the target frame in the fish image is extracted to locate the position of the fish target in the image frame;
[0084] Set the IoU threshold, calculate the IoU between the target frames at the same position in the previous and next frames, and compare the IoU with the IoU threshold. If the IoU is greater than the IoU threshold, the two corresponding target frames are considered to be matched successfully, and they are taken as a matching pair and added to the initial matching result.
[0085] Select a target box in the initial matching result. If the target box only matches one target box, keep the corresponding matching pair in the initial matching result. If the target box matches multiple target boxes, use the target box as the source target box, and the multiple target boxes it matches as the target boxes to be matched, and add the corresponding matching pair to the first matching result.
[0086] When there are few targets and no occlusion, generally speaking, one target frame only matches one target frame. In this case, the target can be directly matched by intersection and union. When there are many targets and there are occlusions, one target frame may match multiple target frames. In this case, further processing is required to determine the best matching target. The second matching method is specifically:
[0087] Extract features from each target frame in the first matching result to obtain key points and corresponding descriptors;
[0088] For the descriptor of each key point, traverse all descriptors in the target frame to be matched, find the descriptor with the smallest distance, take the corresponding two descriptors as the first descriptor matching pair, and add them to the first candidate matching result;
[0089] The order of the source target frame and the target frame to be matched is swapped, the distance between the corresponding descriptors is calculated, and the two descriptors with the smallest distance are found as the second descriptor matching pair, and added to the second candidate matching result;
[0090] The first candidate matching result and the second candidate matching result are compared. If there is a first descriptor match that matches the second descriptor match, the corresponding two descriptors are taken as a final matching pair and added to the target matching result.
[0091] Specifically, the distance is calculated using the Euclidean distance. In the second matching, since there are fewer key points to be matched, for each key point descriptor in the first image, the distance between it and each key point descriptor in the second image is calculated, and the key point with the smallest distance is considered to be matched. In order to improve the matching accuracy, a cross-check method is used to verify the matching results. It can effectively reduce false matches and improve the accuracy of key point matching.
[0092] Through the above steps, the target box matching is preliminarily determined, and the key points in the target box are accurately matched. Next, this information is used to achieve target tracking.
[0093] Update target position: In each frame, the displacement information of the target is calculated using the matched key points and the position of the fish is updated. This allows tracking the movement trajectory of the fish in the image sequence, especially when there are occlusions and posture changes, key point matching can provide more robust tracking results.
[0094] Trajectory drawing: record the position of the fish in each frame and connect them to form a trajectory line to obtain the movement trajectory of the fish.
[0095] Specifically, this two-step matching strategy, coarse matching based on the target frame and fine matching based on key points, can effectively solve the tracking problems caused by occlusion and posture changes. Coarse matching quickly locks possible matches through the intersection of the target frame and the fine matching reduces mismatches through the refined matching of key points, thereby achieving high-precision target tracking and obtaining the target's motion trajectory. This method not only improves the accuracy of the tracking algorithm, but also takes into account the computational efficiency. It is particularly suitable for tracking fish targets in complex scenes with many targets.
[0096] Specifically, in order to accurately count the number of fish passing through a certain path and avoid missed detection, the present invention adopts a double line-tripping mechanism. Under this mechanism, the number of fish can be accurately counted by analyzing the virtual line-tripping judgment based on the fish movement trajectory. Step S4 specifically includes:
[0097] S41 sets a first virtual mixing line and a second virtual mixing line;
[0098] S42 calculates the position of the fish target in the current frame and the position of the fish target in the previous frame based on the target motion trajectory, and determines whether the two positions are located on both sides of the first virtual mixing line. If so, it is determined that the fish target has passed the first virtual mixing line, and the counter is incremented by 1 and the information of the fish target is recorded. If not, the count remains unchanged and step S43 is executed;
[0099] S43 calculates the position of the fish target in the current frame and the position of the fish target in the previous frame again, and determines whether the two positions are located on both sides of the second virtual mixing line. If so, it is determined that the fish target has passed the second virtual mixing line, and the counter is incremented by 1 and the information of the fish target is recorded;
[0100] S44 repeats steps S42-S43, and performs fish passing determination on the fish targets in the image frame to obtain the final number of fish passing.
[0101] Among them, for the target motion trajectory that is no longer updated, each point in the entire trajectory list is checked to ensure that all are located on the same side of the first virtual mixing line. If the condition is met, it is considered to be an invalid count.
[0102] In step S42, based on the target motion trajectory, the current frame target position and the previous frame target position are calculated to determine whether the two positions are located on both sides of the first virtual mixing line. This determination is achieved by calculating the points on the left and right sides of the line segment.
[0103] Judgment method: Use vector cross product to calculate whether the target point crosses the mixing line. This can be achieved by the equation of the point and line in the Cartesian coordinate system.
[0104] If the target position is determined to be on both sides of the first mixing line, it is considered that the target has passed the first mixing line. At this time, the counter is incremented by 1 and the ID of the target is recorded; if the target position is on the same side, the count remains unchanged and the next step of calculation is continued.
[0105] For the target trajectory that is no longer updated, the integrity check of the tracking trajectory is performed. If all points of the target trajectory are located on the same side of the first virtual mixing line, the target tracking is considered to be interrupted and the counting of the first mixing line cannot be completed.
[0106] Judgment condition: Check every point in the entire trajectory list to ensure that all are on the same side. If the condition is met, it is considered an invalid count.
[0107] If the counting has been completed at the first virtual trip line, the counting is not repeated. On the contrary, if the counting is not completed at the first virtual trip line, the position of the target is calculated again to determine whether it is located on both sides of the second virtual trip line.
[0108] Counting rules: Once a target that is not counted at the first virtual trip wire passes through the second virtual trip wire, the counter is incremented by 1.
[0109] According to the target's movement trajectory, the target's movement direction (upward or downward) is further analyzed. This step not only helps to understand the target's behavior, but also can further accurately determine the position and direction.
[0110] Direction determination: By analyzing the direction of the target trajectory vector (i.e. calculating the motion vector from the trajectory point coordinates), determine whether the target is going up or down.
[0111] Specifically, the present invention implements a target counting method based on a double-line mechanism in fish image target tracking to improve counting accuracy and prevent missed detection. In this method, first, the target trajectory is analyzed to determine whether the target crosses the first virtual line, and the target count and ID record are updated in real time. At the same time, for the target trajectory that is no longer updated, the trajectory integrity is checked to ensure that the tracking information of all targets is accurate and effective. Next, the passing status of the uncounted targets is further confirmed by the determination of the second virtual line, thereby supplementing the situation where the first line is not counted. In the process of determining whether the target passes through the virtual line, the vector cross product method is used to determine the position of the point on both sides of the line segment to ensure the accuracy of the determination. Finally, according to the target trajectory obtained by analysis, the movement direction of the target is calculated to determine its upward or downward behavior. Through the double-line mechanism, the accurate statistics of the number of fish targets crossing the line are achieved, and the movement direction is effectively analyzed, providing a solid data foundation for behavioral research and pattern recognition.
[0112] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for accurately counting fish passing through a fishway, characterized in that: The steps include: S1 obtains a video sequence and extracts image frames, generates a background model based on the image frames, extracts the motion area using the background model, takes the motion area as the area to be classified, builds and trains a deep learning target classification model, and uses the deep learning target classification model to identify the area to be classified to obtain a fish image; S2 builds and trains a key point recognition model, uses the key point recognition model to recognize fish images, and obtains key points of the fish images; S3 uses the first matching method to perform rough matching on the fish image, and then uses the second matching method to perform precise matching on the key points of the fish image to obtain a target matching result, and implements target tracking to obtain a target motion trajectory; S4 uses the double-line mechanism to determine the fish passing through the target movement trajectory and obtain the number of fish passing through.
2. A method for accurately counting fish passing through a fishway as claimed in claim 1, characterized in that: Step S1 includes: S11 obtains a video sequence, extracts image frames, sums and averages selected multiple frames, and obtains an initial background model; S12 updates the background model using the set learning rate in subsequent image frame processing, and obtains the updated background model when the image frame processing is completed; S13 performs a difference operation between the current frame and the background model to extract a foreground mask; S14 extracts a foreground target area, i.e., a motion area, from the foreground mask according to connected component analysis; S15 repeats steps S13-S14, completes processing of all image frames, and obtains the area to be classified of each image frame; S16 constructs and trains a deep learning target classification model, inputs the image frame into the deep learning target classification model, performs target classification and recognition on the classified area, and obtains fish images.
3. A method for accurately counting fish passing through a fishway as claimed in claim 2, characterized in that: The deep learning target classification model uses the ResNet-50 network as the feature extraction backbone network. During training, the loss function used by the deep learning target classification model is the cross entropy loss function.
4. A method for accurately counting fish passing through a fishway as claimed in claim 1, characterized in that: The key points of fish images include the head, dorsal fin, pelvic fin, pectoral fin, anal fin, and caudal fin.
5. A method for accurately counting fish passing through a fishway as claimed in claim 4, characterized in that: The key point recognition model includes: 5 convolutional layers, the first convolutional layer includes 128 convolutional kernels, each of which is 5*5 in size and has a step size of 2; the second convolutional layer includes 128 convolutional kernels, each of which is 5*5 in size and has a step size of 2; the third convolutional layer includes 96 convolutional kernels, each of which is 3*3 in size and has a step size of 2; the fourth convolutional layer includes 96 convolutional kernels, each of which is 3*3 in size and has a step size of 2; the fifth convolutional layer includes 100 convolutional kernels, each of which is 3*3 in size and has a step size of 2; 5 pooling layers, each pooling layer uses average pooling; 6 activation function layers, using ReLU activation function; 2 fully connected layers.
6. A method for accurately counting fish passing through a fishway as claimed in claim 1, characterized in that: When training the key point recognition model, the loss function used is Euclidean distance.
7. A method for accurately counting fish passing through a fishway as claimed in claim 1, characterized in that: The first matching method is: According to the recognition results of the deep learning target classification model, the target frame in the fish image is extracted to locate the position of the fish target in the image frame; Set the IoU threshold, calculate the IoU between the target frames at the same position in the previous and next frames, and compare the IoU with the IoU threshold. If the IoU is greater than the IoU threshold, the two corresponding target frames are considered to be matched successfully, and they are taken as a matching pair and added to the initial matching result. Select a target box in the initial matching result. If the target box only matches one target box, keep the corresponding matching pair in the initial matching result. If the target box matches multiple target boxes, use the target box as the source target box, and the multiple target boxes it matches as the target boxes to be matched, and add the corresponding matching pair to the first matching result.
8. A method for accurately counting fish passing through a fishway as claimed in claim 7, characterized in that: The second matching method is: Extract features from each target frame in the first matching result to obtain key points and corresponding descriptors; For the descriptor of each key point, traverse all descriptors in the target frame to be matched, find the descriptor with the smallest distance, take the corresponding two descriptors as the first descriptor matching pair, and add them to the first candidate matching result; The order of the source target frame and the target frame to be matched is swapped, the distance between the corresponding descriptors is calculated, and the two descriptors with the smallest distance are found as the second descriptor matching pair, and added to the second candidate matching result; The first candidate matching result and the second candidate matching result are compared. If there is a first descriptor match that matches the second descriptor match, the corresponding two descriptors are taken as a final matching pair and added to the target matching result.
9. A method for accurately counting fish passing through a fishway as claimed in claim 1, characterized in that: Step S4 includes: S41 sets a first virtual mixing line and a second virtual mixing line; S42 calculates the position of the fish target in the current frame and the position of the fish target in the previous frame based on the target motion trajectory, and determines whether the two positions are located on both sides of the first virtual mixing line. If so, it is determined that the fish target has passed the first virtual mixing line, and the counter is incremented by 1 and the information of the fish target is recorded. If not, the count remains unchanged and step S43 is executed; S43 calculates the position of the fish target in the current frame and the position of the fish target in the previous frame again, and determines whether the two positions are located on both sides of the second virtual mixing line. If so, it is determined that the fish target has passed the second virtual mixing line, and the counter is incremented by 1 and the information of the fish target is recorded; S44 repeats steps S42-S43, and performs fish passing determination on the fish targets in the image frame to obtain the final number of fish passing.
10. A method for accurately counting fish passing through a fishway as claimed in claim 9, characterized in that: For the target motion trajectory that is no longer updated, each point in the entire trajectory list is checked to ensure that all points are located on the same side of the first virtual mixing line. If the condition is met, it is considered to be an invalid count.
Citation Information
Cited By
Pan-tilt recognizing and capturing method and system based on abnormal scene
CN119478795A
Pan / tilt recognition and capture method and system based on abnormal scenarios
CN119478795B
AI camera-based fishing information acquisition system of lamplight cover net fishing boat
CN120673331A
