From: <ste...@us...> - 2008-02-16 12:51:59
|
Revision: 2865 http://hugin.svn.sourceforge.net/hugin/?rev=2865&view=rev Author: stereo_sl Date: 2008-02-16 04:51:57 -0800 (Sat, 16 Feb 2008) Log Message: ----------- * debug - fixed some issues with descriptor * created MatchPoint executable that(currently) behaves as generatekeys(from autopano) * now the suite can be used as a replacement for generatekeys Modified Paths: -------------- gsoc07_featuredetection/APImage.cpp gsoc07_featuredetection/APImage.h gsoc07_featuredetection/CMakeLists.txt gsoc07_featuredetection/Descriptor.cpp gsoc07_featuredetection/Descriptor.h gsoc07_featuredetection/HessianDetector.cpp Modified: gsoc07_featuredetection/APImage.cpp =================================================================== --- gsoc07_featuredetection/APImage.cpp 2008-02-16 08:38:25 UTC (rev 2864) +++ gsoc07_featuredetection/APImage.cpp 2008-02-16 12:51:57 UTC (rev 2865) @@ -42,19 +42,54 @@ if(info.isGrayscale()) { // create a gray scale image of appropriate size + vigra::BImage in(info.width(), info.height()); this->imgBW=new BImage(info.width(), info.height()); // import the image just read importImage(info, destImage(*this->imgBW)); } else { - BRGBImage rgbImage(info.width(), info.height()); - importImage(info, destImage(rgbImage)); - // convert to grayscale + BRGBImage in(info.width(), info.height()); + + //TODO: this does not work. How to make a conversion from RGB to BW image in vigra??? this->imgBW=new BImage(info.width(), info.height()); - RGBToGrayAccessor<RGBValue<UInt8> > rgb2g; - copyImage(srcImageRange(rgbImage, rgb2g), destImage(*(this->imgBW))); + + importImage(info, destImage(in)); + + // create image iterator that points to upper left corner + // of source image + vigra::BRGBImage::Iterator sy = in.upperLeft(); + + // create image iterator that points past the lower right corner of + // source image (similarly to the past-the-end iterator in the STL) + vigra::BRGBImage::Iterator send = in.lowerRight(); + + // create image iterator that points to upper left corner + // of destination image + vigra::BImage::Iterator dy = (*this->imgBW).upperLeft(); + + // iterate down the first column of the images + for(; sy.y != send.y; ++sy.y, ++dy.y) + { + // create image iterator that points to the first + // pixel of the current row of the source image + vigra::BRGBImage::Iterator sx = sy; + + // create image iterator that points to the first + // pixel of the current row of the destination image + vigra::BImage::Iterator dx = dy; + + // iterate across current row + for(; sx.x != send.x; ++sx.x, ++dx.x) + { + RGBValue<int,0u,1u,2u> pixel = *sx; + // calculate grayscale value + // Y = 0.3*R + 0.59*G + 0.11*B + *dx = vigra::round(0.3*pixel.red() + 0.59*pixel.green() + 0.11*pixel.blue()); + } + } + //exportAPImage(srcAPImageRange(*this->imgBW), vigra::APImageExportInfo("ttt.jpg")); } return true; } @@ -204,9 +239,16 @@ */ void APImage::integrate() { - cout << "Height:"<< this->getHeightBW() <<"\n"; - cout << "Width:"<< this->getWidthBW() <<"\n"; + /*cout << "Height:"<< this->getHeightBW() <<"\n"; + cout << "Width:"<< this->getWidthBW() <<"\n";*/ + /*for(int i=0;i<10;i++) { + for(int j=0; j<10;j++) { + cout << this->getPixel(j,i)<<" "; + } + cout << "\n"; + }*/ + this->integral.clear(); this->integral.resize(this->getWidthBW()); for(int i=0;i<this->getWidthBW();i++) { @@ -217,6 +259,15 @@ } //cout << "\n"; } + + /*for(int i=0;i<10;i++) { + for(int j=0; j<10;j++) { + cout << this->getIntegralPixel(j,i)<<" "; + } + cout << "\n"; + } + + cout << this->getRegionSum(2,1,2,3) <<"dddddd\n";*/ } int APImage::_getValue4Integral(int x, int y) { if(x==-1 || y==-1) return 0; @@ -239,3 +290,26 @@ string APImage::getPath() { return this->path; } + +void APImage::test() { + // empty edgel list + std::vector<vigra::Edgel> edgels; + + // find edgels at scale of the interest point + vigra::cannyEdgelList(srcIterRange( this->imgBW->upperLeft() + vigra::Diff2D(250, 250), + this->imgBW->upperLeft() + vigra::Diff2D(550, 450)), + edgels, 1.2); + cout << "Size:" << edgels.size() << endl; + vector<vigra::Edgel>::iterator iter2 = edgels.begin(); + int a=0; + while( iter2 != edgels.end()) { //loop over every canny pixel + vigra::Edgel edgePoint=*iter2; + //cout << edgePoint.strength << endl; + if(edgePoint.strength>5) { + this->drawCircle(round(edgePoint.x)+250,round(edgePoint.y)+250,0); + a++; + } + iter2++; + } + cout << a << endl; +} Modified: gsoc07_featuredetection/APImage.h =================================================================== --- gsoc07_featuredetection/APImage.h 2008-02-16 08:38:25 UTC (rev 2864) +++ gsoc07_featuredetection/APImage.h 2008-02-16 12:51:57 UTC (rev 2865) @@ -36,6 +36,7 @@ #include "vigra/imageinfo.hxx" #include "vigra/impex.hxx" #include "vigra/stdimagefunctions.hxx" +#include "vigra/edgedetection.hxx" #endif @@ -65,7 +66,12 @@ bool open(); void show(); + void test(); +#ifdef USE_VIGRA + vigra::BImage* imgBW; +#endif + /* private slots: */ @@ -80,9 +86,7 @@ vector<vector<int> > integral; string path; int _getValue4Integral(int x, int y); -#ifdef USE_VIGRA - vigra::BImage* imgBW; -#endif + /*IplImage* img; IplImage* imgBW;*/ Modified: gsoc07_featuredetection/CMakeLists.txt =================================================================== --- gsoc07_featuredetection/CMakeLists.txt 2008-02-16 08:38:25 UTC (rev 2864) +++ gsoc07_featuredetection/CMakeLists.txt 2008-02-16 12:51:57 UTC (rev 2865) @@ -1,27 +1,25 @@ -PROJECT(opencv) +PROJECT(MatchPoint) #if you don't want the full compiler output, remove the following line #SET(CMAKE_VERBOSE_MAKEFILE ON) # check for opencv -FIND_PATH(OPENCV_INCLUDE_DIR cv.h PATH_SUFFIXES opencv) -INCLUDE_DIRECTORIES(${OPENCV_INCLUDE_DIR}) +#FIND_PATH(OPENCV_INCLUDE_DIR cv.h PATH_SUFFIXES opencv) +#INCLUDE_DIRECTORIES(${OPENCV_INCLUDE_DIR}) #add definitions, compiler switches, etc. ADD_DEFINITIONS(-Wall -O2 -g) #list all source files here -ADD_EXECUTABLE(main main.cpp APImage.cpp HessianDetector.cpp Descriptor.cpp) +ADD_EXECUTABLE(MatchPoint MatchPoint.cpp APImage.cpp HessianDetector.cpp Descriptor.cpp) #need to link to some other libraries ? just add them here -#TARGET_LINK_LIBRARIES(main highgui cv cxcore png jpeg) -TARGET_LINK_LIBRARIES(main vigraimpex png jpeg tiff) +TARGET_LINK_LIBRARIES(MatchPoint /usr/lib/libvigraimpex.so png jpeg tiff) #list all source files here -ADD_EXECUTABLE(FeatureMatching FeatureMatching.cpp APImage.cpp HessianDetector.cpp Descriptor.cpp FeatureMatcher.cpp) -ADD_EXECUTABLE(gabor_feature_extractor FeatureExtractor.cpp APImage.cpp HessianDetector.cpp Descriptor.cpp FeatureMatcher.cpp) +#ADD_EXECUTABLE(MatchPoint.cpp APImage.cpp HessianDetector.cpp Descriptor.cpp FeatureMatcher.cpp) +#ADD_EXECUTABLE(matchpoint APImage.cpp HessianDetector.cpp Descriptor.cpp) #need to link to some other libraries ? just add them here #TARGET_LINK_LIBRARIES(FeatureMatching highgui cv cxcore png jpeg) -TARGET_LINK_LIBRARIES(FeatureMatching vigraimpex png jpeg tiff) -TARGET_LINK_LIBRARIES(gabor_feature_extractor vigraimpex png jpeg tiff) +#TARGET_LINK_LIBRARIES(/usr/lib/libvigraimpex.so png jpeg tiff) Modified: gsoc07_featuredetection/Descriptor.cpp =================================================================== --- gsoc07_featuredetection/Descriptor.cpp 2008-02-16 08:38:25 UTC (rev 2864) +++ gsoc07_featuredetection/Descriptor.cpp 2008-02-16 12:51:57 UTC (rev 2865) @@ -180,7 +180,8 @@ return (1/(2*PI*pow(stdev,2.0)))*exp(-(pow((double)x,2.0)+pow((double)y,2.0))/(2*stdev)); } double Descriptor::_getMaxima(int x,int y) { - return this->hd->getMaxima(x,y); + //return this->hd->getMaxima(x,y); + return 1.6; } double Descriptor::_euclidianDistance(int x1, int y1, int x2, int y2) { return sqrt(pow((double)(x1-x2),2.0)+pow((double)(y1-y2),2.0)); @@ -625,6 +626,9 @@ void Descriptor::createDescriptors() { +// TODO (zoran#8#): Current version detects edges using canny algorithm in the region around the interest point - here is a lot of redundancy. \ +// Need to change: using vigras cannyEdgeImage first run edge detection on the entire picture and then create desciptors. + cout << "Creating descriptors..."<< endl; int regionSize; int i=0; this->interestPoints->resize(this->interestPoints->size()); @@ -638,12 +642,12 @@ descriptor.push_back(0); } - regionSize=round(20*this->_getMaxima(interestPoint[0], interestPoint[1])); + regionSize=round(40*this->_getMaxima(interestPoint[0], interestPoint[1])); - int xStart=(interestPoint[1]-regionSize); - int xEnd=(interestPoint[1] +regionSize); - int yStart=(interestPoint[0]-regionSize); - int yEnd=(interestPoint[0]+regionSize); + int xStart=(interestPoint[0]-regionSize); + int xEnd=(interestPoint[0] +regionSize); + int yStart=(interestPoint[1]-regionSize); + int yEnd=(interestPoint[1]+regionSize); /* double result; @@ -659,14 +663,21 @@ // empty edgel list std::vector<vigra::Edgel> edgels; + //cout << "Maxima:" << this->_getMaxima(interestPoint[0], interestPoint[1]) << endl; + //cout << "Point:" << interestPoint[0] << "," << interestPoint[1]<< endl; + // find edgels at scale of the interest point vigra::cannyEdgelList(srcIterRange( this->image->imgBW->upperLeft() + vigra::Diff2D(xStart, yStart), this->image->imgBW->upperLeft() + vigra::Diff2D(xEnd, yEnd)), edgels, this->_getMaxima(interestPoint[0], interestPoint[1])); + //cout << "Size:" << edgels.size() << endl; vector<vigra::Edgel>::iterator iter2 = edgels.begin(); while( iter2 != edgels.end()) { //loop over every canny pixel vigra::Edgel edgePoint=*iter2; + /*if(edgePoint.strength<5) { + iter2++; continue; + }*/ //cout << edgePoint.x << ","<<edgePoint.y << "; orientation:"<<edgePoint.orientation<<",strength:"<<edgePoint.strength<<endl; edgePoint.x+=xStart; edgePoint.y+=yStart; @@ -688,13 +699,22 @@ else if(edgePoint.x>=interestPoint[0] && edgePoint.y<=interestPoint[1]) sector=3; else if(edgePoint.x>=interestPoint[0] && edgePoint.y>=interestPoint[1]) sector=0; - double distance=_euclidianDistance(interestPoint[1],interestPoint[0],edgePoint.x,edgePoint.y); - if(distance<=13) descriptor[orientSector*9 + 8]+=edgePoint.strength; - else if(distance>13 && distance<=23) descriptor[orientSector*9 + sector*2+0]+=edgePoint.strength; - else if(distance>23) descriptor[orientSector*9 + sector*2+1]+=edgePoint.strength; + double distance=_euclidianDistance(interestPoint[0],interestPoint[1],edgePoint.x,edgePoint.y); + distance = sqrt(distance); + + if(distance<=0.78) descriptor[orientSector*9 + 8]+=edgePoint.strength; + else if(distance>0.78 && distance<=1.43) descriptor[orientSector*9 + sector*2+0]+=edgePoint.strength; + else if(distance>1.43) descriptor[orientSector*9 + sector*2+1]+=edgePoint.strength; + + /*double distance=_euclidianDistance(interestPoint[0],interestPoint[1],edgePoint.x,edgePoint.y); + if(distance<=27) descriptor[orientSector*9 + 8]+=edgePoint.strength; + else if(distance>27 && distance<=50) descriptor[orientSector*9 + sector*2+0]+=edgePoint.strength; + else if(distance>50) descriptor[orientSector*9 + sector*2+1]+=edgePoint.strength; +*/ + iter2++; } - //cout << "adding d:"<< i<<endl; + this->descriptors.push_back(descriptor); iter1++; } @@ -702,32 +722,41 @@ vector<vector<double> >* Descriptor::getDescriptors() { return &this->descriptors; } -void Descriptor::printDescriptors(std::ostream & o) +bool Descriptor::printDescriptors(string name) { - o << DESCRIPTOR_SIZE << endl; - o << interestPoints->size() << endl; - vector<vector<int> >::iterator iter1 = interestPoints->begin(); - vector<vector<double> >::iterator iterDesc = descriptors.begin(); + ofstream o (name.c_str()); + if (o.is_open()) { + o << DESCRIPTOR_SIZE << endl; + o << interestPoints->size() << endl; + vector<vector<int> >::iterator iter1 = interestPoints->begin(); + vector<vector<double> >::iterator iterDesc = descriptors.begin(); - //int c=0; - while( iter1 != interestPoints->end()) { - vector<int > tmp2=*iter1; - double r = _getMaxima(tmp2[0], tmp2[1])*HD_INIT_KERNEL_SIZE; - o <<tmp2[1]<<" "<<tmp2[0]<<" " << 1/(r*r) << " " << 0 << " " << 1/(r*r) << " "; - for (vector<double>::iterator it = iterDesc->begin(); it != iterDesc->end(); ++it) { - o << *it << " "; - } - o << endl; - iter1++; - iterDesc++; - } + //int c=0; + while( iter1 != interestPoints->end()) { + vector<int > tmp2=*iter1; + double r = _getMaxima(tmp2[0], tmp2[1])*HD_INIT_KERNEL_SIZE; + o <<tmp2[1]<<" "<<tmp2[0]<<" " << 1/(r*r) << " " << 0 << " " << 1/(r*r) << " "; + for (vector<double>::iterator it = iterDesc->begin(); it != iterDesc->end(); ++it) { + o << *it << " "; + } + o << endl; + iter1++; + iterDesc++; + } + o.close(); + return true; + } else return false; } -void Descriptor::printDescriptorsXML(std::ostream &xmlFile) { +bool Descriptor::generateAutopanoXML(string name) { + cout << "Generating XML file: "<<name<<endl; + ofstream xmlFile (name.c_str()); + if (xmlFile.is_open()) + { xmlFile << "<?xml version=\"1.0\" encoding=\"utf-8\"?>"<< endl; xmlFile << "<KeypointXMLList xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n"; - xmlFile << " <XDim>"<< this->image->getHeight() <<"</XDim>"<< endl; - xmlFile << " <YDim>"<< this->image->getWidth() <<"</YDim>"<< endl; + xmlFile << " <XDim>"<< this->image->getWidth() <<"</XDim>"<< endl; + xmlFile << " <YDim>"<< this->image->getHeight() <<"</YDim>"<< endl; xmlFile << " <ImageFile>"<< this->image->getPath() <<"</ImageFile>"<< endl; xmlFile << " <Arr>"<< endl; @@ -739,8 +768,8 @@ vector<int > tmp2=*iter1; xmlFile << " <KeypointN>"<< endl; - xmlFile << " <X>"<< tmp2[1] <<"</X>"<<endl; - xmlFile << " <Y>"<< tmp2[0] <<"</Y>"<<endl; + xmlFile << " <X>"<< tmp2[0] <<"</X>"<<endl; + xmlFile << " <Y>"<< tmp2[1] <<"</Y>"<<endl; xmlFile << " <Scale>"<< this->_getMaxima(tmp2[0],tmp2[1]) <<"</Scale>"<<endl; xmlFile << " <Orientation>"<< 0 <<"</Orientation>"<<endl; xmlFile << " <Dim>"<< DESCRIPTOR_SIZE <<"</Dim>"<<endl; @@ -759,4 +788,9 @@ xmlFile << " </Arr>"<< endl; xmlFile << "</KeypointXMLList>"<< endl; + + xmlFile.close(); + return true; + } + else return false; } Modified: gsoc07_featuredetection/Descriptor.h =================================================================== --- gsoc07_featuredetection/Descriptor.h 2008-02-16 08:38:25 UTC (rev 2864) +++ gsoc07_featuredetection/Descriptor.h 2008-02-16 12:51:57 UTC (rev 2865) @@ -39,8 +39,8 @@ void orientate(); void createDescriptors(); vector<vector<double> >* getDescriptors(); - void printDescriptors(std::ostream & o); - void printDescriptorsXML(std::ostream & o); + bool printDescriptors(string name); + bool generateAutopanoXML(string name); vector<vector<int> >* interestPoints; @@ -59,4 +59,7 @@ vector<vector<double> > descriptors; int orientations[]; }; + + + #endif // DESCRIPTOR_H_INCLUDED Modified: gsoc07_featuredetection/HessianDetector.cpp =================================================================== --- gsoc07_featuredetection/HessianDetector.cpp 2008-02-16 08:38:25 UTC (rev 2864) +++ gsoc07_featuredetection/HessianDetector.cpp 2008-02-16 12:51:57 UTC (rev 2865) @@ -60,7 +60,6 @@ } else if(this->convolutionType==HD_SLIDING_WINDOW) { return this->_slidingWDetect(); } - return false; } bool HessianDetector::_slidingWDetect() { @@ -227,6 +226,7 @@ } bool HessianDetector::_boxFilterDetect() { + int height = this->image->getHeightBW(); int width = this->image->getWidthBW(); @@ -236,8 +236,8 @@ const int iMax=std::numeric_limits<int>::max(); - int offsetX=width*0.05; - int offsetY=height*0.05; + int offsetX=width*0.15; + int offsetY=height*0.15; int xStart=offsetX; int yStart=offsetY; @@ -255,6 +255,8 @@ vector<vector<int> >::iterator it; it = orderedList.begin(); + double sum=0; + double count=0; //point (x,y) => (j,i) for(int j=yStart;j<yEnd;j++) { for(int i=xStart; i<xEnd;i++) { @@ -265,6 +267,8 @@ * This can also be done in a loop. * */ + count++; + sum+=determinants[i][j]; if(determinants[i][j]>determinants[i-1][j-1] && determinants[i][j]>determinants[i-1][j] && @@ -273,11 +277,12 @@ determinants[i][j]>determinants[i][j+1] && determinants[i][j]>determinants[i+1][j-1] && determinants[i][j]>determinants[i+1][j] && - determinants[i][j]>determinants[i+1][j+1]) { - this->_insertToList(&i,&j); + determinants[i][j]>determinants[i+1][j+1] && + determinants[i][j]>25000) { + //this->_insertToList(&i,&j); /*cout << maximas[i][j]<<","<<determinants[i][j]<< ";"; cout << i<<","<<j<< "\n";*/ - /*vector<int> point; + vector<int> point; point.resize(2); point[0]=i; @@ -285,13 +290,14 @@ this->orderedList.push_back(point); //it = orderedList.insert ( it , point); -*/ + } //cout << maximas[i][j]<<","<<determinants[i][j]<< " "; } //cout << "\n"; } cout << "Detected points:"<< this->orderedList.size() <<" "; + cout << "Average:"<< sum/count <<" "; return true; } @@ -304,8 +310,7 @@ 15,27,39,51, 21,45,69,93 }; - double interp1; - double interp2; + double interp1, interp2; //first octave interp1=(this->_convolutePixel(&x,&y,&octaves[0][0])+this->_convolutePixel(&x,&y,&octaves[0][1]))/2; @@ -554,6 +559,7 @@ } return det; } + void HessianDetector::_insertToList(int* x, int* y) { vector<int> point; point.resize(2); @@ -602,7 +608,7 @@ //int c=0; while( iter1 != orderedList.end()) { vector<int > tmp2=*iter1; - //cout << "("<<tmp2[0]<<","<<tmp2[1]<<","<<tmp2[2]<<")\n"; + cout << "("<<tmp2[0]<<","<<tmp2[1]<<","<<tmp2[2]<<")\n"; this->image->drawCircle(tmp2[0],tmp2[1],maximas[tmp2[0]][tmp2[1]]*HD_INIT_KERNEL_SIZE); //c++; //this->image->drawCircle(tmp2[1],tmp2[0],1); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |