android中的图像点检测

时间:2016-11-21 06:31:04

标签: android opencv

我想问一下什么是最好的算法,用于使用安卓摄像头检测斑点(例如叶斑)的教程。我现在很陌生。希望得到积极的回应。谢谢!如果有人对opencv的这种合作有所了解,那我真的需要你的帮助!

1 个答案:

答案 0 :(得分:0)

首先看看Official Documentation。然后,首先,尝试使用颜色分割方法:

1)将图像拆分为HSV窗格:

Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2HSV);
final Mat frameH = channels.get(0);
final Mat frameV = channels.get(2);

2)阈值获得二进制图像所需的颜色(例如黄点的黄色色调值):

Imgproc.threshold(frameH, frameH, <hue_min>, <hue_max>, Imgproc.THRESH_BINARY);
Imgproc.threshold(frameV, frameV, <value_min>, <value_max>, Imgproc.THRESH_BINARY);
Core.bitwise_and(frameH, frameV, thresholdMat);

3)扩张以填补空白:

Imgproc.dilate(thresholdMat, thresholdMat, new Mat(), new Point(-1, 1), 3);

4)找到区域的边界轮廓:

List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Imgproc.findContours(thresholdMat, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

5)现在你已经在contours列表中找到了轮廓的轮廓,你可以用它来做你的魔术:

Iterator<MatOfPoint> each = contours.iterator();
while (each.hasNext()) {
    MatOfPoint contour = each.next();

    // do your magic with contour here
}

并且不要忘记过滤以消除图像噪音。