Contour segmentation [closed]
Hey there,
I have a contour which consists of curved segments and straigth segments. Is there any possibility to segment the contour into the curved and straigth parts? So this is an example for a contour
I would like to have a segmentation like this:
Do you have any idea how I could solve such a problem
Thank you very much and best regards
The solution is to calculate the curvature:
vector<double> getCurvature(vector<Point> const& tContourPoints, int tStepSize)
{
int iplus;
int iminus;
double acurvature;
double adivisor;
Point2f pplus;
Point2f pminus;
Point2f a1stDerivative;
Point2f a2ndDerivative;
vector< double > rVecCurvature( tContourPoints.size() );
if ((int)tContourPoints.size() < tStepSize)
{
return rVecCurvature;
}
for (int i = 0; i < (int)tContourPoints.size(); i++ )
{
const Point2f& pos = tContourPoints[i];
iminus = i-tStepSize;
iplus = i+tStepSize;
if(iminus < 0)
{
pminus = tContourPoints[iminus + tContourPoints.size()];
}
else
{
pminus = tContourPoints[iminus];
}
if(iplus > (int)tContourPoints.size())
{
pplus = tContourPoints[iplus - (int)tContourPoints.size()];
}
else
{
pplus = tContourPoints[iplus];
}
a1stDerivative.x = (pplus.x - pminus.x) / ( iplus-iminus);
a1stDerivative.y = (pplus.y - pminus.y) / ( iplus-iminus);
a2ndDerivative.x = (pplus.x - 2*pos.x + pminus.x) / ((iplus-iminus)/2*(iplus-iminus)/2);
a2ndDerivative.y = (pplus.y - 2*pos.y + pminus.y) / ((iplus-iminus)/2*(iplus-iminus)/2);
adivisor = a2ndDerivative.x*a2ndDerivative.x + a2ndDerivative.y*a2ndDerivative.y;
if ( abs(adivisor) > 10e-8 )
{
acurvature = abs(a2ndDerivative.y*a1stDerivative.x - a2ndDerivative.x*a1stDerivative.y) / pow(adivisor, 3.0/2.0 ) ;
}
else
{
acurvature = numeric_limits<double>::infinity();
}
rVecCurvature[i] = acurvature;
}
return rVecCurvature;
}
and the you can segment it with a specific border value
if i find the 4 corners,can it help you to solve the problem?
Have you read this ?
so the upper images are just to show the problem. The real forms can be more complicate. To find the contures isn't a problem. But I don't know how I can divide the contour in segments.
What I would do is find the contour, approximate it with a bounding rect and then try to reproduce some sort of convexityDefect function. Take a look here. It will just require you to approximate the rectangle found with a convex hull, and the defects will do the rest for you I guess.
so I solved the problem with calculate the curvatur of the contour points (reffered to (http://stackoverflow.com/questions/32...)
It might be nice if you actually added the solution here, rather than posting a SO question.
@stan123 added some karma, so youcan write a proper answer. please do so !