Water quality detection method, device, equipment and storage medium based on image recognition
Through the water quality detection method based on image recognition, the window attention mechanism is used to extract the water quality characteristic vector, which solves the problem of water quality detection reliance on artificial experience, and achieves a more objective and efficient water quality detection.
Patent Information
- Application Number
- CN202510480313.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-17
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2045-04-17
AI Technical Summary
Existing water quality testing technologies rely too much on manual experience, resulting in the detection results being affected by human factors, lack of objectivity and inefficiency.
The water quality detection method based on image recognition is adopted, and the water quality image is featured through the window attention mechanism, the water quality characteristic vector is obtained, and the water quality pollution type in the water area is determined based on the water quality characteristic vector, so as to reduce the dependence on artificial experience.
It improves the objectivity and efficiency of water quality testing results, reduces the influence of human factors, simplifies the inspection process, and saves time.
Smart Images

Figure CN119992241B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a water quality detection method, device, equipment and storage medium based on image recognition. Background Art
[0002] With the acceleration of economic development and urbanization, water resources are facing increasing pollution pressure. Monitoring water quality is crucial to ensuring water environment safety and human health.
[0003] In related technologies, water quality testing personnel operate professional instruments and equipment to obtain relevant information on water quality. Based on this relevant information, combined with manual experience and professional knowledge, the relevant information is used for data statistics and data analysis to determine the pollution problems in the water quality and then adopt corresponding methods to treat the sewage.
[0004] However, in the above-mentioned related technologies, water quality detection relies too much on human experience, and the water quality detection results are subject to human subjective factors. Summary of the Invention
[0005] The present invention provides a method, apparatus, device, and storage medium for water quality detection based on image recognition, which can improve the objectivity of water quality detection results. The technical solution is as follows:
[0006] In one aspect, an embodiment of the present application provides a water quality detection method, the method comprising:
[0007] Acquire water quality images to be processed;
[0008] Performing feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area to which the water quality image belongs;
[0009] Based on the water quality feature vector, a water quality detection result of the water area is obtained, where the water quality detection result is used to indicate the type of water pollution in the water area.
[0010] On the other hand, an embodiment of the present application provides a water quality detection device based on image recognition, the device comprising:
[0011] An image acquisition module, used for acquiring water quality images to be processed;
[0012] a feature extraction module, configured to perform feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area to which the water quality image belongs;
[0013] The result acquisition module is used to obtain the water quality detection result of the water area based on the water quality feature vector, and the water quality detection result is used to indicate the water pollution type of the water area.
[0014] On the other hand, an embodiment of the present application provides a computer device, which includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the above-mentioned water quality detection method based on image recognition.
[0015] On the other hand, an embodiment of the present application provides a non-temporary computer-readable storage medium having a computer program stored thereon, which implements the above-mentioned water quality detection method based on image recognition when executed by a processor.
[0016] On the other hand, an embodiment of the present application provides a computer program product, which, when executed, enables a computer device to execute the above-mentioned water quality detection method based on image recognition.
[0017] The technical solutions provided in the embodiments of the present application can bring the following beneficial effects:
[0018] The water quality image is processed for feature extraction through the window attention mechanism to obtain the water quality feature vector, and then the water pollution type of the water area is determined based on the water quality feature vector, which reduces the dependence of water quality detection on manual experience, reduces the impact of human factors on the water quality detection results, and improves the objectivity of the water quality detection results; moreover, the water quality image is detected in combination with the window attention mechanism, and there is no need for manual statistics and analysis of relevant water quality information, which simplifies the water quality detection process, improves the efficiency of water quality detection, and saves time. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.
[0020] Figure 1 is a schematic diagram of a water quality detection system provided by an embodiment of the present application;
[0021] Figure 2 A schematic diagram of a water quality detection model is shown as an example;
[0022] Figure 3 This is a flow chart of a water quality detection method based on image recognition provided by an embodiment of the present application;
[0023] Figure 4 A schematic diagram illustrating a process of water quality detection based on image recognition is shown;
[0024] Figure 5 is a flow chart of a water quality detection method based on image recognition provided by another embodiment of the present application;
[0025] Figure 6 This is a flow chart of a water quality detection method based on image recognition provided by another embodiment of the present application;
[0026] Figure 7 This is a block diagram of a water quality detection device based on image recognition provided by one embodiment of the present application;
[0027] Figure 8 This is a block diagram of a water quality detection device based on image recognition provided by another embodiment of the present application. DETAILED DESCRIPTION
[0028] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.
[0029] Please refer to Figure 1 , which shows a schematic diagram of a water quality detection system provided by an embodiment of the present application. The water quality detection system may include: an image acquisition device 10 and an image processing device 20.
[0030] The image acquisition device 10 is used to acquire water quality images. Exemplarily, the image acquisition device 10 can be any device with image acquisition capabilities, such as a camera, video camera, scanner, wearable device, or mobile terminal equipped with a camera, and this embodiment of the present application is not limited thereto. In this embodiment of the present application, before image detection, the image acquisition device 10 acquires water quality images from the surrounding area of the water area. Optionally, one or more image acquisition devices 10 may be located around the water area.
[0031] The image processing device 20 is used to perform image processing on the water quality image. Exemplarily, the image processing device 20 can be any device with image processing capabilities, such as a mobile phone, tablet computer, wearable device, backend server, or PC (Personal Computer), and this embodiment of the present application is not limited thereto. In this embodiment of the present application, after acquiring the water quality image, the image processing device 20 performs image processing on the water quality image and, based on the water quality image, obtains the water quality test results for the corresponding water area to determine the type of pollution present in the water area, thereby facilitating subsequent sewage treatment in the water area based on the pollution type.
[0032] Optionally, the image processing device 20 processes the water quality image based on a pre-trained water quality detection model. The water quality detection model detects the water quality image through a window attention mechanism. For example, Figure 2As shown, the water quality detection model includes a patch partitioning layer (PatchPartition), a first fully connected layer, a patch encoding layer (PatchEmbedding), four window attention mechanisms (Swin Transformer) blocks, a second fully connected layer, and an activation function (Softmax). After acquiring the water quality image, the image processing device resizes the water quality image to 224×224 (resolution). The water quality detection model then divides the water quality image into non-overlapping 4×4 image blocks using PatchPartition. The first fully connected layer performs linear projection to obtain the initial feature maps corresponding to each image block. PatchEmbedding adds position encoding. Four Swin Transformer blocks perform feature extraction on the position-encoded initial feature maps to obtain the final feature maps corresponding to each image block. The second fully connected layer performs feature fusion and nonlinear transformation on the final feature maps corresponding to each image block to obtain the water quality feature vector of the water quality image. The Softmax activation function converts the water quality feature vector into a probability distribution of pollution types, where the sum of the probability distributions of all pollution types is 1. Optionally, the first fully connected layer and the second fully connected layer may be the same fully connected layer or different fully connected layers, which is not limited in this embodiment of the present application.
[0033] Alternatively, as Figure 2 As shown in Figure 1, the above Swin Transformer blocks are connected through a patch merging layer (PatchMerging), and each Swin Transformer block includes window attention (W-MSA) and offset window attention (SW-MSA).
[0034] For the first Swin Transformer block, the initial feature map corresponding to the image block has a resolution of 56×56 and a channel number of 96. The initial feature map corresponding to each image block is divided into 7×7 windows. The initial feature map after adding position encoding is extracted by W-MSA in units of windows to obtain the first intermediate feature map corresponding to each image block. Afterwards, the window is offset by half the window size so that adjacent windows partially overlap and can communicate with each other. The first intermediate feature map is extracted by SW-MSA in units of the offset window to obtain the first feature map corresponding to each image block.
[0035] For the second Swin Transformer block, the first feature map is transformed into the first merged feature map through PatchMerging. The resolution of the first merged feature map is 28×28 and the number of channels is 129. The first merged feature map corresponding to each image block is divided into 7×7 windows. The first merged feature map is extracted by W-MSA in units of windows to obtain the second intermediate feature map corresponding to each image block. After that, the window is offset by half the window size so that adjacent windows partially overlap and can communicate with each other. The second intermediate feature map is extracted by SW-MSA in units of the offset window to obtain the second feature map corresponding to each image block.
[0036] For the third Swin Transformer block, the second feature map is transformed into a second merged feature map through PatchMerging. The resolution of the second merged feature map is 14×14 and the number of channels is 384. The second merged feature map corresponding to each image block is divided into 7×7 windows. The second merged feature map is extracted by W-MSA in units of windows to obtain the third intermediate feature map corresponding to each image block. After that, the window is offset by half the window size so that adjacent windows partially overlap and can communicate with each other. The third intermediate feature map is extracted by SW-MSA in units of the offset window to obtain the third feature map corresponding to each image block.
[0037] In the fourth Swin Transformer block, the third feature map is transformed into a third merged feature map using PatchMerging. The third merged feature map has a resolution of 7×7 and 768 channels. The third merged feature map corresponding to each image block is divided into 7×7 windows. W-MSA is used to extract features from the third merged feature map in units of windows to obtain the fourth intermediate feature map corresponding to each image block. The windows are then offset by half the window size to allow for partial overlap between adjacent windows, allowing for communication. SW-MSA is used to extract features from the fourth intermediate feature map using the offset windows as the basic unit to obtain the fourth feature map corresponding to each image block. The fourth feature map is normalized to obtain the final feature map corresponding to each image block.
[0038] Optionally, the water quality detection system further includes a model training device 30 for training the water quality detection model. Exemplarily, the model training device 30 can be any device with model training capabilities, such as a tablet computer, a backend server, or a PC (Personal Computer), though this embodiment of the present application is not limiting in this regard. Optionally, the model training device 30 and the image processing device 20 can be the same device or different devices. In this embodiment of the present application, the image acquisition device 10 captures water quality images of different environments, seasons, and pollution types. The model training device 30 classifies the water quality image labels and divides the captured water quality images into a training sample set and a test sample set. The model training device 30 then trains the water quality detection model using the training sample set. After training is complete, the water quality detection model is tested using the test sample set to determine the accuracy of the water quality detection model's detection results and prevent model overfitting. Optionally, the model training device 30 divides 80% of the water quality images into training samples and 20% into test samples.
[0039] Optionally, the image acquisition device 10, the image processing device 20 and the model training device 30 are connected via a network.
[0040] Please refer to Figure 3 , which shows a flow chart of a water quality detection method based on image recognition provided by an embodiment of the present application. Figure 1 The image processing device in the water quality detection system shown in FIG. The method may include the following steps (301-303):
[0041] Step 301: Acquire a water quality image to be processed.
[0042] A water quality image refers to an image that records water information within a water area. In an embodiment of the present application, the image processing device obtains a water quality image to be processed before performing water quality testing on the water area. Optionally, the image processing device acquires water area image data from the water area using an image acquisition device, and then obtains the water quality image to be processed based on the water area image data.
[0043] Optionally, the water area image data includes one or more water area images.
[0044] In a possible implementation, the water area image data includes a water area image. Optionally, after acquiring the water area image, the image processing device directly determines the water area image as the water quality image to be processed.
[0045] In another possible embodiment, the water area image data includes multiple water area images. Optionally, after acquiring the water area image data, the image processing device performs image fusion processing on the water area images contained in the water area image data, and determines the fused image as the water quality image to be processed. Exemplarily, the image processing device traverses each water area image, obtains the pixel value of each pixel point in the water area image, and then averages the pixel values using the pixel point as the basic unit, and determines the image composed of the average pixel values as the water quality image to be processed. The pixel value is used to indicate the color information of the pixel point in the image.
[0046] Optionally, the resolution of the water quality image is 224×224. If the resolution of the initial water quality image acquired by the image processing device is not 224×224, the initial water quality image can be resized so that the resolution of the water quality image is 224×224.
[0047] Step 302: Perform feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area to which the water quality image belongs.
[0048] In an embodiment of the present application, after acquiring the above-mentioned water quality image, the image processing device performs feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area to which the water quality image belongs. The water quality feature vector is used to indicate the water area characteristics contained in the water quality image. Optionally, the water area characteristics include but are not limited to at least one of the following: color characteristics, bubble characteristics, texture characteristics, algae characteristics, light and shadow characteristics, sediment characteristics, suspended matter characteristics, transparency characteristics, etc., which are not limited in this embodiment of the present application.
[0049] In a possible embodiment, the above-mentioned water quality image only contains water body information and does not contain any other information except the water body information. After obtaining the water quality image, the image processing device directly performs feature extraction processing on the water quality image through the window attention mechanism to obtain the above-mentioned water quality feature vector.
[0050] In another possible embodiment, the water quality image includes other information in addition to water body information. After acquiring the water quality image, the image processing device obtains a region of interest from the water quality image, and then performs feature extraction processing on the region of interest through a window attention mechanism to obtain the water quality feature vector. Optionally, after acquiring the water quality image, the image processing device performs contour detection processing on the water quality image to determine the contour of the water body region in the water quality image, and then determines a minimum bounding rectangle based on the water body region contour. Based on the minimum bounding rectangle, a water body region image is obtained from the water quality image, and the water body region image is determined as the region of interest. Feature extraction processing is performed on the water body region image through a window attention mechanism to obtain the water quality feature vector.
[0051] Step 303: Obtain the water quality detection result of the water area based on the water quality feature vector.
[0052] The water quality test results are used to indicate the type of water pollution in the water area. In this embodiment of the present application, after obtaining the water quality feature vector, the image processing device obtains the water quality test results of the water area based on the water quality feature vector. Optionally, the image processing device processes the water quality feature vector using a Softmax activation function to obtain the water quality test results of the water area.
[0053] Optionally, the water quality test result includes at least one pollution type and the probability corresponding to each pollution type, wherein the probability corresponding to the pollution type is used to indicate the possibility of the pollution type existing in the water area.
[0054] To sum up, in the technical solution provided in the embodiment of the present application, feature extraction and processing of water quality images are performed through the window attention mechanism to obtain water quality feature vectors, and then the water pollution type of the water area is determined based on the water quality feature vectors, which reduces the dependence of water quality detection on manual experience, reduces the impact of human factors on water quality detection results, and improves the objectivity of water quality detection results; moreover, by combining the window attention mechanism to detect water quality images, there is no need for manual statistics and analysis of relevant information on water quality, which simplifies the water quality detection process, improves water quality detection efficiency, and saves time.
[0055] The following is a detailed introduction to the method of obtaining water quality feature vectors.
[0056] In an exemplary embodiment, the above step 302 includes the following steps:
[0057] 1. Divide the water quality image into blocks to obtain at least two image blocks.
[0058] In an embodiment of the present application, after acquiring the water quality image, the image processing device performs image segmentation processing on the water quality image to obtain at least two image blocks. There is no overlapping area between the image blocks. For example, the image processing device uses PatchPartition to divide the water quality image into non-overlapping 4×4 image blocks.
[0059] 2. Perform linear projection on each image block to obtain the initial feature map corresponding to each image block.
[0060] In an embodiment of the present application, after acquiring the at least two image blocks, the image processing device performs linear projection on each image block to obtain an initial feature map corresponding to each image block. Exemplarily, the image processing device performs linear projection on each image block through a first fully connected layer to obtain an initial feature map corresponding to each image block.
[0061] 3. Add position encoding to each initial feature map.
[0062] The position code is used to indicate the position of the image block in the water quality image. In an embodiment of the present application, the image processing device adds a position code to each initial feature map after performing linear projection. Exemplarily, the image processing device adds a position code to the initial feature map corresponding to each image block through PatchEmbedding.
[0063] 4. The window attention mechanism is used to perform feature extraction on the initial feature maps after each added position encoding to obtain the final feature maps corresponding to each image block.
[0064] In an embodiment of the present application, after adding the position encoding, the image processing device performs feature extraction processing on each initial feature map after adding the position encoding through a window attention mechanism to obtain a final feature map corresponding to each image block. Exemplarily, the image processing device performs feature extraction processing on the initial feature map after adding the position encoding through a Swin Transformer block to obtain a final feature map corresponding to each image block.
[0065] Taking the target image block among the at least two image blocks mentioned above as an example, in an exemplary embodiment, the image processing device performs window division on the target initial feature map after adding the position code; based on the window division result, the target initial feature map after adding the position code is subjected to feature extraction processing through a multi-head attention mechanism with the window as the basic unit to obtain a first intermediate feature map corresponding to the target image block; a window offset operation is performed on the first intermediate feature map, and the offset distance of the window offset operation is less than the shortest edge length of the window, so that adjacent windows have partial overlap and can communicate with each other; based on the window offset result, the first intermediate feature map is subjected to feature extraction processing through a multi-head attention mechanism with the offset window as the basic unit to obtain a first feature map corresponding to the target image block; and a target final feature map is obtained based on the first feature map. Wherein, the target image block mentioned above is any one of the at least two image blocks mentioned above.
[0066] Exemplarily, the image processing device includes four Swin Transformer blocks. Taking the target image block as an example, in an exemplary embodiment, after obtaining the above-mentioned first feature map, the image processing device performs patch merging on the first feature map to obtain a first merged feature map; performs feature extraction processing on the first merged feature map through window division, window offset and multi-head attention mechanism to obtain a second feature map; performs patch merging on the second feature map to obtain a second merged feature map; performs feature extraction processing on the second merged feature map through window division, window offset and multi-head attention mechanism to obtain a third feature map; performs patch merging on the third feature map to obtain a third merged feature map; performs feature extraction processing on the third merged feature map through window division, window offset and multi-head attention mechanism to obtain a fourth feature map; and obtains the target final feature map based on the fourth feature map. Exemplarily, the image processing device performs patch merging on the feature maps through PatchMerging.
[0067] Exemplarily, the image processing device normalizes the fourth feature map based on a given mean and standard deviation to obtain a target final feature map. Exemplarily, the mean is [0.485, 0.456, 0.406] and the standard deviation is [0.229, 0.224, 0.225].
[0068] It should be noted that the number of the above-mentioned Swin Transformer blocks can be flexibly set and adjusted according to actual conditions, and the embodiments of the present application do not limit this.
[0069] 5. Perform feature fusion on the final feature maps corresponding to each image block.
[0070] In an embodiment of the present application, after obtaining the above-mentioned final feature map, the image processing device performs feature fusion on the final feature maps corresponding to each image block.
[0071] 6. Perform nonlinear transformation on the result after feature fusion to obtain the water quality feature vector.
[0072] In an embodiment of the present application, after performing feature fusion, the image processing device performs a nonlinear transformation on the result of the feature fusion to obtain a water quality feature vector. For example, the image processing device performs feature fusion and nonlinear transformation on the final feature maps corresponding to each image block through the second fully connected layer to obtain the water quality feature vector of the water quality image.
[0073] To sum up, in the technical solution provided in the embodiment of the present application, after the image is segmented, feature extraction processing is performed on each image block separately through the window attention mechanism. While reducing the impact of human factors on the water quality detection results, the image blocks do not overlap, and the local features of the water quality image can be captured more comprehensively, thereby improving the accuracy of water quality detection.
[0074] In addition, feature extraction and processing of water quality images are performed with windows as the basic unit. Each window is calculated independently, which makes it easy to distribute tasks on parallel devices, which is conducive to improving the efficiency of water quality detection. Window offset can capture the correlation between adjacent elements in the water quality image, improve the accuracy of feature capture, and thus improve the accuracy of water quality detection. Moreover, by patch merging, feature extraction is performed layer by layer on the feature map, which can obtain feature information under different fields of view and improve the accuracy of water quality detection.
[0075] Next, the method of obtaining water quality images is introduced.
[0076] In an exemplary embodiment, the above step 301 includes the following steps:
[0077] 1. Obtain a water surface image from water area image data.
[0078] The water area image data includes at least one water area image. A water surface image refers to an image that records water surface information in a water area. In an embodiment of the present application, after acquiring the water area image data of a water area, the image processing device acquires a water surface image from the water area image data of the water area. Optionally, the water area image corresponds to marking information, and the marking information is used to indicate the direction of the image acquisition device relative to the water surface during image acquisition. In an exemplary embodiment, the image processing device determines, from the water area image data, based on the marking information corresponding to each water area image, a water area image whose marking information indicates a water surface as a candidate water surface image, and then acquires a water surface image based on the candidate water surface image.
[0079] Optionally, the water area image data includes one or more candidate water surface images, which is not limited in this embodiment of the present application.
[0080] In a possible implementation, the water area image data includes a candidate water surface image. Optionally, after acquiring the candidate water surface image, the image processing device directly determines the candidate water surface image as the water surface image.
[0081] In another possible embodiment, the water area image data includes multiple candidate water surface images. Optionally, after acquiring multiple candidate water surface images, the image processing device performs image fusion processing on the multiple candidate water surface images, and determines the fused image as a water surface image. In an exemplary embodiment, the image processing device traverses each candidate water surface image, respectively obtains the pixel value of each pixel point in the candidate water surface image, and then averages the pixel values with the pixel point as the basic unit, and determines the image composed of the average pixel value as the water surface image. Optionally, the water area image corresponds to depth information, and the depth information is used to indicate the distance between the image acquisition device and the water surface when the image is acquired. Based on the depth information corresponding to each candidate water surface image, the image processing device performs image fusion processing on the candidate water surface images with the same depth information to obtain at least one fused water surface image, and then performs image stitching processing on each fused water surface image to obtain a water quality image. Different fused water surface images correspond to different depth information.
[0082] Optionally, the depth information is included in the tag information. Exemplarily, the depth information is the absolute value of the tag information. For example, if the tag information of a water area image is "+0.5 meters," the water area image is a surface image with a depth of 0.5; if the tag information of a water area image is "0," the water area image is a surface image with a depth of 0; and if the tag information of a water area image is "-10 meters," the water area image is an underwater image with a depth of 10.
[0083] 2. Perform contour detection on the water surface image to determine the contour of the water area in the water surface image.
[0084] In an embodiment of the present application, after acquiring the water surface image, the image processing device performs contour detection on the water surface image to determine the contour of the water body region in the water surface image. Optionally, the image processing device converts the water surface image into a grayscale image to reduce computational complexity, then performs Gaussian blur on the water surface image to reduce noise interference, then performs morphological operations on the binary image to remove noise and fill holes, and then uses a contour detection algorithm to find the contour of the water body region in the water surface image.
[0085] It should be noted that the above-mentioned water surface image may include one or more water area contours, which is not limited in this embodiment of the present application.
[0086] 3. Based on the contour of the water body area, the water surface quality image is intercepted from the water surface image.
[0087] In an embodiment of the present application, after determining the water body region outline, the image processing device intercepts the water surface quality image from the water surface image based on the water body region outline. Optionally, the image processing device determines a minimum bounding rectangle based on the water body region outline, and intercepts the water surface quality image from the water surface image based on the minimum bounding rectangle.
[0088] Optionally, if the water surface image includes multiple water area contours, the minimum circumscribed rectangle corresponding to each water area contour is determined respectively, and then the water surface image is intercepted and spliced based on the multiple minimum circumscribed rectangles to obtain a water surface water quality image.
[0089] 4. Obtain a water quality image based on the water surface water quality image.
[0090] In an embodiment of the present application, after acquiring the above-mentioned water surface water quality image, the image processing device acquires a water quality image based on the water surface water quality image.
[0091] In a possible implementation, the water body information includes water surface information. Optionally, after acquiring the water surface water quality image, the image processing device directly determines the water surface water quality image as the water quality image.
[0092] In another possible implementation, the water body information includes water surface information and underwater information. Optionally, the water area image data includes an underwater image, which refers to an image that records underwater information within the water area. Optionally, after acquiring the water area image data, the image processing device acquires an underwater image from the water area image data, further acquires an underwater water quality image based on the underwater image, and splices the underwater water quality image with the surface water quality image to acquire a water quality image.
[0093] In an exemplary embodiment, after acquiring the water area image data, the image processing device obtains at least one underwater image from the water area image data. Optionally, the water area images may be associated with tag information, and the image processing device, based on the tag information associated with each water area image in the water area image data, determines as an underwater image a water area image that has the tag information indicating it is underwater.
[0094] In an exemplary embodiment, the water area image corresponds to depth information, and the depth information is used to indicate the distance between the image acquisition device and the water surface when the image is acquired. After acquiring the at least one underwater image, the image processing device performs image fusion processing on the underwater images with the same depth information based on the depth information corresponding to each underwater image, and obtains at least one underwater water quality image. Exemplarily, for underwater images with the same depth information, when performing image fusion processing, each underwater image is traversed, and the pixel value of each pixel point in the underwater image is obtained respectively, and then the pixel values are averaged with the pixel point as the basic unit, and the image composed of the average pixel value is determined as the underwater water quality image corresponding to the depth information. Of course, in other possible implementations, the image processing device can also ignore the depth information and directly perform image fusion processing on the at least one underwater image by averaging the pixel values.
[0095] In an exemplary embodiment, after acquiring the at least one underwater water quality image, the image processing device performs splicing processing on the surface water quality image and the at least one underwater water quality image to obtain a water quality image. It should be noted that different underwater water quality images correspond to different depth information.
[0096] Optionally, in order to improve the utilization rate of the water surface image, background information can also be obtained through the above water surface image, and the background information is used to indicate the source of sewage in the water area. After obtaining the above water surface image, the image processing device obtains the background information of the water area based on other areas outside the water area outline in the water surface image; further, based on the background information, the channel weight information for the water quality image is obtained, and the channel weight information is used to enhance the feature channels related to the task in the feature extraction process of the window attention mechanism. For example, Figure 4 As shown, after acquiring the water area image data, the image processing device obtains a water surface image and multiple underwater images from the water area image data. For the water surface image, the image processing device obtains the water body contour area from the water surface image through contour detection, obtains the water surface water quality image from the water body contour area, and obtains background information from other areas outside the water body area contour. For the underwater image, the image processing device clusters and fuses the multiple underwater images based on the depth information to obtain underwater water quality images corresponding to different depth information. Afterwards, the image processing device performs image stitching processing on the water surface water quality image and each underwater water quality image to obtain a water quality image, obtains channel weight information for the water quality image based on the background information, and then uses the water quality image as input and the channel weight information as an intermediate adjustment parameter to obtain the water quality detection result through the window attention mechanism.
[0097] To sum up, in the technical solution provided in the embodiments of the present application, a water surface water quality image containing a water body area is obtained from a water surface image through contour detection, a water quality image is obtained based on the water surface water quality image, and other areas in the water surface image except the water body area are removed, thereby reducing the noise information contained in the water quality image, improving the water quality detection efficiency, and improving the accuracy of the water quality detection results obtained based on the water quality image.
[0098] In addition, the water quality image is obtained by splicing the underwater water quality image and the surface water quality image, so that the water quality image contains both surface information and underwater information, which is convenient for obtaining relevant information such as sediment through the underwater information, increases the information contained in the water quality image, and improves the accuracy of the water quality detection results obtained based on the water quality image; moreover, based on the depth information, multiple underwater images are clustered and fused to obtain the underwater water quality image, so that different underwater water quality images correspond to different depth information, and thus the water quality image has water body information at different depths in the water area, further increasing the information contained in the water quality image, and making the water quality detection results obtained based on the water quality image more accurate.
[0099] Please refer to Figure 5 , which shows a flow chart of a water quality detection method based on image recognition provided by another embodiment of the present application. Figure 1 The image processing device in the water quality detection system shown in FIG. The method may include the following steps (501-505):
[0100] Step 501: Acquire a water quality image to be processed.
[0101] The above step 501 and Figure 3 Step 301 in the embodiment is similar, see Figure 3 The embodiments are not described in detail here.
[0102] Step 502: Obtain background information corresponding to the water quality image.
[0103] Background information is used to indicate the source of sewage in a water area. Sewage sources include, but are not limited to, at least one of the following: industrial wastewater, domestic sewage, aquaculture wastewater, etc., which are not limited in this embodiment of the application. Optionally, a water area may include one or more sewage sources.
[0104] In an embodiment of the present application, before water quality testing, an image processing device obtains background information corresponding to the water quality image. Optionally, the background information can be obtained from the water quality image or from a source other than the water quality image, which is not limited in this embodiment of the present application. Optionally, the background information can be obtained from text description information, image information, video information, etc., which is not limited in this embodiment of the present application.
[0105] Step 503: Acquire channel weight information for the water quality image based on the background information.
[0106] In an embodiment of the present application, after obtaining the background information, the image processing device obtains channel weight information for the water quality image based on the background information. The channel weight information is used to enhance the feature channels related to the task during the feature extraction process of the window attention mechanism.
[0107] In one possible embodiment, the channel weight information is obtained from pre-stored information. Optionally, a correspondence between different sewage sources and channel weight information is pre-stored. After obtaining the background information, the image processing device determines the channel weight information from this correspondence based on the sewage source indicated by the background information. The correspondence between the sewage source and the channel weight information can be pre-stored in the image processing device or in another device, and this embodiment of the application is not limited to this.
[0108] In another possible implementation, the channel feature information is obtained through a pre-trained neural network, such as SENet, etc. Optionally, after obtaining the background information, the image processing device inputs the background information into the pre-trained neural network to obtain the channel weight information.
[0109] Optionally, in the process of extracting features from water quality images through the window attention mechanism, the channel weights contained in the channel weight information are multiplied by the feature map channel by channel to achieve enhancement of the feature channel. Wherein, the above-mentioned feature map includes but is not limited to at least one of the following: an initial feature map, a first feature map, a second feature map, a third feature map, a fourth feature map, a final feature map, etc., and the embodiment of the present application does not limit this. It should be noted that when enhancing the feature channel, the degree of enhancement corresponding to different feature channels may be the same or different, and the embodiment of the present application does not limit this. For example, if the background information indicates that the source of sewage in the water area is industrial wastewater, and since industrial wastewater is clear but contains heavy metals, it may appear blue (containing copper) or yellow (containing chromium), then the feature channel related to the task is the color feature channel. Based on the channel weight information, in the process of feature extraction and processing of the water quality image through the window attention mechanism, the color feature channel is enhanced; if the background information indicates that the source of sewage in the water area is domestic sewage, and since domestic sewage is turbid, it may appear grayish yellow, may contain suspended matter such as plastic fragments and paper towels, and may have foam (containing surfactants), then the feature channels related to the task are the transparency feature channel, the color feature channel, the suspended matter feature channel and the bubble feature channel. Based on the channel weight information, in the process of feature extraction and processing of the water quality image through the window attention mechanism, the color feature channel is enhanced. In the process of feature extraction of water quality images through the window attention mechanism, the transparency feature channel, color feature channel, suspended matter feature channel and bubble feature channel are enhanced; if the background information indicates that the source of sewage in the water area is agricultural sewage, since agricultural sewage may appear yellow-green turbid (containing soil particles), or may appear grayish white due to pesticides, and may contain straw and animal feces residues, the feature channels related to the task are the transparency feature channel, color feature channel, suspended matter feature channel and sediment feature channel. Based on the channel weight information, in the process of feature extraction of water quality images through the window attention mechanism, the transparency feature channel, color feature channel, suspended matter feature channel and sediment feature channel are enhanced.
[0110] Optionally, the image processing device can also suppress feature channels irrelevant to the task during feature extraction of the water quality image using the window attention mechanism based on the channel weight information. In this embodiment of the present application, the task is water quality detection.
[0111] Step 504 : Perform feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area to which the water quality image belongs.
[0112] Step 505: Obtain the water quality detection result of the water area based on the water quality feature vector.
[0113] The above steps 504 and 505 are the same as Figure 3 Steps 302 and 303 in the embodiment are similar, see Figure 3The embodiments are not described in detail here.
[0114] To sum up, in the technical solution provided in the embodiment of the present application, channel weight information is obtained through background information, and then the feature channels related to the task are enhanced based on the channel weight information in the feature extraction process of the window attention mechanism. Taking into account the different impacts of different backgrounds on water quality, the feature channels related to the task are enhanced based on the channel weight information, thereby improving the accuracy of the water quality detection results. In actual applications, different background information is obtained to obtain different channel weight information, so that the feature channels can be adaptively adjusted according to actual conditions under different backgrounds, thereby improving the adaptability of water quality detection to different backgrounds.
[0115] Please refer to Figure 6 , which shows a flow chart of a water quality detection method based on image recognition provided by another embodiment of the present application. Figure 1 The image processing device in the water quality detection system shown in FIG. The method may include the following steps (601-605):
[0116] Step 601: Acquire a water quality image to be processed.
[0117] Step 602: Perform feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area to which the water quality image belongs.
[0118] Step 603: Obtain the water quality detection result of the water area based on the water quality feature vector.
[0119] The above steps 601-603 are Figure 3 Steps 301-303 in the embodiment are similar, see Figure 3 The embodiments are not described in detail here.
[0120] Step 604: Obtain historical water quality test results.
[0121] The historical water quality test results refer to the water quality test results for the aforementioned water area prior to the current water quality test. In the embodiment of the present application, the image processing device obtains the historical water quality test results after obtaining the aforementioned water quality test results. Optionally, the historical water quality test results are the water quality test results obtained from the most recent water quality test in terms of time.
[0122] Step 605: Determine the sewage treatment method for the water area based on the water quality test results and historical water quality test results.
[0123] In an embodiment of the present application, after obtaining the above-mentioned historical water quality test results, the image processing device determines the sewage treatment method for the water area based on the water quality test results and the historical water quality test results. Optionally, the image processing device obtains comparison information between the water quality test results and the historical water quality test results, and determines the sewage treatment method for the water area based on the comparison information. The above-mentioned comparison information is used to indicate changes in water pollution in the water area. Optionally, if it is determined based on the comparison information that the water pollution situation has improved, the image processing device determines the historical sewage treatment method as the sewage treatment method for the water area this time.
[0124] In an embodiment of the present application, the water quality test result includes at least one pollution type and the probability corresponding to each pollution type. Optionally, one pollution type corresponds to multiple levels, and different levels are used to indicate different degrees of pollution. Taking the pollution type of metallic copper pollution as an example, there are four pollution levels, ABCD, where the degree of pollution indicated by level A is greater than the degree of pollution indicated by level B, the degree of pollution indicated by level B is greater than the degree of pollution indicated by level C, and the degree of pollution indicated by level C is greater than the degree of pollution indicated by level D.
[0125] Optionally, the above-mentioned comparison information includes a comparison relationship between different level probabilities of each pollution type. The level probability of a pollution type is used to indicate the possibility of the existence of a pollution type of this level in the water area. In an exemplary embodiment, after obtaining the above-mentioned water quality test results and the above-mentioned historical water quality test results, the image processing device determines the treatment method for the first pollution type in the historical sewage treatment method as the treatment method for the first pollution type in the sewage treatment method when the first level probability of the first pollution type in the water quality test results is less than the first level probability of the first pollution type in the historical water quality test results, and the second level probability of the first pollution type in the water quality test results is greater than the second level probability of the first pollution type in the historical water quality test results. The pollution degree of the first pollution type indicated by the first level is greater than the pollution degree of the first pollution type indicated by the second level, and the first pollution type can be any pollution type contained in the water quality test results.
[0126] Optionally, the sewage treatment method includes a treatment method for at least one pollution type. In an exemplary embodiment, after obtaining the water quality test results and the historical water quality test results, the image processing device determines a treatment method for a different pollution type based on comparison information between the two, similar to the first pollution type.
[0127] Optionally, if it is determined based on the comparison information that the water pollution situation has not improved, a new sewage treatment method is determined based on the historical sewage treatment method, and the new sewage treatment method is determined as the sewage treatment method for the water area this time. The sewage treatment capacity of the new sewage treatment method is greater than the sewage treatment capacity of the historical sewage treatment method.
[0128] Optionally, the new sewage treatment method can be obtained manually or through a pre-stored sewage treatment plan, which is not limited in the embodiment of the present application.
[0129] To sum up, in the technical solution provided in the embodiment of the present application, the sewage treatment method for the water area is obtained by combining the water quality test results with historical water quality test results. That is, the present application provides an automated sewage treatment solution that can effectively save human resources.
[0130] In addition, by comparing the probability of water quality test results with historical water quality test results, we can accurately grasp the changes in water pollution. When the pollution level is reduced, we can determine that the historical sewage treatment method is effective, and continue to use the historical sewage treatment method to treat sewage in the water area. In the process of automated sewage treatment, by accurately grasping the changes in water pollution, we can choose a reasonable sewage treatment method to treat sewage, which saves human resources and improves the sewage treatment effect.
[0131] Optionally, in an embodiment of the present application, when obtaining a water quality test result based on a water quality image, the image processing device uses the water quality image as input, invokes a water quality test model, and determines the output of the water quality test model as the water quality test result. The water quality test model is a pre-trained neural network model that performs feature extraction processing using a window attention mechanism.
[0132] In an exemplary embodiment, the training process of the water quality detection model is as follows:
[0133] 1. Obtain a training sample set, which includes at least two sample images, and each sample image corresponds to one label;
[0134] 2. Train the water quality detection model based on the training sample set to obtain the output results corresponding to each sample image; the water quality detection model includes a window attention mechanism;
[0135] 3. Determine the loss of the water quality detection model based on the output results corresponding to each sample image and the labels corresponding to each sample image; optionally, the model training device determines the loss of the water quality detection model using a cross entropy loss function;
[0136] 4. When the loss function of the water quality inspection model determined based on the loss converges, the training of the water quality detection model is determined to be completed; wherein, the trained water quality detection model is used to obtain the water quality detection results of the water area based on the water quality image.
[0137] In an exemplary embodiment, the water quality detection model is trained based on the training sample data set to obtain output results corresponding to each sample image, including the following steps:
[0138] Dividing the sample image into blocks to obtain at least two sample image blocks; wherein there is no overlapping area between the sample image blocks;
[0139] Perform linear projection on each sample image block to obtain the initial sample feature map corresponding to each sample image block;
[0140] Adding a sample position code to each initial sample feature map, where the sample position code is used to indicate the position of the sample image block in the sample image;
[0141] The initial sample feature maps after encoding the added sample positions are respectively subjected to feature extraction processing through the window attention mechanism to obtain the final sample feature maps corresponding to each sample image block;
[0142] Perform feature fusion on the final sample feature maps corresponding to each sample image block;
[0143] Perform nonlinear transformation on the result of feature fusion to obtain the sample feature vector;
[0144] Based on the sample feature vector, the output result of the water quality detection model for the sample image is obtained.
[0145] In an exemplary embodiment, the above-mentioned step of performing feature extraction processing on each initial sample feature map after adding sample position encoding through the window attention mechanism to obtain the final sample feature map corresponding to each sample image block includes the following steps:
[0146] For the target sample image block in the at least two sample image blocks, performing window division on the target initial sample feature map after adding the sample position encoding;
[0147] Based on the window division result, the target initial sample feature map after adding sample position encoding is extracted through a multi-head attention mechanism with the window as the basic unit to obtain the first intermediate sample feature map corresponding to the target sample image block;
[0148] Performing a window offset operation on the first intermediate sample feature map, where the offset distance of the window offset operation is less than the shortest edge length of the window;
[0149] Based on the window offset result, the first intermediate sample feature map is subjected to feature extraction processing through a multi-head attention mechanism with the offset window as the basic unit to obtain the first sample feature map corresponding to the target sample image block;
[0150] A target final sample feature map is obtained based on the first sample feature map.
[0151] In an exemplary embodiment, the step of obtaining the target final sample feature map based on the first sample feature map includes the following steps:
[0152] Performing patch merging on the first sample feature map to obtain a first merged sample feature map;
[0153] Through window division, window offset and multi-head attention mechanism, feature extraction processing is performed on the first merged sample feature map to obtain the second sample feature map;
[0154] Performing patch merging processing on the second sample feature map to obtain a second merged sample feature map;
[0155] Through window division, window offset and multi-head attention mechanism, feature extraction is performed on the second merged sample feature map to obtain a third sample feature map;
[0156] Performing patch merging processing on the third sample feature map to obtain a third merged sample feature map;
[0157] Perform feature extraction on the third merged sample feature map through window division, window offset and multi-head attention mechanism to obtain a fourth sample feature map;
[0158] A target final sample feature map is obtained based on the fourth sample feature map.
[0159] In an exemplary embodiment, the training process of the water quality detection model further includes the following steps:
[0160] Acquire background information corresponding to the sample image; optionally, the background information is acquired by the model training device based on other areas outside the water area outline in the sample image;
[0161] Based on the background information, channel weight information for the sample image is obtained; wherein the channel weight information is used to enhance the feature channels related to the task during the feature extraction process of the window attention mechanism.
[0162] The following are device embodiments of the present application, which can be used to implement the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.
[0163] Please refer to Figure 7, which shows a block diagram of an image recognition-based water quality detection device provided by one embodiment of the present application. This device has the function of implementing the aforementioned image recognition-based water quality detection method. This function can be implemented by hardware or by hardware executing corresponding software. This device can be the aforementioned image processing device or can be incorporated into an image processing device. This device 700 may include: an image acquisition module 710, a feature extraction module 720, and a result acquisition module 730.
[0164] The image acquisition module 710 is used to acquire the water quality image to be processed.
[0165] The feature extraction module 720 is used to perform feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area to which the water quality image belongs.
[0166] The result acquisition module 730 is used to acquire the water quality detection result of the water area based on the water quality feature vector, and the water quality detection result is used to indicate the water pollution type of the water area.
[0167] In an exemplary embodiment, as Figure 8 As shown, the feature extraction module 720 includes: an image blocking unit 721, a linear projection unit 722, a code adding unit 723, a final acquisition unit 724, a feature fusion unit 725 and a vector acquisition unit 726.
[0168] An image segmentation unit 721 is configured to segment the water quality image into at least two image blocks, wherein no overlapping areas exist between the image blocks;
[0169] A linear projection unit 722 is configured to perform linear projection on each of the image blocks to obtain an initial feature map corresponding to each of the image blocks;
[0170] a code adding unit 723, configured to add a position code to each of the initial feature maps, wherein the position code is used to indicate the position of the image block in the water quality image;
[0171] A final acquisition unit 724 is configured to perform feature extraction processing on each of the initial feature maps after adding position encoding using the window attention mechanism to obtain a final feature map corresponding to each of the image blocks;
[0172] A feature fusion unit 725 is configured to perform feature fusion on the final feature maps corresponding to each of the image blocks;
[0173] The vector acquisition unit 726 is used to perform nonlinear transformation on the result of feature fusion to obtain the water quality feature vector.
[0174] In an exemplary embodiment, the final obtaining unit 724 is configured to:
[0175] For a target image block in the at least two image blocks, performing window division on the target initial feature map after adding the position encoding;
[0176] Based on the window division result, a multi-head attention mechanism is used to perform feature extraction processing on the target initial feature map after adding position encoding, with the window as the basic unit, to obtain a first intermediate feature map corresponding to the target image block;
[0177] performing a window offset operation on the first intermediate feature map, where an offset distance of the window offset operation is less than a shortest edge length of the window;
[0178] Based on the window offset result, performing feature extraction processing on the first intermediate feature map through the multi-head attention mechanism with the offset window as a basic unit to obtain a first feature map corresponding to the target image block;
[0179] A target final feature map is obtained based on the first feature map.
[0180] In an exemplary embodiment, the final obtaining unit 724 is configured to:
[0181] Performing patch merging on the first feature map to obtain a first merged feature map;
[0182] Performing feature extraction processing on the first merged feature map through window division, window offset and the multi-head attention mechanism to obtain a second feature map;
[0183] Performing patch merging processing on the second feature map to obtain a second merged feature map;
[0184] Performing feature extraction processing on the second merged feature map through window division, window offset and the multi-head attention mechanism to obtain a third feature map;
[0185] Performing patch merging processing on the third feature map to obtain a third merged feature map;
[0186] Performing feature extraction processing on the third merged feature map through window division, window offset and the multi-head attention mechanism to obtain a fourth feature map;
[0187] The target final feature map is obtained based on the fourth feature map.
[0188] In an exemplary embodiment, as Figure 8 As shown, the image acquisition module 710 includes: a water surface acquisition unit 711, a contour detection unit 712, an image interception unit 713 and an image acquisition unit 714.
[0189] The water surface acquisition unit 711 is configured to acquire a water surface image from the water area image data of the water area.
[0190] The contour detection unit 712 is configured to perform contour detection processing on the water surface image to determine the contour of the water body area in the water surface image.
[0191] The image capture unit 713 is configured to capture a water surface quality image from the water surface image based on the water body area contour.
[0192] The image acquisition unit 714 is configured to acquire the water quality image based on the water surface water quality image.
[0193] In an exemplary embodiment, the image acquisition unit 714 is used to
[0194] Acquire at least one underwater image from the water area image data;
[0195] Based on the depth information corresponding to each of the underwater images, underwater images with the same depth information are subjected to image fusion processing to obtain at least one underwater water quality image; wherein the depth information is used to indicate the distance between the image acquisition device and the water surface when the image was acquired;
[0196] The water surface water quality image and the at least one underwater water quality image are spliced to obtain the water quality image.
[0197] In an exemplary embodiment, as Figure 8 As shown, the device 700 further includes: a background acquisition module 740 and a weight acquisition module 750 .
[0198] The background acquisition module 740 is used to acquire background information corresponding to the water quality image, where the background information is used to indicate the source of sewage in the water area.
[0199] The weight acquisition module 750 is used to obtain channel weight information for the water quality image based on the background information; wherein the channel weight information is used to enhance the task-related feature channels in the feature extraction process of the window attention mechanism.
[0200] In an exemplary embodiment, as Figure 8 As shown, the device 700 further includes: a sewage treatment module 760.
[0201] The sewage treatment module 760 is used to obtain historical water quality test results; based on the water quality test results and the historical water quality test results, determine the sewage treatment method for the water area.
[0202] In an exemplary embodiment, the sewage treatment module 760 is used to:
[0203] When the first level probability of the first pollution type in the water quality test result is less than the first level probability of the first pollution type in the historical water quality test result, and the second level probability of the first pollution type in the water quality test result is greater than the second level probability of the first pollution type in the historical water quality test result, the treatment method for the first pollution type in the historical sewage treatment method is determined as the treatment method for the first pollution type in the sewage treatment method;
[0204] The pollution degree of the first pollution type indicated by the first level is greater than the pollution degree of the first pollution type indicated by the second level; and the sewage treatment method includes a treatment method for at least one pollution type.
[0205] To sum up, in the technical solution provided in the embodiment of the present application, feature extraction and processing of water quality images are performed through the window attention mechanism to obtain water quality feature vectors, and then the water pollution type of the water area is determined based on the water quality feature vectors, thereby reducing the dependence of water quality detection on manual experience, reducing the impact of human factors on water quality detection results, and improving the objectivity of water quality detection results; moreover, by combining the window attention mechanism to detect water quality images, there is no need for manual statistics and analysis of relevant information on water quality, which simplifies the water quality detection process, improves water quality detection efficiency, and saves time.
[0206] In an exemplary embodiment, a computer device is also provided, which includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the above-mentioned water quality detection method based on image recognition.
[0207] In an exemplary embodiment, a non-transitory computer-readable storage medium is further provided, on which a computer program is stored. When the computer program is executed by a processor, the above-mentioned water quality detection method based on image recognition is implemented.
[0208] In an exemplary embodiment, a computer program product is also provided. When the computer program product is run, a computer device executes the above-mentioned water quality detection method based on image recognition.
[0209] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with this technology to understand the content of the present invention and implement it accordingly, and they are not intended to limit the scope of protection of the present invention. For those skilled in the art, it is obvious that the present invention is not limited to the details of the above exemplary embodiments, and that the present invention can be implemented in other specific forms without departing from the spirit or basic characteristics of the present invention. Therefore, no matter from which point of view, the embodiments should be regarded as exemplary and non-restrictive. The scope of the present invention is defined by the appended claims rather than the above description, and it is intended that all changes that fall within the meaning and scope of the equivalent elements of the claims are included in the invention.
[0210] It should be understood that the "multiple" mentioned in this article refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship. In addition, the step numbers described in this article only illustrate a possible execution sequence between the steps. In some other embodiments, the above steps may not be executed in the order of the numbers, such as two steps with different numbers are executed at the same time, or two steps with different numbers are executed in the opposite order to the diagram. The embodiments of the present application do not limit this.
[0211] The above description is merely an exemplary embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.
Claims
1. A water quality detection method based on image recognition, characterized in that: The method comprises: obtaining a water surface image from water area image data of the water area; Performing contour detection processing on the water surface image to determine the contour of the water body area in the water surface image; Based on the water body area contour, intercepting a water surface water quality image from the water surface image; Acquire at least one underwater image from the water area image data; Based on the depth information corresponding to each of the underwater images, underwater images with the same depth information are subjected to image fusion processing to obtain at least one underwater water quality image; wherein the depth information is used to indicate the distance between the image acquisition device and the water surface when the image was acquired; performing splicing processing on the water surface water quality image and the at least one underwater water quality image to obtain a water quality image; Acquire background information corresponding to the water quality image, where the background information is used to indicate a source of sewage in the water area to which the water quality image belongs, wherein the source of sewage includes industrial wastewater, domestic sewage, and aquaculture sewage; Based on the background information, obtaining channel weight information for the water quality image from a correspondence relationship, wherein the correspondence relationship refers to a pre-stored correspondence relationship between different sewage sources and channel weight information; Performing feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area; wherein the channel weight information is used to enhance the feature channels related to the task during the feature extraction process of the window attention mechanism; Based on the water quality feature vector, obtaining a water quality detection result of the water area, wherein the water quality detection result is used to indicate the type of water pollution in the water area; Obtain historical water quality test results; Based on the water quality test results and the historical water quality test results, a sewage treatment method for the water area is determined.
2. The method according to claim 1, characterized in that The feature extraction process of the water quality image is performed through the window attention mechanism to obtain the water quality feature vector of the water area, including: Dividing the water quality image into blocks to obtain at least two image blocks; wherein no overlapping areas exist between the image blocks; Performing linear projection on each of the image blocks to obtain initial feature maps corresponding to each of the image blocks; adding a position code to each of the initial feature maps, wherein the position code is used to indicate the position of the image block in the water quality image; Performing feature extraction processing on each of the initial feature maps after adding position encoding through the window attention mechanism to obtain a final feature map corresponding to each of the image blocks; Performing feature fusion on the final feature maps corresponding to each of the image blocks; The result after feature fusion is subjected to nonlinear transformation to obtain the water quality feature vector.
3. The method according to claim 2, characterized in that The process of performing feature extraction on each of the initial feature maps after adding position encoding by the window attention mechanism to obtain a final feature map corresponding to each of the image blocks includes: For a target image block in the at least two image blocks, performing window division on the target initial feature map after adding the position encoding; Based on the window division result, a multi-head attention mechanism is used to perform feature extraction processing on the target initial feature map after adding position encoding, with the window as the basic unit, to obtain a first intermediate feature map corresponding to the target image block; performing a window offset operation on the first intermediate feature map, where an offset distance of the window offset operation is less than a shortest edge length of the window; Based on the window offset result, performing feature extraction processing on the first intermediate feature map through the multi-head attention mechanism with the offset window as a basic unit to obtain a first feature map corresponding to the target image block; A target final feature map is obtained based on the first feature map.
4. The method according to claim 3, characterized in that The obtaining of a target final feature map based on the first feature map includes: Performing patch merging on the first feature map to obtain a first merged feature map; Performing feature extraction processing on the first merged feature map through window division, window offset and the multi-head attention mechanism to obtain a second feature map; Performing patch merging processing on the second feature map to obtain a second merged feature map; Performing feature extraction processing on the second merged feature map through window division, window offset and the multi-head attention mechanism to obtain a third feature map; Performing patch merging processing on the third feature map to obtain a third merged feature map; Performing feature extraction processing on the third merged feature map through window division, window offset and the multi-head attention mechanism to obtain a fourth feature map; The target final feature map is obtained based on the fourth feature map.
5. The method according to any one of claims 1 to 4, characterized in that The water quality test result includes at least one pollution type and the probability corresponding to each pollution type; The determining of a sewage treatment method for the water area based on the water quality test result and the historical water quality test result includes: When the first level probability of the first pollution type in the water quality test result is less than the first level probability of the first pollution type in the historical water quality test result, and the second level probability of the first pollution type in the water quality test result is greater than the second level probability of the first pollution type in the historical water quality test result, the treatment method for the first pollution type in the historical sewage treatment method is determined as the treatment method for the first pollution type in the sewage treatment method; The pollution degree of the first pollution type indicated by the first level is greater than the pollution degree of the first pollution type indicated by the second level; and the sewage treatment method includes a treatment method for at least one pollution type.
6. A water quality detection device based on image recognition, characterized in that: The device comprises: An image acquisition module is configured to acquire a water surface image from water area image data of a water area; perform contour detection processing on the water surface image to determine the contour of a water body region in the water surface image; based on the contour of the water body region, intercept a water surface water quality image from the water surface image; acquire at least one underwater image from the water area image data; based on the depth information corresponding to each of the underwater images, perform image fusion processing on underwater images having the same depth information to obtain at least one underwater water quality image; wherein the depth information is used to indicate the distance between the image acquisition device and the water surface when the image was acquired; and perform splicing processing on the water surface water quality image and the at least one underwater water quality image to obtain a water quality image; A background acquisition module is used to obtain background information corresponding to the water quality image, where the background information is used to indicate the source of sewage in the water area to which the water quality image belongs, and the source of sewage includes industrial wastewater, domestic sewage, and aquaculture sewage; A weight acquisition module, configured to acquire channel weight information for the water quality image from a correspondence relationship based on the background information, wherein the correspondence relationship refers to a pre-stored correspondence relationship between different sewage sources and channel weight information; a feature extraction module, configured to perform feature extraction processing on the water quality image through a window attention mechanism to obtain a water quality feature vector of the water area; wherein the channel weight information is used to enhance task-related feature channels during the feature extraction process of the window attention mechanism; A result acquisition module, configured to acquire a water quality test result of the water area based on the water quality feature vector, wherein the water quality test result is used to indicate a type of water pollution in the water area; Sewage treatment module, used to obtain historical water quality test results; The sewage treatment module is further used to determine the sewage treatment method for the water area based on the water quality test results and the historical water quality test results.
7. A computer device, characterized in that: The computer device includes a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the method according to any one of claims 1 to 5.
8. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.
Citation Information
Patent Citations
Underwater image splicing method and device and storage medium
CN113160059A
Water body remote sensing image expansion and eutrophication prediction method based on atmosphere-water quality multi-modal information
CN118735752A