Skip to main content
. 2019 Nov 28;19(23):5230. doi: 10.3390/s19235230
Algorithm 3 Water Detection Algorithm
  • 1: 

    Convert an image to grayscale, use bilateral filter, and blur the image;

  • 2: 

    Detect edges using Canny edge detector and find contours;

  • 3: 

    For each contour:

  • 4:      

    Calculate length of the contour (using curve approximation);

  • 5:      

    Calculate the contour area;

  • 6:      

    When the length is less than 100 or the area is less than 30, discard the contour;

  • 7: 

    Calculate average length of the remaining contours and find the longest contour;

  • 8: 

    Return water when number of contours is less than 3, the maximum length is less than 250, and average length is less than 40.