Arduino + WebCam = VolumetriaArduino + WebCam = Volumetry
Um dos projectos que tenho trabalhado ocasionalmente nos ultimos meses foi arranjar maneira de medir volumes com material "low-cost"!
Pensei no desafio e comecei a meter mãos ao trabalho e consegui resultados surpreendentes a usar um webcam comum e um arduino com um sensor.
Para começar vamos falar do hardware:
- Arduino + Sharp Distance Sensor GP2Y0A02 (20-150cm) : Devo dizer que pensei que era o mais simples mas falhei redondamente.
Para conseguir resultados aceitaveis (cerca de 1 centimetro de desvio em distancias perto do limite do sensor) tive de seguir um conjunto de procedimentos manhosos isto porque o sensor tende a retornar montes de ruido e assim não temos resultados precisos.
Primeiro faço 10 leituras do valor e determino a media, seguindamente determinamos o limite superior e inferior de valores a partir desta primeira media, exluimos os valores que ultrapassam este valor capturamos mais uns 10 valores e fazemos a media de tudo.
Devo dizer que isto resultou muito bem
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; }
Para conseguir volumetria usei a biblioteca Emgu e uns quantos filtros para conseguir encontrar os contornos do objecto com base numa mascara. Ou seja temos de ter uma mascara do ambiente de fundo para poder fazer a exclusão do que ja la estava e ficarmos apenas com o novo objecto na imagem. Usamos uns quantos truques de image processing, uns calculos trigonometricos e voilá aqui esta o resultado
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