Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/326.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用opencv java计算殖民地?_Java_Opencv - Fatal编程技术网

如何使用opencv java计算殖民地?

如何使用opencv java计算殖民地?,java,opencv,Java,Opencv,我在计算这个盘子里的准确菌落时遇到了问题。如果有人能帮我找到正确的算法,我将不胜感激 首先,我找到了容器/板,然后使用以下代码: 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

我在计算这个盘子里的准确菌落时遇到了问题。如果有人能帮我找到正确的算法,我将不胜感激

首先,我找到了容器/板,然后使用以下代码:

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);
           }
Imgproc.cvtColor(imageMat,result,Imgproc.COLOR\u RGB2HSV);
Imgproc.medianBlur(结果,结果,7);
Core.inRange(结果,新标量(15,2120),新标量(150,255,180),结果);
结果,结果,新大小(3,3),0;
阈值(result,result,-1255,Imgproc.THRESH_BINARY+Imgproc.THRESH_OTSU);
扩大(结果、结果、要素);
Imgproc.findContours(结果、轮廓、层次、Imgproc.RETR_树、Imgproc.CHAIN_近似值_简单);
Imgproc.cvtColor(结果,结果,Imgproc.COLOR_GRAY2RGB);
对于(int i=0;i3000000)
{
MatOfPoint2f contour2f=新的MatOfPoint2f(outlows.get(i.toArray());
双接近距离=Imgproc.arcLength(轮廓2f,真值)*0.02;
Imgproc.approxPolyDP(轮廓2f,approxCurve,approxDistance,true);
//转换回MatOfPoint
MatOfPoint points=新的MatOfPoint(approxCurve.toArray());
Rect Rect=Imgproc.boundingRect(点);
矩形(result,rect.tl(),rect.br(),新标量(255,0,0),1,8,0);
} 
其他的
{
colonyCount++;
Imgproc.drawContours(结果,轮廓,i,新标量(255,0,0),核心填充);
}
System.out.println(“菌落计数:“+colonyCount”); 结果图像是这样的


我想消除图版的边界和图版周围的噪音。请帮助我解决这个问题。谢谢。

这个问题接近计算机科学问题,不是问题。我对图像处理是新手。这是我第一次使用opencv。你有什么建议吗?谢谢。