Hello,
recently, I have been working on a small side project with a colleague, who is involved in a research regarding sustainable technologies in buildings. He wanted autonomous control of the water level in a cylindrical separating funnel with water refill (when the water level drops below a certain threshold). An optical method was chosen to measure and analyze the water level and based on the measurements, a microcontroller was used to control a fish tank pump to refill the water.
To simplify the problem, I separated the design process into the following steps:
1. System setup
To position the separating funnel, a white plastic block was machined on the CNC as shown in Figure 1. The larger groove (running along the entire length of the block) was used to insert the separating funnel in such a way that the outside edge was co-planar to the front surface of the block (important for perspective projection calibration - homography). The four smaller holes were drilled symetrically (also on CNC) and are used for calibration of the perspective distortion (see 2. System calibration).
Figure 1. The model of the plastic block for separating funnel positioning.
The selected camera was a high-end webcamera Logitech C920, with full HD capabilities and Zeiss optics. It's DirectShow compliant and capable of adjusting numerous camera parameters (exposure, focus, contrast, etc...). The characteristics of the camera are:
Resolution: 2304 x 1536 pix
Sensor size:4.80mm x 3.60mm
Focal length: 3.67mm
The dimensions of the plastic block are 150 mm x 150 mm x 60 mm (width, heigth, depth respectively). A rough calculation gives the approximate distance of the camera from the plastic block:
D_H = HFOV * F / SENSOR_WIDTH = 150 mm * 3.67 mm / 4.80 mm ≈ 115 mm
D_V = VFOV * F / SENSOR_HEIGTH = 150 mm * 3.67 mm / 3.60 mm ≈ 150 mm
Taking the larger value, the minimum distance is approximatelly 150 mm. The image resolution along the heigth of the sensor is:
IMAGE_RESOLUTION_V = NOofPIXELS_V / VFOV = 1536 pix / 150 mm ≈ 10 pix/mm.
Since the water level is measured in the vertical direction, we could rotate the camera by 90 degrees to obtain even higher resolution (≈ 15 pix/mm). In this case the camera is not rotated, since the resolution of 10 pix/mm is enough. Remember that the theoretical calculations are only used as a guideline for the camera setup.
The lighting (incandescent light bulb) was positioned on the left and the right side of the camera. There were some interference problems with the flickering due to the polarity changes of the power supply. This was reduced by modifying the exposure time of the camera.
A microcontroller (Arduino Uno) was used to drive the fish tank pump via a relay. So, when the water needs to be refilled (detected by the optical system), a signal is sent to the microcontroller using the RS232, which in turn controls the relay. When the water level reaches a defined upper threshold, the pump is disabled.
2. System calibration
In order to achieve accuracy of measurements, the optical system needs to be calibrated. Eventhough the lens distortion is not significant, the intrinsic camera calibration was still performed using a grid dot pattern. A calibration interface was developed for this purpose (see Figure 2a).
Figure 2. The camera calibration interface; intrinsic camera calibration (a) and perspective camera calibration (b).
After the intrinsic camera calibration, the plastic block with the separating funnel and the camera are attached to a pedestal in such a way that the relative position between them is constant. This is important for the perspective calibration, which is based on plane-to-plane homography. At least four corresponding points are needed to solve the homography problem (or more for minimization approach). For this reason, the four drilled holes (see Figure 1) are used as the anchor points for perspective distortion correction. Their real-word distance (center to center) is known, so they need to be detected on the image also. Hough circle detection is used to extract the image coordinates of the holes centers and finally the perspective distortion is corrected.
3. Measurements
The measurements are based on the edge detection of water level and the separating funnel scale at every 20 mL. In the first step (performed only once), the horizontal lines of the scale are detected and the heigth-to-volume conversion function is obtained (using a 3rd order polynomial fit). This makes it possible to calculate the volume of the liquid based on the reference scale of the separating funnel. Figure 3 shows the measurement interface (a part of the interface on the left is missing due to the image croping). Along the two vertical lines (green and black) the edge detection is performed. The black line is used for water level detection and the green line for the detection of the separating funnel scale at 20 mL interval. The shorter horizontal lines (red) are the upper and the lower threshold, which are used to consequently turn on/off the water pump. The shortest horizontal line (white) shows the detected water level.
Figure 3. The water level measurerment interface.
The image shown in Figure 3 is not rectified (without perspective correction), since this happens in the background only on the relevant pixels. The control "PumpAuto" is used to enable automatic water refill. If necessary, the water can also be manually refilled by the "PumpManual" control. The error indicator shows the average root mean square deviation of the distances between the four holes (using known distance as a reference, i.e. 110 mm).
Lastly, a consumer-producer architecture is used to save the water level (volume) at discrete time intervals along with the current time.
The application has been running for about a month now and it performs robustly and reliably so far. The colleague seems to be happy and I get to write another post after a long time .
P.S.: The user interfaces could be a little neater, but considering that this was just a side/hobby project, it turned out pretty well I guess.
Best regards,
K
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.