OpenCV中文网站

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

如何画出轮廓的内切圆?

[复制链接]
发表于 2015-5-5 14:32:47 | 显示全部楼层 |阅读模式
获取轮廓的最小外接圆,可以使用cvMinEnclosingCircle函数 如下图的红线。蓝线是cvFitEllipse2做的椭圆。..那最大内切圆呢 怎么画出来 G~%%AQ7714FP2@L5M5D8PMX.png
回复

使用道具 举报

发表于 2017-5-8 23:05:47 | 显示全部楼层
OK,圆这个问题有思路了,参考
http://answers.opencv.org/questi ... t-working-properly/

jsxyhelu 2017/5/8 22:51:35
首先,了解一个函数
PointPolygonTest编辑
本词条缺少信息栏、名片图,补充相关内容使词条更完整,还能快速升级,赶紧来编辑吧!
PointPolygonTest
测试点是否在多边形中
double cvPointPolygonTest( const CvArr* contour,              CvPoint2D32f pt, int measure_dist );
contour
输入轮廓.
pt
针对轮廓需要测试的点。
measure_dist
如果非0,函数将估算点到轮廓最近边的距离。
函数cvPointPolygonTest 决定测试点是否在轮廓内,轮廓外,还是轮廓的边上(或者共边的交点上),它的返回值是正负零,相对应的,当measure_dist=0时,返回值是1, -1,0, 同样当 measure_dist≠0 ,它是返回一个从点到最近的边的带符号距离。[1]
下面是函数输出的结果,用图片
的每一个象素去测试轮廓的结果。

jsxyhelu 2017/5/8 22:52:38
然后,转变一个思路。所谓最大内切圆,就是在轮廓中找一中心点,是的轮廓上所有的点到这个中心的距离 在所有可能中最大。

jsxyhelu 2017/5/8 22:53:10
那么,然后就是一个简单遍历的问题。当然,如果如贾所说,首先控制搜索空间,会提高速度。
22:53:40
jsxyhelu 2017/5/8 22:53:40
've tried to replicate your results, but it works fine for me. Here is the code (C++)Note that I have padded the input image, in order to have the correct contour (findContours() splits the contour because it touches the image edges). It may that this is your problem.Also, note the different parameters for findContours. With your flags, the correct contour is the second one (index 1, not 0) in my test. With my flags, the good one is the first (index 0).cv::MatcontourImg=imread("contour.png");std::vector<cv::Mat>channels;cv::split(contourImg,channels);// On these lines, the input image is paddedcv::Matgray(contourImg.rows+20,contourImg.cols+20,CV_8UC1);gray=255;channels[0].copyTo(gray(cv::Rect(10,10,contourImg.cols,contourImg.rows)));cv::imshow("Original",gray);std::vector<std::vector<cv:oint>>contours;cv::findContours(gray,contours,CV_RETR_LIST,CV_CHAIN_APPROX_NONE);cv::Matdrawing(gray.size(),CV_8UC3);cv::Matdraw2=drawing.clone();cv::drawContours(drawing,contours,0,cv::Scalar(20,175,20),1,CV_AA);doubledist,maxdist=-1;cv:ointcenter;for(inti=0;i<contourImg.cols;i++){for(intj=0;j<contourImg.rows;j++){dist=pointPolygonTest(contours[0],cv:oint(i,j),true);if(dist>maxdist){maxdist=dist;center=cv:oint(i,j);}}}cv::circle(drawing,center,maxdist,cv::Scalar(220,75,20),1,CV_AA);cv::imshow("Contours",drawing);cv::waitKey();return0;
回复 支持 反对

使用道具 举报

发表于 2018-10-15 10:21:55 | 显示全部楼层
参考
转变一个思路。所谓最大内切圆,就是在轮廓中找一中心点,是的轮廓上所有的点到这个中心的距离 在所有可能中最大。

回复 支持 反对

使用道具 举报

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

本版积分规则

手机版|OpenCV中文网站

GMT+8, 2024-4-20 16:43 , Processed in 0.009584 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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