An example using the fitEllipse technique
#include <iostream>
static void help()
{
cout <<
"\nThis program is demonstration for ellipse fitting. The program finds\n"
"contours and approximate it by ellipses.\n"
"Call:\n"
"./fitellipse [image_name -- Default ../data/stuff.jpg]\n" << endl;
}
int sliderPos = 70;
void processImage(int, void*);
int main( int argc, char** argv )
{
"{help h||}{@image|../data/stuff.jpg|}"
);
{
help();
return 0;
}
string filename = parser.
get<
string>(
"@image");
if( image.empty() )
{
cout << "Couldn't open image " << filename << "\n";
return 0;
}
createTrackbar(
"threshold",
"result", &sliderPos, 255, processImage );
processImage(0, 0);
return 0;
}
void processImage(int , void*)
{
vector<vector<Point> > contours;
Mat bimage = image >= sliderPos;
for(size_t i = 0; i < contours.size(); i++)
{
size_t count = contours[i].size();
if( count < 6 )
continue;
continue;
ellipse(cimage, box.
center, box.
size*0.5f, box.
angle, 0, 360,
Scalar(0,255,255), 1,
LINE_AA);
for( int j = 0; j < 4; j++ )
}
}