2.1. Processing pest images for feature extraction
For pest detection we used images received from real-time video with a resolution of 400 by 400 pixels. For correct image recognition, it is initially necessary to distinguish the characteristic features of each pest against the background of a cultivated plant. We considered the following functions of OpenCV library which is the most popular in works on the search for pests on images (https://github.com/Ildaron/Pest_OpenCV-image-preprocessing-python):
- Detection by color:
- Color filters (cv2.createTrackbar);
- Color detection (cv2.inRange, cv2.findContours).
- Smoothing Images:
- Convolution (cv2.filter2D);
- Image Blurring (cv2.blur);
- Bilateral Filtering (cv2.bilateralFilter);
- Laplacian (cv2.Laplacian).
- Morphological Transformations:
- Erosion (cv2.erode);
- Dilation (cv2.dilate);
- Opening (cv2.MORPH_OPEN);
- Morphological Gradient (cv2.MORPH_GRADIENT);
- Top Hat (cv2.MORPH_OPEN);
- Black Hat (cv2.MORPH_BLACKHAT).
Edge Detection:
- Contours (cv.drawContours);
- Figure (cv2.rectangle, cv2.minEnclosingCircle, cv2.circle);
- Fill (cv2.floodFill).
Thresholding:
- Binary (cv2.THRESH_BINARY);
- Binary_inv (cv2.THRESH_BINARY_INV);
- Trunc (cv2.THRESH_TRUNC);
- Tozero_inv (cv2.THRESH_TOZERO_INV).
Geometrical image transformation:
- Resize (cv2.resize);
- Translation cv2.warpAffine();
- Affine Transformation (cv2.getAffineTransform);
- Perspective Transformation (cv2.getPerspectiveTransform).
Image Derivatives:
- Sobel derivatives (cv2.Sobel);
- Scharr derivatives (cv2.Scharr).
For example, in figure 1 the image processing with cabbage caterpillar with a thresholding filter is shown.
To process the image with cabbage caterpillar we selected the next filters presented in figure 2.
2.2. Neural networks models for pest detection
After the image preprocessing process, we considered different types of convolutional neural networks (CNN) for the task of tracking pests. Today these networks have already become the standard in the field of machine vision and there are many different neural networks implemented in this technology. But not all networks are suitable for real-time tracking tasks. The use of convolutional neural networks on RaspberriePi is complicated due to the limited amount of RAM on the Raspberry Pi (1–4 GB) and the low processor frequency of 1.5 GHz. For example, the following popular models have the following size: ResNet50> 100 MB, VGGNet> 550 MB, AlexNet> 200 MB, GoogLeNet> 30 MB. Real-time detection with R-CNN, Fast R-CNN, Faster R-CNN, RetinaNet has the same recognition speed problem. The solution may be to use - NVIDIA Jetson TX1 and TX2 - a special platform for computing neural networks. The main disadvantage is that these devices cost a lot. Depending on the configuration, prices for the Jetson TX1 start at $ 300. The cost of the Raspberry PI 4 is around $ 40. Raspberry PI analogs - Orange PI and Banana PI have a wider line of unicameral computers of various types at a lower price but their characteristics are not higher. Therefore, we focused on the methods that can be implemented on the Raspberry Pi, which allows you to create an economical and compact device. We used a deep neural network, YoloV3, to detect pests. This neural network we used sequential 3 × 3 and 1 × 1 convolutional layers, as recommended by the authors of this neural network [26]. Diagram of the CNN in figure 3 is shown.
The architecture of this neural network makes it possible to track objects in real-time. In our case, due to the low performance of the raspberry pi3, we focused on a simpler task - monitoring about 10 objects every second. We trained the model without using any initial weights in Google Collab. At the initial stage, it took time, about 16 hours, and required many images, we used 2800 images for every pest. After that we can use the obtained model weights to train quickly the neural model to detect a new type of pest. To do this, we need only to freeze the model with the initial weights and activate only the last layers of the model and train the last layers already for a specific type of pest. As a result, this will reduce the training time for recognizing a new type of insect. The complete code of the neural model (training the model, using the model) is implemented in python https://github.com/Ildaron/Pest_YoloV3_python_custom-data.
2.3. Test neural networks models for pest detection
At the initial stage, to check the operation of the neural network and configure the executive program on RaspberryPI, we created the program for simulation of the laser operation. The program implemented in Python3.6 language received coordinates from the neural network and then, as a simulation of the laser operation with a delay of 50 milliseconds, the position of the pest in the video was determined by drawing a red point. If the coordinate received from the python of the program coincided with the coordinates received from the neural network, it meant pest had been destroyed, figure 4.
We checked the trained neural network and the laser simulation on the video with pests. The results are presented in Table 1.
Table 1. Test results of the neural network and the laser simulation
№
|
Average time to detect, ms
|
Pests amount
|
Total recognition (correct and not)
|
Recognition accuracy
|
Neutralized
|
Millisecond neutralization, ms
|
Cabbage caterpillar
|
300
|
100
|
90
|
80
|
75
|
50
|
Aphid
|
350
|
120
|
85
|
45
|
30
|
50
|
Grasshopper
|
250
|
80
|
20
|
30
|
20
|
60
|
The higher result we achieved for the cabbage caterpillar: what happened due to the low speed of the caterpillars, their large size, and color contrast with the background. Aphid recognition accuracy is 2 times lower due to the lack of pronounced color contrast. Grasshopper moves too fast, because of this the camera and raspberries cannot determine their position in the dynamics. Later, for experimental research of the laser, we used only cabbage caterpillar.