This is a bit of a funny question but...

We have a web-cam in our office kitchenette focused at our coffee maker. The coffee pot is clearly visible. Both the location of the coffee pot and the camera are static. Is it possible to calculate the height of coffee in the pot using image recognition? I've seen image recognition used for quite complex stuff like face-recognition. As compared to those projects, this seems to be a trivial task of measuring the height.

(That's my best guess and I have no idea of the underlying complexities.)

How would I go about this? Would this be considered a very complex job to partake? FYI, I've never done any kind of imaging-related work.



You're looking for edge detection. But you only need to do it between the brown/black of the coffee and the color of the background behind the pot.

Ignacio Vazquez-Abrams

There is the Python Image Library which can do edge detection. But I'm not a Python user :).

+2  A: 

First do thresholding, then segmentation. Then you can more easily detect edges.


You should turn this question into a school assignment for an IT student. Most IT schools teach Computer Vision. Asking the question here is funny, getting a student and a teacher researching the subject would be hilarious!

Symen Timmermans
+2  A: 

Steps that I'd try:

  1. Convert the image in grayscale.
  2. Binarize the image, and leave only the coffee. You can discover a good threshold manually through experimentation.
  3. Blob extraction. Blob's area (number of pixels) is one way to calculate the height, ie area / width.
Nick D
+4  A: 

Since the coffee pot position is stationary, get a sample frame and locate a single column of pixels where the minimum and maximum coffee quantities can easily be seen, in a spot where there are no reflections. Check the green vertical line segment in the following picture:

The easiest way is to have two frames, one with the pot empty, one with the pot full (obviously under the same lighting conditions, which typically would be the case), convert to grayscale (colorsys.rgb_to_hsv each RGB pixel and keep only the v (3rd) component) and sum the luminosity of all pixels in the chosen line segment. Let's say the pot-empty case reaches a sum of 550 and the pot-full case a sum of 220 (coffee is dark). By comparing an input frame sum to these two sums, you can have a rough estimate of the percentage of coffee in the pot.

I wouldn't bet my life on the accuracy of this method, though, and the fluctuations even from second to second might be wild :)

N.B: in my example, the green column of pixels should extend to the bottom of the pot; I just provided an example of what I meant.

That looks so good I'm going to get some coffee right now.
Paul Nathan
@Paul: sure, as if you needed an external stimulus to have some coffee. Take responsibility of your addictions, sir! :)
  • make pictures of the pot with different levels of coffe in it.
  • downsample the image to maybe 4*10 pixels.
  • make the same in a loop for each new live picture.
  • calculate the difference of each pixels value compared to the reference images.
  • take the reference image with the least difference sum and you get the state of your coffe machine.

you might experiment if a grayscale version or only red or green might give better results.

if it gives problems with different light settings this aproach is useless. just buy a spotlight for the coffe machine, or lighten up, or darken each picture till the sum of all pixels reaches a reference value.