Multispectral Cameras and Machine Learning integrated into Portable Devices as Enabling Technology for Smart Farms

The present work proposed a low-cost portable device as an enabling technology for 1 Smart Farms using multispectral imaging and Machine Learning in soil texture. Clay is an 2 important factor for the verification and monitoring of soil use due to its fast reaction to chemical 3 and surface changes. The system developed uses the analysis of reflectance in wavebands for clay 4 prediction. The selection of each wavelength is performed through an LED lamp panel. A NoIR 5 microcamera controlled by a Raspberry Pi device is employed to acquire the image and unfold it 6 in RGB histograms. Results showed an good prediction performance with R2 of 0.96, RMSEC of 7 3.66% and RMSECV of 16.87%. The high portability allows the equipment to be used in a field 8 providing strategic information related to soil sciences. 9


Introduction
Smart Farming represents the use of information and communication technology 12 systems applied in agriculture with the objective of obtaining better results, greater 13 performance and higher quality production with safety and precision while optimizing 14 human work [1,2]. From these new technologies, an cultivation area can be divided 15 into as many plots as it has internal differences supported by soil analysis and each plot 16 can receive a customized treatment to obtain the maximum benefit from it. This is also 17 known as precision agriculture [3][4][5].
The traditional way of collecting soil in the fields and analyzing it in the laboratory 30 is the most accurate, but it takes time and uses an alkaline solution that need to be 31 neutralized before wasting [9]. New research has been proposed to optimize this, but 32 with limitations. Satellite images are important for obtaining quick information on the 33 surface of soils in large areas. However, mapping large areas of soil presents difficulties 34 as most areas are usually covered by vegetation [10]. 35 The use of spectral images expands the capacity of studies in several areas and their 36 application has been growing in agriculture in order to recognize patterns [11][12][13]. For 37 these types of analysis, two well-known scientific methodologies are used: spectroscopy 38 and imaging. Optical spectroscopy is a term used to describe the phenomena involving 39 a spectrum of light intensities at different wavelengths. Imaging can be conceptualized 40 as the science of image acquisition of the spatial shape of objects. Currently, the most 41 advanced way to capture images is digitaly [14]. 42 Multispectral and hyperspectral imaging systems are image analysis techniques 43 that are also based on capturing the same image at different wavelengths.The difference 44 consists by the number of captured wavelengths: while multispectral systems use up 45 to 10, hyperspectral systems can exceed 100 wavelengths, with the latter generating 46 grander amounts of data [15]. 47 Since single-board computers became more accessible to the general public, the 48 Raspberry Pi has become one of the more popular systems, mainly in the scientific 49 community, promoting solutions in IOT and all features involved [16,17]. The increase 50 of scientific articles that adopted this tool to solve challenges is highlighted by imple-51 mentations where the Raspberry Pi provided low-cost, compact hardware and flexibility 52 [18,19]. 53 In addition, Machine Learning tools as Partial Least Regression (PLSR) have been 54 applied for multivariate calibration in soil spectroscopy [20], images [21] and sensor 55 data [22]. These algorithms eliminate variables that do not correlate with the property of 56 interest, such as those that add noise, non-linearities or irrelevant information [23].

57
Considering the importance of research in areas involving soils (agriculture, geo-58 chemistry, geology), the ability to use devices such as the Raspberry Pi and the use of 59 Computer Vision techniques such as spectral imaging, the following research problem 60 was defined: "Is it possible to use multispectral imaging techniques to predict clays?".

61
The main objective is to develop a computer vision system to predict the amount 62 of clay in the soil using multispectral imaging techniques on a Raspberry Pi device.

63
The relevance of this work is in the absence of a fast, mobile, ship and non-destructive 64 method to measure clay content in soil.

65
This article is structured in six sections. Section two presents an approach to the 66 soil texture and colors, multispectral images, Machine Learning and OpenCV libraries.

67
Section three describes the related works while section four presents materials and meth-68 ods employed. Section five shows the results of the implementation and its discusions.

69
Finally the last section is intended for conclusions and future works.

71
The process of building a clay prediction system based on multispectral images 72 covers several areas of knowledge such as optics, soil science, computer vision and 73 artificial intelligence. behavior where characteristics such as humidity, deterioration and decomposition are 80 agents that influence the performance of its identification. Thus, the amount of bands in 81 the spectrum required for the identification of a given material, depends on the amount 82 of material discriminated and also on its variations [24]. 83 Light is a special band of electromagnetic radiation within the spectrum that can 84 be perceived by the human eye, this band is divided into six regions, which are violet, 85 blue, green, yellow, orange, red, whose perception of these colors is determined by light 86 reflected by an object. For example, green colored objects mainly reflect wavelengths 87 between 500 and 570 nm (green color in the electromagnetic spectrum), and absorb most 88 other wavelengths [25]. 89 A spectral imaging system is, essentially, composed of four components: lighting, 90 focus lens, a detector and a wavelength selection system. The first spectral imaging 91 systems were designed to filter the object's light and use a monochrome digital camera 92 to record the reflected light. More modern systems illuminated the sampling object with 93 a monochromatic light [26]. In recent years, LED lamps are adopted due to presenting 94 the advantage of less variation in brightness when compared to ordinary white lamps 95 [27]. Hue: it is usually red or yellow; 103

2.
Value: it is light or dark, the darker the closer the value is zero; 104 3. Chroma: it corresponds to the brightness, with zero corresponding to gray [28].

105
The color of the soil is directly influenced by three factors: organic matter, water 106 concentration and the oxidation state of iron and manganese oxides. Since soils with 107 higher water contents are darker than when dry, water also interferes with the amount 108 of microorganisms present, which also makes the soil darker. Oxidation in high quantity 109 leaves the soil more grayish or bluish, otherwise it will be more reddish [29]. containing air and water for root development.

118
And of poor quality:

166
Other figures of merit also used to evaluate a prediction model are: 167 1. Linearity, defined by the Coefficient of Determination (R 2 ), is aware of the model's ability to provide results directly proportional to the amount of analyte present in the sample, as shown in the Equation(1) [35].
Veracity: it is the degree of accuracy between the reference values and the predicted values. In the case of multivariate analysis is used the Root Means Squares Errors of Calibration (RMSEC), as shown in the Equation(2) [35]. The same equation is apllied to evaluate RMSECV.
The Kennard-Stone algorithm is a uniform mapping algorithm that selects samples selected. For this purpose, the algorithm uses the Euclidean distance [36]. field measurements with inexpensive and readily available remotely sensed inputs [38].  The obtained results show similar prediction accuracy for all spaceborne sensors but 196 some limitations occured in multispectral data [40]. multispectral imaging, which served as the basis for the present study [41].   Table 2.

232
The processing of the reflected spectra captured by the microcamera is performed 233 by the Raspberry Pi 3 Model B, which has the capacity to perform this type of task, 234 presenting small dimensions, low-energy consumption and offering low-costs. The   reflected in the sample, as presented in Figure 2(b).

273
The application software was developed using the Python 2.7 programming lan- Computer Vision, it covers the extraction, manipulation and analysis of images in order 281 to obtain useful information from them to perform a specific task [33].    Table 3 shows the steps of the algorithm developed for the acquisition and process-296 ing of images and the prediction of clay results. The first step consists to acquire images controlling all LEDs invidividually using   Table 4. that all models could be compared from the same configuration, according to Table 5. regarding linearity (R 2 equal to 0.962) and RMSEC (3.66). About the figure of merit 329 RMSECV, the result was shown to be greater than in the first generated model. Figure 5   330 shows the linear performance of this model.   Clay is one of the required parameters, among others, in order to assess soil fertility.

351
As presented in this work, the concentration of this substance in the soil was quantita-352 tively achieved through a multispectral camera. It was also possible to perceive a great 353 potential in the correlation with the official routine analysis.

354
As advantages, the methodologies that were developed in this work are simple and  Future research will organize the data collected in Context Histories [44,45] to allow 367 the pattern recognition [46], context prediction [47] and similarity analysis [48]. These The following abbreviations are used in this manuscript: