Application of Computer Vision Technology in Agricultural Products and Food Inspection

As a non-destructive testing method, computer vision has the advantages of rapidity, simplicity and less sample preparation, and has been widely used in the quality inspection of agricultural products such as size, shape, color, defects and freshness. It has become the development trend of agricultural products and food inspection work to replace manual operation with visual technology. By extracting the size, shape, color, texture and other characteristics of agricultural products and foods, combined with the prediction model, the digital image processing method can realize the non-contact and non-damage treatment of agricultural products and foods. This paper summarizes the application research and development of computer vision technology in agricultural products and food inspection at home and abroad.


Introduction
Computer vision technology refers to a technology that obtains the image of the desired object through the image sensor, converts the image into the corresponding data matrix, and then uses the computer to expand the analysis, thus completing the related visual tasks [1]. This technology was gradually developed in 1970s on the basis of the successful application of remote sensing image processing and medical image processing technology, and was applied in many fields [2]. Computer vision technology is a cross and combination of multiple disciplines, which involves many disciplines such as computer, mathematics, optics, psychology, physiology, physics, signal processing, etc. It is a new subject in the world today.
The quality inspection and grading of agricultural products is an important link in the process of circulation and processing. The level of inspection and grading is directly related to people's health, and it is also an important factor in the international and domestic market competition of agricultural products. Such as nutrient deficiency caused by nutrient deficiency, pollution diseases caused by harmful gases in the environment and weed diseases caused by overgrowth of weeds. In recent years, with the continuous improvement of computer hardware and software technology, computer vision technology has been greatly developed in the field of food processing. Gonzalez et al. [3] used the characteristics of eggplant such as length, diameter, volume, color and surface defects to realize eggplant classification; Wang Lingli [4] realizes automatic grading and screening by using the color of pomegranate grains; Combined with computer vision technology, an automatic method for objective evaluation of carcass quality can be established, which has the advantages of high accuracy, saving labor time, strong objectivity and simple operation.
Using computer vision technology in food grading can accurately grade a large number of foods in a short time, save a lot of labor, reduce production costs and keep the appearance of products well. This paper mainly discusses the application of computer vision inspection technology in agricultural products and food inspection from the logistics links such as storage, transportation, distribution and packaging.

Concept of Computer Vision Technology
Computer vision technology is an important part in the field of artificial intelligence. Computer vision technology can be defined as firstly obtaining images automatically by computer and analyzing images by software calculation method. Among them, the image acquisition link includes an illumination device and a camera; Image analysis includes image acquisition card, i.e., frame grabber or digitizer and analysis software. The purpose of preprocessing is to eliminate irrelevant information in the image, restore and strengthen useful information, enhance the testability of relevant information and simplify data to a great extent, so as to improve the reliability of image segmentation, feature extraction and recognition analysis. Perception of three-dimensional properties of space objects, with some functions of human brain, transmit, transform, abstract and identify this information, so as to make judgments and command the system to finally achieve the desired purpose [5].
Sample images acquired by image acquisition equipment are transmitted to a computer and converted into digital images. See fig. 1 for the processing process of sample images at all levels.  Computer vision technology is a technology that obtains the target image through computer vision hardware, and then uses the image processing process to extract the useful information in the image, and carries out quality analysis and process control. Edge detection is used to enhance edge information and perform threshold processing. Using Sobel algorithm, a black-and-white binary image containing only edge information can be obtained. Lighting includes front light and backlight, the front light is mainly used to detect the external surface features of products, while the backlight is used to enhance the background of objects [6]. Among the external factors, the illumination condition varies with the measured object and the surrounding environment. In order to extract the data information of the scanned static target or dynamic target, this technology is a technology and means to simulate the explicit or visual function of living things from a macro perspective.

Nondestructive testing of food quality during storage and transportation
During the storage and transportation of food, especially fruit, it is easy to cause surface friction between food and container, and the fruit is stabbed by the fruit stalk, which often damages the surface of food, which not only affects the quality, but also will soon rot and infect the surrounding food. Research on computer vision inspection technology of fruits and vegetables is an important measure to ensure the quality and safety of fruits and vegetables and to gain competitiveness in the international fruit and vegetable market. Using computer vision technology in food grading can accurately grade a large number of foods in a short time and save a lot of labor. The detection model reflecting the nutritional status of plants can filter out environmental interference such as soil noise and climatic conditions in real time, and realize rapid, accurate and nondestructive detection of plant nutritional components. Its idea is to move a window with odd pixels in sequence on the image, arrange the gray values of the pixels in the window from small to large at each position, and then take the gray value in the middle as the output value of the pixel in the center of the window.
Because of the different internal components and external characteristics of food, there will be different absorption or reflection under different wavelength light irradiation, that is, the spectral reflectance will be larger than other parts in a specific wavelength range. Liu Tongjin et al. [7], based on virtual instrument, conducted an experimental study on testing the external quality of Yali pear by using machine vision technology. This study can detect the defects, color, size and shape of Yali pear comprehensively. Tone H and saturation S are usually determined by the light absorption and reflection characteristics of the raw materials constituting the object, which accurately reflect the color types and have low sensitivity to changes in external lighting conditions. Typical image segmentation algorithms include threshold method, morphology method, image segmentation based on genetic algorithm and so on. The spectral characteristics and reflected ground object information of different types and different bands are different, so it is necessary to select appropriate instruments and technologies for measurement and analysis according to specific conditions.

Intelligent detection of storage pests by computer vision technology
In the aspect of fruit quality inspection, foreign countries not only carry out external quality inspection, but also carry out nondestructive inspection of its internal quality. Some inspection items have been commercialized and achieved real-time speed. Due to the differences of varieties, feeds and other factors, the egg hearts of duck eggs have different colors of red and yellow. The system can effectively distinguish the color of the egg center without destroying the eggshell, and avoid the disadvantages such as high labor intensity, low production efficiency and unqualified grading quality. Yang Minhui [8] proposed a method based on integer Bresenham algorithm to find the direction projection value and detect the tilt angle of the image by using the direction projection value. A M M A et al.
[9] studied the citrus maturity index based on the ratio of surface color to solid acid, established a machine vision system for citrus maturity detection, determined the suitable background color, and conducted the spectral reflectance test of citrus. Based on RGB and HIS color space models, computer vision can extract the color parameters of the target, and extract the texture features of the surface texture analysis target to identify the freshness.

Application of product surface defect and damage identification
Automatic identification of surface defects and damages has always been a difficult problem in the classification of agricultural products. Sugawara et al. [10] put forward the method of detecting fruit freshness by color region ratio. When the classification threshold is 0.88, it means that fresh fruits are above this threshold, while rotten fruits are below this threshold, which can realize the detection and classification of fruit freshness. Green component G and chroma H component of leaves are linearly related to nitrogen content, which can be used as indicators for rapid diagnosis of crop growth by machine vision. Using computer image recognition method to distinguish the ratio of red and white, and judging the ratio of lean meat to fat, a comprehensive functional module is formed, which realizes the automatic processing of white motion detection and classification of rain eggplant defects. It also shows the results of detection and classification, and the classification results include three items: laceration, musical injury and healing.
Automatic computer vision sorting system is generally composed of CCD camera detection device, transmission device, computer, control system, etc. In the process of fruit sorting, the fruit is located on the conveyor belt, and the C C D cameras are arranged above and around the conveyor belt, and the damage detection devices are installed on both sides of the conveyor belt. When fruits pass through CCD camera, the color, size, shape and surface damage of fruits are recorded, and these information can be processed by computer to complete the general sorting operation (Figure 2). The size, shape, color and defects of fruits and vegetables are the most important and direct sensory attributes of fruits and vegetables, which affect their value at the point of sale and consumers' purchasing behavior. In 1989, Yan Tao [11] proposed a new calculation method for processing the gray image of apple surface by using infrared scanning camera, which can not only determine the damage area, but also distinguish different damages. For scratches without obvious edges, near infrared images are used to identify them, and finally defects are classified according to the regulations of USDA. In foreign countries, according to the appearance characteristics of eggs, apples, etc., the computer image processing system has been developed accordingly to improve the speed and accuracy of the grading machinery for these products [12].

Application in color detection
Color is one of the important qualities of agricultural products and food. Using computer vision system to evaluate the color of products can overcome the fatigue and difference of human eyes, and at the same time, it can make corresponding judgments by using the color difference of each part of products. Shi Weikun et al. [13] created a real-time feature extraction algorithm, which can detect the quality according to the color features of corn. As long as it is properly calibrated, the accuracy and speed of the system are higher than those of previous methods. This has laid a certain technical foundation for the development of large-scale and industrial-level automatic grain quality detection system. Specifically, we first find a seed pixel for each region to be segmented as the starting point for growth, and then merge the neighborhood around the seed pixel with the region where the seed pixel is located or pixels with similar properties (determined according to some predetermined growth or similarity criteria) into the region where the seed pixel is located. Under different conditions, such as the types of illumination sources, illuminance and reflection characteristics of objects, the measured RGB color values are scattered, and the three components change with each other. According to the randomly sampled images, the computer can calculate the grading information of the fruits in this image, such as the size, middle and small, excellent and poor, and the proportion of damaged conditions, and make a comprehensive quality judgment. This method is not only time-saving and labor-saving, but also objective and fair.

Application of agricultural product size and area detection
On the basis of comprehensive analysis of fruit shape, six characteristic parameters are proposed to represent fruit shape, and artificial neural network is used to identify and grade fruit shape. Gui Ruili [14] compared manual detection with machine vision technology, and found that, compared with manual detection, the accuracy of detection with vision is higher, and the time spent is only about 1/3 of that of manual detection method. By capturing the apple image in the pipeline state, the size, shape, color and defect of apple were characterized by selecting the maximum fruit diameter, twodimensional Fourier dynamic transform, chroma image and pixel area of defect point. Scan the image line by line to find the point where the R gray scale and G gray scale change at the same time, if so, mark it and continue to look down. In order to remove the fruit stalks of citrus picked by robots, some researchers have studied three methods to identify fruit stalks, namely, color segmentation method based on linear discrete analysis technology, contour curvature analysis method and image thinning method. These algorithms can determine the existence and position of fruit stalks from the random position map of citrus, and the accuracy is higher than 90%. Taking apple grading as an example, firstly, an apple with the best fruit shape is selected from the samples with superior fruit shape, and other samples take the fruit as the standard to calculate various parameters, and then these parameters are averaged as the characteristic parameters of the reference shape. Devi et al. [15] developed a computer vision system suitable for quality inspection of huanghuali. In order to meet the requirements of randomness of fruit direction and irregularity of fruit shape in actual production, the method of fruit size inspection has better adaptability. However, when leaves are attached to the fruit stalk or the fruit stalk breaks, it is very laborious to find the intersection point between the fruit stalk and the fruit body, and it is impossible to judge whether the fruit stalk is complete or not. The intelligent visual recognition function in the computer vision system can comprehensively judge any fruit grade, determine its accurate information, and then transmit certain instructions to the grading system through the control module in the recognition system, thus completing the grading work of fruits.

Application in fruit shape recognition
The shape of fruit is also one of the factors that affect the quality of fruit. After ripening, the shape of fruit is ever-changing, so it is difficult to identify it by mathematical method. The shape and other external features of objects are the main features to distinguish and identify. Using computer vision system to identify complex target images is to extract and analyze the features of object images. Compared with fruit, the stem of apple is obviously narrower. By using one-dimensional linear scanning method, we can successfully identify whether the fruit has stem or not. Chaw et al. [16] used computer vision to measure the seed size distribution of lentils from a large number of sample images, used morphological processing technology to segment seed boundaries, and classified seed sizes into different types on histogram. The results show that computer vision can be used to obtain the size distribution of a large number of lentils. He Fang [17], based on pattern recognition technology and digital image analysis technology, used a special algorithm for tomato orientation and classified according to its shape, size and surface defect points, determined the tomato calyx and defect position by using gray gradient curve, and successfully developed a machine vision tomato quality grading device with illumination device and orientation mechanism.
According to the gray value variation characteristics of damaged and undamaged areas of apple surface, different areas are segmented by the regional features of the image to find out the damaged areas. In order to expand the application scope of the agricultural product defect classification system, the characteristic parameters of damaged areas should be designed and extracted as fully and comprehensively as possible, so as to select and use them for the defect analysis process of different varieties of agricultural products. When fruits pass through, it is required that the visual system can quickly check the whole surface of each fruit, even if the defect area is small, the fruit grade will change greatly. Therefore, under the condition of given threshold, defects can be separated. Through the established standard sphere gray model, fruit defects are segmented, and only a single threshold is used in segmentation, without considering the threshold boundary problem. The size, damage number and damage area, calyx color, fruit shape and fruit curvature of eggplant can be extracted and detected from the obtained images. In foreign countries, the computer vision technology for detecting crush injuries of apples, peaches and plums can not only determine the damage area, but also distinguish the crush injuries from bird pecking, insect biting and brown spots.

Conclusion
Computer vision technology is mainly used in real-time diagnosis, forecasting, prevention and control of diseases in industrial high agricultural production, and improves the reliability, automation and intelligence of disease diagnosis or forecasting. In recent years, food safety has gradually become the focus of attention. Therefore, food classification and quality inspection system based on computer vision technology has attracted more and more attention. Using machine vision to classify fruits can comprehensively classify multiple standards, including the size, color, shape and surface defects of fruits at one time. At the same time, the research of computer vision in agricultural engineering has taken a big step towards practicality, from the study of the correlation between the initial image characteristics and a certain characteristic of materials to the detection and grading system with computer vision system as the leading component.