scieee AI-readable full text Open interactive document viewer

Grape cluster and peduncle 3D localization

Torres Rodríguez, Iván Jesús

Full text

Master’s Thesis Double Master’s degree in Industrial Engineering and Automatic Control and Robotics Grape cluster and peduncle 3D localization Author: Iván Jesús Torres Rodríguez Director: Alberto Sanfeliu Cortés Call: Juny 2022 Escola Tècnica Superior d’Enginyeria Industrial de Barcelona Abstract This Master’s Thesis is part of a larger European project called CANOPIES. This project is a H2020 European Project, whose aim is to tackle the problem of precision agriculture. As the final objective of the project, the agricultural workers and the robot will be able to work together to achieve different agronomic tasks such as harvesting or pruning table grape vineyards. This project presents many complexities from different fields: mechanics, computer vision, human-robot interaction and control. Within each field there are also different problems, this Master’s Thesis addresses one of the problems in the field of computer vision, which is obtaining the depths of the peduncles. This measurement is necessary for the robot to perform pruning or harvesting tasks, for example. Working with depth in the field of robotics is a crucial problem as more and more robots are being designed to be used in dynamic 3D environments. To tackle this problem, different techniques are explored, from classical computer vision techniques as triangulation to modern approaches based on neural networks. The developed methods are prepared to work under different circumstances. For instance, a method allows estimating the depth of the peduncle when it is only possible to see the cluster is described. Having depth estimation methods that work with different sources of data adds robustness to the system. The information from the different methods is mixed to improve the estimation of the depth. All developments were tested in the laboratory using a mock-up that simulates the field environment. The performance achieved by the method proposed fulfils the requirements of the project. The depth estimation after mixing the data yields an error that is generally below 0.5 cm, which is enough for the requirements of the robot, whose tolerance is 3 cm. Acknowledgements This work was supported by the EU project CANOPIES (H2020-ICT-2020-2-101016906). I want to thank Alberto Sanfeliu who has helped me in this and other projects since I started the Masters. I also want to thank Gabriel Coll for all the work he has done to make the project possible and for the support he has given me. I want to thank the IRI team of the mobile robotics laboratory. Especially to the people who helped labeling the dataset necessary for the segmentation: Iván Del Pino, Javier, Joan, José Enrique, Nicolás, Óscar, Stevedan and Xavier. Thanks also to my friends, especially to David and Nicolás for always being willing to help. Finally, I would like to thank my family for the unconditional support they have always given me. Contents 1 Introduction 11 1.1 Scope .......................................... 12 1.2 Objectives........................................ 13 1.3 Outline ......................................... 13 2 State of the art 15 2.1 Agricultureworks.................................... 15 2.2 Imagesegmentation .................................. 16 2.3 Depthmethods..................................... 17 3 Problem description 19 4 Depth estimation methods 23 4.1 Introduction....................................... 23 4.2 Triangulation ...................................... 24 4.2.1 Theoretical explanation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 4.2.2 Pixels width computation . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.2.3 RANSACFiltering............................... 32 4.2.4 Algorithmindetail............................... 33 4.2.5 Implementation................................. 36 4.2.6 Results ..................................... 36 4.3 Peduncle estimation from cluster . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4.3.1 Theoretical explanation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 4.3.2 Algorithmindetail............................... 42 4.3.3 Implementation................................. 43 4.3.4 Results ..................................... 44 4.4 Densereconstruction.................................. 45 4.4.1 Mixing neural net data with real depth . . . . . . . . . . . . . . . . . . . . 46 4.4.2 Theoretical explanation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 4.4.3 Algorithmindetail............................... 48 4.4.4 Implementation................................. 50 5 6 Memory 4.4.5 Results ..................................... 51 4.5 Directmeasure ..................................... 53 4.6 XandYcomputation ................................. 55 5 System architecture 57 5.1 Introduction....................................... 57 5.2 Systemstructure .................................... 58 6 User interface 63 6.1 Introduction....................................... 63 6.2 Interacttools ...................................... 64 7 Experimental testing 67 7.1 Gettingthedata .................................... 67 7.2 Mixing methods to get depth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 7.2.1 Methods for data fusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 8 Conclusions 73 9 Future work 75 10 Economic Cost and Environmental Impact 77 10.1Economicanalysis ................................... 77 10.2Environmentalimpact ................................. 78 List of Figures 3.1 Elementsofthevineyard................................ 20 3.2 Flat-roofsystem .................................... 21 3.3 Ytrellissystem..................................... 21 3.4 Double-roofsystem................................... 21 4.1 Occlusion of the peduncle corresponding to the right cluster . . . . . . . . . . . . 24 4.2 Segmented image with small blob . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 4.3 Obtained skeleton of the peduncle . . . . . . . . . . . . . . . . . . . . . . . . . . 29 4.4 Diagram of PCA method to compute width of peduncle in pixels . . . . . . . . . 30 4.5 Masksusedasfilters .................................. 31 4.6 Diagram of template matching method to obtain width of peduncle in pixels . . . 31 4.7 Plot of the filtered points using RANSAC . . . . . . . . . . . . . . . . . . . . . . 32 4.8 Setup for the experiments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 4.9 Distances obtained with the triangulation method . . . . . . . . . . . . . . . . . . 38 4.10RGBimagefromacluster............................... 39 4.11 Segmentation from the RGB image . . . . . . . . . . . . . . . . . . . . . . . . . . 39 4.12 3D points from a cluster . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 4.13 3D reconstruction only with the first filter . . . . . . . . . . . . . . . . . . . . . . 40 4.14 3D reconstruction after using the z-score to filter . . . . . . . . . . . . . . . . . . 41 4.15 Final 3D reconstruction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 4.16 Diagram of the peduncle from cluster method . . . . . . . . . . . . . . . . . . . . 44 4.17 Results from 20 to 90 cm of the peduncle from cluster method . . . . . . . . . . . 44 4.18 Results from 35 cm to 90 cm of the peduncle from cluster method . . . . . . . . . 45 4.19 Depth analysis with boosting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.20 Depth analysis with MiDaS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 4.21 Dense reconstruction flux diagram . . . . . . . . . . . . . . . . . . . . . . . . . . 51 4.22 Dense reconstruction results from 20 to 90 centimeters . . . . . . . . . . . . . . . 52 4.23 Dense reconstruction results from 35 centimeters to 90 centimeters . . . . . . . . 52 4.24 Direct measure from 20 centimeters to 90 centimeters . . . . . . . . . . . . . . . . 54 4.25 Direct measure from 35 to 90 centimeters . . . . . . . . . . . . . . . . . . . . . . 54 7 Chapter 2 State of the art Before going deeper into the work developed in this Master’s Thesis, in the chapter is given a brief survey of the approaches used to obtain or estimate depth using video cameras. It is important to remark that depth estimation has not been deeply analyzed in the vineyard field. The fact that the whole process is complex in the case of depth estimation in agrifood, is reflected in the state of the art, where there are few publications. This chapter briefly analyses the works done in the field of automatic agriculture, but it also presents some works done in the detection and depth fields. 2.1 Agriculture works In this case, the analysis will be focused on the perception and localization problem. In [4], it is described a technique that is used in this project. The image is segmented with Mask R-CNN [5] and once the grape is detected, a pointcloud (depth information) is extracted and filtered. A Random Sample Consensus (RANSAC) technique is used to fit the pointcloud to a cylinder and then, the depth of the peduncle is obtained. It is important to notice that this work was applied to grapes, but there are other projects done for other fruits. The way of facing the problem could be similar for different fruits, but it is important to take into account the particularities of the fruit analyzed. For instance, in [6], the work is done with sweet pepper. In [7], the fruit used to perform the study was the strawberry. Whereas others such as [8] work with apples. In the field, there are many problems that appear and need to be studied in detail in the process of validating a method. In this sense, the illumination, the overlapping or the different colors of the fruit can cause problems. In fact, some papers like [9] study the non-structured environment where the robot would have to work. To address the problem of detection, that is the base for localization, the preferred solutions tend to use convolutional neural nets. This is because they have good capabilities for extracting features and generalize well in these non-structured environments. There are many examples of approaches where different nets have been used. In [10], the architecture of the Faster R-CNN 15 16 Chapter 2 – State of the art [11] is used for detecting different fruits: apples, oranges and mangoes. The convolutional and pooling layers of the base architecture were improved to get a better detection of the fruits. Another approach was the one taken by [12] that developed a new Faster R-CNN by merging multiple classifier fusion strategies. The problem of the methods described above is that they use bounding boxes and they are not able to extract contours and shape information. To face this problem one approach is presented in [13] that used a convolutional neural network called SegNet [14], to segment branches and apple tree trunks from RGB-D images. In terms of works done to deal with 3D information in agriculture there are some that are directly focused on 3D localization of the fruit, and others that work on tracking and three-dimensional association such as [15]. In [16], they present methods for the detection of sweet peppers and managing 3D information to be able to crop the peduncle. It is a similar problem to the one faced in this Master’s Thesis. However, it is important to notice that the peduncles of the peppers are bigger than the ones of the grapes. This makes it easier to obtain the peduncle location directly from the RGB-D camera. 2.2 Image segmentation This problem consists in being able to identify objects on an image. This means knowing the location in the image and the type of object, commonly known as a class. Inside this area, there are several approaches, object detection is one of them. Its goal is to obtain bounding boxes in the areas where an object is located with its corresponding class. However, the used approach in this project is based on instance segmentation that provides an individual mask with the class of each object located in the image. One of the best known methods to do this, is using Mask-RCNN [5] which is a method used in some approaches previously seen. This net is able to perform instance segmentation, bounding box detection and it is also able to perform human pose estimation. Nevertheless, the important performance in this case is related to instance segmentation where the AP (Average Precision) using mask IoU (Intersection over Union) moves between 33.1 and 37.1 depending on the backbone. Other work in this field is the Mask scoring RCNN [17]. This method improves Mask-RCNN, it gives an AP of 35.4 when Mask-RCNN provides an AP of 34.3 on COCO 2017 test-dev with ResNet-101 backbone in both cases. Apart from the Region Based Convolutional Neural Networks (RCNN), there are other architectures for solving the problem of instance segmentation, one of them is YOLACT [18] that uses Convolutional Neural Networks (CNN). The main advantage of this approach is that is able to run at 30 FPS (Frames Per Second) on a Titan Xp graphic card. In terms of AP, the results are worse than the ones obtained using Mask-RCNN. YOLACT gives an AP of 29.8 using R- 101-FPN backbone, whereas Mask-RCNN provides an AP of 38.3 for the same backbone. The comparison of the frame rate is that YOLACT can get 30 FPS, but Mask-RCNN can only obtain Grape cluster and peduncle 3D localization 17 8.6 FPS. 2.3 Depth methods To address the problem of depth estimation, there are different ways of proceeding. One is using a specific sensor such as a stereo camera or a LIDAR, but there is another solution based on Neural Nets (NN). The most recent investigation field is getting depth from monocular images. There are methods that can estimate metric depth from monocular images [19]. This method has an absolute relative error of 0.115 on KITTI dataset. The problem with these kinds of datasets is that they do not generalize well, in this case, the net only works for the autonomous driving cars case. What is more, it only works fine if the camera is located at the front. There are some solutions to the driving problem that provide metric depth, this is possible thanks to the big amount of data available nowadays from LIDARs and depth cameras located on cars. However, this is not the case for problems in less studied environments like vineyards. For cases like this one, there are more general approaches that work with relative depth. One interesting architecture is the one known as MiDaS [20]. This method is based on the visiontransformer model for depth estimation presented in [21]. This solution has different models that could be used depending on the available hardware. The one used is the "version 2 large" that gives an absolute relative error from 0.1246 to 0.3270 depending on the dataset used. This solution provides relative depth maps. The great advantage that it presents for the case of study, it is that it has been trained with different datasets so it is able to provide results for the vineyards case. Moreover, it is able to run at 50 FPS for an RTX3090, which is fast enough for general applications. Apart from this network, another interesting one is the one presented in [22]. This method is based on MiDaS, but is able to output relative depth maps with a higher resolution. This is thanks to the observed effect of the input image resolution in the resolution of the output depth map. What is observed is that using a lower resolution for the input image makes that many details are lost. The use of high resolution provides more detail on the depth map, but the structural consistency decreases. Knowing this, the method tries to find the optimal relation between detail and structural consistency. The fact of getting detailed depth maps could be a great advantage for segmentation and may help in the image processing. However, the results in terms of depth are more inconsistent than the ones from MiDaS. In the supplementary material [23] of the paper, in section A, the authors wrote "We notice a discrepancy between the apparent visual improvement gained from depth refinement techniques and numerical results based on common metrics". This is clearly appreciated in some comparisons presented on the supplementary material, for instance, for Ibims1 dataset [24] MiDaS gets an absolute relative error of 2.0325 while Boosting gets 2.0510. Chapter 3 Problem description Nowadays, the table grape is one of the most requested fruits over the world with around 28 millions tons yearly harvested. This is a key fact to understand the big demand of this fruit. Although it is a demanded fruit, the agricultural sector is experiencing a shortage of workers. This implies that countries like US and Australia have suffered a loss of product as there were not enough workers to cover the demand. The field of robotics and automation could be of great help for these cases. However, a case like the one studied is not much developed. Here is where CANOPIES proposes a novel integrated system where farmworkers can safely collaborate with robots. The three main technologies defining precision agriculture that are explored in CANOPIES are the following: •Collect data in the vineyard with the maximum possible resolution. •Analyse this data. •Perform harvesting and pruning operations with great control and precision by using proper equipment. This Master’s Thesis will be related to all the points, the first thing is to collect data where the depth camera is going to be used, so it is important to define which data will be recorded. Then, the data is analysed to see how to use it to develop the task of this Thesis, which is the localization of the peduncle. The point involving the movement of the robot is the least related to this project, because this Thesis will not study in detail the movements to perform, but it will provide the information necessary for the planning module. There are a lot of varieties of grapes in the world. In this project the ones that are studied are the European grapes (Vitis Vinifera), this is the most important species of the family Vitacae. Two other commercial species are Vitis Labrusca (American grapes) and Vitis Rotundifolia (Muscadine grape). 19 20 Chapter 3 – Problem description Now, some photos are shown to understand the situation of the grapes in the field, that varies according to the structure used. In Figure 3.1 it can be seen the different elements of the vineyard. On these photos it can be seen that the detection and processing of the distance will be hard. This is due to the small size of the peduncles and the difficulty to identify them, since the whole image has a similar color. Figure 3.1: Elements of the vineyard There are different structures to support the vineyards, the most common ones are the Flatroof Pergola system, Y trellis system and Double-roof system. In Figure 3.2 it can be seen the Flat-roof system. In this case, the localization of the peduncle is hard, due to the homogeneous colors. In Figure 3.3 the Y trellis system is shown. This method allows the leaves to cover the peduncles quite easily. Finally the double-roof system is in Figure 3.4. Grape cluster and peduncle 3D localization 21 Figure 3.2: Flat-roof system Figure 3.3: Y trellis system Figure 3.4: Double-roof system These different structures show how differently the clusters can be distributed. This emphasises the importance of doing a method as general as possible. Chapter 4 Depth estimation methods In this chapter, the different studied methods for depth estimation will be described. 4.1 Introduction To address the problem of depth in real world, it is common to use stereo cameras or LIDARs. In both cases, the resolution and architecture of the sensor are crucial to detect small objects and estimate the depth. LIDAR sensors have different resolutions, typically 4, 16, 64, 128 or 256 beams. For the detection of vine peduncles, these resolutions are not enough. Moreover, they are very expensive. Stereo cameras are a good solution for depth estimation as they are cheaper than LIDARs. This type of cameras have more depth points than a 16 beams LIDAR. However, the resolution is not enough when addressing a problem like the peduncle depth measurement. Some trials were done with a RealSense D435i camera, but due to the reduced width of the peduncles and the resolution limitations of the stereo cameras only a few depth points of the peduncle could be obtained. Sometimes the direct measure is enough for getting a good estimation, but to make the system robust, additional methods have to be implemented. Using a stereo camera the minimum distance of measurement is a key issue. For the Realsense, the ideal range goes from 30 centimeters to 3 meters. However, when it is needed to be closer than 30 centimeters, alternative methods to compute the depth of the peduncle must be implemented. We made a study in the field of different sensors, and we realized that the LIDAR sensor gave very poor results and low resolution, while the D435i stereo camera had good resolution and also provided an image. For this reason, it was chosen for estimating the depth of the peduncle. Apart from obtaining more depth points, this sensor also provides an image that can be used to detect the objects of interest on the image, as well as the alignment of the object. It is important to notice that the environment where the robot is going to be used is complex, this means that the fields are not prepared to perform the image processing tasks. This could 23 30 Chapter 4 – Depth estimation methods Segment image Filter small blobs Compute the skeleton Sample the skeleton Crop around each point from the sampled ones Compute eigenvalues for the points of the skeleton inside the sampling box Select eigenvector with higher eigenvalue Expand in perpendicular direction until leaving the mask Figure 4.4: Diagram of PCA method to compute width of peduncle in pixels This approach is time consuming. Thus, a different approach was implemented to see if the results improved and the time taken by the algorithm was reduced. The first thing when analysing a point, is performing a crop around the point of interest, as done in the previous method. Then, the concept of this second approach is to generate patterns with lines that go through the point of analysis with different angles. An example of the created masks can be seen in Figure 4.5. Each mask is multiplied element-wise by the performed crop around the point. After each multiplication, the number of pixels with value one are counted and saved. The line that best fits the direction of the peduncle has the highest number of pixels. Now, that the angle is known, it is only necessary to count the pixels in the perpendicular direction until leaving the mask. This method proved to work faster than the previous one and the results improved. Therefore it will be used in the final implementation. Figure 4.6 shows the diagram to obtain the width of the peduncle using this method. Grape cluster and peduncle 3D localization 31 Figure 4.5: Masks used as filters Segment image Filter small blobs Compute the skeleton Sample the skeleton Create filters Perform template matching on sampled points taking into account the skeleton Get best template to know the angle of the peduncle Expand in perpendicular direction until leaving the mask Figure 4.6: Diagram of template matching method to obtain width of peduncle in pixels 32 Chapter 4 – Depth estimation methods 4.2.3 RANSAC Filtering From the sampling process there are many points obtained with their corresponding width, so, it was necessary to apply a filtering technique that could remove the outliers. To do this, Random Sample Consensus (RANSAC) was applied. From every width corresponding to a point, the coordinate x and y on image is also known. The strategy to filter the points is to project them on 2D removing the x coordinate. As the peduncles are straight, the expected output of projecting the points into a yz plane is a line. The RANSAC method searches the line that best fits the data and returns only the valid points without outliers. The result of applying the method to a set of points from a peduncle is shown in Figure 4.7. Figure 4.7: Plot of the filtered points using RANSAC The pseudocode corresponding to this algorithm is presented in Algorithm 1. Grape cluster and peduncle 3D localization 33 Algorithm 1 RANSAC Algorithm Being: i the number of iterations Being: k the number of inliers Being: margin the distance margin to count a sample as inlier Set: max_trials 100 while i < max_trials do Select a random number of data points Adjust the previous sample to a line D←distance of data points to the line for j in range(len(D)) do ▷Count how many points are within a predefined distance to the line →Inliers if D[j]<=margin then k[i]=k[i]+1 ▷Record number of inliers end end i++ end Keep line with highest number of inliers 4.2.4 Algorithm in detail Having seen the idea behind this method, the algorithm will now be detailed. The first function implements Equation 4.3 as seen above. Then, there is a function to process the received masks, which is shown in Algorithm 2. 34 Chapter 4 – Depth estimation methods Algorithm 2 Process and triangulate Input: im ←image to process Input: imshape ←image dimensions Input: masks ←(height ×width ×n) structure with the masks of the clusters and peduncles detected, being n the number of detected objects Input: ids ←array of classes of the detected objects ▷If the id of an object is 1 it is a peduncle, if the id is 2 it is a cluster Input: scores ←array of scores of the detected objects Output: index ←array of indexes of the processed objects Output: depths ←array of depths of the processed objects Being: n_sz an integer to define the size of the filter Being: ang_inc an integer to define the angle increment for the filter n_sz = 20 ang_inc = 5 flts ←create_filters(n_sz,ang_inc) ▷The filters for detecting the angle of the peduncles that are presented in Figure 4.5 f←getRosMsgs(camera_info) ▷The focal length is obtained from the information of the camera of ROS for i < length(scores)do if ids[i] == 1 then index.append(i) mask ←masks[i] mask ←FilterBySize(mask,100) width_list, pts ←width_computation(mask,flts,n_sz,n_points = 100)▷Compute width of the peduncles, pts is the x and y coordinates of each point filtered_data ←RANSAC(pts[:,0],pts[:,1],width_list) ▷To apply RANSAC the points are projected to yz plane mean_width ←mean(filtered_data) depth_aux ←triangulate(mean_width) ▷Apply Equation 4.3 depths.append(depth_aux) end end From the previous algorithm, the function FilterBySize is simple so it will not be described in detail. This function only checks the size of each blob of a mask and if it is smaller than the given value, the blob is removed. Apart from that, the create_filters and width_computation functions are detailed below in Algorithm 3 and 4. Grape cluster and peduncle 3D localization 35 Algorithm 3 Width computation Input: mask ←mask with an object Input: flts ←array of filters Input: sz ←size of the filter Input: n_points ←maximum number of points to get from the sampling process of the skeleton Output: w_list ←array of widths of the peduncle Output: pts ←array of points sampled from the skeleton skel ←skeletonize(mask) ▷Obtain the skeleton from the mask Being: pts the points obtained from the sampling process pts ←samplePoints(skel, n_points) ▷Function to get the n_points closer to the center for i<n_points do w←compute_width(mask,skel,pts[i],sz,flts) if w>0 then w_list.append(w) end end Function compute_width(mask,skel,pt, n_sz,flts): neigh ←skel[pt[0]-n_sz//2:pt[0]+n_sz//2,pt[1]-n_sz//2:pt[1]+n_sz//] ▷Crop around the point of analysis with desired size for kernel in flts do out ←sum(neigh x kernel) ▷To count the pixels that match between filter and crop from the skeleton outs.append(out) end best ←argmax(outs) ▷Get filter with higher coincidence theta ←best * (pi/(length(flts)+1)) c←[x/2 for x in [sz,sz]] p1 ←[c[0]+cos(theta),c[1]+sin(theta)] p2 ←[c[0]-cos(theta),c[1]-sin(theta)] vec ←[p2[i]-p1[i] for i in range(2)] x_v2 ←vec[0] ▷x_v2 and y_v2 are the components of the vector perpendicular to theta y_v2 ←-vec[1] p1 ←pt p2 ←pt inc ←Increment of 1 unit in perpendicular direction to peduncle while mask[p1[0], p1[1]] >0do p1[0] ←p1[0] + incx p1[1]←p1[1] + incy end while mask[p2[0], p2[1]] >0do p2[0] ←p2[0] + incx p2[1]←p2[1] + incy end w←sqrt((p2[0] −p1[0])2+ (p2[1] −p1[1])2) End function 36 Chapter 4 – Depth estimation methods Algorithm 4 Create filters Input: sz ←size of the filter Input: step ←increment in degrees between each filter ▷Each filter represents a line passing through the center at a given angle between 0 and 180 degrees Being: center the coordinates of the center of the image Output: flts ←array of filters for theta from 0to pi every step do flt ←zeros(sz) ▷Create square matrix of zeros of size sz p1=[center[0] + cos(theta)·10 ·sz/2, center[1] + sin(theta)·10 ·sz/2] p2=[center[0] −cos(theta)·10 ·sz/2, center[1] −sin(theta)·10 ·sz/2] flt ←createLine(flt,p2,p1) ▷Add line to the previously created matrix flts.append(flt) end 4.2.5 Implementation The software developed is based on ROS. Therefore, it is important to explain which nodes and services are offered. The most basic service is the triangulate depth one. This service is used to do the calculus of the triangulation: it receives the width in pixels, the focal length and the assumed real width of a peduncle. Then, the response of the service is the computed depth. In addition, there is a service called "process and triangulate". This service is used to process the received masks applying the process described in 2. The different computations are split into functions inside the node. This service does a call to the triangulate depth service. 4.2.6 Results After applying this method in the laboratory, the results were the ones shown in Table 4.1. All the results were obtained from a dataset of around 200 samples. The data was obtained measuring different grapes from several positions. The ground truth data was obtained using a laser meter. The setup for the experiments can be seen in Figure 4.8. Grape cluster and peduncle 3D localization 37 Figure 4.8: Setup for the experiments Id Min. Dist. (cm) Max. Dist. (cm) Max. error (cm) MAE (cm) MSE (cm2) RMSE (cm) 1 21.9 50 14.0889 6.9207 59.3402 7.7033 2 21.9 30 8.8125 4.2283 21.9088 4.6807 3 21.9 25 5.1143 3.3415 13.6413 3.6934 Table 4.1: Triangulation errors From the results shown in Table 4.1, it can be seen that the error is higher when the cluster is located far away. This is due to several factors, the value of the real width of the peduncle is variable and as the dataset is obtained from different clusters the results will have errors. Moreover, the segmentation is not perfect, so, when computing the width in pixels the value is not exact. Analysing the errors, an important metric is the maximum error because the goals given should not be outside the tolerance of the robot. However, it is true that during the movement of the robot, several measurements could be done, to correct punctual deviations. In this case, it is clear that when the camera is closer, system performance improves. In fact, the maximum error for the range until 25 cm is around 5 cm, the tolerance for the robot was 3 cm, so this is not enough, but is a good approach. Moreover, the mean absolute error (MAE) is around 3 cm, this is a good result given it is inside the tolerance of the robot. As the MAE weights equally all errors, an interesting metric to add is the root mean squared error (RMSE) as it gives higher weight to large errors. The value of the RMSE does not reach 4 cm. Nevertheless, when the distance increases the results get worse, which proves that this measurement alone is only suitable for close distances. The results from the different measurements are shown in Figure 4.9. This figure shows how the results change depending on the distance to the cluster. 38 Chapter 4 – Depth estimation methods Figure 4.9: Distances obtained with the triangulation method 4.3 Peduncle estimation from cluster This section will explain the method that can be used to estimate the peduncle position from the cluster mask. This method uses the Realsense depth map to do a reconstruction of the cluster. As mentioned in the introduction, it may be useful when the peduncle is not visible. For example, the peduncle detection method tends to fail for long distances to the grapes, being impossible to estimate the depth without this method. 4.3.1 Theoretical explanation As in all methods, the information available is the mask of each cluster and peduncle. When a mask is received from a cluster, the depth map information for the location of the mask can also be obtained. To show the process, an example is made using Figure 4.10 as starting point. The segmentation of this image is in Figure 4.11. As it can be seen, the peduncle is not detected, being an example of a detection failure when the distance to the grapes exceeds the limitations of the detection algorithm. Grape cluster and peduncle 3D localization 39 Figure 4.10: RGB image from a cluster Figure 4.11: Segmentation from the RGB image First, the multiplication of the mask by the depth map is performed. One problem is that the mask probably will not fit the grape cluster perfectly. This has some implications such as the appearance of some close or distant points that are not part of the cluster. Moreover, if a branch appears in front of the grapes, this could also affect. The result of this multiplication is shown in Figure 4.12. 46 Chapter 4 – Depth estimation methods where there is not information from the depth camera, due to resolution limitations. 4.4.1 Mixing neural net data with real depth This approach uses a neural net that provides relative depth to increase the information on the depth map from the Realsense. As discussed at the beginning of the document, the Realsense has limited resolution in terms of depth. This problem is more noticeable when it comes to obtain the depth of small objects, which is the case of the peduncles. To perform this task it is important to use a network that is consistent when computing the depth map. This means that even if the scale varies between images, in a single image the depth values produced by the network share a reference. This consistency problem can be identified in the comparison done afterwards. The first thing that was done was to select the net according to the speed and depth produced. There was a first network which is the one presented in [22], this one was used in the first steps of the project to help with segmentation. This network produces very impressive results as it is capable of getting a very high resolution depth map from an RGB image. However, the results are not consistent enough to apply the developed method to perform absolute depth estimation. The problem with this network comes when analysing the depth values in detail. The analysis performed consists of detecting the clusters in an RGB image, then picking the center of the cluster and making a circle proportional to the width of the bounding box. From these circles shown in red, the depth image values produced by the network are compared to the Realsense depth values. In Figure 4.19 it can be clearly seen that the depth produced by the net has good resolution, but when looking at the plot it is noticeable that there are many horizontal lines, which means that for a real depth value the net assigns a wide range of values. This could happen because the implementation focuses on getting good resolution, highlighting the edges of elements in the image, but reduces the structural consistency. Apart from this problem, there is another one related to speed, taking about 2 seconds during the tests carried out. However, it varies depending on the image resolution and could take up to 5 seconds. Grape cluster and peduncle 3D localization 47 Figure 4.19: Depth analysis with boosting Given the problems of this network, other networks were studied. The most interesting was the one known as MiDaS described in [20]. To process an image this network takes less than a second, which is approximately 4 times faster than the boosting case. However, it is true that the depth image produced has less resolution than the one from boosting. Nevertheless, it is not a problem since it still has a good resolution and also great structural consistency. In Figure 4.20 it was performed the same analysis as before, this time using MiDaS. Figure 4.20: Depth analysis with MiDaS It is clear that the results are more consistent than with boosting. However, it is not possible 48 Chapter 4 – Depth estimation methods to directly find a function that works to map MiDaS values to real depth for all the images. An algorithm must be applied to obtain good results with the method, which will be introduced afterwards. 4.4.2 Theoretical explanation This method uses the image produced by the network with MiDaS architecture that builds a depth map with relative depths. The problem with this kind of networks is that they are used to get an idea of how objects are distributed in space, but not to have an absolute measure of the depth. Having this in mind, the idea was to take advantage from the information of the depth camera and mix it in order to be able to extrapolate depths. For some uses, mainly in automotive applications, it is possible to get a function that maps the grayscale values of the depth map to the real absolute distance. Those networks are typically trained with real distances as input, which are available in many of the datasets that contain LIDAR data. However, these types of datasets are not available for grapes. As the information obtained from MiDaS is relative, the first step will be to carry out a calibration process. This calibration process has a few steps. To being with, it is necessary to sample the true depth image, searching areas where there is information without much deviation, this is done to avoid problems with outliers. To do so, the image will be randomly sampled with squares of a defined size whose points must have a maximum standard deviation. In this case, the size is 10 by 10 pixels and the maximum standard deviation allowed is 1.5 cm. In addition, the points must be closer than 1 meter and further than 20 cm. Once the depth image is sampled, the same process has to be carried out with the MiDaS image. After this sampling, the information of a point in the depth image can be related to the same information in the MiDaS image. Having the information of some points, a function that relates both images has to be searched. In order to accomplish that, a polynomial regression is done. When carrying out the fit process, the RMSE of each degree is calculated to know which of the adjustments is the best. With the best model, the values on the depth image can be converted to absolute depth. The degree of the polynomial changes from 1 to 12 since in this application overfitting is not necessarily a problem, because the adjustment is going to be used only for one image. 4.4.3 Algorithm in detail The detail of the main part of the algorithm is presented in Algorithm 6. Grape cluster and peduncle 3D localization 49 Algorithm 6 Dense reconstruction algorithm Input: image_midas ←depth image from MiDas Input: image_depth ←depth image from the Realsense Input: imshape ←shape of the image Input: masks ←(height ×width ×n) structure with the masks of the clusters and peduncles detected, being n the number of detected objects Input: ids ←array of classes of the detected objects ▷ids = 1 means that the mask corresponds to a peduncle Input: scores ←array of scores of the detected objects Input: num_iterations ←number of iterations Output: index ←array of indexes of the processed objects Output: depths ←array of depths of the processed objects Being: max_std the maximum standard deviation allowed for the points in a sampling box Being: neigh_sz the size of the crops in pixels Being: degrees_to_try the maximum degree to try to adjust the polynomial nplist ←linspace(30,80,num_iterations) for i < len(scores)) do if ids[i]==1 then peduncle_midas ←image_midas * masks[i] X_test ←peduncle_midas[peduncle_midas>0] ▷Save the information of the peduncle from the MiDaS image rmse_old ← ∞ for j < num_iterations do pt_list, means_depth ←sample_depth_im(image_depth,nplist[j],max_std,neigh_sz) ▷This function samples the depth image in squares midas_depth ←obtainMidasValue(image_midas,pt_list,neigh_sz) ▷This function gets the values from the same sampling squares of the previous step but in the MiDaS image predictions_aux, rmse ←adjust(midas_depth, means_depth, degrees_to_try,X_test) ▷This fuction makes the adjust of the data obtained from the samples of the RealSense and MiDaS to a polynomial, then it returns the predictions for the depth from the mask of the peduncle and the RMSE that is used as measure of quality for each adjustment. The RMSE is calculated for points that are previously split as test points if rmse<rmse_old then rmse_old ←rmse predictions ←predictions_aux end end if rmse_old<50 then index.append(i) depths.append(mean(predictions)) end end end 50 Chapter 4 – Depth estimation methods The function of adjustment is detailed in Algorithm 7. Algorithm 7 Adjustment function for dense reconstruction Function adjust(midas_depth, means_depth, degrees_to_try,X_test_peduncle): rmse_old ← ∞ X_train, X_test, y_train, y_test =train_test_split(midas_depth, means_depth, test_size = 0.3) for i in range(1,degrees_to_try+1) do polynomial = adjust_to_polynomial(X_train, y_train, i) polynomial_predict = polynomial.predict(X_test) rmse = sqrt(mean_squared_error(y_test, polynomial_predict)) if rmse<rmse_old then degree_opt=i polynomial_best = polynomial rmse_old = rmse end end peduncle_depths = polynomial_best.predict(X_test_peduncle) Return peduncle_depths, rmse_old, degree_opt End function 4.4.4 Implementation This method, as the other ones, is implemented using a ROS service. It receives the depth images produced by the network and the depth image from the Realsense. Apart from that, the information of the masks with their ids and scores is also needed. Finally, it needs the number of iterations, that is the maximum number of times the image will be randomly sampled. The process explained above is done when the service is called. It is important to keep in mind that the process can fail, in this case the server does not return a response. The failure occurs when the maximum number of iterations have been executed and the adjustment does not fulfill the RMSE requirement. This is determined using a threshold for the RMSE that is set to 5 centimeters. The flux diagram of the process for obtaining the real depth is shown in Figure 4.21. Grape cluster and peduncle 3D localization 51 Randonmly define squares inside the depth image Check standard deviation is below a threshold Compute the mean of each square Perform the mean of the same squares in the MiDaS image Try to adjust to a polynomial of degree n=1:12 the information from the sampling squares of the RealSense and MiDaS Save the polynomial with lower RMSE Give MiDaS values of peduncle to the polynomial to predict real depth Get the mean value of the predictions Figure 4.21: Dense reconstruction flux diagram 4.4.5 Results With this method the results are generally inside the tolerance of the robot. The problem comes, as occurred in the peduncle from cluster method, when the camera is too near to the cluster. Below 28 centimeters, the method gives poor results. This is because it is capable of obtaining few points in the sampling process. In Figure 4.22 it can be appreciated that the results are good from 30 centimeters until the end of the range. To perform the measurements close to the cluster the maximum RMSE allowed was changed to 25 cm, for testing purposes. 52 Chapter 4 – Depth estimation methods Figure 4.22: Dense reconstruction results from 20 to 90 centimeters In Figure 4.23, the range where the method works better is shown. The results are always around the real value, nevertheless, when the camera gets further the results get worse. Figure 4.23: Dense reconstruction results from 35 centimeters to 90 centimeters As in the other cases, the error in the different ranges are presented in Table 4.3. The maximum error of this method when the camera is closer than 28 cm is around 30 centimeters, which is not acceptable. However, when studying the range from 35 to 90 cm the maximum error is reduced to 12 cm. This is not a good result, but it is not a general case as the mean absolute error for that range is around 2 cm. This means that the method could punctually give a bad result, but in general it works well. Grape cluster and peduncle 3D localization 53 Id Min. Dist. (cm) Max. Dist. (cm) Max. error (cm) MAE (cm) MSE (cm2) RMSE (cm) 1 21.9 86.8 29.0985 3.9329 48.5519 6.9679 2 35 86.8 12.1632 2.3629 9.5386 3.0885 3 35 50 12.1632 2.047 8.9965 2.9994 Table 4.3: Dense reconstruction errors This method can give good information for the later stage of data fusion. Nevertheless, it works worse than the peduncle from cluster method. 4.5 Direct measure This method is described in a different way, due to its simplicity. It consists solely of obtaining the depth of the Realsense in the area of the peduncles. This method will be the ideal one in terms of simplicity and accuracy. The problem is that, as stated at the beginning of the document, the Realsense has problems obtaining depth in small objects. The tests performed at the laboratory showed that, to get one depth map containing points in the peduncle it was necessary to do around 4 attempts. The algorithm used in this case is described in Algorithm 8. Algorithm 8 Direct measure method Input: image_depth ←depth image from the Realsense Input: imshape ←shape of the image Input: masks ←(height ×width ×n) structure with the masks of the clusters and peduncles detected, being n the number of detected objects Input: ids ←array of classes of the detected objects ▷ids = 1 means that the mask corresponds to a peduncle Input: scores ←array of scores of the detected objects Output: index ←array of indexes of the processed objects Output: depths ←array of depths of the processed objects for i < len(scores)) do if ids[i]==1 then index.append(i) roi ←image_depth * masks[i] ▷Get the information of depth from the region of interest (ROI) roi_filtered ←filterByDistance(roi,20) ▷Erase points closer than 20 cm roi_filtered ←filterByZscore(roi_filtered,1.) depth ←mean(roi_filtered) depths.append(depth) end end At the moment of testing, when the camera is closer than 28 cm, the values obtained have large 54 Chapter 4 – Depth estimation methods errors as can be seen in Figure 4.24. Figure 4.24: Direct measure from 20 centimeters to 90 centimeters However, when the camera is farther than 35 centimeters the results are good. Figure 4.25 shows the results from 35 centimeters to 90 centimeters. Figure 4.25: Direct measure from 35 to 90 centimeters It is noticeable that when the camera is close the results have more variability. Apart from that, in the rest of the range the results are accurate and do not show significant variability. In terms of errors, Table 4.4 shows the results for this method. The results are inside the tolerance of the robot from 35 centimeters to 90 centimeters in terms of MAE. The maximum error is not inside the tolerance because in some punctual captures of Grape cluster and peduncle 3D localization 55 Id Min. Dist. (cm) Max. Dist. (cm) Max. error (cm) MAE (cm) MSE (cm2) RMSE (cm) 1 21.9 86.8 2257.3 53.1948 88322.6114 297.1912 2 35 86.8 35.5 2.2238 21.5425 4.6414 3 45 80 7.1 1.3411 3.3749 1.8371 Table 4.4: Direct measure errors the Realsense, the depth points were not accurate or the segmentation was not good. All the information from the different methods is mixed as explained in Chapter 7. 4.6 X and Y computation Having an estimate of the depth of the peduncle, the X and Y coordinates with respect to the camera frame can be obtained. This process is done using the information from the camera’s intrinsic matrix. Let us the Equation 4.15 the intrinsic matrix of the camera, where cxand cyrepresent the x and y coordinates of the center of the image. Other than that, the letters uand vare the xand y image coordinates of the point of interest. K=   fx0 0 s fy0 cxcy1   (4.15) (x=depth fx·(u−cx) y=depth fy·(v−cy)(4.16) Using Equation 4.16 the x,y position of the peduncle in centimeters is obtained. To compute the point of interest for the cluster or for the peduncle, the centroid of the analysed mask must be computed. Chapter 6 User interface This chapter is devoted to explain the GUI of the system, its visualization tools and the options it offers. 6.1 Introduction The project GUI is divided vertically into two zones with different uses. The left side of the GUI has the necessary tools for visualization, while the right side is devoted to the user interaction with the system. The GUI is presented in Figure 6.1. Figure 6.1: Capture of the GUI The visualization part of the GUI contains four different parts. The one located at the top left is the RGB image received from the Realsense. Then, at the bottom left, the result of the 63 64 Chapter 6 – User interface segmentation process is displayed. The clusters are drawn in blue and the peduncles in orange. Each cluster and peduncle comes with its unique id. The cropped image is displayed at the bottom right, which is necessary when using manual cropping. Finally, at the top right part, there is a console that prints the information of the depths obtained from the different methods and from the data fusion. The printed information is the index of the measured object and the depth obtained. 6.2 Interact tools This section explains the different options on the right side of the GUI (Figure 6.2). The first group of options comes from the data fusion node, which is the core of the system as explained above. The rate option is to set the rate at which the system must perform in Hz. It is implemented but it is not used since for now the system works slowly. The "save" and "save fusion" options are used to build datasets. If selected, the system creates a CSV file and saves the measurements. When "save fusion" is not selected, the result of the data fusion is not saved. After these checkboxes, there is a slider to select the real distance at which the peduncle is located. This is used when creating the dataset to save the real measurement taken by the user. The margin option is the distance in centimeters that the robot should leave as margin when approaching the peduncle. The options related to the movement of the robot are implemented, as well as the necessary nodes for moving the robot towards the peduncle. However, they have not been explained due to the lack of tests performed, since the robot has not been available. These tests will be carried out in the next stage of the project. The "capture" option is to make a measurement with the selected options. When the checkbox is clicked all the process is executed, this checkbox works as a button. The "doZoom" parameter is used to indicate whether the system has to crop around the detected clusters and repeat the detection to try to improve segmentation. The "move" option is to make the robot move towards a peduncle. The target peduncle for the robot is selected with the goal slider, giving the desired "id". Then, the "show time stats" option is used to show the time it has taken to execute the entire process. The "plot" option aims to show some plots in the middle of the process to help in visualizing the different processes that are going on. The "cyclic option" is to make the process run cyclically. Finally, there are two dropdown menus to select the depth method to use and the data fusion method. Apart from the data fusion options, the crop node provides four sliders to select the percentage of crop from each side of the image. Grape cluster and peduncle 3D localization 65 Figure 6.2: Capture of the right part of the GUI Chapter 7 Experimental testing This chapter explains how the data was captured, and how it was used to establish and test the data fusion method. 7.1 Getting the data In order to obtain the data, a mock-up was used. In the laboratory, the Realsense was placed on a tripod and moved to different distances and heights, whose real values were obtained with a measuring laser. The used laser was the TLM130i from STANLEY, it has a precision of +/- 2 mm. The setup for doing this process can be seen in Figure 7.1. Figure 7.1: Laboratory setup The process was carried out doing captures with the "save" option selected to save the data in a CSV file. The real distance was selected with the slider. The data was captured every 5 cm, approximately, by changing the position of the camera. The number of points captured was around 200 and the the data ranges from 21.9 cm to 86.8 cm. 67 68 Chapter 7 – Experimental testing 7.2 Mixing methods to get depth In this section, some methods are analysed to make the fusion of the data obtained with the depth methods. The direct measurement method will not be used to perform the fusion since it is a method that fails, complicating the process of obtaining depth. It is worth mentioning that before performing the data fusion, there is a process performed to match the detected peduncles with the cluster, which is explained in [3]. 7.2.1 Methods for data fusion To perform the data fusion, a regression is going to be carried out. There are many ways of performing a regression. For this work several were tested and compared according to error metrics and the R2-score. Before analysing the different methods, the problem will be divided into two parts. The regression problem over the full range of measurements and the same problem for the range from 30 to 90 centimeters. This division is done because the results of the methods seem to give random values when the Realsense is too close to the cluster, so it will not be possible to use this data to build the regression. Nevertheless, that range will also be studied. The range in which the estimation will be worse is from 0 cm to 30 cm, since the gripper makes the camera be 25 cm away from the grasping zone, this range could be covered by the triangulation method if necessary. This range would be only 5 cm long, here it could be used the absolute depth or make an incremental approach. Another option would be to give the final goal to the robot when it is just 30 cm away from the cluster. This way it will only cover a 5 cm distance, which is a small distance taking into account that the scenario is mainly static. To start with the proven methods, a brief description of them will be given. •RANSAC (Random Sample Consensus): This method was previously used to filter out outliers in the triangulation method. This is an iterative method that allows to robustly estimate the parameters from a subset of inliers from a dataset. •Decision Tree: It builds a regression model in form of a tree structure. •Elastic Net: The Elastic Net regression is a penalized linear regression model which includes L1 and L2 penalties. •Huber: It is a linear regression model that is robust to outliers. It uses a particular loss function introduced by Peter Jost Huber that is used for robust regression problems. •K-Nearest Neighbors Regressor: It is based on K-nearest neighbors algorithm. It predicts the target by interpolating the targets associated to the nearest neighbors in the training set. •SGD (Stochastic Gradient Descent): This is a linear model fitted by minimizing a regularized empirical loss with SGD. Grape cluster and peduncle 3D localization 69 As a first step, the analysis is performed with the full dataset. In order to test the regressors with data that was not used to fit them, 67 samples of the dataset will be kept as testing data. All methods have been adjusted and tested on the same data for a fairer comparison. Table 7.1 shows the results for the different methods. Method R2-score Max. error (cm) MAE (cm) MSE (cm2) RMSE (cm) RANSAC 0.9470 26.2765 2.8278 23.9801 4.897 Decision Tree 0.9408 32.5 1.0746 26.8101 5.1778 Elastic net 0.9502 23.2399 3.2093 22.5208 4.7456 Huber 0.9509 26.0393 2.7086 22.2070 4.7124 KNN Weight=Uniform 0.9969 4.25 0.5246 1.3919 1.1798 KNN Weight=Distance 0.9985 2.5078 0.3533 0.6359 0.7974 SGD 0.9499 23.1351 3.2163 22.6673 4.761 Table 7.1: Data fusion errors for the whole range of data From these results, it can be identified that the regression method that works better is the KNN one. However, the other methods remain close. It is true that they have a large maximum error, but the remaining metrics show good performance, the R2-score ideally has to be 1 and it is always around 0.95. Moreover, the MAE and RMSE are in general lower than 5 cm. The K-nearest neighbors algorithm is used with a kvalue of 2. This method performs well on test data from the dataset. This algorithm has to save the data used for training because it works by finding the two closest samples to the test sample according to the Euclidean distance. Once these samples are located, the algorithm can weigh the samples using two methods. The uniform method weights all points equally, while the distance method weighs the points by the inverse of their distance, meaning that nearest neighbors have more influence than other neighbors. This configuration of parameters was determined using a grid search for the number of neighbours and the way of weighting. The results for the KNN using the distance weight are very good. The maximum error is 2.5 cm which is lower than the 3 cm of tolerance for all the range of measurements. Apart from that, the MAE is only 0.35 cm and the RMSE is 0.8 cm. This means that, in general, the results have an error lower than a centimeter, which is quite good. These results are validated by having a look at the plot in Figure 7.2. It can be seen that there is no large deviation in any of the distance ranges and the given measurement is accurate. Nevertheless, the range with greater deviation is the one from 20 to 30 cm. 70 Chapter 7 – Experimental testing Figure 7.2: Results for the KNN method for fusion using the distance as way of weighting and k = 2 The problem with this method is that as the results from two of the characteristics seem to have random noise under 30 cm, it will probably not work under other conditions. However, performing more tests in the laboratory with completely fresh data from different days, and changing the location of the mock-up and clusters showed that the results for close distances continued to be inside the expected values. Perhaps in the field with a completely different environment, the results will vary for the "peduncle from cluster" and "dense reconstruction" methods. This will imply that the KNN regressor will not perform well, as it will probably take the two closest samples from somewhere in the rest of the range of measures. Taking this possible problem into account, the methods for data fusion were also studied when measurements were further than 30 cm. The results are presented in Table 7.2. Moreover, the code to obtain the models for data fusion is prepared to easily introduce new datasets and use different features. This means that if in a real scenario the data fusion does not perform well using triangulation, for example, as one of the features, it could be deleted. In this case, the "peduncle from cluster" and "dense reconstruction" will be used, or the direct measurement could be even used, bearing in mind that it will be more difficult to obtain a measurement. Grape cluster and peduncle 3D localization 71 Method R2-score Max. error (cm) MAE (cm) MSE (cm2) RMSE (cm) RANSAC 0.9972 3.8323 0.6901 0.9271 0.9628 Decision Tree 0.9981 5.0000 0.2132 0.6421 0.8013 Elastic net 0.9972 4.0344 0.6852 0.9516 0.9755 Huber 0.9975 3.8842 0.6344 0.8481 0.9209 KNN Weight=Uniform 0.9967 4.2000 0.3632 1.1141 1.0555 KNN Weight=Distance 0.9974 4.2000 0.3134 0.8591 0.9269 SGD 0.9960 5.1444 0.8207 1.3304 1.1534 Table 7.2: Data fusion errors for the range of 30 cm to 90 cm In this case, all the methods work fine. Taking into account that the KNN with distance worked well for the case of using the entire dataset, it will be the most suitable method to use in real applications. The maximum error is 4.2 cm but it is a punctual case given that the MAE is just 0.3134 cm and the RMSE is around 1 cm. The errors obtained are low given the complexity of the scenario. Figure 7.3: Results for the KNN method for fusion using the distance as way of weighting and k = 2, for the range of 30-90 cm The Figure 7.3 shows the results obtained for the test set. It is a good way to identify that the 78 Chapter 10 – Economic Cost and Environmental Impact The last cost to consider is the cost of electricity. To calculate it, it is necessary to know that the MSI laptop consumes 280 W. The price of the electricity will be considered as 0.3 e/kWh 2. Electricity cost = 0.28 kW ·1000 hours ·0.3e kWh = 84 e(10.3) The cost of the development can be seen in Table 10.1. Concept Cost ( e) Engineer cost 15000 Cost of amortization of the devices 300 Cost of electricity 84 Total cost 15384 Table 10.1: Costs of the project The total cost of the project will be 15384 e. 10.2 Environmental impact To calculate the environmental impact of the project, the only thing that will be taken into account is the computer, since the camera is always connected to it and does not have any external power supply. To know the emissions of CO2the relationship between consumed electricity and CO2emissions has to be consulted. This can be obtained from the document on emission factors published by the Spanish government 3. Assuming that IRI’s electricity supplier is ENDESA, the emission factor would be 0.258 kgCO2e/kWh. Taking into account that the laptop consumes 280kWh of energy, the calculus of the CO2emis- sions is presented in Equation 10.4. Total emissions = 0.258(kgCO2e/kWh)·280 kW h = 72.24 kg of CO2e (10.4) 2Information on: https://tarifaluzhora.es/ 3Information on: https://www.miteco.gob.es/es/cambio-climatico/temas/ mitigacion-politicas-y-medidas/factoresemision_tcm30-479095.pdf Bibliography [1] CANOPIES EU Project website. https://cordis.europa.eu/project/id/101016906/es. Accessed: 18-04-2022. [2] CANOPIES website. https://canopies-project.eu/. Accessed: 18-04-2022. [3] Gabriel Coll-Ribes, Iván J. Torres-Rodríguez, Antoni Grau, Edmundo Guerra, and Alberto Sanfeliu. Detection and depth estimation of table grapes and peduncles combining monocular depth estimation and cnn methods. Computers and Electronics in Agriculture, 2022 (submitted). [4] Zhengtong Ning Jian Ye Zhiqiang Dong Wei Yin, Hanjin Wen and Lufeng Luo. Fruit detection and pose estimation for grape cluster–harvesting robot using binocular imagery based on deep neural networks. Frontiers in Robotics and AI, 2021. [5] Kaiming He, Georgia Gkioxari, Piotr Dollar, and Ross Girshick. Mask r-cnn. IEEE Transactions on Pattern Analysis and Machine Intelligence, PP:1–1, 06 2018. [6] Cornelis Wouter Bac, Jochen Hemming, Bart Tuijl, Ruud Barth, Ehud Wais, and E.J. Van Henten. Performance evaluation of a harvesting robot for sweet pepper. Journal of Field Robotics, 34, 03 2017. [7] Young Bum Lee Sang Chul Kim Dong Hyuk Im Hong Ki Choi Heon Hwang Kil-Su Han, Si- Chan Kim. Strawberry harvesting robot for bench-type cultivation. Journal of Biosystems Engineering, 2012. [8] Ji Wei Zhang Ying Chen Yu Zhao De-An, Lv Jidong. Design and control of an apple harvesting robot. Journal of Biosystems Engineering, 110:112–122, 2011. [9] Li Yang Dongxing Zhang Yang Yu, Kailiang Zhang. Fruit detection for strawberry harvesting robot in non-structural environment based on mask-rcnn. Computers and Electronics in Agriculture, 163, 2019. [10] Shaohua Wan and Sotirios Goudos. Faster r-cnn for multi-class fruit detection using a robotic vision system. Computer Networks, 168:107036, 12 2019. 79 80 Memory [11] Shaoqing Ren, Kaiming He, Ross Girshick, and Jian Sun. Faster r-cnn: Towards real-time object detection with region proposal networks. IEEE Transactions on Pattern Analysis and Machine Intelligence, 39, 06 2015. [12] Xiaochun Mai, Hong Zhang, Xiao Jia, and Max Meng. Faster r-cnn with classifier fusion for automatic detection of small fruits. IEEE Transactions on Automation Science and Engineering, PP:1–15, 01 2020. [13] Yaqoob Majeed, Jing Zhang, Xin Zhang, Longsheng Fu, Manoj Karkee, Qin Zhang, and Matthew Whiting. Apple tree trunk and branch segmentation for automatic trellis training using convolutional neural network based semantic segmentation. IFAC-PapersOnLine, 51:75–80, 01 2018. [14] Kalule Ramanzani, Hamid Abderrahmane, Waleed Alameri, and Mohamed Sassi. Segnet: A deep convolutional encoder-decoder architecture for image segmentation. 06 2021. [15] Thiago Santos, Leonardo Souza, Andreza Santos, and Sandra Avila. Grape detection, segmentation and tracking using deep neural networks and three-dimensional association. 07 2019. [16] Inkyu Sa, Christopher Lehnert, Andrew English, Chris Mccool, Feras Dayoub, Ben Upcroft, and Tristan Perez. Peduncle detection of sweet pepper for autonomous crop harvestingcombined color and 3-d information. IEEE Robotics and Automation Letters, PP:1–1, 01 2017. [17] Zhaojin Huang, Lichao Huang, Yongchao Gong, Chang Huang, and Xinggang Wang. Mask scoring r-cnn. pages 6402–6411, 06 2019. [18] Daniel Bolya, Chong Zhou, Fanyi Xiao, and Yong Jae Lee. Yolact: Real-time instance segmentation. pages 9156–9165, 10 2019. [19] Clément Godard, Oisin Mac Aodha, Michael Firman, and Gabriel J. Brostow. Digging into self-supervised monocular depth prediction. October 2019. [20] René Ranftl, Katrin Lasinger, David Hafner, Konrad Schindler, and Vladlen Koltun. Towards robust monocular depth estimation: Mixing datasets for zero-shot cross-dataset transfer. IEEE Transactions on Pattern Analysis and Machine Intelligence (TPAMI), 2020. [21] René Ranftl, Alexey Bochkovskiy, and Vladlen Koltun. Vision transformers for dense prediction. ArXiv preprint, 2021. [22] S. Mahdi H. Miangoleh, Sebastian Dille, Long Mai, Sylvain Paris, and Yağız Aksoy. Boosting monocular depth estimation models to high-resolution via content-adaptive multi-resolution merging. 2021. Grape cluster and peduncle 3D localization 81 [23] S. Mahdi H. Miangoleh, Sebastian Dille, Long Mai, Sylvain Paris, and Yağız Aksoy. Boosting monocular depth estimation models to high-resolution via content-adaptive multi-resolution merging supplementary material. 2021. [24] Tobias Koch, Lukas Liebel, Friedrich Fraundorfer, and Marco Körner. Evaluation of CNN- Based Single-Image Depth Estimation Methods: Munich, Germany, September 8-14, 2018, Proceedings, Part III, pages 331–348. 01 2019.