【问题标题】:I want to find the biggest contour of the image我想找到图像的最大轮廓
【发布时间】:2015-07-23 07:09:05
【问题描述】:

我想找到最大轮廓的凸面并获得凸面缺陷。这是我寻找最大轮廓的代码。我使用 opencv for android。有人可以帮帮我吗。

       Imgproc.cvtColor (inputFrame.rgba(), mIntermediateMat, Imgproc.COLOR_RGB2YCrCb, 4);
        Core.inRange(mIntermediateMat, new Scalar(1, 133, 77), new Scalar(255, 173, 127), mGray);
        Imgproc.erode(mGray,mGray, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4,4)));        
        Imgproc.dilate(mGray, mGray, Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(4, 4)));
        Imgproc.blur(mGray, mGray, new Size(3.0, 3.0));
        Imgproc.adaptiveThreshold(mGray, mcontour, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,Imgproc.THRESH_BINARY_INV, 3, 1);
        mRgba = inputFrame.rgba();
        maxContourArea=0;
        contours= new ArrayList<MatOfPoint>();
        Imgproc.findContours(mcontour, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
        for (int idx = 0; idx < contours.size(); idx++) 
        {
               contour = contours.get(idx);

             double contourarea = Imgproc.contourArea(contour);
              if (contourarea > maxContourArea ) 
              {

                       maxContourArea = contourarea;
                       maxAreaIdx = idx;

              }
        }

        if(maxContourArea>1000)
        {
        Imgproc.drawContours ( mRgba, contours, maxAreaIdx, new Scalar(120,120,120),2);
        }
        contours.clear();

【问题讨论】:

标签: android opencv


【解决方案1】:

有关于的功能

cv::convexityDefects()查找轮廓的凸面缺陷

cv::isContourConvex() 测试轮廓凸度

http://docs.opencv.org/3.0.0/d3/dc0/group__imgproc__shape.html

【讨论】:

  • 我明白了..谢谢大家。
猜你喜欢
  • 2011-11-27
  • 1970-01-01
  • 2017-04-06
  • 2020-09-14
  • 2018-07-09
  • 1970-01-01
  • 2021-01-05
  • 2018-02-21
  • 1970-01-01
相关资源
最近更新 更多