title: How to detect water level in a transparent container?
body: <p><a href="https://i.stack.imgur.com/71qFE.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/71qFE.jpg" alt="Original image"></a></p>
  
  <p>I am using opencv-python library to do the liquid level detection. So far I was able to convert the image to gray scale and applying canny edge detection the container has been identified. </p>
  
  <pre><code>import numpy as np
  import cv2
  import math
  from matplotlib import pyplot as plt
  from cv2 import threshold, drawContours
  
  
  img1 = cv2.imread('botone.jpg')
  kernel = np.ones((5,5),np.uint8)
  #convert the image to grayscale
  imgray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
  edges = cv2.Canny(imgray,120,230)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/e8Ts9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e8Ts9.png" alt="I applied different threshold effect to see which edge detection is better. Apparently, the final edge detection was chosen for directly on gray-scale image."></a></p>
  
  <p>I need to know how to find water level from this stage.
  Should I try machine learning, or is there any other option or algorithm available?</p>
  
  <p>I took an approach of finding out the horizontal line in the edge detected image. If the horizontal line crosses certain threshold I can consider it as level.But the result is not consistent.</p>
  
  <p>I want to know if there are any other approaches i can go with or white papers for reference?</p>