## 5 Extracting Mango External Features from Captured Images  
The images were segmented with a level of 0 for the pixel area of the mango and 1 for the remaining pixel area in each frame. The next task is to calculate the area of the pixels according to the actual size. This is the step that greatly affects the accuracy of the process. With binary images, the pixel area is used to estimate actual size by Equation (20).  
\[L=KA_{boundary} \tag{20}\]  
Length \(L\) is the length to be estimated, \(A_{boundary}\) is the number of pixels and \(K\) is a ratio constant between size in pixel and the actual size. Moving objects make the distance from the camera to the objects change, therefore the proportional constants are also changed. In other words, the rate of constant changes with the distance from the camera to the object. Therefore, the \(K\) ratio factor should be appropriately estimated. With the same length at each focal distance, the number of pixels representing that length varies. Therefore, the closer to the camera is more pixels that represent for that length. That means the area of each pixel will decrease as the distance decreases. To determine the size of the mango from a binary image whose coefficient of \(K\) changes due to the motion of the mango, the scale factor from real data is estimated \(K\approx F(Length)\). This is a linear function because as the number of pixels increases, the length also increases. So linear planning is an appropriate option. The length is \(L\), the number of pixels in the image is \(A\), and the values are considered on \(n\) images. The average length \(\overline{L}\) is given by Equation (21).  
\[\overline{L}=\frac{1}{n}{\sum\limits_{i=1}^{n}{L_{i}}} \tag{21}\]  
From Equation (19), the \(\hat{K}\) ratio factor can be found in Equation (22).  
\[\hat{K}=\frac{\sum\limits_{i=1}^{n}{A_{i}{L_{i}}}-n\overline{AL}}{\sum\limits _{i=1}^{n}{A_{i}^{2}}-n\overline{A}^{2}} \tag{22}\]  
The length \(\hat{L}=\hat{K}A_{boundary}\) is estimated by \(\hat{K}\) in Equation (20). The coefficient of determination is defined in Equation (23).  
\[r^{2}=1-\frac{\sum{e_{i}^{2}}}{\sum{L_{i}^{2}}-\frac{\left({\frac{\sum{L_{i}} }{{n}}}\right)^{2}}{n}}=\frac{\sum{\left({L-\hat{L}}\right)^{2}}}{\sum{L_{i}^ {2}}-\frac{\left({\frac{\sum{L_{i}}}{{n}}}\right)^{2}}{n}} \tag{23}\]  
The error of \(K\) is given in Equation (24).  
\[\varepsilon=\frac{1}{n}{\sum\limits_{i=1}^{n}{\left({L_{i}}-\left({\hat{K}A }\right)\right)^{2}}} \tag{24}\]  
The defect of the mango is the damage on the surface caused by insects or collisions during its growth that can be scars, dark, spots, etc. The defect areas are detected by the boundaries of the rectangle (Figure 6). All defects are accumulated on the whole surface and then give the final defect level of each mango. Therefore, the areas of its disability should first be detected and zoned to be detected effectively based on the specific areas of the binary image. The disabled areas are quite small, so they should be covered by the rectangle, so the area of the disability is the area of those rectangles. The mango defects are identified by the total pixel's area of the zero value inside the mango boundary in the binary image. Because the pixel size ratio is \(K\), the area of each pixel is \(K^{2}\). Where \(A_{defect}\) is the number of defect pixels, (\(\hat{de}\)) is estimated defect; (\(\Delta de\)) is error of defect depending on the error (\(\epsilon\)) of \(K\). We can calculate the actual defect by Equation (25).  
\[de=\hat{de}+\Delta de=(K^{2}+2\epsilon K)A_{defect} \tag{25}\]  
In this section, the actual dimensions of mango are estimated through the implemented algorithms. Based on a series of calculation, the size in pixel is determined to the actual size with an acceptable error. The estimation is calibrated depending on the hardware of the machine. Besides, the size of defects on the mango's surface is calculated based on summing defective areas.