Detecting the gabbages by using OpenCV
Overall
The smart farm is the hot topic in VietNam over recent year. In this project we try to use the computer vision and arm robot in order to harvest the vegetables at one smart farm. The project is deivided to part. One is CV and one is robot.
Figure 1. One Soilless Growing Farm in Viet Nam – All systems are controlled automationly
This demon will so you how to use the OpenCV to detect the center of the gabbages. Because the camera is set up look down and we want a fast implement, we won't use the deep learning in this task, use the traditional image processing algorithm for all.
Figure 2. The robot and camera system – This is the first design and
Figure 3. The result of all processing – We want to know where are the centers of tha gabbages.
Step by Step
Ok, let start. First, when looking down we have a image as below.
Figure 4. The raw image – The image we get it when looking down.
We can se the gabbages is green and it's the effect feature for dectecting. Furthermore, The white pipes is one additional feature. The first step is median filter, The median filter is the simple and basic method for removing noise.
medianBlur(img, imgMedian, 7);
Figure 5. The image after median filter processing
cvtColor(imgMedian, imgHSV, COLOR_BGR2HSV);
inRange(imgHSV, cv::Scalar(35, 60, 40, 0), cv::Scalar(80, 255, 255, 0), imgTh);
inRange(imgHSV, cv::Scalar(0, 0, 200, 0), cv::Scalar(180, 50, 255, 0), imgThW);
erode(imgTh, imgTh, Mat(), Point(0, 0), 2, 1, 1);
imgAfMask = Mat::zeros(img.size(), CV_8UC3);
img.copyTo(imgAfMask, imgTh);
Figure 6. The mask after using threshold algrorithm
Because the gabbages touch eac other, It's make very difficult to perform segmantation by one threshold algorithm. So, we use the watershed algorithm. You can enter the links for more detailed tutorial :
https://docs.opencv.org/3.3.1/d3/db4/tutorial_py_watershed.html https://docs.opencv.org/3.4/d2/dbd/tutorial_distance_transform.html