Contour segmentation [closed]

asked 2017-03-23 03:56:00 -0600

stan123 gravatar image

updated 2017-03-29 00:54:49 -0600

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

image description

I would like to have a segmentation like this:

image description

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

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by stan123
close date 2017-03-28 07:52:57.467130

Comments

if i find the 4 corners,can it help you to solve the problem?

jsxyhelu gravatar imagejsxyhelu ( 2017-03-23 05:31:10 -0600 )edit

Have you read this ?

Balaji R gravatar imageBalaji R ( 2017-03-23 05:45:26 -0600 )edit

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.

stan123 gravatar imagestan123 ( 2017-03-23 06:46:38 -0600 )edit

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.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-03-24 08:25:41 -0600 )edit

so I solved the problem with calculate the curvatur of the contour points (reffered to (http://stackoverflow.com/questions/32...)

stan123 gravatar imagestan123 ( 2017-03-28 07:52:13 -0600 )edit
1

It might be nice if you actually added the solution here, rather than posting a SO question.

StevenPuttemans gravatar imageStevenPuttemans ( 2017-03-28 08:55:55 -0600 )edit

@stan123 added some karma, so youcan write a proper answer. please do so !

berak gravatar imageberak ( 2017-03-29 01:03:23 -0600 )edit