android opencv画轮廓,android – 在轮廓openCV中找到直线

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

解决方法:

然后在这里你只是寻找简化的多边形(三角形和正方形).你试过在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,contour

来源: https://codeday.me/bug/20190625/1286429.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值