#include <iostream>
#include <string>
static void help()
{
printf("\n"
"This program demonstrates a method for shape comparisson based on Shape Context\n"
"You should run the program providing a number between 1 and 20 for selecting an image in the folder ../data/shape_sample.\n"
"Call\n"
"./shape_example [number between 1 and 20, 1 default]\n\n");
}
static vector<Point> simpleContour(
const Mat& currentQuery,
int n=300 )
{
vector<vector<Point> > _contoursQuery;
vector <Point> contoursQuery;
for (size_t border=0; border<_contoursQuery.size(); border++)
{
for (size_t p=0; p<_contoursQuery[border].size(); p++)
{
contoursQuery.push_back( _contoursQuery[border][p] );
}
}
int dummy=0;
for (
int add=(
int)contoursQuery.size()-1;
add<n;
add++)
{
contoursQuery.push_back(contoursQuery[dummy++]);
}
random_shuffle(contoursQuery.begin(), contoursQuery.end());
vector<Point> cont;
for (int i=0; i<n; i++)
{
cont.push_back(contoursQuery[i]);
}
return cont;
}
int main(int argc, char** argv)
{
string path = "../data/shape_sample/";
{
help();
return 0;
}
int indexQuery = parser.
get<
int>(
"@input");
{
help();
return 1;
}
if (indexQuery < 1 || indexQuery > 20)
{
help();
return 1;
}
stringstream queryName;
queryName<<path<<indexQuery<<".png";
vector<Point> contQuery = simpleContour(query);
int bestMatch = 0;
float bestDis=FLT_MAX;
for ( int ii=1; ii<=20; ii++ )
{
if (ii==indexQuery) continue;
stringstream iiname;
iiname<<path<<ii<<".png";
cout<<"name: "<<iiname.str()<<endl;
vector<Point> contii = simpleContour(iiIm);
if ( dis<bestDis )
{
bestMatch = ii;
bestDis = dis;
}
std::cout<<" distance between "<<queryName.str()<<" and "<<iiname.str()<<" is: "<<dis<<std::endl;
}
stringstream bestname;
bestname<<path<<bestMatch<<".png";
imshow(
"BEST MATCH", bestToShow);
return 0;
}