Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

APIExample.cpp

Go to the documentation of this file.
00001 #include <iostream>
00002 #include <string>
00003 #include <vector>
00004 
00005 #include "SiftTekkotsu.h"
00006 
00007 using namespace std;
00008 
00009 void convertPGMImgToImageBuffer(PGMImg& pgmImg, ImageBuffer& buffer);
00010 
00011 int main(int argc, char** argv){
00012   
00013   SiftTekkotsu mySiftTekkotsu;
00014   
00015   /// Set parameters
00016   mySiftTekkotsu.setParameter("probOfMatch", 0.9);
00017   
00018   
00019   ///Training phase
00020   
00021   // Creating an ImageBuffer from an actual PGM image for use
00022   ImageBuffer buffer;
00023   PGMImg pgmImg;
00024   pgmImg.fromFile("../images/duck/duck01.pgm");
00025   convertPGMImgToImageBuffer(pgmImg, buffer);
00026   
00027   // Create database of duck images
00028   int duckID = mySiftTekkotsu.train_addNewObject(buffer);
00029   mySiftTekkotsu.setObjectName(duckID, "Duckie-duck");
00030   cout << "Duck21: " << mySiftTekkotsu.train_addToObject(duckID, "../images/duck/duck21.pgm") << endl << endl << endl << endl;
00031   cout << "Duck08: " << mySiftTekkotsu.train_addNewModel(duckID, "../images/duck/duck08.pgm") << endl << endl << endl << endl;
00032   
00033   // Remember to free ImageBuffer memory after use
00034   free(buffer.byteArray);
00035   
00036   // Create database of doubleshot can images
00037   int doubleshotID = mySiftTekkotsu.train_addNewObject("../images/doubleshot/doubleshot01.pgm");
00038   mySiftTekkotsu.setObjectName(doubleshotID, "Coffee can");
00039   cout << "Doubleshot21: " << mySiftTekkotsu.train_addToObject(doubleshotID, "../images/doubleshot/doubleshot21.pgm") << endl << endl << endl << endl;
00040   cout << "Doubleshot05: " << mySiftTekkotsu.train_addToObject(doubleshotID, "../images/doubleshot/doubleshot05.pgm") << endl << endl << endl << endl;
00041   
00042   mySiftTekkotsu.saveToFile("duckAndDoubleshot.kb", false);
00043   mySiftTekkotsu.loadFile("duckAndDoubleshot.kb");
00044   
00045   /// Matching tests
00046   vector<SiftMatch*> matchesFound;
00047   
00048   // Look for duck objects only
00049   cout << "Matching ../images/duckanddoubleshot.pgm against duck:\n";
00050   mySiftTekkotsu.findObjectInImage(duckID, "../images/duckanddoubleshot.pgm", matchesFound);
00051   for (unsigned int i = 0; i < matchesFound.size(); i++){
00052     cout << "Match # " << i << ": " << mySiftTekkotsu.getObjectName(matchesFound[i]->objectID) << endl;
00053     matchesFound[i]->print("\t");
00054     delete matchesFound[i];
00055   }
00056   matchesFound.clear();
00057   cout << endl << endl << endl << endl;
00058   
00059   // Look for doubleshot can objects only
00060   cout << "Matching ../images/duckanddoubleshot.pgm against doubleshot:\n";
00061   mySiftTekkotsu.findObjectInImage(doubleshotID, "../images/duckanddoubleshot.pgm", matchesFound);
00062   for (unsigned int i = 0; i < matchesFound.size(); i++){
00063     cout << "Match # " << i << ": " << mySiftTekkotsu.getObjectName(matchesFound[i]->objectID) << endl;
00064     matchesFound[i]->print("\t");
00065     delete matchesFound[i];
00066   }
00067   matchesFound.clear();
00068   cout << endl << endl << endl << endl;
00069   
00070   // Look for all known objects of any kind
00071   cout << "Matching ../images/duckanddoubleshot.pgm against all objects:\n";
00072   mySiftTekkotsu.findAllObjectsInImage("../images/duckanddoubleshot.pgm", matchesFound);
00073   for (unsigned int i = 0; i < matchesFound.size(); i++){
00074     cout << "Match # " << i << ": " << mySiftTekkotsu.getObjectName(matchesFound[i]->objectID) << endl;
00075     matchesFound[i]->print("\t");
00076     delete matchesFound[i];
00077   }
00078   matchesFound.clear();
00079   cout << endl << endl << endl << endl;
00080   
00081 }
00082 

Tekkotsu v5.1CVS
Generated Mon May 9 04:58:35 2016 by Doxygen 1.6.3