# Intelligent Control System to Irrigate Orchids Based on Visual Recognition and 3D Positioning
## 2 System Design and Methodology
### Positioning of the Watering Point  
The established identification and depth map of YOLOv3 will be merged. According to actual requirements, when seedlings appear within the field of view of binocular lens, the following processes are executed: 1. Apply YOLOv3 to identify whether there is a target in the image (the junction between stems and leaves) through the left lens; 2. if the target object is detected, the coordinates of pixels at the upper-left and lower-right corners, on the prediction box in Figure 6, are, respectively, \((x_{min},\,y_{min})\) and \((x_{max},\,y_{max})\), which are returned to calculate the central position of the prediction box; 3. input the center position to the map to obtain the corresponding real 3D coordinates. After the 2D coordinates of the central point of the prediction box are obtained, its actual 3D coordinates can be obtained by feeding the 2D coordinates and the depth map to _cv2.ReprojectimageTo3D()_. To refrain from diseases caused by directly watering on the leaves, the direction vector of the leaves (called _leaf vector_ elsewhere), acquired by image processing, is defined as the fitted straight-line vector of the two main contours of leaves, as shown in Figure 7. After  
Figure 5: Effect after pseudo-color process, the deeper red (blue) is the closer (farther). the leaf vector is calculated, the desired watering point is locked to the stem-root junction of the seedling, as depicted in Figure 7.  
After selecting the junction position between the stem and the leaf through the YOLOv3 frame, the image of the center point of the prediction box is cropped, as provided in Figure 8. As different image sizes will induce redundant adjustments during the following erosion and expansion processes, the shorter length (or width) of the cropped image is set to be constant by the OpenCV function _cv2.resize()_ to simplify the image processing. Then, to reduce noises, the function _cv2.cottColor()_ is used for grayscale processing of the cropped image. Moreover, the function of Gaussian blur, _cv2.GaussianBlur()_ is utilized to blur the noises, such as spots, and finally the function _cv2.Canny()_ is applied for edge detection. The effects of grayscale processing, Gaussian blur and edge detection are demonstrated in Figure 9a-c, respectively. Figure 8: Cropped image of YOLOv3 prediction frame. Figure 6: Illustration of center coordinates of the prediction box. Figure 7: Direction vector of the leaf and target watering point to be modified (stem-root junction). In order to merge the effective line segments at the edge of the main body, the contour is expanded using the function _cv2.dilate()_, as shown in Figure 10a. As the corner of the line segment may influence the calculation process of the leave vector, i.e., the folding of the line segment may reduce the single directionality of the contour area, the function _cv2.erode()_ is invoked to properly erode the expanded contour, as illustrated in Figure 10b. The function _cv2.findContours()_ is utilized to calculate the areas of all blocks, the largest ones of which, selected through the function _sorted()_, represents the contour-of-interest of the image. As represented in Figure 11a, the area marked in red is the largest part, for which the function _cv2.fitLine()_ is used to get the unit vector of the fitting line, clearly overlapped on the original image, as depicted in Figure 11b. The desired watering point on the stem-root junction is calculated after obtaining the actual 3D coordinates of the center point and the leaf vector. Through the customized  
Figure 11: Fitted line effect: (**a**) Marked largest area; (**b**) fitted line. Figure 10: Effects of dilation and erode processes. Figure 9: Edge detection effect: (**a**) grayscale process; (**b**) Gaussian blur; and (**c**) edge detection. function, the original fitted line vector is inputted to compute the vertical unit vector by the inner product.