Academic Journal of Science and Technology ISSN: 2771-3032 | Vol. 5, No. 1, 2023 136 Research on Navigation Line Extraction Algorithm Based on Onion Ridge Edge Features Yangqian Ren1, Yong Yang1, *, Haibo Wang 2, Dong Wang2 1 Academy of Mechanical and Automotive Engineering, Qingdao University of Technology, Qingdao, 266520, China 2 Qingdao Special Steel Co., Ltd, Qingdao, 266409, China * Corresponding author: Yong Yang (Email: yyong901@163.com) Abstract: Aiming at the phenomenon that the existing shallot harvester cannot realize the automatic operation in the harvesting process of green onion, a navigation path acquisition method of green onion harvester is proposed, which is applied to the automatic driving of the shallot harvester. Firstly, the original image is grayed by G-R algorithm, and then the gray image is segmented by maximum inter-class variance method to obtain binaryized image; secondly, the morphological operation is applied to the binary map for noise reduction processing and hole filling to obtain the green onion ridge with good connectivity; then, according to the geometric characteristics of the green onion ridge, the left and right edge feature points of the green onion ridge are detected, and the midpoint of the left and right edge feature points is taken as the navigation key point; finally, the navigation key point is fitted with the least squares method. Gets the navigation line for the green onion ridge. Experimental results show that the proposed algorithm takes about 71ms to process an image with a resolution of 450 pixels and 330 pixels, and the average error angle of the navigation line is 0.649°. The algorithm can accurately and quickly extract the navigation line of the green onion ridge, and can provide accurate navigation information for the automatic driving of the green onion harvester. Keywords: Green onion harvester, Edge features, Image processing, Navigation line. 1. Introduction China has a long history of green onion cultivation and is the world's largest producer and exporter of green onions [1]. The green onion industry has become a pillar industry in some regions of China to promote the sustainable development of rural economy and a major economic source to increase farmers' income [2]. The cultivation of green onions requires multiple production links, and the harvesting of green onions is the most important part of the green onion industry. Harvesting requires more labor, and the quality of harvesting determines the final quality of green onions [3]. In order to further promote the high-quality development of the green onion industry, we must vigorously develop the mechanization and intelligent harvesting technology of green onions. Automatic driving during the operation of the green onion harvester is one of the key technologies to realize the intelligent harvesting of green onions. At present, the navigation methods used in automatic driving of agricultural machinery mainly include global satellite navigation [4], lidar navigation [5] and machine vision navigation [6]. Machine vision navigation is less expensive than the other two navigation methods and is suitable for complex agricultural environments [7-8]. Therefore, machine vision navigation is more suitable for autonomous driving scenarios where green onions are harvested. He Yong et al. [9] proposed a deep learning model MobileV2-UNet for paddy area segmentation, which uses frame-correlation and random sampling consensus algorithms to detect boundary lines, and realizes the automatic detection of paddy boundary lines. Yang Yang et al. [10] proposed a dynamic ROI (Region of Interest, ROI) region division algorithm for plant protection machine wheels walking between corn rows, and extracted navigation lines in the dynamic ROI region for real-time extraction of navigation lines between corn rows. Liao Juan et al. [11] proposed a seedling row centerline extraction based on sub-regional feature point clustering, which was applied to transplanter navigation. To summarize the existing research, the existing research on the acquisition method of farmland navigation path mainly focuses on agricultural machinery such as rice and corn, while the navigation path acquisition method for green onion harvester has not been reported. In view of this situation, this paper proposes a visual navigation path acquisition algorithm for green onion harvesting operations. After preprocessing the image, the holes in the onion ridge are filled, and based on the geometric difference between the onion ridge and other areas, the left and right edge feature points of the green onion ridge are extracted, the midpoint of the left and right edge feature points is used as the key point, and the least squares method is used to fit to obtain the green onion ridge navigation line. 2. Image Preprocessing Green onion information and soil background are included in the acquired green onion color image, as shown in Figure 1. Color pictures are essentially three-dimensional matrix, the information content is too large, in order to improve the speed of operation, reduce the impact of interference information, it is necessary to preprocess the original image collected. Image preprocessing mainly includes grayscale processing, binary processing and morphological processing of images. The color space of the original image acquired is the RGB color space, and other color spaces need to be converted from the RGB color space. In order to avoid image distortion and reduce operation time during color space conversion, this paper uses RGB color space to preprocess images. 137 Figure 1. Original image 2.1. Image grayscale As a green plant, the value of the G component of green onions is much higher than that of the R component and the B component. The color of the soil part is brown, and the values of the three components of R, G and B are not much different. In order to better separate the green onion and soil background, it is necessary to select an image grayscale processing method that can increase the weight of the G component. Therefore, this paper uses the G-R algorithm to grayscale the original image. Figure 2. Grayscale image 2.2. Image binarization F The purpose of the binarization of the image is to separate the green onion information from the soil background. Among the existing image segmentation methods, threshold segmentation is simpler and more efficient than other image segmentation methods [12]. In this paper, the maximum between-class variance method that can automatically calculate the threshold is used to binarize the grayscale map. The obtained binary plot is shown in Figure 3, which shows that the threshold segmentation algorithm can better realize the segmentation of green onions and land background. Figure 3. Binary image 2.3. Image morphological processing The binary plot obtained by threshold segmentation contains a lot of noise and holes. If these interference information is not removed, direct detection of edge information will not only increase the operation time, but also interfere with the calculation results, which will affect the real-time and accuracy of the entire system. Morphological processing of the image removes noise and fills holes. After performing a closed operation and a morphological opening operation on Figure 3, the results are shown in Figure 4. From the figure, it can be seen that most of the small area noise is cleared, and the connectivity of the green onion ridge area is good. Figure 4. Morphological image 3. Navigation Line Extraction Since green onions are planted in rows, the line segments that run through the rhizome of each crop serve as its navigation line. But the rhizome of green onions is difficult to detect. From the growth characteristics of green onions, it can be seen that the center of the green onion ridge is close to the rhizome position of green onion. Therefore, the midpoint of the green onion ridge can be used as the key point for navigation line extraction. The midpoint of the green onion ridge can be obtained based on the edge information of the green onion ridge, and then the navigation line can be extracted. Therefore, the detection of onion ridge edge information is a necessary prerequisite for obtaining navigation lines. 138 3.1. Navigation keypoint extraction based on edge features The traditional extraction algorithm of crop row navigation key points is mostly based on the overall edge information of crops [13]. This method of extracting navigation keys based on the overall edge information of the crop is easily affected by irregular leaf growth, resulting in the extraction of key points deviating from the center of the ridge row and cannot be directly applied to the fitting of the navigation line [14]. In view of the above shortcomings, this paper proposes a method for detecting the edge of green onion ridges based on geometric differences. The irregularly growing leaves of green onions are much smaller than the ridges in lateral width. Therefore, the edge of the black fragment with the largest width value in each row in the image is the edge of the green onion ridge. Green onion ridges can be detected by comparing the widths of all black fragments in each row, and the edge information of the green onion ridges can be extracted. The specific algorithm steps are as follows: 1)Scan the preprocessed image row by row, and store all the column coordinates with pixel values of 0 in the picture in list L by row, that is, the column coordinates with pixel values of 0 in row i are stored in the sublist L[i] of list L. 2) Detect the elements of list L by row, and classify the elements in the sublist L [i] of list L with a numerical difference equal to 1 as a class. Store the set of elements of the same category in the sublist L[i] as a list to the sublist Q[i] in list Q. 3) Detect the elements of list Q by rows, calculate the length of all sublists in list Q[i] and add the index of the sublist with the largest length to the list index in Q[i], then the longest sublist in list Q[i] can be represented as Q[i][index[i]]. 4) The information stored in the list Q[i][index[i]] is the column coordinates of the green onion ridge. The first element (Q[i][index[i]][0]) is the left-edge feature column coordinate of row i, and the last element (Q[i][index[i]][-1]) is the right-edge feature point column coordinate of row i. Q[i][index[i]][0] and Q[i][index[i]][-1] are added to Listing B by row, then the left edge feature point coordinates of the onion ridge are (i,B[i][i][0]), then the right edge feature point coordinates of the green onion ridge are (i,B[i][1]). 5) Take the midpoint of the left and right edge feature points of the green onion ridge as the navigation key point. Traversing each line of the image is computationally intensive, reducing real-time. Therefore, this paper extracts navigation key points every 10 lines, which improves the real- time detection under the premise of ensuring accuracy. 3.2. Navigation Line Extraction The coordinate information of the navigation key points has been determined above, and it can be fitted to a straight line to extract the green onion ridge navigation line. Common straight-line fitting methods Hough transform [15], RANSAC algorithm [16], least squares method [17]. The Hough transform can fit multiple straight lines at the same time, which is more suitable for the extraction of navigation lines for multi-ridged crops. The RANSAC algorithm is not affected by outliers, but the accuracy is affected by the number of iterations and the operation time is long. Compared with the Hough transform and RANSAC algorithm, the least squares method has high fitting accuracy and fast speed, which is more suitable for the set of navigation key points with small error extracted in this paper. Therefore, the least squares method is used to fit the extracted navigation keys in a straight line. 4. Application and Analysis of New Algorithms 4.1. Comparison of navigation key extraction algorithms The traditional navigation key point extraction algorithm first extracts the overall edge information of the crop by edge detection of the preprocessed image through the edge detection operator, then detects all the edge points of the crop by row, and finally takes the mean point of all the edge points of the row as the navigation key. According to the geometric features of the green onion ridge, the algorithm extracts the left and right edge feature points of the green onion ridge on the preprocessed image, and then takes the midpoint of the left and right edge feature points of the green onion ridge as the navigation key. Two different algorithms are used to extract navigation key points from the same image, and the navigation key extraction results are compared and analyzed. The traditional navigation row key extraction algorithm takes 45 milliseconds to process an image with a resolution of 450 pixels × 330 pixels, and the result is shown in Figure 5. The navigation row key extraction algorithm in this paper takes 40 milliseconds to process an image with a resolution of 450 pixels × 330 pixels, and the results are shown in Figure 6. Figure 5. Traditional algorithm navigation key point extraction results Figure 6. This article algorithmically navigates key points to extract the results From Figure 5 and 6, it can be intuitively seen that the 139 navigation key points extracted by the traditional algorithm are significantly deviated from the center of the green onion ridge, while the navigation key points extracted by the algorithm in this paper have a small deviation from the center of the green onion ridge. Compared with the traditional navigation key extraction algorithm, the proposed algorithm can reduce the influence of irregular growth leaves, and the extracted navigation key points are more accurate and can be directly applied to the extraction of navigation lines. At the same time, compared with the traditional algorithm, the proposed algorithm does not significantly increase the time consumption, and will not adversely affect the real-time performance of the entire system. 4.2. Comparison of navigation line extraction algorithms The Hough transform controls the straight-line fitting results of navigation keys through three parameters: polar distance resolution, polar angle resolution, and accumulation threshold. To improve the accuracy of straight-line fitting, set the polar distance resolution to 1 pixel and the polar angle resolution to 1rad. The accumulation threshold is used to determine the number of straight lines fitted, and when the accumulation threshold is too small, multiple straight lines are fitted, which is not conducive to the extraction of navigation parameters. It is known through experiments that when the accumulation threshold is greater than 94 and less than 99, a straight line is fitted. Therefore, set the accumulation threshold to 95. The results of the Hough transform navigation line extraction are shown in Figure 7. Figure 7. Hough transforms navigation lines to extract results The RANSAC algorithm is a learning technique that estimates model parameters by randomly sampling the observed data. First, two random points are selected from the set of navigation keys for parameter estimation. The estimation model is then tested with all navigation keys. By continuously establishing hypotheses and testing iterations, the optimal straight line is obtained. The parameters of the RANSAC algorithm are set as follows: success probability P = 0.99, total data n=65, acceptable difference between data and model Sigma = 0.1, let w represent the probability of selecting an interior point each time a point is selected (w is the number of inside points divided by the total number of points). Number of iterations: K=(log(1-P)) ∕ (log(1-w^n)) . (1) The navigation line extraction results of the RANSAC algorithm are shown in Figure 8. Figure 8. The results of the navigation line extraction by the RANSAC method Compared with the above two algorithms, the least squares method is a relatively simple straight-line fitting method. When using the least squares method for line fitting, parameter settings are not necessary. Therefore, the navigation line extraction results are only related to the navigation key points. The results of the least squares navigation line extraction are shown in Figure 9. Figure 9. Least squares navigation line extraction results In order to judge the accuracy of the extracted navigation lines, this paper uses the manually drawn center line of the green onion ridge as the reference standard. The angle between the extracted navigation line and the manually drawn center line of the green onion ridge is the error angle extracted by the navigation line, and when the error angle is less than 5°, the extracted navigation line can meet the requirements of accurate navigation. From Figure 7, 8 and 9, it can be intuitively seen that the navigation lines extracted by applying the least squares method are significantly better than the other two algorithms. In order to further verify the advantages of least squares method, this paper uses least squares method, Hough transform, and RANSAC algorithm to extract navigation lines from 50 images, and compares and analyzes the navigation lines extracted by the three algorithms, and the results are shown in Table 1. Compared with the Hough 140 transform, the error angle of the navigation line extracted by the least squares method is reduced by 1.478°, and the time consumption is reduced by 17ms. Compared with the RANSAC algorithm, the error angle of the navigation line extracted by the least squares method is reduced by 4.379°, and the time consumption is reduced by 61ms. The experimental results show that the least squares method is superior to the other two algorithms in terms of navigation accuracy and real-time performance. Table 1. Comparison of error angles and time consumption of different algorithms Algorithm name Number of images/(frame) Average error angle/(°) Average time consumption per frame/(ms) Hough transform 50 2.127 88 RANSAC algorithm 50 5.028 132 Least squares 50 0.649 71 5. Conclusion 1) The original image was preprocessed by G-R algorithm, maximum between-class variance method and image morphological operation, and the green onion ridges with good connectivity were successfully separated from the soil background. 2) Aiming at the shortcomings of the traditional navigation key point extraction algorithm, a navigation key extraction algorithm based on the edge features of the verdant edge is proposed. The algorithm can eliminate the influence of irregular growth leaves and weeds, and there are no outliers in the set of extracted navigation key points, which can be directly applied to the extraction of navigation lines without the culling of outliers. Then, the least squares method is applied to fit the navigation key points in a straight line to obtain the green onion ridge navigation line. 3) The application and comparative analysis of the new algorithm show that the new algorithm takes about 71ms to process an image with a resolution of 450 pixels × 330 pixels, and the average error angle of navigation lines is 0.649°. Compared with the traditional method, the algorithm has high accuracy and good real-time performance, which can provide more reliable visual navigation information for green onion harvesting operations. References [1] G. O. Young, “Synthetic structure of industrial plastics (Book style with paper title and editor),” in Plastics, 2nd ed. vol. 3, J. Peters, Ed. New York: McGraw-Hill, 1964, pp. 15–64. [2] W.-K. Chen, Linear Networks and Systems (Book style). Belmont, CA: Wadsworth, 1993, pp. 123–135. [3] H. Poor, An Introduction to Signal Detection and Estimation. New York: Springer-Verlag, 1985, ch. 4. [4] Wei Shuang, Huang Shichao, Zhang Man, et al. GNSS-based automatic navigation path search and steering control of agricultural machinery[J]. Transactions of the CSAE, 2017, 33(S1): 70-77. [5] LI Yanzhou, Shi Yifeng, Tu Wei, et al. Research on autonomous navigation between rows of sugarcane field in full growth cycle based on lidar[J]. Journal of Chinese Agricultural Mechanization, 2022, 43(03): 153-158+177. [6] Guo Xiangyu, Xu Xinyu. Extraction method of navigation line in rice seed production based on machine vision[J]. Journal of Chinese Agricultural Mechanization, 2022, 43(03): 153- 158+177. [7] Hu Jingtao, Gao Lei, Bai Xiaoping, et al. Research progress on automatic navigation technology of agricultural machinery[J]. Transactions of the CSAE, 2015, 31(10): 1-10. [8] Zhang Man, Ji Yuhan, Li Shichao, et al. Research progress of agricultural machinery navigation technology[J]. Transactions of the Chinese Society for Agricultural Machinery, 2020, 51(04): 1-18. [9] He Yong, Zhang Xiya, Zhang Zeqing, et al. Automated detection of boundary line in paddy field using MobileV2- UNet and RANSAC[J]. Computers and Electronics in Agriculture, 2022, 194. [10] Yang Yang, Zhang Boli, Zha Jiayi, et al. Real-time extraction of navigation lines between corn rows[J]. Transactions of the CSAE, 2020, 36(12): 162-171. [11] Liao Juan, Wang Yao, Yin Junnan, et al. Extraction of seedling row centerline based on subregional feature point clustering[J]. Transactions of the Chinese Society for Agricultural Machinery, 2019, 50(11): 34-41. [12] Qian Jinlei. Research on image segmentation method of green plants in field under natural illumination[D]. Huhehaote: Inner Mongolia University, 2018. [13] Gong Jinliang, Wang Xiangxiang, Zhang Yanwen, et al. Extraction method of maize rhizome navigation line based on edge detection and area localization[J]. Transactions of the Chinese Society for Agricultural Machinery, 2020, 51(10): 26- 33. [14] Li Xiuzhi, Peng Xiaobin, Fang Huimin, et al. Navigation path detection of plant protection robot based on RANSAC algorithm[J]. Transactions of the Chinese Society for Agricultural Machinery, 2020, 51(09): 40-46. [15] Wang Shanshan, Yu Shanshan, Zhang Wenyi, et al. Rice seedling row detection based on feature point neighborhood Hough transform[J]. Transactions of the Chinese Society for Agricultural Machinery, 2020, 51(10): 18-25. [16] Lu Zefeng, Xu Ying, Shan Xin, et al. A Lane Detection Method Based on a Ridge Detector and Regional G-RANSAC[J]. Sensors, 2019, 19(18). [17] SI Yongsheng, JIANG Guoquan, LIU Gang, et al. Early crop row centerline detection method based on least squares method[J]. Transactions of the Chinese Society for Agricultural Machinery, 2010, 41(07): 163-167+185.