Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 在轮廓openCV中找到直线大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_616_4@ 我正在使用 android openCV,我想检测图像中的三角形,矩形和圆形.所以我这样做:CAnny => findContours => approxPolyDP并获取图片
Image Hosted by ImageShack.us http://imageshack.us/a/img839/8100/device20130114224716.png

但是,approxPolyDP的结果包含很多顶点,所以我无法确定它是哪个形状.为了消除顶点,我想检测每个轮廓中的线并找到它们的交点.如何为单个轮廓做到这一点?

解决方法

对于圆圈检测,请使用 HoughCircles.

然后在这里你只是寻找简化的多边形(三角形和正方形).你试过在aptPolyDP中调整epsilon吗?

以下是openCV squares.cpp sample code的示例代码段 – 了解近似精度(epsilon,aboutPolyDP的第三个参数)是如何相对于轮廓的大小设置的.

C代码,但openCV接口应该是相同的,所以我确信它可以直接适应您的环境.

// test each contour
  for( size_t i = 0; i < contours.size(); i++ )
      {
          // approximate contour with accuracy proportional
          // to the contour perimeter
      approxPolyDP(Mat(contours[i]),approx,arcLength(Mat(contours[i]),truE)*0.02,truE);

          // square contours should have 4 vertices after approximation
          // relatively large area (to filter out noisy contours)
          // and be convex.
          // Note: absolute value of an area is used because
          // area may be positive or negative - in accordance with the
          // contour orientation
      if( approx.size() == 4 &&
         fabs(contourArea(Mat(approX))) > 1000 &&
         isContourConvex(Mat(approX)) )
          {
          double maxCosine = 0;

          for( int j = 2; j < 5; j++ )
              {
                  // find the maximum cosine of the angle between joint edges
              double cosine = fabs(angle(approx[j%4],approx[j-2],approx[j-1]));
              maxCosine = MAX(maxCosine,cosinE);
              }

              // if cosines of all angles are small
              // (all angles are ~90 degreE) then write quandrange
              // vertices to resultant sequence

          if( maxCosine < 0.3 )
              squares.push_BACk(approX);
          }
      }

大佬总结

以上是大佬教程为你收集整理的android – 在轮廓openCV中找到直线全部内容,希望文章能够帮你解决android – 在轮廓openCV中找到直线所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。