Water quality detection method, device and equipment based on image recognition and storage medium
Through the water quality detection method based on image recognition, the window attention mechanism is used to extract the water quality images, which solves the problem that water quality detection results in the prior art are susceptible to artificial subjective influence, and achieves more objective and efficient water quality detection.
Patent Information
- Application Number
- CN202510480313.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-17
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2045-04-17
AI Technical Summary
Existing water quality testing technologies rely on artificial experience and are susceptible to subjective factors, resulting in insufficient objectivity of the test results.
The water quality detection method based on image recognition is adopted, and the water quality image is featured through the window attention mechanism, and the water quality characteristic vector is obtained, thereby determining the type of water quality pollution in the water area.
It reduces the dependence of water quality testing on artificial experience, reduces the impact of human factors on the test results, improves the objectivity of water quality testing results, simplifies the testing process and improves efficiency.
Smart Images

Figure CN119992241A_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 of water quality is crucial to ensuring water environment safety and human health.
[0003] In the relevant technology, water quality testing personnel operate professional instruments and equipment to obtain relevant information about water quality, and then use the relevant information as a benchmark, combined with manual experience and professional knowledge, to conduct data statistics, data analysis, etc., 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 embodiment of the present application provides a water quality detection method, device, equipment and storage medium based on image recognition, which can improve the objectivity of water quality detection results. The technical solution is as follows: On the one hand, an embodiment of the present application provides a water quality detection method, the method comprising: Acquire a water quality image to be processed; 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; Based on the water quality feature vector, a water quality detection result of the water area is obtained, and the water quality detection result is used to indicate the type of water pollution in the water area.
[0006] On the other hand, an embodiment of the present application provides a water quality detection device based on image recognition, the device comprising: An image acquisition module, used for acquiring water quality images to be processed; A feature extraction module, used for 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; The result acquisition module 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.
[0007] On the other hand, an embodiment of the present application provides a computer device, which includes a processor and a memory, wherein the memory stores a computer program, and the computer program is loaded and executed by the processor to implement the above-mentioned water quality detection method based on image recognition.
[0008] On the other hand, an embodiment of the present application provides a non-temporary computer-readable storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the above-mentioned water quality detection method based on image recognition is implemented.
[0009] 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.
[0010] The technical solution provided in the embodiments of the present application can bring the following beneficial effects: 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 quality 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 the relevant information of water quality, which simplifies the water quality detection process, improves the efficiency of water quality detection, and saves time. BRIEF DESCRIPTION OF THE DRAWINGS
[0011] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. 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 creative work.
[0012] Figure 1 is a schematic diagram of a water quality detection system provided by an embodiment of the present application; Figure 2 A schematic diagram of a water quality detection model is exemplarily shown; Figure 3 is a flow chart of a water quality detection method based on image recognition provided by an embodiment of the present application; Figure 4 A schematic diagram showing a process of water quality detection based on image recognition is exemplified; Figure 5 is a flow chart of a water quality detection method based on image recognition provided by another embodiment of the present application; Figure 6is a flow chart of a water quality detection method based on image recognition provided by another embodiment of the present application; Figure 7 is a block diagram of a water quality detection device based on image recognition provided by an embodiment of the present application; Figure 8 It is a block diagram of a water quality detection device based on image recognition provided by another embodiment of the present application. DETAILED DESCRIPTION
[0013] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.
[0014] 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.
[0015] The image acquisition device 10 is used to acquire water quality images. Exemplarily, the image acquisition device 10 can be any device with an image acquisition function, such as a camera, a video camera, a scanner, a wearable device, or a mobile terminal equipped with a camera, etc., which is not limited in the embodiment of the present application. In the embodiment of the present application, before image detection, the image acquisition device 10 acquires water quality images from around the water area. Optionally, there can be one or more image acquisition devices 10 around the water area.
[0016] 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 function, such as a mobile phone, a tablet computer, a wearable device, a background server or a PC (Personal Computer), etc., and the embodiment of the present application does not limit this. In the 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 obtains the water quality detection result of the corresponding water area based on the water quality image to determine the type of pollution existing in the water area, so as to facilitate the subsequent sewage treatment of the water area according to the pollution type.
[0017] 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 above water quality image, the image processing device adjusts the size of the water quality image to 224×224 (resolution); then, the water quality detection model divides the water quality image into non-overlapping 4×4 image blocks through PatchPartition, performs linear projection through the first fully connected layer to obtain the initial feature map corresponding to each image block, adds position coding through PatchEmbedding, and performs feature extraction processing on the initial feature map after adding position coding through four Swin Transformer blocks to obtain the final feature map corresponding to each image block, and performs feature fusion and nonlinear transformation on the final feature map corresponding to each image block through the second fully connected layer to obtain the water quality feature vector of the water quality image, and converts the water quality feature vector into the probability distribution of the pollution type through the Softmax activation function, and the sum of the probability distribution 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 the embodiment of the present application.
[0018] Alternatively, if Figure 2 As shown, 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).
[0019] 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 maps corresponding to each image block are divided into 7×7 windows. The initial feature maps after adding position encoding are subjected to feature extraction processing in units of windows by W-MSA to obtain the first intermediate feature maps 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 maps are subjected to feature extraction processing in units of the offset windows by SW-MSA to obtain the first feature maps corresponding to each image block.
[0020] 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 maps corresponding to each image block. After that, the window is offset by half the window size so that adjacent windows overlap partially 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 maps corresponding to each image block.
[0021] For the third Swin Transformer block, the second feature map is transformed into the 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 maps corresponding to each image block. After that, the window is offset by half the window size so that adjacent windows overlap partially 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 maps corresponding to each image block.
[0022] For the fourth Swin Transformer block, the third feature map is transformed into the third merged feature map through PatchMerging. The resolution of the third merged feature map is 7×7 and the number of channels is 768. The third merged feature map corresponding to each image block is divided into 7×7 windows. The third merged feature map is extracted by W-MSA in units of windows to obtain the fourth intermediate feature map corresponding to each image block. After that, the window is offset by half the window size so that there is partial overlap between adjacent windows and they can communicate with each other. The fourth intermediate feature map is extracted by SW-MSA in units of the offset window 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.
[0023] Optionally, the water quality detection system further includes: a model training device 30, which is used to train the water quality detection model. Exemplarily, the model training device 30 can be any device with a model training function, such as a tablet computer, a backend server or a PC (Personal Computer), etc., which is not limited in the embodiment of the present application. Optionally, the model training device 30 and the image processing device 20 can be the same device or different devices. In the embodiment of the present application, the image acquisition device 10 acquires water quality images of different environments, different seasons, different pollution types, etc., and the model training device 30 classifies the water quality image labels and divides the acquired water quality images into a training sample set and a test sample set. Afterwards, the model training device 30 uses the training sample set to train the water quality detection model. After the training is completed, the water quality detection model is tested by sampling the test sample set to determine the accuracy of the detection results of the water quality detection model to prevent the model from overfitting. Optionally, the model training device 30 divides 80% of the water quality images into training samples and 20% of the water quality images into test samples.
[0024] Optionally, the image acquisition device 10, the image processing device 20 and the model training device 30 are connected via a network.
[0025] 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. The method is applied to Figure 1 The image processing device in the water quality detection system shown in the figure. The method may include the following steps (301-303): Step 301, obtaining a water quality image to be processed.
[0026] A water quality image refers to an image that records water information in 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 detection on the water area. Optionally, the image processing device acquires water area image data from the water area through an image acquisition device, and then acquires a water quality image to be processed based on the water area image data.
[0027] Optionally, the water area image data includes one or more water area images.
[0028] 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.
[0029] In another possible implementation, the water area image data includes a plurality of 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, respectively obtains the pixel value of each pixel point in the water area 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 quality image to be processed. The pixel value is used to indicate the color information of the pixel point in the image.
[0030] 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.
[0031] Step 302, 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.
[0032] 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. Among them, 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 the embodiment of the present application.
[0033] In a possible implementation, the water quality image only contains water body information and does not contain any other information except the water body information. After acquiring the water quality image, the image processing device directly performs feature extraction processing on the water quality image through a window attention mechanism to obtain the water quality feature vector.
[0034] In another possible implementation, the water quality image includes other information in addition to the water body information. After acquiring the water quality image, the image processing device acquires the 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 the minimum bounding rectangle based on the water body region contour, acquires a water body region image from the water quality image based on the minimum bounding rectangle, determines the water body region image as the region of interest, and performs feature extraction processing on the water body region image through a window attention mechanism to obtain the water quality feature vector.
[0035] Step 303: Obtain the water quality detection result of the water area based on the water quality feature vector.
[0036] The water quality detection result is used to indicate the type of water pollution in the water area. In the embodiment of the present application, after obtaining the above-mentioned water quality feature vector, the image processing device obtains the water quality detection result of the water area based on the water quality feature vector. Optionally, the image processing device processes the water quality feature vector through a Softmax activation function to obtain the water quality detection result of the water area.
[0037] 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.
[0038] To sum up, in the technical solution provided in the embodiment of the present application, feature extraction processing is performed on water quality images 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 water quality related information, which simplifies the water quality detection process, improves water quality detection efficiency, and saves time.
[0039] The following is a detailed introduction to the method of obtaining water quality feature vectors.
[0040] In an exemplary embodiment, the above step 302 includes the following steps: 1. Divide the water quality image into blocks to obtain at least two image blocks.
[0041] In an embodiment of the present application, after acquiring the water quality image, the image processing device performs image block processing on the water quality image to obtain at least two image blocks. There is no overlapping area between the image blocks. Exemplarily, the image processing device divides the water quality image into non-overlapping 4×4 image blocks through PatchPartition.
[0042] 2. Perform linear projection on each image block to obtain the initial feature map corresponding to each image block.
[0043] In an embodiment of the present application, after acquiring the at least two image blocks, the image processing device linearly projects each image block to obtain an initial feature map corresponding to each image block. Exemplarily, the image processing device linearly projects each image block through a first fully connected layer to obtain an initial feature map corresponding to each image block.
[0044] 3. Add position encoding to each initial feature map.
[0045] 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 position codes to each initial feature map after performing linear projection. Exemplarily, the image processing device adds position codes to the initial feature maps corresponding to each image block through PatchEmbedding.
[0046] 4. The initial feature maps after each added position encoding are respectively subjected to feature extraction through the window attention mechanism to obtain the final feature maps corresponding to each image block.
[0047] In an embodiment of the present application, after adding the position coding, the image processing device performs feature extraction processing on each initial feature map after adding the position coding through the window attention mechanism to obtain the 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 coding through the Swin Transformer block to obtain the final feature map corresponding to each image block.
[0048] Taking the target image block in the at least two image blocks as an example, in an exemplary embodiment, the image processing device performs window division on the target initial feature map after adding the position coding; based on the window division result, the target initial feature map after adding the position coding is subjected to feature extraction processing through a multi-head attention mechanism with the window as the basic unit, and obtains the first intermediate feature map corresponding to the target image block; performs a window offset operation 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 there is partial overlap between adjacent windows for mutual communication; 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, and obtains the first feature map corresponding to the target image block; obtains the target final feature map based on the first feature map. Wherein, the target image block is any one of the at least two image blocks.
[0049] Exemplarily, the image processing device includes 4 Swin Transformer blocks. Taking the target image block as an example, in an exemplary embodiment, after acquiring 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 processing 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 processing 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 map through PatchMerging.
[0050] 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].
[0051] 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.
[0052] 5. Perform feature fusion on the final feature maps corresponding to each image block.
[0053] In an embodiment of the present application, after acquiring the above-mentioned final feature map, the image processing device performs feature fusion on the final feature maps corresponding to each image block.
[0054] 6. Perform nonlinear transformation on the result of feature fusion to obtain the water quality feature vector.
[0055] In an embodiment of the present application, after performing feature fusion, the image processing device performs a nonlinear transformation on the result of feature fusion to obtain a water quality feature vector. Exemplarily, 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.
[0056] 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 influence 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 more comprehensively captured, thereby improving the accuracy of water quality detection.
[0057] In addition, feature extraction is performed on water quality images with windows as the basic unit. Each window is calculated independently, which makes it easy to distribute tasks on parallel devices, which is beneficial to improving the efficiency of water quality detection. Window offset can capture the correlation between adjacent elements in water quality images, improve the accuracy of feature capture, and thus improve the accuracy of water quality detection. Moreover, feature extraction of feature maps layer by layer is performed through patch merging, which can obtain feature information under different fields of view and improve the accuracy of water quality detection.
[0058] Next, the method of acquiring water quality images is introduced.
[0059] In an exemplary embodiment, the above step 301 includes the following steps: 1. Obtain a water surface image from water area image data of the water area.
[0060] 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.
[0061] 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.
[0062] 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.
[0063] In another possible implementation, the water area image data includes a plurality of candidate water surface images. Optionally, after acquiring a plurality of candidate water surface images, the image processing device performs image fusion processing on the plurality of 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 acquires the pixel value of each pixel point in the candidate water surface image, and then averages the pixel value 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. The image processing device performs image fusion processing on the candidate water surface images with the same depth information based on the depth information corresponding to each candidate water surface image, obtains 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.
[0064] Optionally, the depth information is included in the marking information. Exemplarily, the depth information is the absolute value of the marking information. For example, if the marking information of the water area image is "+0.5 meters", the water area image is a water surface image with a depth information of 0.5; if the marking information of the water area image is "0", the water area image is a water surface image with a depth information of 0; if the marking information of the water area image is "-10 meters", the water area image is an underwater image with a depth information of 10.
[0065] 2. Perform contour detection on the water surface image to determine the contour of the water area in the water surface image.
[0066] In the embodiment of the present application, after acquiring the above-mentioned water surface image, the image processing device performs contour detection processing on the water surface image to determine the contour of the water body area in the water surface image. Optionally, the image processing device converts the water surface image into a grayscale image to reduce the computational complexity, and then performs Gaussian blur on the water surface image to reduce noise interference, and 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 area in the water surface image.
[0067] One thing that needs to be explained is 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.
[0068] 3. Based on the contour of the water body area, the water surface water quality image is intercepted from the water surface image.
[0069] In an embodiment of the present application, after determining the above-mentioned water body area outline, the image processing device intercepts the water surface water quality image from the water surface image based on the water body area outline. Optionally, the image processing device determines the minimum bounding rectangle based on the water body area outline, and intercepts the water surface water quality image from the water surface image based on the minimum bounding rectangle.
[0070] 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.
[0071] 4. Obtain a water quality image based on the water surface water quality image.
[0072] In the 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.
[0073] 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.
[0074] 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 in 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, and then 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.
[0075] In an exemplary embodiment, after acquiring the water area image data, the image processing device acquires at least one underwater image from the water area image data. Optionally, the water area image corresponds to tag information, and the image processing device determines the water area image whose tag information indicates that it is underwater as an underwater image based on the tag information corresponding to each water area image in the water area image data.
[0076] 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, so as to obtain 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 may also ignore the depth information and directly perform image fusion processing on the at least one underwater image by averaging the pixel values.
[0077] 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.
[0078] Optionally, in order to improve the utilization rate of the water surface image, background information can also be obtained through the water surface image, and the background information is used to indicate the source of sewage in the water area. After obtaining the 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 acquires a water surface image and multiple underwater images from the water area image data. For the water surface image, the image processing device acquires the water body contour area from the water surface image through contour detection, acquires the water surface water quality image from the water body contour area, and acquires background information from other areas outside the water body area contour. For the underwater image, the image processing device clusters and fuses multiple underwater images through 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, acquires channel weight information for the water quality image based on the background information, and then, takes the water quality image as input, takes the channel weight information as the intermediate adjustment parameter, and obtains the water quality detection result through the window attention mechanism.
[0079] To summarize, in the technical solution provided in the embodiments of the present application, a water surface water quality image including 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 except the water body area in the water surface image 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.
[0080] 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 then the water quality image has water body information at different depths in the water area, further increases the information contained in the water quality image, and makes the water quality detection results obtained based on the water quality image more accurate.
[0081] 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. The method is applied to Figure 1 The image processing device in the water quality detection system shown in FIG. The method may include the following steps (501-505): Step 501, obtaining a water quality image to be processed.
[0082] 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.
[0083] Step 502: Obtain background information corresponding to the water quality image.
[0084] The background information is used to indicate the source of sewage in the water area. The sewage source includes but is not limited to at least one of the following: industrial wastewater, domestic sewage, aquaculture sewage, etc., which is not limited in the present embodiment. Optionally, a water area may include one or more sewage sources.
[0085] In an embodiment of the present application, before water quality detection, the image processing device obtains the background information corresponding to the above-mentioned water quality image. Optionally, the background information can be obtained from the water quality image, or from outside the water quality image, which is not limited in the embodiment of the present application. Optionally, the background information can be obtained from text description information, or from image information, or from video information, etc., which is not limited in the embodiment of the present application.
[0086] Step 503: Acquire channel weight information for the water quality image based on the background information.
[0087] In an embodiment of the present application, after acquiring the above background information, the image processing device acquires channel weight information for the above water quality image based on the background information, wherein 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.
[0088] In a possible implementation, 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 acquiring the background information, the image processing device determines the channel weight information from the 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 other devices, and the embodiment of the present application does not limit this.
[0089] 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.
[0090] Optionally, in the process of extracting features from a water quality image through a window attention mechanism, the channel weights contained in the channel weight information are multiplied channel by channel with the feature map to enhance 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., which is not limited in the embodiments of the present application. 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, which is not limited in the embodiments of the present application. Exemplarily, if the background information indicates that the source of sewage in the water area is industrial wastewater, 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, and based on the channel weight information, in the process of feature extraction 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, 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, and based on the channel weight information, in the process of feature extraction 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 have 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.
[0091] Optionally, the image processing device can also suppress feature channels irrelevant to the task in the process of extracting features from the water quality image using the window attention mechanism based on the channel weight information. In the embodiment of the present application, the task is water quality detection.
[0092] Step 504, 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.
[0093] Step 505: Obtain the water quality detection result of the water area based on the water quality feature vector.
[0094] The above steps 504 and 505 are Figure 3 Steps 302 and 303 in the embodiment are similar, see Figure 3The embodiments are not described in detail here.
[0095] To sum up, in the technical solution provided by 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 effects 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 practical 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.
[0096] 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. The method is applied to Figure 1 The image processing device in the water quality detection system shown in FIG. The method may include the following steps (601-605): Step 601, obtaining a water quality image to be processed.
[0097] Step 602, 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.
[0098] Step 603, based on the water quality feature vector, obtain the water quality detection result of the water area.
[0099] The above steps 601-603 and Figure 3 Steps 301-303 in the embodiment are similar, see Figure 3 The embodiments are not described in detail here.
[0100] Step 604, obtaining historical water quality test results.
[0101] The historical water quality test results refer to the water quality test results for the above water area before 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 above 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 time.
[0102] Step 605, based on the water quality test results and historical water quality test results, determine the sewage treatment method for the water area.
[0103] 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 the changes in water pollution in the water area. Optionally, when 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.
[0104] 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, a pollution type corresponds to multiple levels, and different levels are used to indicate different pollution levels. Taking the pollution type of metal copper pollution as an example, there are four pollution levels ABCD corresponding to the pollution level A, the pollution level indicated by the level A is greater than the pollution level indicated by the level B, the pollution level indicated by the level B is greater than the pollution level indicated by the level C, and the pollution level indicated by the level C is greater than the pollution level indicated by the level D.
[0105] Optionally, the 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 the pollution type of this level in the water area. In an exemplary embodiment, after the image processing device obtains the water quality test results and the historical water quality test results, 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 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 first pollution type can be any pollution type included in the water quality test results.
[0106] 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 the treatment method for different pollution types based on the comparison information between the two, similar to the first pollution type.
[0107] Optionally, if it is determined based on the above 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 stronger than the sewage treatment capacity of the historical sewage treatment method.
[0108] Optionally, the new sewage treatment method may be obtained manually or through a pre-stored sewage treatment plan, which is not limited in the embodiments of the present application.
[0109] 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 the historical water quality test results. That is, the present application provides an automated sewage treatment solution that can effectively save human resources.
[0110] 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, thereby saving human resources and improving the sewage treatment effect.
[0111] Optionally, in an embodiment of the present application, when obtaining a water quality detection result based on a water quality image, the image processing device uses the water quality image as input, calls a water quality detection model, and determines the output result of the water quality detection model as the water quality detection result. The water quality detection model is a pre-trained neural network model that performs feature extraction processing through a window attention mechanism.
[0112] In an exemplary embodiment, the training process of the water quality detection model is as follows: 1. Obtain a training sample set, which includes at least two sample images, and one sample image corresponds to one label; 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; 3. Based on the output results corresponding to each sample image and the labels corresponding to each sample image, determine the loss of the water quality detection model; optionally, the model training device determines the loss of the water quality detection model through a cross entropy loss function; 4. When the loss function of the water quality inspection model based on loss converges, it is determined that the training of the water quality detection model is 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.
[0113] 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: 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; Perform linear projection on each sample image block to obtain an initial sample feature map corresponding to each sample image block; 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; 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; Perform feature fusion on the final sample feature maps corresponding to each sample image block; Perform nonlinear transformation on the result of feature fusion to obtain the sample feature vector; Based on the sample feature vector, the output result of the water quality detection model for the sample image is obtained.
[0114] 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: For a target sample image block in at least two sample image blocks, performing window division on the target initial sample feature map after adding the sample position encoding; Based on the window division result, the target initial sample feature map after adding sample position encoding is subjected to feature extraction processing through a multi-head attention mechanism with the window as the basic unit, and the first intermediate sample feature map corresponding to the target sample image block is obtained; Performing a window shift operation on the first intermediate sample feature map, where the shift distance of the window shift operation is less than the shortest edge length of the window; 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, so as to obtain a first sample feature map corresponding to the target sample image block; A target final sample feature map is obtained based on the first sample feature map.
[0115] In an exemplary embodiment, the step of obtaining a target final sample feature map based on the first sample feature map comprises the following steps: Performing patch merging on the first sample feature map to obtain a first merged sample feature map; Through window division, window offset and multi-head attention mechanism, feature extraction is performed on the first merged sample feature map to obtain a second sample feature map; Performing patch merging processing on the second sample feature map to obtain a second merged sample feature map; Through window division, window offset and multi-head attention mechanism, feature extraction processing is performed on the second merged sample feature map to obtain a third sample feature map; Performing patch merging processing on the third sample feature map to obtain a third merged sample feature map; Performing feature extraction processing on the third merged sample feature map through window division, window offset and multi-head attention mechanism to obtain a fourth sample feature map; A target final sample feature map is obtained based on the fourth sample feature map.
[0116] In an exemplary embodiment, the training process of the water quality detection model also includes the following steps: 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 contour in the sample image; 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 in the feature extraction process of the window attention mechanism.
[0117] The following is an embodiment of the device of the present application, which can be used to execute the embodiment of the method of the present application. For details not disclosed in the embodiment of the device of the present application, please refer to the embodiment of the method of the present application.
[0118] Please refer to Figure 7 , which shows a block diagram of a water quality detection device based on image recognition provided by an embodiment of the present application. The device has the function of implementing the above-mentioned water quality detection method based on image recognition, and the function can be implemented by hardware, or by hardware executing corresponding software. The device can be the above-mentioned image processing device, and can also be set in the image processing device. The device 700 may include: an image acquisition module 710, a feature extraction module 720 and a result acquisition module 730.
[0119] The image acquisition module 710 is used to acquire the water quality image to be processed.
[0120] 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.
[0121] 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.
[0122] In an exemplary embodiment, if Figure 8 As shown, the feature extraction module 720 includes: an image segmentation 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.
[0123] An image block division unit 721 is used to divide the water quality image into blocks to obtain at least two image blocks; wherein there is no overlapping area between the image blocks; A linear projection unit 722 is used to perform linear projection on each of the image blocks to obtain an initial feature map corresponding to each of the image blocks; A code adding unit 723, used for 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; A final acquisition unit 724 is used to perform 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; A feature fusion unit 725 is used to perform feature fusion on the final feature maps corresponding to each of the image blocks; The vector acquisition unit 726 is used to perform nonlinear transformation on the result after feature fusion to obtain the water quality feature vector.
[0124] In an exemplary embodiment, the final acquisition unit 724 is used to: 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 coding; 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, taking 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, wherein an offset distance of the window offset operation is less than a shortest edge length of the window; Based on the window offset result, feature extraction processing is performed on the first intermediate feature map by 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.
[0125] In an exemplary embodiment, the final acquisition unit 724 is used to: 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.
[0126] In an exemplary embodiment, if 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.
[0127] The water surface acquisition unit 711 is used to acquire a water surface image from the water area image data of the water area.
[0128] The contour detection unit 712 is used to perform contour detection processing on the water surface image to determine the contour of the water body area in the water surface image.
[0129] The image capture unit 713 is used to capture a water surface water quality image from the water surface image based on the water body area contour.
[0130] The image acquisition unit 714 is used to acquire the water quality image based on the water surface water quality image.
[0131] In an exemplary embodiment, the image acquisition unit 714 is used to Acquire at least one underwater image from the water area image data; Based on the depth information corresponding to each of the underwater images, the 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 is acquired; The water surface water quality image and the at least one underwater water quality image are spliced to obtain the water quality image.
[0132] In an exemplary embodiment, if Figure 8 As shown, the device 700 further includes: a background acquisition module 740 and a weight acquisition module 750 .
[0133] The background acquisition module 740 is used to acquire background information corresponding to the water quality image, and the background information is used to indicate the source of sewage in the water area.
[0134] 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.
[0135] In an exemplary embodiment, if Figure 8 As shown, the device 700 also includes: a sewage treatment module 760.
[0136] 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.
[0137] In an exemplary embodiment, the sewage treatment module 760 is used to: 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.
[0138] To sum up, in the technical solution provided in the embodiment of the present application, feature extraction processing is performed on water quality images 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 water quality related information, which simplifies the water quality detection process, improves water quality detection efficiency, and saves time.
[0139] 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.
[0140] In an exemplary embodiment, a non-transitory computer-readable storage medium is also provided, on which a computer program is stored, and when the computer program is executed by a processor, the above-mentioned water quality detection method based on image recognition is implemented.
[0141] In an exemplary embodiment, a computer program product is also provided. When the computer program product is executed, a computer device executes the above-mentioned water quality detection method based on image recognition.
[0142] 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 cannot be used 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 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 limited by the attached claims rather than the above description, and it is intended to include all changes within the meaning and scope of the equivalent elements of the claims in the invention.
[0143] 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: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the objects associated before and after 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 are not limited to this.
[0144] The above description is only 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 protection scope of the present application.
Claims
1. A water quality detection method based on image recognition, characterized in that: The method comprises: Acquire a water quality image to be processed; 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 to which the water quality image belongs; Based on the background information, acquiring channel weight information for the water quality image; 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 channel 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 a water pollution type of 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 there is no overlapping area 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, respectively, 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 processing 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 comprises: 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 coding; 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, taking 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, wherein an offset distance of the window offset operation is less than a shortest edge length of the window; Based on the window offset result, feature extraction processing is performed on the first intermediate feature map by 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 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 claim 1, characterized in that The step of obtaining the water quality image to be processed comprises: Acquire a water surface image from the 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; The water quality image is acquired based on the water surface water quality image.
6. The method according to claim 5, characterized in that The acquiring the water quality image based on the water surface water quality image comprises: Acquire at least one underwater image from the water area image data; Based on the depth information corresponding to each of the underwater images, the 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 is acquired; The water surface water quality image and the at least one underwater water quality image are spliced to obtain the water quality image.
7. The method according to any one of claims 1 to 6, characterized in that: The water quality test result includes at least one pollution type and the probability corresponding to each pollution type; The method of sewage treatment for the water area is determined based on the water quality test result and the historical water quality test result, including: 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.
8. A water quality detection device based on image recognition, characterized in that: The device comprises: An image acquisition module, used for acquiring water quality images to be processed; A background acquisition module, used to acquire background information corresponding to the water quality image, wherein the background information is used to indicate the source of sewage in the water area to which the water quality image belongs; A weight acquisition module, used for acquiring channel weight information for the water quality image based on the background information; A feature extraction module, used for 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 channel related to the task in the feature extraction process of the window attention mechanism; A result acquisition module, used for acquiring a water quality detection result of the water area based on the water quality feature vector, wherein the water quality detection result is used for indicating the 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.
9. A computer device, characterized in that: The computer device comprises 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 7.
10. 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 7 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