The disclosure relates to the field of computer vision, in particularly to a transparency detection method based on machine vision.
Water transparency of bodies of water is a commonly used indicator to measure the water quality. A common method for measuring the transparency of water bodies is the employment of a Secchi disk. The employment of Secchi disk requires users to judge the ambiguity degree of the Secchi disk and read the depth of the water ruler. This is subject to the subjective factors of the observer, resulting in greater uncertainty in the measurement of transparency. In addition, external objective factors, such as the intensity of the light, the shake of the Secchi disk, etc., will also have an impact on the measurement of transparency. Such prior methods of transparency measurement require higher operator experience, and have greater uncertainty and instability. Now with the improvement of environmental and ecological requirements, water transparency has become a very important indicator. Accurate and real-time monitoring of changes in water transparency will help environmental protection departments make timely responses to urban river management. In the field of aquaculture, the level of water transparency will directly affect the production of aquaculture. Therefore, the accurate measurement of water body transparency is of great significance for promoting life and production.
There are a number of ways to measure transparency. For example, Chinese Patent Publication No. CN109859183A discloses a multi-element integrated water body intelligent identification method and an ecological station based on edge computing. In this method, the image of the target water area immersed in the Secchi disk is input into a preset SSD deep learning network, and based on the image recognition result of the Secchi disk output by the SSD deep learning network, the edge computing method is applied to obtain a current second water body transparence information in the target water area. However, this method needs to acquire at least one first water body transparency information and at least one first water level information of the target water area currently collected by the water body detection sensing component. The Chinese Patent Publication No. CN109784259A discloses an intelligent identification method of water body transparency based on image identification and a Secchi disk assembly. In the method, the image of the target water area immersed in the Secchi disk is input into a preset image recognition model, and the output of the image recognition model is used as the image recognition result of the Secchi disk. However, this method requires a plurality of disks including two-color working surfaces, and each of the disks is arranged around the cylinder in a spirally stepped arrangement. The Chinese Patent Publication No. CN110672563A discloses a method for image recognition and detection of transparency in smart water environment, which requires a special threaded rod with a Secchi disk to be vertically fixed at a water quality monitoring point. The above methods often need to obtain data in advance or require a specific device, the operation is relatively complicated, and the practicability is not strong.
With the tremendous development of computer vision technology, the use of computer vision technology to process image data can effectively avoid the influence of subjective and objective factors. Using computer vision technology to process image data has the advantages of high accuracy, wide application scenarios and strong generalization ability. This disclosure combines deep learning, image processing technology and Secchi disk measurement technology, and proposes an intelligent image processing and recognition technology based on machine vision for the measurement of water transparency.
One object of the present disclosure is to provide a transparency detection method based on machine vision. Number of the camera in the in the present disclosure may be one or two. When the water is clear, one camera may be used. When the transparency of the water quality is turbid, and one camera is not sufficient to track the movement of the Secchi disk and the water ruler at the same time, two cameras may be employed. One of the two cameras is used for taking pictures of the Secchi disk, and the other for the water ruler. The two cameras shoot at the same time, imitating the action of a person measuring the transparency of the water body with the Secchi disk (looking at the Secchi disk while looking at the water ruler), and obtain a clearer video of the Secchi disk and the water ruler. The captured video is transmitted to a computer for processing directly or through the cloud.
In order to achieve the above objects, the present disclosure includes two aspects. One of the two aspects is the judgment of the critical position of the Secchi disk, and the other is the identification of the water ruler. The schematic flowchart is shown in
1) Operation of the Secchi disk to start the water transparency measurement, and turning on the camera for shooting;
2) Determination of a critical position of the Secchi disk;
3) Identification of the water ruler and calculation of the reading of the water ruler;
4) Output and display.
In step 2), the determination of the critical position of the Secchi disk: the critical position of the Secchi disk refers to a position when the Secchi disk is barely visible. It includes the steps of preliminary segmentation of the Secchi disk, fine segmentation of the Secchi disk, and determination of the critical position of the Secchi disk. More specifically:
2-1) preliminary segmentation of the Secchi disk: segmenting the white part of the Secchi disk from the video image; specifically includes steps: determining the Secchi disk size, positioning the Secchi disk in the image, and determining the threshold value.
2-1-1) Determining the Secchi disk size: in this disclosure, the Faster RCNN algorithm is used to identify the Secchi disk size:
It should be noted that the size here does not refer to the area of the Secchi disk, but an area of a rectangle. The four sides of the rectangle are fitted to enclose the Secchi disk. First, frame extraction is performed on the video containing the Secchi disk. In order to reduce the calculation amount of subsequent image processing, one image is captured every 3 frames in this disclosure. Then, the captured image is stored in a fixed folder. For the first image in the folder, using the Faster RCNN algorithm to identify the Secchi disk; the collected data is labeled with the image labeler function in Matlab2020b; the result of Faster RCNN identifying the Secchi disk size is shown in
2-1-2) Positioning the Secchi disk in the image:
The position and size of the rectangular frame are obtained after recognizing the image of the Secchi disk in the initial position using the Faster RCNN. All images are divided into upper and lower parts with an upper edge of the rectangular frame being the dividing line. In this disclosure, starting from an upper left corner of the lower parts of the image, the previously determined rectangular frame is moved on the entire image with a certain step size; each time the rectangular frame is moved, the content in the rectangular frame is intercepted, and the average brightness in the frame is calculated. Because the white part on the Secchi disk has high brightness, the location of the sampling rectangular frame with a high average brightness value is the location of the Secchi disk.
When the image contains background objects whose brightness is higher than or similar to that of the Secchi disk, the background subtraction method based on the mean value is used in this disclosure: taking the images in the last few seconds of the video, there is no Secchi disk in the last few seconds of the video, so the last 10 frames of images of the video can be mean and taken as the background image; subtracting the background image from the images containing the Secchi disk, so the background part of the images becomes nearly 0 after subtraction; and then the location of the Secchi disk can be determined by the previous method in the subtracted image.
2-1-3) Determining the threshold
After positioning of the Secchi disk, extracting the Secchi disk from the original image, as shown in
Step one, recording the brightness value of the entire image as set C; the brightness values are divided into two categories, one is recorded as set C1, and the other is recorded as set C2, and C1∩C2=0, C1∪C2=C.
Step two, taking the brightness value k, and putting the brightness values in the range of [0, k−1] into the set C1, and put the remaining brightness values into the set C2. The mean value of the brightness values in the set C1 is recorded as m1, and the ratio of the element number in the set C1 to the element number in the set C is recorded as p1; the mean value of the brightness values in the set C2 is recorded as m2, and the ratio of element number in the set C2 to the element number of the set C is recorded as p2; the mean value of the brightness values in the set C is recorded as m; the calculation formula of the inter-class variance is recorded as: g=p1*(m1-m)∧2+p2*(m2-m)∧2.
Step three: the brightness value k is taken from 0 to 255 one by one; each time a value is taken, the corresponding maximum inter-class variance is calculated. The value k corresponding to the maximum inter-class variance is divided by 255 to obtain the final threshold.
After determining the threshold, keep all the brightness higher than the threshold, and remove the others, and then switch the image back to the RGB space to obtain the white part on the Secchi disk.
2-2) Fine segmentation of the Secchi disk: when the Secchi disk is almost invisible, the white part on the Secchi disk is segmented; in order to realize the fine segmentation of the Secchi disk, the present disclosure uses the following two steps:
2-2-1) Determining the segmentation threshold of the Secchi disk and segmenting it when the Secchi disk is almost invisible.
According to step 2-1), intercepting a Secchi disk video, using the method of step 2-1) to determine the threshold value of all the intercepted images, and creating a line graph of the threshold value of each image, as shown in
Firstly, determine the position of the rectangular frame where the Secchi disk is located when the Secchi disk is very blurred. At the critical position, the Secchi disk is very blurred, and the Secchi disk will be invisible as long as the Secchi disk is descended a short distance. The diameter of a standard Secchi disk is 20 cm, and the short distance is much smaller than the diameter of the Secchi disk. Therefore, recording the height of the rectangular frame where the Secchi disk is located in the previous image of the transition point of the Secchi disk image as h, the width as w, the coordinates of the upper left corner vertex as [x, y], and using [x, y] as the starting point to create a rectangular area with a width of 1.6*w and a height of 1.6*h. This can ensure that the Secchi disk in the late images will appear in this rectangular area.
Then, use the threshold change trend to determine the threshold. Linear fitting is performed on the threshold data before the threshold transition point, and the fitted curve is used to predict the threshold after the transition point, and the predicted value is used as the segmentation threshold of the images after the transition point. For the determination of the transition point, the present disclosure adopts the K-means clustering analysis method. More specifically:
Step one, obtaining differences of the thresholds of adjacent points, and taking the absolute value of all differences;
Step two, using the K-means function that comes with MATLAB to classify these differences and divide them into two categories;
Step three, calculating the mean value of each category of differences, and take the category of difference with a greater mean value. The position where the category of difference first appears is the position of the transition point.
Finding the transition point position, and making the original threshold curve, threshold difference curve, and threshold fitting curve as shown in
2-2-2) The critical threshold is determined by the background subtraction method based on the mean value; when the Secchi disk is completely invisible, the water is excluded from being segmented as Secchi disk.
In the present disclosure, the background subtraction method based on the mean value is used to obtain the background image. Each time the Secchi disk is segmented from the original image, the background image of the corresponding position is also segmented. Since the background images are all water, the background brightness values are in a normal distribution. Suggesting the mean value of the background brightness values is u, and the standard deviation is σ, and using u+2σ to replace the threshold value of the image to ensure that most of the parts will not be segmented when the Secchi disk is completely invisible in the image. This provides the basis for the determination of the critical position in step 2-3).
2-3) Determination of the critical position of the Secchi disk: using the classification network to determine the critical position of the Secchi disk; the specific steps are as follows:
2-3-1) Scaling up or down the segmentation results of all the white parts of the Secchi disk to a uniform size (e.g., 160*160*3). In the present disclosure, using the ResNet-18 network of MATLAB2020b to build a classification network to category the segmentation result of the Secchi disk. In this disclosure, the input of ResNet-18 is modified to a uniform size (e.g., 160*160*3 in this disclosure), and the parameters of each layer of the network are shown in Table 1.
2-3-2) Collecting more Secchi disk videos and create a dataset for classification network training. The data in this disclosure is divided into two categories, one for having Secchi disk, and the other without Secchi disk. Some of the dataset image is shown in
2-3-3) Using the trained classification network to determine the critical position of the Secchi disk.
2-3-4) After obtaining the critical position of the Secchi disk, performing correction on the critical position. Due to the perspective distance difference between human eyes and the camera, and the accuracy of the current cameras are getting higher and higher, there is an error between the eyes and the camera. In fact, the judgment distance between people, the judgment distance of each person in different states is also different. Therefore, a standard is needed, and the camera as a standard is undoubtedly relatively more objective. However, the error is relatively fixed. Providing the error is ΔD, then the actual critical position of the Secchi disk is the critical position of the Secchi disk+ΔD.
3) Recognition of the water ruler and calculation of the water ruler reading. In this disclosure, the Deeplabv3+ algorithm is used to identify and segment the water ruler at the position, then extracting the characters on the water ruler, classifying the characters, and calculating the water ruler reading to obtain the transparency value. More specifically:
3-1) Using the Deeplabv3+ algorithm to identify and segment the water ruler at the position; comprising the following steps:
3-1-1) Creating a data set; in this example; more than 120 water ruler images are collected as a training data set, and the Image Labeler function that comes with MATLAB2020b is used for data labeling. Some of the water ruler images and the labeling results are shown in
3-1-2) Using Deeplabv3+ for network training;
3-1-3) Using the trained Deeplabv3+ for water ruler segmentation.
3-2) Extracting the characters on the water ruler; including the following steps:
3-2-1) Tilt correction of water ruler.
The result of Deeplabv3+ segmentation is tilted by least squares estimation, and the calculation formula is shown in formula (1):
Let the coordinates of the point on the left or right edge of the water ruler be (xi, yi), where xi represents the abscissa, yi represents the ordinate, i ∈ [1, n], and calculate the slope of the water ruler.
3-2-2) Determine the edge position of the corrected water ruler, and then segment the water ruler from the original image.
3-2-3) Transpose and mirror the segmented water ruler to make the segmented water ruler rotate 90 degrees to the right to become a horizontal water ruler.
3-2-4) Use the im2bw function of MATLAB to binarize the segmented water ruler, invert the binarized image, and use the corrosion algorithm to disconnect the characters.
3-2-5) Use the regionprops( )function in MATLAB to mark all characters with a rectangular box, as shown in
3-2-6) Use K-means clustering analysis to separate large characters from small characters.
After the above steps, the valid characters (larger characters) to be obtained in this disclosure are still retained in the image, while the other characters (small characters) are either eroded or retained. In this disclosure, the K-means clustering algorithm is used to separate large characters from small characters. More specifically as follows:
Step one, calculating the area of the rectangular frame surrounding the character.
Step two, using the kmeans( )function in MATLAB to perform clustering analysis on the area of said rectangular frame, and divide the areas of rectangular frames into two categories.
Step three, calculating the mean value of each category. The category with the greater mean value is the large characters, and the large category having the large character is segmented. The large characters obtained by clustering are shown in
3-3) Classify the characters of the water ruler; in this disclosure, a CNN classification network is constructed to classify the characters of the water ruler, and the ResNet-18 network of MATLAB2020b is used as the classifier. A total of 10 classes are set, and each number from 0 to 9 belongs to one class. This disclosure uses the digital character data set in MATLAB, binarizes all the images in the data set, and scales them to a size of 64*64*1.
3-4) Calculate the reading of the water ruler to get the transparency value; more specifically as follows:
For a horizontal water ruler, the position of each full ten scale is located between each non-zero number and the number 0 immediately to the right of non-zero number. For example, the position of the mark 70 is between the character 7 and the character 0 to the right of the character 7. Let the non-zero number be k, the position of the right edge of the number k is recorded as x_right(k); the position of the left edge of the number 0 immediately to the right of the number k is recorded as x_left(k); then the position of each full ten scale is x(k) is calculated as shown in (2):
Marking the minimum non-zero number on the water ruler as i, then the calculation formula of the reading of the water ruler can be obtained according to the ratio relationship as shown in (3):
4) Output and display the reading of the water ruler.
Compared with the prior art, the advantages of the present disclosure are as follows.
The above technical solution proposes an image processing-based intelligent Secchi disk and water ruler identification technology, which combines traditional Secchi disk with image processing, deep learning and other technologies to accurately measure the transparency of water bodies and overcome the need for manual measurement. Due to subjective and objective factors in the process, there are errors in readings and inaccurate disc position judgment. The method in the present disclosure has high accuracy, stable and objective numerical values, and is not affected by individual subjective factors, and has high application value.
In order to make the objectives, technical solutions and advantages of the present disclosure clearer, the present disclosure will be further described below with reference to the embodiments and the accompanying drawings. Obviously, the described embodiments are some, but not all, embodiments of the present disclosure. Based on the described embodiments, all other embodiments obtained by those of ordinary skill in the art without creative efforts fall within the protection scope of the present disclosure.
Unless otherwise defined, technical or scientific terms used in the present disclosure should have the ordinary meaning as understood by one of ordinary skill in the art to which the present disclosure belongs. When used herein, “comprising” or “including” and similar words mean that the elements or things appearing before the word encompass the elements or things listed after the word and their equivalents, but do not exclude other elements or things. Words like “connected” or “connected” are not limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. Terms “up”, “down”, “left”, “right”, etc. are only used to represent the relative positional relationship, and when the absolute position of the described object changes, the relative positional relationship may also change accordingly.
Referring to
One object of the present disclosure is to provide a transparency detection method based on machine vision. Number of the camera in the in the present disclosure may be one or two. When the water is clear, one camera may be used. When the transparency of the water quality is turbid, and one camera is not sufficient to track the movement of the Secchi disk and the water ruler at the same time, two cameras may be employed. One of the two cameras is used for taking pictures of the Secchi disk, and the other for the water ruler. The two cameras shoot at the same time, imitating the action of a person measuring the transparency of the water body with the Secchi disk (looking at the Secchi disk while looking at the water ruler), and obtain a clearer video of the Secchi disk and the water ruler. The captured video is transmitted to a computer for processing directly or through the cloud. In order to achieve the above objects, the present disclosure includes two aspects. One of the two aspects is the judgment of the critical position of the Secchi disk, and the other is the identification of the water ruler. The schematic flowchart is shown in
S100, operating the Secchi disk to start the water transparency measurement, and turning on the camera for shooting.
S200, determining a critical position of the Secchi disk; the critical position of the Secchi disk refers to a position when the Secchi disk is barely visible. The step of determining the critical position of the Secchi disk includes the steps of preliminary segmentation of the Secchi disk, fine segmentation of the Secchi disk, and determination of the critical position of the Secchi disk. More specifically as follows.
S210, preliminary segmentation of the Secchi disk: segmenting the white part of the Secchi disk from the video image; specifically includes steps: determining the Secchi disk size, positioning the Secchi disk in the image, and determining the threshold value.
S211, determining the Secchi disk size: in this disclosure, the Faster RCNN algorithm is used to identify the Secchi disk size. First, frame extraction is performed on the video containing the Secchi disk. In order to reduce the calculation amount of subsequent image processing, one image is captured every 3 frames in this disclosure. Then, the captured image is stored in a fixed folder. For the first image in the folder, using the Faster RCNN algorithm to identify the Secchi disk; the collected data is labeled with the image labeler function in Matlab2020b; the result of Faster RCNN identifying the Secchi disk size is shown in
S212, Positioning the Secchi disk in the image.
The position and size of the rectangular frame are obtained after recognizing the image of the Secchi disk in the initial position using the Faster RCNN. All images are divided into upper and lower parts with an upper edge of the rectangular frame being the dividing line. In this disclosure, starting from an upper left corner of the lower parts of the image, the previously determined rectangular frame is moved on the entire image with a certain step size; each time the rectangular frame is moved, the content in the rectangular frame is intercepted, and the average brightness in the frame is calculated. Because the white part on the Secchi disk has high brightness, the location of the sampling rectangular frame with a high average brightness value is the location of the Secchi disk.
When the image contains background objects whose brightness is higher than or similar to that of the Secchi disk, the background subtraction method based on the mean value is used in this disclosure: taking the images in the last few seconds of the video, there is no Secchi disk in the last few seconds of the video, so the last 10 frames of images of the video can be mean and taken as the background image; subtracting the background image from the images containing the Secchi disk, so the background part of the images becomes nearly 0 after subtraction; and then the location of the Secchi disk can be determined by the previous method in the subtracted image.
S213, Determining the threshold.
After positioning of the Secchi disk, extracting the Secchi disk from the original image, as shown in
Step one, recording the brightness value of the entire image as set C; the brightness values are divided into two categories, one is recorded as set C1, and the other is recorded as set C2, and C1∩C2=0, C1∪C2=C.
Step two, taking the brightness value k, and putting the brightness values in the range of [0, k−1] into the set C1, and put the remaining brightness values into the set C2. The mean value of the brightness values in the set C1 is recorded as m1, and the ratio of the element number in the set C1 to the element number in the set C is recorded as p1; the mean value of the brightness values in the set C2 is recorded as m2, and the ratio of element number in the set C2 to the element number of the set C is recorded as p2; the mean value of the brightness values in the set C is recorded as m; the calculation formula of the inter-class variance is recorded as: g=p1*(m1−m)∧2+p2*(m2−m)∧2.
Step three: the brightness value k is taken from 0 to 255 one by one; each time a value is taken, the corresponding maximum inter-class variance is calculated. The value k corresponding to the maximum inter-class variance is divided by 255 to obtain the final threshold.
After determining the threshold, keep all the brightness higher than the threshold, and remove the others, and then switch the image back to the RGB space to obtain the white part on the Secchi disk.
S220, Fine segmentation of the Secchi disk. When the Secchi disk is almost invisible, the white part on the Secchi disk is segmented. In order to realize the fine segmentation of the Secchi disk, the present disclosure uses the following two steps:
S221, Determining the segmentation threshold of the Secchi disk and segmenting The Secchi disk when the Secchi disk is almost invisible.
According to step S210, intercepting a Secchi disk video, using the method of step 2-1) to determine the threshold value of all the intercepted images, and creating a line graph of the threshold value of each image, as shown in
Firstly, determine the position of the rectangular frame where the Secchi disk is located when the Secchi disk is very blurred. At the critical position, the Secchi disk is very blurred, and the Secchi disk will be invisible as long as the Secchi disk is descended a short distance. The diameter of a standard Secchi disk is 20 cm, and the short distance is much smaller than the diameter of the Secchi disk. Therefore, recording the height of the rectangular frame where the Secchi disk is located in the previous image of the transition point of the Secchi disk image as h, the width as w, the coordinates of the upper left corner vertex as [x, y], and using [x, y] as the starting point to create a rectangular area with a width of 1.6*w and a height of 1.6*h. This can ensure that the Secchi disk in the late images will appear in this rectangular area.
Then, use the threshold change trend to determine the threshold. Linear fitting is performed on the threshold data before the threshold transition point, and the fitted curve is used to predict the threshold after the transition point, and the predicted value is used as the segmentation threshold of the images after the transition point. For the determination of the transition point, the present disclosure adopts the K-means clustering analysis method. The K-means clustering analysis method is specified as follows.
Step one, obtaining differences of the thresholds of adjacent points, and taking the absolute value of all differences.
Step two, using the K-means function that comes with MATLAB to classify these differences and divide them into two categories.
Step three, calculating the mean value of each category of differences, and take the category of difference with a greater mean value. The position where the category of difference first appears is the position of the transition point.
Finding the transition point position, and making the original threshold curve, threshold difference curve, and threshold fitting curve as shown in
S222, determining the critical threshold by the background subtraction method based on the mean value; when the Secchi disk is completely invisible, the water is excluded from being segmented as Secchi disk.
In the present disclosure, the background subtraction method based on the mean value is used to obtain the background image. Each time the Secchi disk is segmented from the original image, the background image of the corresponding position is also segmented. Since the background images are all water, the background brightness values are in a normal distribution. Suggesting the mean value of the background brightness values is u, and the standard deviation is σ, and using u+2σ to replace the threshold value of the image to ensure that most of the parts will not be segmented when the Secchi disk is completely invisible in the image. This provides the basis for the determination of the critical position in S230.
S230, determining the critical position of the Secchi disk: using the classification network to determine the critical position of the Secchi disk. The specific steps for S230 are as follows.
S231, scaling up or down the segmentation results of all the white parts of the Secchi disk to a uniform size (e.g., 160*160*3). In the present disclosure, using the ResNet-18 network of MATLAB2020b to build a classification network to category the segmentation result of the Secchi disk. In this disclosure, the input of ResNet-18 is modified to a uniform size (e.g., 160*160*3 in this disclosure), and the parameters of each layer of the network are shown in Table 1.
S232, collecting more Secchi disk videos and create a dataset for classification network training. The data in this disclosure is divided into two categories, one for having Secchi disk, and the other without Secchi disk. Some dataset image is shown in
S233, using the trained classification network to determine the critical position of the Secchi disk.
S234, after obtaining the critical position of the Secchi disk, performing correction on the critical position. Due to the perspective distance difference between human eyes and the camera, and the accuracy of the current cameras are getting higher and higher, there is an error between the eyes and the camera. In fact, the judgment distance between people, the judgment distance of each person in different states is also different. Therefore, a standard is needed, and the camera as a standard is undoubtedly relatively more objective. However, the error is relatively fixed. Providing the error is ΔD, then the actual critical position of the Secchi disk is +ΔD. In the present disclosure, ΔD=−5 cm.
S300, identifying the water ruler and calculating the water ruler reading. In this disclosure, the Deeplabv3+ algorithm is used to identify and segment the water ruler at the position, then extracting the characters on the water ruler, classifying the characters, and calculating the water ruler reading to obtain the transparency value. More specifically as follows.
S310, using the Deeplabv3+ algorithm to identify and segment the water ruler at the position; comprising the following steps:
S311, creating a data set; in this example; more than 120 water ruler images are collected as a training data set, and the Image Labeler function that comes with MATLAB2020b is used for data labeling. Some of the water ruler images and the labeling results are shown in
S312, using Deeplabv3+ for network training;
S313, using the trained Deeplabv3+ for water ruler segmentation.
S320, extracting the characters on the water ruler. The step of S320 includes the following steps.
S321, Tilt correction of water ruler. The result of Deeplabv3+ segmentation is tilted by least squares estimation, and the calculation formula is shown in formula (1):
Let the coordinates of the point on the left or right edge of the water ruler be (xi, yi), where xi represents the abscissa, yi represents the ordinate, i ∈ [1, n], and calculate the slope of the water ruler.
S322, determining the edge position of the corrected water ruler, and then segmenting the water ruler from the original image.
S323, transposing and mirroring the segmented water ruler to make the segmented water ruler rotate 90 degrees to the right to become a horizontal water ruler.
S324, using the im2bw function of MATLAB to binarize the segmented water ruler, inverting the binarized image, and using the corrosion algorithm to disconnect the characters.
S325, using the regionprops( ) function in MATLAB to mark all characters with a rectangular box, as shown in
S326, using K-means clustering analysis to separate large characters from small characters.
After the above steps, the valid characters (larger characters) to be obtained in this disclosure are still retained in the image, while the other characters (small characters) are either eroded or retained. In this disclosure, the K-means clustering algorithm is used to separate large characters from small characters. More specifically as follows:
Step one, calculating the area of the rectangular frame surrounding the character.
Step two, using the kmeans( ) function in MATLAB to perform clustering analysis on the area of said rectangular frame, and divide the areas of rectangular frames into two categories.
Step three, calculating the mean value of each category. The category with the greater mean value is the large characters, and the large category having the large character is segmented. The large characters obtained by clustering are shown in
S330, Classifying the characters of the water ruler. In this disclosure, a CNN classification network is constructed to classify the characters of the water ruler, and the ResNet-18 network of MATLAB2020b is used as the classifier. A total of 10 classes are set, and each number from 0 to 9 belongs to one class. This disclosure uses the digital character data set in MATLAB, binarizes all the images in the data set, and scales them to a size of 64*64*1.
S340, calculating the reading of the water ruler to get the transparency value. more specifically as follows.
For a horizontal water ruler, the position of each full ten scale is located between each non-zero number and the number 0 immediately to the right of non-zero number. For example, the position of the mark 70 is between the character 7 and the character 0 to the right of the character 7. Let the non-zero number be k, the position of the right edge of the number k is recorded as x_right(k); the position of the left edge of the number 0 immediately to the right of the number k is recorded as x_left(k); then the position of each full ten scale is x(k) is calculated as shown in (2):
Marking the minimum non-zero number on the water ruler as i, then the calculation formula of the reading of the water ruler can be obtained according to the ratio relationship as shown in (3):
S400, Output and display the reading of the water ruler.
| Number | Date | Country | Kind |
|---|---|---|---|
| 202110579783.3 | May 2021 | CN | national |
This application is a continuation of PCT patent Application No. PCT/CN2021/130867, filed on 16 Nov. 2021, entitled “Transparency Detection Method Based on Machine Vision,” which claims foreign priority of Chinese Patent Application No. 202110579783.3, filed 26 May 2021 in the China National Intellectual Property Administration (CNIPA), the entire contents of which are hereby incorporated by reference in their entireties.
| Number | Date | Country | |
|---|---|---|---|
| Parent | PCT/CN2021/130867 | Nov 2021 | US |
| Child | 17662652 | US |