Amélioration Save/Load + Tests Robobo + modif gitIgnore

This commit is contained in:
Unknown 2018-08-08 15:45:19 +02:00
parent 09d1eeb838
commit 1cd55aba7a
6734 changed files with 102638 additions and 39401 deletions

View file

@ -1,6 +1,6 @@
#include "ASIFT_matcher.hpp"
ASIFT_matcher::ASIFT_matcher(): _nb_refs(0), _total_num_matchings(0), _resize_imgs(false), _showDebug(false)
ASIFT_matcher::ASIFT_matcher(): _nb_refs(0), _total_num_matchings(0), _resize_imgs(false), _showDebug(false), _showInfo(true)
{
default_sift_parameters(_siftParam);
}
@ -63,111 +63,10 @@ bool ASIFT_matcher::addReference(const char* image_path, unsigned int num_tilts)
size_t w1=gray.width(), h1=gray.height();
ipixels1.assign(gray.begin(), gray.end());
std::cout<<"Building reference from "<< image_path << std::endl;
if(_showInfo)
std::cout<<"Building reference from "<< image_path << std::endl;
return addReference(ipixels1, w1, h1, num_tilts);
// ///// Resize the images to area wS*hW in remaining the apsect-ratio
// ///// Resize if the resize flag is not set or if the flag is set unequal to 0
// float wS = IM_X;
// float hS = IM_Y;
// float zoom1=0;
// int wS1=0, hS1=0;
// vector<float> ipixels1_zoom;
// if(_resize_imgs)
// {
// cout << "WARNING: The input image is resized to " << wS << "x" << hS << " for ASIFT. " << endl
// << " But the results will be normalized to the original image size." << endl << endl;
// float InitSigma_aa = 1.6;
// float fproj_p, fproj_bg;
// char fproj_i;
// float *fproj_x4, *fproj_y4;
// int fproj_o;
// fproj_o = 3;
// fproj_p = 0;
// fproj_i = 0;
// fproj_bg = 0;
// fproj_x4 = 0;
// fproj_y4 = 0;
// float areaS = wS * hS;
// // Resize image 1
// float area1 = w1 * h1;
// zoom1 = sqrt(area1/areaS);
// wS1 = (int) (w1 / zoom1);
// hS1 = (int) (h1 / zoom1);
// int fproj_sx = wS1;
// int fproj_sy = hS1;
// float fproj_x1 = 0;
// float fproj_y1 = 0;
// float fproj_x2 = wS1;
// float fproj_y2 = 0;
// float fproj_x3 = 0;
// float fproj_y3 = hS1;
// /* Anti-aliasing filtering along vertical direction */
// if ( zoom1 > 1 )
// {
// float sigma_aa = InitSigma_aa * zoom1 / 2;
// GaussianBlur1D(ipixels1,w1,h1,sigma_aa,1);
// GaussianBlur1D(ipixels1,w1,h1,sigma_aa,0);
// }
// // simulate a tilt: subsample the image along the vertical axis by a factor of t.
// ipixels1_zoom.resize(wS1*hS1);
// fproj (ipixels1, ipixels1_zoom, w1, h1, &fproj_sx, &fproj_sy, &fproj_bg, &fproj_o, &fproj_p,
// &fproj_i , fproj_x1 , fproj_y1 , fproj_x2 , fproj_y2 , fproj_x3 , fproj_y3, fproj_x4, fproj_y4);
// }
// else
// {
// ipixels1_zoom.resize(w1*h1);
// ipixels1_zoom = ipixels1;
// wS1 = w1;
// hS1 = h1;
// zoom1 = 1;
// }
// // image new_ref;
// // new_ref.img = ipixels1_zoom;
// // new_ref.width = wS1;
// // new_ref.height = hS1;
// ///// Compute ASIFT keypoints
// asift_keypoints keys;
// // vector< vector< keypointslist > >* keys = new vector< vector< keypointslist > >;
// int num_keys = 0;
// time_t tstart, tend;
// tstart = time(0);
// num_keys = compute_asift_keypoints(ipixels1_zoom, wS1, hS1, num_tilts, _showDebug, keys, _siftParam);
// tend = time(0);
// //Save data
// _im_refs.push_back(ipixels1_zoom);
// _size_refs.push_back(make_pair(wS1,hS1));
// _zoom_refs.push_back(zoom1);
// _num_keys.push_back(num_keys);
// _num_tilts.push_back(num_tilts);
// _keys.push_back(keys);
// _nb_refs++;
// cout<<"Reference built in "<< difftime(tend, tstart) << " seconds." << endl;
// cout<<" "<< num_keys <<" ASIFT keypoints found in "<< image_path << endl;
// return true;
}
//Image : Gray scale image (image size = w*h)
@ -193,8 +92,9 @@ bool ASIFT_matcher::addReference(const vector<float>& image, unsigned int w, uns
if(_resize_imgs)
{
cout << "WARNING: The input image is resized to " << wS << "x" << hS << " for ASIFT. " << endl
<< " But the results will be normalized to the original image size." << endl << endl;
if(_showInfo)
cout << "WARNING: The input image is resized to " << wS << "x" << hS << " for ASIFT. " << endl
<< " But the results will be normalized to the original image size." << endl << endl;
float InitSigma_aa = 1.6;
@ -273,8 +173,9 @@ bool ASIFT_matcher::addReference(const vector<float>& image, unsigned int w, uns
_nb_refs++;
cout<<"Reference built in "<< difftime(tend, tstart) << " seconds." << endl;
cout<<" "<< num_keys <<" ASIFT keypoints found."<< endl;
if(_showInfo)
cout<<"Reference built in "<< difftime(tend, tstart) << " seconds." << endl
<<" "<< num_keys <<" ASIFT keypoints found."<< endl;
return true;
}
@ -284,7 +185,7 @@ unsigned int ASIFT_matcher::match(const char* image_path, unsigned int num_tilts
{
if(_nb_refs<=0)
{
cout<<"ASIFT_matcher Error : Trying to match without reference"<<endl;
std::cerr<<"ASIFT_matcher Error : Trying to match without reference"<<std::endl;
return 0;
}
@ -327,7 +228,8 @@ unsigned int ASIFT_matcher::match(const char* image_path, unsigned int num_tilts
size_t w1=gray.width(), h1=gray.height();
ipixels1.assign(gray.begin(), gray.end());
std::cout<<"Matching from "<<image_path<<std::endl;
if(_showInfo)
std::cout<<"Matching from "<<image_path<<std::endl;
return match(ipixels1, w1, h1, num_tilts);
}
@ -356,8 +258,9 @@ unsigned int ASIFT_matcher::match(const vector<float>& image, unsigned int w, un
if(_resize_imgs)
{
cout << "WARNING: The input image is resized to " << wS << "x" << hS << " for ASIFT. " << endl
<< " But the results will be normalized to the original image size." << endl << endl;
if(_showInfo)
cout << "WARNING: The input image is resized to " << wS << "x" << hS << " for ASIFT. " << endl
<< " But the results will be normalized to the original image size." << endl << endl;
float InitSigma_aa = 1.6;
@ -424,8 +327,10 @@ unsigned int ASIFT_matcher::match(const vector<float>& image, unsigned int w, un
num_keys = compute_asift_keypoints(ipixels1_zoom, wS1, hS1, num_tilts, _showDebug, keys, _siftParam);
tend = time(0);
cout<< "Keypoints computation accomplished in " << difftime(tend, tstart) << " seconds." << endl;
cout<<" "<< num_keys <<" ASIFT keypoints found."<< endl;
if(_showInfo)
cout<< "Keypoints computation accomplished in " << difftime(tend, tstart) << " seconds." << endl
<<" "<< num_keys <<" ASIFT keypoints found."<< endl;
//// Match ASIFT keypoints
_total_num_matchings=0;
@ -435,7 +340,8 @@ unsigned int ASIFT_matcher::match(const vector<float>& image, unsigned int w, un
int num_matchings = 0;
matchingslist matchings;
cout << "Matching the keypoints..." << endl;
if(_showInfo)
cout << "Matching the keypoints..." << endl;
tstart = time(0);
try
{
@ -449,7 +355,8 @@ unsigned int ASIFT_matcher::match(const vector<float>& image, unsigned int w, un
// cout<< _keys[i].size()<< " " << _keys[i][0].size() <<" "<< _keys[i][0][0].size()<<endl;
tend = time(0);
cout << "Keypoints matching accomplished in " << difftime(tend, tstart) << " seconds." << endl;
if(_showInfo)
cout << "Keypoints matching accomplished in " << difftime(tend, tstart) << " seconds." << endl;
_num_matchings.push_back(num_matchings);
_total_num_matchings += num_matchings;
@ -536,7 +443,8 @@ bool ASIFT_matcher::computeCenter(int& cx, int& cy) const
//Return true if successfull
bool ASIFT_matcher::distFilter(int threshold=2)
{
cout<<"filtering keypoint..."<<endl;
if(_showInfo)
cout<<"filtering keypoint..."<<endl;
if(getNbMatch()==0)
{
cerr<<"Error : cannot filter points without matchs"<<endl;
@ -627,12 +535,16 @@ bool ASIFT_matcher::saveReferences(const char* ref_path) const
// Follow the same convention of David Lowe:
// the first line contains the number of keypoints and the length of the desciptors (128)
// Added number of tilts
// Added sizes
file_key1 << _num_keys[j] << " " << VecLength << " " <<_size_refs[j].first<<" "<<_size_refs[j].second<<" "<<std::endl; //<<_num_tilts[j] << " "
for (int tt = 0; tt < (int) kps.size(); tt++)
// Added sizes (* zoom_ref useful ?)
file_key1 << _num_keys[j] << " " << VecLength << " " <<_size_refs[j].first*_zoom_refs[j]<<" "<<_size_refs[j].second*_zoom_refs[j]<<" "<<_num_tilts[j] << " "<<std::endl; //<<_num_tilts[j] << " "
for (int tt = 0; tt < (int) kps.size(); tt++) //kps.size = num_tilt
{
file_key1<<kps[tt].size()<<" "<<std::endl;
for (int rr = 0; rr < (int) kps[tt].size(); rr++)
{
file_key1<<kps[tt][rr].size()<<" "<<std::endl;
keypointslist::iterator ptr = kps[tt][rr].begin();
for(int i=0; i < (int) kps[tt][rr].size(); i++, ptr++)
{
@ -662,13 +574,12 @@ bool ASIFT_matcher::saveReferences(const char* ref_path) const
//Load reference data necessary for the matching
//Doesn't load references images or Sift parameters
//TODO : split data between different tilts
bool ASIFT_matcher::loadReferences(const char* ref_path)
{
std::ifstream ref_file(ref_path);
std::string line, tmp;
std::stringstream iss;
pair<int,int> size_tmp;
pair<int,int> img_size_tmp;
if (ref_file.is_open())
{
std::getline(ref_file, line);
@ -678,7 +589,7 @@ bool ASIFT_matcher::loadReferences(const char* ref_path)
_keys = std::vector<asift_keypoints>(_nb_refs);
_num_keys = std::vector< int >(_nb_refs);
_size_refs= std::vector< pair<int,int> >(_nb_refs);
_num_tilts = std::vector< int >(_nb_refs,1);
_num_tilts = std::vector< int >(_nb_refs);
_zoom_refs = std::vector<float>(_nb_refs,1);
for(unsigned int i = 0; i<_nb_refs;i++)
{
@ -695,61 +606,75 @@ bool ASIFT_matcher::loadReferences(const char* ref_path)
return false;
}
// std::getline(iss,tmp,' ');
// _num_tilts[i]=atoi(tmp.c_str());
std::getline(iss,tmp,' ');
img_size_tmp.first=atoi(tmp.c_str());
std::getline(iss,tmp,' ');
size_tmp.first=atoi(tmp.c_str());
img_size_tmp.second=atoi(tmp.c_str());
_size_refs[i]=img_size_tmp;
std::getline(iss,tmp,' ');
size_tmp.second=atoi(tmp.c_str());
_num_tilts[i]=atoi(tmp.c_str());
_size_refs[i]=size_tmp;
keypointslist list;
for(unsigned int j =0; j<(unsigned int)_num_keys[i];j++)
asift_keypoints nakp(_num_tilts[i]);
for(unsigned int j =0; j<(unsigned int)_num_tilts[i];j++)
{
keypoint nkp;
std::getline(ref_file, line);
std::stringstream iss(line);
// if(j==0)
// cout<<line<<endl;
std::getline(iss,tmp,' ');
// std::stof(nb_ref, nkp.x); //C++11
nkp.x=atof(tmp.c_str());
// if(j<5)
// cout<<"x : "<<nkp.x<<endl;
std::getline(iss,tmp,' ');
nkp.y=atof(tmp.c_str());
// if(j<5)
// cout<<"y : "<<nkp.y<<endl;
std::getline(iss,tmp,' ');
nkp.scale=atof(tmp.c_str());
// if(j<5)
// cout<<"Scale : "<<nkp.scale<<endl;
std::getline(iss,tmp,' ');
nkp.angle=atof(tmp.c_str());
int veclist_size_tmp = atoi(line.c_str());
for(unsigned int k=0; k<(int) VecLength; k++)
std::vector< keypointslist > vkpl(veclist_size_tmp);
for(unsigned int k =0; k<(unsigned int)veclist_size_tmp;k++)
{
std::getline(iss,tmp,' ');
nkp.vec[k]=atof(tmp.c_str());
std::getline(ref_file, line);
std::stringstream iss(line);
int list_size_tmp = atoi(line.c_str());
keypointslist list(list_size_tmp);
for(unsigned int l =0; l<(unsigned int)list_size_tmp;l++)
{
keypoint nkp;
std::getline(ref_file, line);
std::stringstream iss(line);
// if(j==0)
// cout<<line<<endl;
std::getline(iss,tmp,' ');
// std::stof(nb_ref, nkp.x); //C++11
nkp.x=atof(tmp.c_str());
// if(j<5)
// cout<<"x : "<<nkp.x<<endl;
std::getline(iss,tmp,' ');
nkp.y=atof(tmp.c_str());
// if(j<5)
// cout<<"y : "<<nkp.y<<endl;
std::getline(iss,tmp,' ');
nkp.scale=atof(tmp.c_str());
// if(j<5)
// cout<<"Scale : "<<nkp.scale<<endl;
std::getline(iss,tmp,' ');
nkp.angle=atof(tmp.c_str());
for(unsigned int m=0; m<(int) VecLength; m++)
{
std::getline(iss,tmp,' ');
nkp.vec[m]=atof(tmp.c_str());
}
list[l]=nkp;
}
vkpl[k]=list;
}
list.push_back(nkp);
// if(j<5)
// {
// cout<<"x : "<<list[j].x<<endl;
// cout<<"y : "<<list[j].y<<endl;
// cout<<"Scale : "<<list[j].scale<<endl;
// }
nakp[j]=vkpl;
}
std::vector< keypointslist > vkps(1,list);
asift_keypoints akps(1,vkps);
_keys[i]=akps;
_keys[i]=nakp;
// std::getline(ref_file, line);
}
}
@ -763,6 +688,156 @@ bool ASIFT_matcher::loadReferences(const char* ref_path)
return true;
}
// bool ASIFT_matcher::saveReferences(const char* ref_path) const
// {
// // Write all the keypoints (row, col, scale, orientation, desciptor (128 integers))
// std::ofstream file_key1(ref_path);
// if (file_key1.is_open())
// {
// file_key1<<_nb_refs<<" "<<std::endl;
// for(unsigned int j=0; j<_keys.size();j++)
// {
// asift_keypoints kps =_keys[j];
// // Follow the same convention of David Lowe:
// // the first line contains the number of keypoints and the length of the desciptors (128)
// // Added number of tilts
// // Added sizes
// file_key1 << _num_keys[j] << " " << VecLength << " " <<_size_refs[j].first<<" "<<_size_refs[j].second<<" "<<std::endl; //<<_num_tilts[j] << " "
// for (int tt = 0; tt < (int) kps.size(); tt++) //kps.size = num_tilt
// {
// for (int rr = 0; rr < (int) kps[tt].size(); rr++)
// {
// keypointslist::iterator ptr = kps[tt][rr].begin();
// for(int i=0; i < (int) kps[tt][rr].size(); i++, ptr++)
// {
// file_key1 << _zoom_refs[j]*ptr->x << " " << _zoom_refs[j]*ptr->y << " " << _zoom_refs[j]*ptr->scale << " " << ptr->angle;
// for (int ii = 0; ii < (int) VecLength; ii++)
// {
// file_key1 << " " << ptr->vec[ii];
// }
// file_key1 << std::endl;
// }
// }
// }
// // file_key1<<std::endl;
// }
// }
// else
// {
// std::cerr << "Unable to open the file :"<<ref_path;
// return false;
// }
// file_key1.close();
// return true;
// }
//Load reference data necessary for the matching
//Doesn't load references images or Sift parameters
//TODO : split data between different tilts
// bool ASIFT_matcher::loadReferences(const char* ref_path)
// {
// std::ifstream ref_file(ref_path);
// std::string line, tmp;
// std::stringstream iss;
// pair<int,int> size_tmp;
// if (ref_file.is_open())
// {
// std::getline(ref_file, line);
// std::string::size_type sz;
// // _nb_refs = std::stoi(line, &sz); //C++11
// _nb_refs = atoi(line.c_str());
// _keys = std::vector<asift_keypoints>(_nb_refs);
// _num_keys = std::vector< int >(_nb_refs);
// _size_refs= std::vector< pair<int,int> >(_nb_refs);
// _num_tilts = std::vector< int >(_nb_refs,1);
// _zoom_refs = std::vector<float>(_nb_refs,1);
// for(unsigned int i = 0; i<_nb_refs;i++)
// {
// std::getline(ref_file, line);
// std::stringstream iss(line);
// std::getline(iss,tmp,' ');
// _num_keys[i]=atoi(tmp.c_str());
// std::getline(iss,tmp,' ');
// if(VecLength!=atoi(tmp.c_str()))
// {
// std::cerr<<"Error VecLength doesn't correspond..."<<std::endl;
// return false;
// }
// std::getline(iss,tmp,' ');
// size_tmp.first=atoi(tmp.c_str());
// std::getline(iss,tmp,' ');
// size_tmp.second=atoi(tmp.c_str());
// _size_refs[i]=size_tmp;
// std::getline(iss,tmp,' ');
// _num_tilts[i]=atoi(tmp.c_str());
// keypointslist list;
// for(unsigned int j =0; j<(unsigned int)_num_keys[i];j++)
// {
// keypoint nkp;
// std::getline(ref_file, line);
// std::stringstream iss(line);
// // if(j==0)
// // cout<<line<<endl;
// std::getline(iss,tmp,' ');
// // std::stof(nb_ref, nkp.x); //C++11
// nkp.x=atof(tmp.c_str());
// // if(j<5)
// // cout<<"x : "<<nkp.x<<endl;
// std::getline(iss,tmp,' ');
// nkp.y=atof(tmp.c_str());
// // if(j<5)
// // cout<<"y : "<<nkp.y<<endl;
// std::getline(iss,tmp,' ');
// nkp.scale=atof(tmp.c_str());
// // if(j<5)
// // cout<<"Scale : "<<nkp.scale<<endl;
// std::getline(iss,tmp,' ');
// nkp.angle=atof(tmp.c_str());
// for(unsigned int k=0; k<(int) VecLength; k++)
// {
// std::getline(iss,tmp,' ');
// nkp.vec[k]=atof(tmp.c_str());
// }
// list.push_back(nkp);
// // if(j<5)
// // {
// // cout<<"x : "<<list[j].x<<endl;
// // cout<<"y : "<<list[j].y<<endl;
// // cout<<"Scale : "<<list[j].scale<<endl;
// // }
// }
// std::vector< keypointslist > vkps(1,list);
// asift_keypoints akps(1,vkps);
// _keys[i]=akps;
// // std::getline(ref_file, line);
// }
// }
// else
// {
// std::cerr << "Unable to open the file :"<<ref_path;
// return false;
// }
// ref_file.close();
// return true;
// }
ASIFT_matcher& ASIFT_matcher::operator=(const ASIFT_matcher& m)
{
@ -792,10 +867,10 @@ void ASIFT_matcher::print() const
{
for(unsigned int i=0; i< _keys.size();i++)
{
cout<<"Ref size:"<<i<<" - size :"<<_keys[i].size()<<endl;
cout<<"Ref :"<<i<<" - Nb tilts : "<<_num_tilts[i]<< " - Nb keys : "<< _num_keys[i]<<endl;
for(unsigned int j=0; j<_keys[i].size();j++)
{
cout<<" "<<j<<" - size :"<<_keys[i][j].size()<<endl;
cout<<" Tilt "<<j<<" - size :"<<_keys[i][j].size()<<endl;
for(unsigned int k=0; k<_keys[i][j].size();k++)
{
cout<<" "<<k<<" - size :"<<_keys[i][j][k].size()<<endl;