Arduino + Webcam = Volumetry

One of the projects I have worked occasionally in recent months was finding a way to measure materials volumes with “low-cost”! I thought about the challenge and started to get down to work and got amazing results using an ordinary webcam and a sensor with an Arduino. To begin with let’s talk about hardware: – Arduino + Distance Sensor Sharp GP2Y0A02 (20-150cm): I must say I thought it was the easiest but failed miserably. To achieve acceptable results (about 1 cm of deviation in distances near the limit of the sensor) I have had to follow a set of procedures that’s tricky because the sensor tends to return lots of noise and so we do not have accurate results. First I do 10 readings and determine the average value, then determine the upper and lower limit values ​​from this first average, capture another 10 and make the average ​​of all the values. I must say it worked really well

float GetAverage(float * _values, uint8_t size)
{
	float avg = 0;
	for(int i = 0; i< size; i++)
	{
		avg += _values[i];
	}
	avg = avg / size;

	float setMax = avg * 1.15;
	float setMin = avg * 0.85;
	float precisionAvg;
	int counter = 0;
	for(int i = 0; i < size; i++)
	{
		if((setMin < _values[i]) && (_values[i] < setMax))
		{
			precisionAvg += _values[i];
			counter++;
		}
	}
	return precisionAvg / counter;
}

To achieve volumetric measuring I used Emgu library and a few filters  to find the contours of the object based on a mask. In other words we must have a mask from the background in order to make the exclusion of what it already was there and just stay with the new object in the image. We use a few tricks of image processing, some trigonometric calculations and voila here is the result

Leave a Reply

Your email address will not be published. Required fields are marked *