标签:
threshold(gray,thresh,240,250,THRESH_OTSU);
erode(thresh,thresh,Mat());
erode(thresh,thresh,Mat());
contours.clear();
selectContours.clear();
findContours(thresh.clone(),contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE);
for (int i=0;i<contours.size();i++)
{
if ( contourArea(contours[i])>188 && contourArea(contours[i])<388 )
{
//drawContours(srcClone,contours,i,Scalar(0,0,255));
selectContours.push_back(contours[i]);//将经过筛选的轮廓保存起来
}
}
for (int i=0;i<selectContours.size();i++)
{
Point2f center;
float radius;
minEnclosingCircle(selectContours[i],center,radius);
if (radius > 10*0.8 && radius < 10*1.4)
{
if (ellipseLikeCircle(minEllipse[i]))
{
circle(src,center,radius,Scalar(0,0,255));
//ellipse( src,minEllipse[i],Scalar(255,0,0));
pair<Point2f,float> tmp;
tmp.first = center;
tmp.second = radius;
resultPair.push_back(tmp);
}
}
}
//打印结果
fstream ftxt;
ftxt.open("c:/GO_FindTube_Param.ini",ios::out); //写入的方式,覆盖写入
if(ftxt.fail())
{
cout<<"can not open it"<<endl;
getchar();
return 0;
}
for (int i=0;i<resultPair.size();i++)
{
pair<Point2f,float> tmp = resultPair[i];
ftxt<<tmp.first.x<<" "<<tmp.first.y<<" "<<tmp.second<<endl;
}
ftxt.close();
标签:
原文地址:http://www.cnblogs.com/jsxyhelu/p/4650152.html