Image target segmentation and anomaly detection method based on pollution source outlet
Through image target segmentation and anomaly detection methods, dense optical flow and K-means algorithms are used to solve the problem of pollution source emission monitoring in the water environment, achieve real-time monitoring and detection of pollution source emission, and improve detection accuracy and efficiency.
Patent Information
- Application Number
- CN202110642415.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-06-09
- Publication Date
- 2024-09-06
- Estimated Expiration
- 2041-06-09
AI Technical Summary
Existing technologies are difficult to effectively monitor and detect pollution source emissions, especially in water environments. They cannot process and analyze video streaming images of pollution source discharge outlets in real time, making river pollution monitoring difficult to achieve.
The image target segmentation and anomaly detection method based on the pollution source outlet is adopted. Through the image target detection segmentation step and the color anomaly detection step, the dense optical flow algorithm is used to segment the fluid contour, the K-means algorithm is used to cluster pixels, and HSV histogram feature detection is used Abnormal colors enable real-time monitoring of pollution source emissions.
It realizes real-time monitoring of pollution source emissions, can effectively segment fluid contours, determine foam and color abnormalities, and improves the detection accuracy and efficiency of pollution source emissions.
Smart Images

Figure CN113344879B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of environmental protection technology, and in particular to an image target segmentation and anomaly detection method based on a pollution source outlet. Background Art
[0002] With the continuous development of social industrialization, more and more water environments have begun to deteriorate, and have entered a period of high incidence of water pollution accidents. At present, many companies discharge factory-treated wastewater into rivers through sewage outlets, thereby causing river pollution. Generally speaking, the color of the water discharged into the river is related to its degree of pollution. Therefore, how to process the collected video stream images of the pollution source outlet and detect abnormalities in the wastewater color in order to monitor the pollution source emissions is an urgent problem to be solved at this stage. Summary of the invention
[0003] The purpose of the present invention is to overcome the shortcomings of the prior art and provide an image target segmentation and anomaly detection method based on the pollution source outlet, which can perform real-time anomaly detection on the collected pollution source outlet video stream images to achieve the purpose of monitoring pollution source emissions.
[0004] The object of the present invention is achieved by the following technical solutions: an image target segmentation and anomaly detection method based on the pollution source outlet, the detection method comprising an image target detection and segmentation step and a color anomaly detection step;
[0005] The image target detection and segmentation step includes: performing a series of processing on the collected real-time video stream of the pollution source outlet to obtain the pixel coordinates of the completed outlet in the video image, and finally segmenting the outlet area;
[0006] The color anomaly detection step includes: setting a time period for color detection and creating a feature vector group, extracting a real-time video stream image at a certain sampling interval, segmenting the outlet area image according to the pixel coordinates of the image target detection and segmentation step, and then performing a foam detection step to determine whether the foam exceeds the standard and / or performing a color detection step to determine whether the color is abnormal.
[0007] The image target detection and segmentation step specifically includes:
[0008] S11. Use the machine vision library opencv to create a real-time video object based on VideoCapture, and extract the previous and next frame images at a certain interval;
[0009] S12, converting each image from RGB channel to gray channel, and calculating dense optical flow between adjacent periodic images;
[0010] S13, set the threshold, use the adaptiveThreshold method of opencv to perform adaptive binarization processing on the optical flow image, and obtain the initial mask;
[0011] S14, performing morphological closing operation and dilation and contraction on the initial mask to eliminate the RGB characteristics of the image and fill in the missing parts in the initial mask;
[0012] S15, using the findContours method of opencv to search for contours of all connected areas in the mask updated in step S14;
[0013] S16, using the contourArea method of opencv to calculate the contour area of all connected areas in the mask, so as to exclude the point-making area in the contour and leave the outlet area;
[0014] S17, using the area ratio between each contour and the mask as a screening condition, screening out contours containing the outlet area that meet the condition, otherwise returning to step S11 for continuous processing;
[0015] S18, combining the outlet area contour obtained in step S17 with the boundingRect method in opencv, calculating the pixel coordinates of the complete outlet in the image, and finally segmenting the outlet area.
[0016] The calculating of dense optical flow between adjacent periodic images comprises:
[0017] The neighborhood information of each pixel is fitted one by one in a sliding window manner to obtain the optical flow features of all pixels in the two frames of images;
[0018] If the two optical flow feature values of the coordinate match remain unchanged, the pixel corresponding to the coordinate is judged to be stationary. Otherwise, the remaining pixels are judged to have moved dx and dy along the x and y axes within the time interval dt.
[0019] Combined with the multi-scale receptive field of the image, the matching of each moving pixel is achieved and the motion trajectory is drawn.
[0020] The contours of all connected regions in the mask updated in step S14 include:
[0021] Normalize the binary image to binary type [0,1], traverse each pixel until f(i,j)=1 and f(i,j-1)=0, and define (i,j) as the starting point of the boundary;
[0022] Take (i,j+k) (k=0,..,n) as the center and search for points with a pixel value of 1 in its neighborhood in a closed-loop manner, and keep them until the search returns to the point (i,j+k).
[0023] The screening condition includes: when the contour area and the image area are known, when the contour area / image area>thresh, it means that the condition is met.
[0024] The foam detection step includes: performing K-means clustering on the image, gathering all pixels in the image whose features meet the foam conditions and blackening them, and determining whether the current emission has excessive foam by counting the number of black pixels.
[0025] The foam detection step is specifically as follows:
[0026] A1. Divide the cluster objects into two categories: foam and water;
[0027] A2. Reconstruct the image with shape = (n, m, 3) into a two-dimensional matrix with shape = (n×m, 3);
[0028] A3. Randomly select two data points in the two-dimensional matrix as cluster centers of foam and water, and retain the data closest to these two points to form data sets belonging to the foam and water categories respectively;
[0029] A4. Update the cluster center points of foam and water according to the set, retain the data closest to the center point, and update the data set belonging to the foam and water categories;
[0030] A5. When the cluster center point is no longer updated or the number of iterations reaches the upper limit, output the set of foam and water data. Otherwise, return to step A3.
[0031] A6. Determine whether the number of pixels belonging to the foam set exceeds the number of pixels in the preset outlet area, and determine whether the foam exceeds the limit.
[0032] The specific contents of the color detection step are as follows:
[0033] B1 converts the channel of the target image of the segmented outlet area into the HSV channel to highlight the color difference between the images;
[0034] B2, loop through each channel of the target image, perform image histogram feature extraction based on pixel-level distribution, and cascade the feature vectors of each channel to obtain the HSV histogram feature vector;
[0035] B3, cyclically storing the feature vectors into the vector group, when the cycle limit is reached, using the Pearson correlation coefficient to calculate the correlation between the first and last vectors in the feature vector group, when the correlation is lower than the threshold, executing step B4;
[0036] B4. Loop through the feature vector group and calculate the correlation of the feature vector group with the sampling interval as the unit. If there is a sudden change in the correlation, it is not determined as a color abnormality. Otherwise, it is determined as a color abnormality.
[0037] The present invention has the following advantages: an image target segmentation and anomaly detection method based on the pollution source outlet, 1. using the dense optical flow algorithm to segment the fluid, solving the problem that the fluid contour and morphology are difficult to capture, and realizing targeted anomaly detection of the target; 2. using the pixel-based image histogram features, through the associated time dimension, continuously and periodically determining the fluid color anomaly; 3. using the K-means algorithm to achieve pixel clustering of the fluid target, and judging the fluid foam anomaly based on the HSV pixel threshold. BRIEF DESCRIPTION OF THE DRAWINGS
[0038] Figure 1 It is a schematic diagram of the process of the present invention. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical scheme and advantages of the embodiments of the present application clearer, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. The components of the embodiments of the present application described and shown in the drawings here can be arranged and designed in various different configurations. Therefore, the detailed description of the embodiments of the present application provided below in conjunction with the drawings is not intended to limit the scope of protection of the application claimed for protection, but merely represents the selected embodiments of the present application. Based on the embodiments of the present application, all other embodiments obtained by those skilled in the art without making creative work belong to the scope of protection of the present application. The present invention is further described below in conjunction with the drawings.
[0040] like Figure 1 As shown, the present invention relates to an image target segmentation and anomaly detection method based on a pollution source outlet, which specifically includes an image target detection and segmentation step and a color anomaly detection step. After obtaining a real-time video stream of the pollution source outlet, the image target detection and segmentation step specifically includes the following contents:
[0041] (1) Use the machine vision library opencv to create a real-time video object based on VideoCapture and extract the previous and next frame images at a certain interval;
[0042] (2) Convert each image from RGB channel to gray channel and calculate the dense optical flow (Optical Flow Farneback) between adjacent periodic images;
[0043] Furthermore, the steps of dense optical flow calculation include:
[0044] In the video, except for the moving object, the environment is static, and the light intensity of the object remains unchanged before and after the movement. Therefore, the neighborhood information of each pixel is fitted one by one in a sliding window manner to obtain the optical flow features of all pixels in the two frames of images.
[0045] If the two optical flow feature values of the coordinate match remain unchanged, the pixel corresponding to the changed coordinate is judged to be stationary, otherwise the remaining pixels are moved by dx and dy along the x and y axes within the interval dt;
[0046] Combined with the multi-scale receptive field (pyramid) of the image, the matching of each moving pixel is achieved and the motion trajectory is drawn.
[0047] (3) Set the threshold and use the adaptiveThreshold method of opencv to adaptively binarize the optical flow image (the pixel values >thresh are set to 255 (white), and the remaining pixel values are set to 0 (black)) to obtain the initial mask;
[0048] Adaptive threshold binarization: Since the brightness of each image is different, setting a unified threshold may not accurately obtain the target area. Therefore, it is necessary to normalize the image brightness according to the pixel histogram of the image and adaptively select the threshold. For example, if an image is darker, the pixels are mostly concentrated between 0 and 127. If the thresh is 128 at this time, the target area may not be locked at all; if an image is brighter, the pixels are mostly concentrated between 128 and 255. If the thresh is 128 at this time, the entire image may be marked as the target area.
[0049] (4) Perform a morphological closing operation (dilate and erod) on the initial mask, dilate and shrink, eliminate the RGB characteristics of the image and fill in the missing parts in the initial mask;
[0050] (5) Use the findContours method of OpenCV to obtain the contours of all connected areas in the mask updated in step 4);
[0051] Further, the step of searching the contour includes:
[0052] Normalize the binary image to binary type [0,1], traverse each pixel until f(i,j)=1 and f(i,j-1)=0, and define (i,j) as the starting point of the boundary;
[0053] Among them, an image with a resolution of m*n can be represented as a matrix with n rows and m columns, i and j correspond to the row index and column index of the matrix respectively, and f(i,j) and f(i,j-1) represent the pixel values of the image at coordinates (i,j) and (i,j-1) respectively.
[0054] Take (i, j+k) (k=0,..,n) as the center point and search for points with pixel value 1 in its 4(8) neighborhood in a closed loop manner, and keep them until the search returns to the point (i, j+k);
[0055] Assuming the pixel value of the coordinate (i, j+n+1) is 0, then (i, j+k) (k=0,..,n) represents all coordinates starting from the coordinate (i, j) whose neighboring pixel value is 1. By traversing the coordinates (i, j+k) (k=0,..,n), and starting from the coordinate (i, j+k), searching and storing all coordinates whose neighboring pixel value is 1, when the search returns to the coordinate (i, j+k), a closed loop is formed, and all the stored pixel points are the contour of the connected area.
[0056] Since real-time video streams inevitably contain image noise, the connected area contour obtained in step (5) not only contains the outlet area, but also carries the image noise area;
[0057] (6) To exclude the noise area, the contour area (the sum of all contour pixels) of all connected areas in the mask is calculated using the contourArea method of OpenCV; the contour area is obtained by summing the number of contour pixels retained when searching for the contour.
[0058] (7) The area ratio between each contour and the mask is used as a screening condition. If the requirement is met, the contour containing the outlet area is output. Otherwise, return to step (1) and continue processing;
[0059] Furthermore, the screening condition is: given the area of each contour and the area of the image, when the contour area / image area>thresh, the condition is met.
[0060] (8) Combine the boundingRect method in opencv with the outlet area contour obtained in step (7) to calculate the pixel coordinates of the complete outlet in the original image, and finally segment the outlet area.
[0061] Among them, since the pixel coordinates within each contour are retained, after the target contour is screened out, it is only necessary to find the largest and smallest coordinates on the x and y axes in the coordinates to form the upper left and lower right coordinates of the rectangular boundary.
[0062] The color anomaly detection steps specifically include the following:
[0063] 1. Set the time period of color detection and create an (empty) feature vector group, extract the real-time video stream image with a sampling interval of seconds, and segment the outlet area image according to the pixel coordinates in the segmentation step (8) of the image target detection;
[0064] 2. Since the HSV space can intuitively express the brightness, hue, and vividness of an image, and is convenient for highlighting the color differences between images, the target image is converted into an image of the HSV channel;
[0065] 3. Perform K-means clustering on the image, gather all pixels in the image that are similar to foam and blacken them, and determine whether the current emission exceeds the foam standard by counting the number of black pixels;
[0066] Among them, the image is transformed from RGB channel to HSV channel (hue-saturation-brightness), and K-means pixel clustering is performed. When the cluster center point satisfies: 180>=H>=0&&30>=S>=0&&255>=V>=221, the pixels adjacent to the center are all bubbles.
[0067] Furthermore, K-means clustering and foam over-limit detection include:
[0068] (a) The cluster objects are divided into two categories: foam and water;
[0069] (b) Reconstruct the image with shape = (n, m, 3) (n rows, m columns, 3 channels) into a two-dimensional matrix with shape = (n×m, 3);
[0070] Among them, shape = (n, m, 3) represents a three-dimensional matrix, that is, an RGB image with a resolution of m*n is reconstructed into a two-dimensional matrix with shape = (n×m, 3) for easy clustering.
[0071] (c) Randomly select two data points in the two-dimensional matrix as the cluster center points of foam and water, and retain the data closest to these two points to form data sets belonging to the foam and water categories respectively;
[0072] (d) Update the cluster center points of foam and water according to the set (take the mean of the data set), retain the data closest to the center point, and update the data set belonging to the foam and water categories;
[0073] (e) When the cluster center point is no longer updated or the number of iterations reaches the upper limit, output the set of foam and water data. Otherwise, return to step (c);
[0074] (f) The foam exceeding standard phenomenon is judged according to whether the number of data (pixels) belonging to the foam set exceeds one third of the number of pixels in the discharge area. If it exceeds, it means that the foam exceeds the standard.
[0075] 4. According to the result in step 2, loop through each channel of the target image, perform image histogram feature extraction based on pixel-level distribution, and cascade the feature vectors of each channel (H直方图特征 concatenate S 直方图特征 concatenate V 直方图特征 ), get the HSV histogram feature vector;
[0076] 5. Circularly store the feature vectors into the vector group. When the cycle limit is reached, use the Pearson Correlation Coefficient to calculate the correlation between the first and last vectors in the feature vector group. When the correlation is lower than the threshold, execute step 6; otherwise, return to step 1 for continuous processing.
[0077] Furthermore, the correlation threshold thresh=0.6 is set, and the alarm sensitivity is comprehensively considered to achieve the purpose of no missed alarms and no false alarms, which is determined based on a large number of images and videos of water body colors and foams ranging from normal to abnormal.
[0078] 6. In order to eliminate the situation where the correlation of image features suddenly drops due to short-term illumination changes, resulting in false alarms of color anomalies, loop through the feature vector group and calculate the correlation between feature vectors in units of sampling intervals. If the correlation suddenly changes, do not determine the anomaly and return to step 1. Otherwise, determine the color anomaly and return to step 1 for continuous processing.
[0079] The above is only a preferred embodiment of the present invention. It should be understood that the present invention is not limited to the form disclosed herein, and should not be regarded as excluding other embodiments, but can be used in various other combinations, modifications and environments, and can be modified within the scope of the concept described herein through the above teachings or the technology or knowledge of the relevant field. The changes and modifications made by those skilled in the art shall not deviate from the spirit and scope of the present invention, and shall be within the scope of protection of the claims attached to the present invention.
Claims
1. Image target segmentation and anomaly detection method based on pollution source outlets, Features: The detection method comprises an image target detection and segmentation step and an anomaly detection step; The image target detection and segmentation step includes: performing a series of processing on the collected real-time video stream of the pollution source outlet to obtain the pixel coordinates of the completed outlet in the video image, and finally segmenting the outlet area; The abnormality detection step includes: setting a time period for color detection and creating a feature vector group, extracting a real-time video stream image at a certain sampling interval, performing a color detection step to determine whether the color is abnormal based on the discharge port area image segmented by the pixel coordinates of the image target detection and segmentation step; The abnormality detection step further includes: performing a foam detection step according to the discharge port area image segmented by the pixel coordinates in the image target detection and segmentation step to determine whether the foam exceeds the standard; The specific contents of the color detection step are as follows: B1 converts the channel of the target image of the segmented outlet area into the HSV channel to highlight the color difference between the images; B2, loop through each channel of the target image, perform image histogram feature extraction based on pixel-level distribution, and cascade the feature vectors of each channel to obtain the HSV histogram feature vector; B3, cyclically storing the feature vectors into the vector group, when the cycle limit is reached, using the Pearson correlation coefficient to calculate the correlation between the first and last vectors in the feature vector group, when the correlation is lower than the threshold, executing step B4; B4, loop through the feature vector group, calculate the correlation of the feature vector group with the sampling interval as the unit, if the correlation suddenly appears, it is not determined as color abnormality, otherwise, it is determined as color abnormality; The image target detection and segmentation step specifically includes: S11. Use the machine vision library opencv to create a real-time video object based on VideoCapture, and extract the previous and next frame images at a certain interval; S12, converting each image from RGB channel to gray channel, and calculating dense optical flow between adjacent periodic images; S13, set the threshold, use the adaptiveThreshold method of opencv to perform adaptive binarization processing on the optical flow image, and obtain the initial mask; S14, performing morphological closing operation and dilation and contraction on the initial mask to eliminate the RGB characteristics of the image and fill in the missing parts in the initial mask; S15, using the findContours method of opencv to search for contours of all connected areas in the mask updated in step S14; S16, using the contourArea method of opencv to calculate the contour area of all connected areas in the mask, so as to exclude the point-making area in the contour and leave the outlet area; S17, using the area ratio between each contour and the mask as a screening condition, screening out contours containing the outlet area that meet the condition, otherwise returning to step S11 for continuous processing; S18, combining the outlet area contour obtained in step S17 with the boundingRect method in opencv, calculating the pixel coordinates of the complete outlet in the image, and finally segmenting the outlet area.
2. The method for image target segmentation and anomaly detection based on the pollution source outlet according to claim 1, Features: The calculating of dense optical flow between adjacent periodic images comprises: The neighborhood information of each pixel is fitted one by one in a sliding window manner to obtain the optical flow features of all pixels in the two frames of images; If the two optical flow feature values of the coordinate match remain unchanged, the pixel corresponding to the coordinate is judged to be stationary. Otherwise, the remaining pixels are judged to have moved dx and dy along the x and y axes within the time interval dt. Combined with the multi-scale receptive field of the image, the matching of each moving pixel is achieved and the motion trajectory is drawn.
3. The method for image target segmentation and anomaly detection based on pollution source outlet according to claim 1, Features: The contours of all connected regions in the mask updated in step S14 include: Normalize the binary image to binary type [0,1], traverse each pixel until f(i,j) = 1 and f(i,j-1) = 0, define (i,j) as the starting point of the boundary, f(i,j) and f(i,j-1) represent the pixel values of the image at coordinates (i,j) and (i,j-1) respectively; Take (i,j+k) as the center and search for points with a pixel value of 1 in its neighborhood in a closed-loop manner, and keep them until the search regresses to the point (i,j+k), where k=0,..,n, and n represents the number of rows in the matrix.
4. The method for image target segmentation and anomaly detection based on pollution source outlet according to claim 1, Features: The screening condition includes: when the contour area and the image area are known, when the contour area / image area>threshold, it means that the condition is met.
5. The method for image target segmentation and anomaly detection based on pollution source outlet according to any one of claims 1 to 4, Features: The foam detection step includes: performing K-means clustering on the image, gathering all pixels in the image that have features that meet the foam adjustment requirements and blackening them, and determining whether the current emission has excessive foam by counting the number of black pixels.
6. The method for image target segmentation and anomaly detection based on pollution source outlet according to claim 5, Features: The foam detection step is specifically as follows: A1. Divide the cluster objects into two categories: foam and water; A2. Reconstruct the image with shape = (n, m, 3) into a two-dimensional matrix with shape = (n×m, 3), where n represents the number of rows and m represents the number of columns; A3. Randomly select two data points in the two-dimensional matrix as cluster centers of foam and water, and retain the data closest to these two points to form data sets belonging to the foam and water categories respectively; A4. Update the cluster center points of foam and water according to the set, retain the data closest to the center point, and update the data set belonging to the foam and water categories; A5. When the cluster center point is no longer updated or the number of iterations reaches the upper limit, output the set of foam and water data. Otherwise, return to step A3. A6. Determine whether the number of pixels belonging to the foam set exceeds the number of pixels in the preset outlet area, and determine whether the foam exceeds the limit.
