OpenCV中文网站

 找回密码
 立即注册
搜索
热搜: 安装 配置
查看: 3524|回复: 2

求助为什么有时候CvInvoke.Canny不返回了

[复制链接]
发表于 2016-4-21 14:32:41 | 显示全部楼层 |阅读模式
做了一个识别图片中白斑的小程序,图片是从工业相机实时抓取的,当连续运行一段时间后显示画面锁死,用onsole.WriteLine()测试是卡在CvInvoke.Canny中没有返回??发现不了问题,图像,请大家帮忙想想
private bool IsTubleExist(Image<Rgb, byte> image)
      {
          Console.WriteLine("IsTubleExist 1");
          image.ROI = this.RectangelGetColor;
          using (Image<Gray, byte> imgtmp = new Image<Gray, byte>(this.RectangelGetColor.Size))
          {
              CvInvoke.CvtColor(image, imgtmp, Emgu.CV.CvEnum.ColorConversion.Rgb2Gray);
              image.ROI = System.Drawing.Rectangle.Empty;
              imgtmp.SmoothGaussian(5);
              CvInvoke.Threshold(imgtmp, imgtmp, 25, 255, Emgu.CV.CvEnum.ThresholdType.Binary);
              Console.WriteLine("IsTubleExist 2");
              //CvInvoke.AdaptiveThreshold(imgtmp, imgtmp, 255, Emgu.CV.CvEnum.AdaptiveThresholdType.GaussianC, Emgu.CV.CvEnum.ThresholdType.Binary, 3, 0);

              //Stopwatch watch = Stopwatch.StartNew();
              double cannyThreshold = 180.0;
              //double circleAccumulatorThreshold = 120;
              //CircleF[] circles = CvInvoke.HoughCircles(imgtmp, HoughType.Gradient, 2.0, 20.0, cannyThreshold, circleAccumulatorThreshold, 5);
              double cannyThresholdLinking = 20.0;
              using (UMat cannyEdges = new UMat())
              {
                  Console.WriteLine("IsTubleExist 3 :"+imgtmp.Bytes.GetLength(0));
                  try
                  {
                      CvInvoke.Canny(imgtmp, cannyEdges, cannyThreshold, cannyThresholdLinking);
                  }
                  catch(Exception e)
                  {
                  }
                  //List<Triangle2DF> triangleList = new List<Triangle2DF>();
                  //List<RotatedRect> boxList = new List<RotatedRect>(); //a box is a rotated rectangle
                  Console.WriteLine("IsTubleExist 4  :"+cannyEdges.Bytes.GetLength(0));
                  using (Emgu.CV.Util.VectorOfVectorOfPoint contours = new Emgu.CV.Util.VectorOfVectorOfPoint())
                  {
                      try
                      {
                          //CvInvoke.FindContours(cannyEdges, contours, null, RetrType.List,RetrType.External, ChainApproxMethod.ChainApproxSimple);
                          CvInvoke.FindContours(cannyEdges, contours, null, RetrType.External, ChainApproxMethod.ChainApproxSimple);
                      }
                      catch (Exception e)
                      {
                      }
                      Console.WriteLine("IsTubleExist 5");
                      int count = contours.Size;
                      for (int i = 0; i < count; i++)
                      {
                          using (Emgu.CV.Util.VectorOfPoint contour = contours[i])
                          {
                              double area = CvInvoke.ContourArea(contour, false);
                              if ((area > 300) && (area < 1500))
                              {
                                  return false;
                              }
                          }
                      }
                  }
              }
          }
          return true;
       }

回复

使用道具 举报

 楼主| 发表于 2016-4-21 14:33:16 | 显示全部楼层
自己顶下
回复 支持 反对

使用道具 举报

 楼主| 发表于 2016-4-21 15:31:55 | 显示全部楼层
高手来了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-4-25 23:48 , Processed in 0.010568 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表