在我的大学项目中,我需要通过检测叶子的边缘来根据植物叶子的形状来识别植物的种类。 (我使用OpenCV 2.4.9和C++),但源图像是在植物的真实环境中拍摄的,并且有不止一片叶子。请参阅下面的示例图片。所以这里我需要提取一片叶子的边缘图案来进一步处理。
![enter image description here](https://i.stack.imgur.com/yeJxE.jpg)
使用 Canny Edge Detector 我可以识别整个图像的边缘。
![enter image description here](https://i.stack.imgur.com/2sdhM.png)
但我不知道如何从这里开始提取一张叶子的边缘图案,可能会更清晰和完整的叶子。我不知道这是否也可能。谁能告诉我这是否可能,如何提取一片叶子的边缘,我只想知道我需要应用于图像的图像处理步骤。我不需要任何代码示例。我是图像处理和 OpenCV 的新手,通过实验进行学习。
提前致谢。
Edit
正如 Luis 所说,在使用 Canny 边缘检测进行边缘检测后,我已经对图像进行了形态学接近,但似乎我仍然很难从图像中找到最大的轮廓。
这是我处理图像所采取的步骤
-
应用双边滤波器降低噪声
bilateralFilter(img_src, img_blur, 31, 31 * 2, 31 / 2);
-
通过直方图均衡调整对比度
cvtColor(img_blur,img_equalized,CV_BGR2GRAY);
-
应用 Canny 边缘检测器
Canny(img_equalized, img_edge_detected, 20, 60, 3);
-
阈值二值图像以去除一些背景数据
threshold(img_edge_detected, img_threshold, 1, 255,THRESH_BINARY_INV);
-
图像的形态接近
morphologyEx(img_threshold, img_closed, MORPH_CLOSE, getStructuringElement(MORPH_ELLIPSE, Size(2, 2)));
以下是我得到的结果图像。
我从上面的原始图像中得到的结果
![enter image description here](https://i.stack.imgur.com/tP3Ci.png)
源图像和第二张图像的结果
来源 :
![enter image description here](https://i.stack.imgur.com/icChm.jpg)
Result :
![enter image description here](https://i.stack.imgur.com/w9OAl.png)
有什么方法可以检测最大轮廓并将其从图像中提取出来吗?
请注意,我的最终目标是使用真实环境图像创建一个植物识别系统,但在这里我不能使用模板匹配或屏蔽之类的东西,因为用户必须拍摄图像并上传它,所以系统没有任何先验想法关于叶子。
这是完整的代码
#include <opencv\cv.h>
#include <opencv\highgui.h>
using namespace cv;
int main()
{
Mat img_src, img_blur,img_gray,img_equalized,img_edge_detected,img_threshold,img_closed;
//Load original image
img_src = imread("E:\\IMAG0196.jpg");
//Apply Bilateral Filter to reduce noise
bilateralFilter(img_src, img_blur, 31, 31 * 2, 31 / 2);
//Adjust contrast by histogram equaliztion
cvtColor(img_blur,img_equalized,CV_BGR2GRAY);
//Apply Canny edge detector
Canny(img_equalized, img_edge_detected, 20, 60, 3);
//Threshold binary image to remove some background data
threshold(img_edge_detected, img_threshold, 15, 255,THRESH_BINARY_INV);
//Morphological close of the image
morphologyEx(img_threshold, img_closed, MORPH_CLOSE, getStructuringElement(MORPH_ELLIPSE, Size(2, 2)));
imshow("Result", img_closed);
waitKey(0);
return 0;
}
谢谢。