我在计算这个盘子中准确的菌落时遇到了问题。如果有人可以帮助我为此获得正确的算法,我将非常感激。
首先,我发现容器/平板然后使用以下代码。:
Imgproc.cvtColor(imageMat, result, Imgproc.COLOR_RGB2HSV);
Imgproc.medianBlur(result, result, 7);
Core.inRange(result, new Scalar(15,2,120), new Scalar(150, 255, 180), result);
Imgproc.GaussianBlur(result, result, new Size(3, 3), 0);
Imgproc.threshold(result,result, -1, 255,Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);
Imgproc.dilate(result, result, element);
Imgproc.findContours (result, contours, hierarchy, Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE );
Imgproc.cvtColor(result, result, Imgproc.COLOR_GRAY2RGB);
for (int i=0; i < contours.size(); i++) {
Rect r=Imgproc.boundingRect(contours.get(i));
if(r.area() > 3000000)
{
MatOfPoint2f contour2f = new MatOfPoint2f( contours.get(i).toArray() );
double approxDistance = Imgproc.arcLength(contour2f, true)*0.02;
Imgproc.approxPolyDP(contour2f, approxCurve, approxDistance, true);
//Convert back to MatOfPoint
MatOfPoint points = new MatOfPoint( approxCurve.toArray() );
Rect rect = Imgproc.boundingRect(points);
Core.rectangle(result, rect.tl(), rect.br(), new Scalar(255, 0, 0), 1,8, 0);
}
else
{
colonyCount++;
Imgproc.drawContours(result,contours,i,new Scalar(255,0,0),Core.FILLED);
}
System.out.println(“Colony count:”+ colonyCount); 结果图像是这样的。 The result image is this
我想消除盘子的边缘和盘子周围的噪音。请帮助我。谢谢。