00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #define USE_VIGRA
00023
00024 #ifdef HAVE_CONFIG_H
00025 #include <config.h>
00026 #endif
00027
00028 #include <stdio.h>
00029 #include <iostream>
00030 #include <stdlib.h>
00031 #include <math.h>
00032 #include <ctime>
00033 #include <algorithm>
00034
00035 #include <string>
00036 #include "APImage.h"
00037 #include "HessianDetector.h"
00038 #include "Descriptor.h"
00039 #include <limits>
00040
00041 using namespace std;
00042
00043
00044
00045 double getDistance(vector<double>* d1,vector<double>* d2) {
00046 double dist=0;
00047 for(int i=0; i<DESCRIPTOR_SIZE;i++) {
00048 dist+=pow((*d1)[i]-(*d2)[i],2);
00049 }
00050 return dist;
00051 }
00052
00053 int main(int argc, char *argv[])
00054 {
00055
00056 clock_t start,finish;
00057 double time;
00058
00059 int nrPoints=250;
00060 if(argc!=3) {
00061 cout << "Usage: ./main img1 img2 " << "\n";
00062 return 0;
00063 }
00064
00065 APImage im1(argv[1]);
00066 if(!im1.open()) {
00067 cout<< "Error! APImage can not be opened"<<"\n";
00068 return 0;
00069 }
00070
00071 APImage im2(argv[2]);
00072 if(!im2.open()) {
00073 cout<< "Error! APImage can not be opened"<<"\n";
00074 return 0;
00075 }
00076
00077
00078 im1.integrate();
00079 im2.integrate();
00080
00081 start = clock();
00082
00083 HessianDetector hd1(&im1,nrPoints, HD_BOX_FILTERS,1);
00084 if(!hd1.detect()) {
00085 cout << "Detection of points failed!";
00086 return 1;
00087 }
00088
00089
00090
00091 finish = clock();
00092
00093 time = (double(finish)-double(start))/CLOCKS_PER_SEC;
00094 cout << "Measured time:"<<time<<"\n";
00095
00096
00097 vector<vector<int> >* interestPoints1=hd1.getPoints();
00098
00099 Descriptor d1(&im1,&hd1);
00100 d1.setPoints(interestPoints1);
00101
00102 d1.createDescriptors();
00103
00104
00105
00106
00107 HessianDetector hd2(&im2,nrPoints, HD_BOX_FILTERS,1);
00108 if(!hd2.detect()) {
00109 cout << "Detection of points failed!";
00110 return 1;
00111 }
00112
00113
00114
00115
00116 vector<vector<int> >* interestPoints2=hd2.getPoints();
00117
00118 Descriptor d2(&im2,&hd2);
00119 d2.setPoints(interestPoints2);
00120
00121 d2.createDescriptors();
00122
00123
00124
00125 vector<vector<double> >* descriptors1=d1.getDescriptors();
00126 vector<vector<double> >::iterator iter1 = (*descriptors1).begin();
00127
00128 vector<vector<double> >* descriptors2=d2.getDescriptors();
00129
00130 int pointCount=0;
00131 int max;
00132 int maxId;
00133
00134 while( iter1 != (*descriptors1).end()) {
00135 vector<double> current1 = *iter1;
00136
00137 vector<vector<double> >::iterator iter2 =(*descriptors2).begin();
00138
00139 max=1;
00140 maxId=0;
00141
00142 vector<double> current2 = *iter2;
00143
00144 double distance=getDistance(¤t1,¤t2);
00145 iter2++;
00146 double diff=distance;
00147 double diff2=std::numeric_limits<double>::max();
00148
00149 while( iter2 != (*descriptors2).end()) {
00150 current2 = *iter2;
00151 distance=getDistance(¤t1,¤t2);
00152
00153 if(distance<diff) {
00154 diff2=diff;
00155 diff=distance;
00156 maxId=max;
00157 } else if(distance<diff2) {
00158
00159 diff2=distance;
00160 }
00161 max++;
00162 iter2++;
00163 }
00164 if(diff<(0.5*diff2)) {
00165 im1.drawCircle((*interestPoints1)[pointCount][1],(*interestPoints1)[pointCount][0],10);
00166 im2.drawCircle((*interestPoints2)[maxId][1],(*interestPoints2)[maxId][0],10);
00167 }
00168
00169 iter1++;
00170 pointCount++;
00171 }
00172 im1.show();
00173 im2.show();
00174 return EXIT_SUCCESS;
00175 }