# Development of a Prototype Solution for Reducing Soup Waste in an Institutional Canteen
## 2 Prototype
### Software Component
#### 2.3.4 Ubuntu Local Server  
The local server is hosted on a virtual machine and performs various functions. Initially, it was created to receive the images from the Raspberry and run the detection and classification models as well as feature extraction. However, for prototyping purposes, it also has the function of hosting both the database and the web application, using Docker [9]. Figure 14: Flowchart of the Python script for capturing and transferring images on the Raspberry Pi. To automate the process, a Python v3.12.3 script was created involving all the functions needed to carry out the detection and classification, extract the features, calculate the volume, and insert the data into the database. Figure 15 shows a flowchart illustrating this process. The directory where the images coming from the Raspberry are stored is under watchdog, which means that when an image arrives, it is immediately processed. This functionality has been implemented using the Python library Watchdog Observer [42]. The first stage of the processing involves detecting and classifying bowls in the images. To do this, we adapted a project available online from the same author as the notebook used to train the model [29]. This detection script, explained in the flowchart in Figure 16, uses Python libraries such as Pytorch [43], Numpy [44], Cv2 [45], OS [46], YAML [47], and Matplotlib [48]. The \"load pre-trained detection model\" step iterates over the images in the directory, detecting and classifying bowls in each one. If the bowl is detected with a threshold higher than 0.8, the image is cropped by the bounding box and the next step is carried out: \"feature extraction\". If no bowl is detected, the image is deleted. The value set for the threshold must be considered acceptable, meaning that the model will only truly consider a bowl if it has a confidence of over 80%. In other words, if the model detects a bowl, but with a confidence of 10%, it will not be considered, and the bounding boxes will not be drawn. Figure 15: Flowchart of the main Python script for processing the images on the server. The next stage is \"feature extraction\". This is where the volume of wasted soup is calculated, i.e., the volume that remains in the bowl when the image of the tray is captured. The Python libraries Cv2, Numpy, Copy [49], and Math [50] were used to implement this functionality. The feature extraction process, illustrated in Figure 17, begins with loading the image and converting it to grayscale. A Gaussian blur [51] is then applied to reduce noise and facilitate edge detection. The \"HoughCircles function\" is used to detect circles and is performed using the Hough algorithm [52], which identifies the circles in the image. Once the circles representing the bowl and the soup have been detected, masks are applied to filter out the orange areas of the image, which represent the soup. The largest circle detected corresponds to the radius of the bowl, while the smallest circle represents the soup in the bowl. Figure 16: Flowchart of the Python script for detecting and classifying bowls in images. Figure 17: Image processing process for detecting circles. The \"calculate soup volume function\" used to calculate the volume of the soup uses the radius of the bowl and the soup calculated earlier. First, it converts the pixel values to centimeters and adjusts the smaller radius of the soup according to the scale of the bowl. Next, the volume is calculated using the formula for the volume of a truncated cone [53], as shown in Equation (4). The function returns the total number of liters (i.e., milliliters) of soup in the bowl. \[\text{V}=\frac{1}{3}\times\pi\times h\times\left(r^{2}+r\times R+R^{2}\right), \tag{4}\]  
where:  
* \(R\) is the radius of the base of the original cone (bottom surface);
* \(r\) is the radius of the top surface;
* \(h\) is the height of our truncated cone.