/* Top level routine. Read PGM images and keypoints from files given in command line arguments, then call FindMatches. */ int main (int argc, char **argv) { int arg = 0; Image im1 = NULL, im2 = NULL; Keypoint k1 = NULL, k2 = NULL; /* Parse command line arguments and read given files. The command line must specify two input images and two files of keypoints using command line arguments as follows: match -im1 i1.pgm -k1 k1.key -im2 i2.pgm -k2 k2.key > result.v */ while (++arg < argc) { if (! strcmp(argv[arg], "-im1")) im1 = ReadPGMFile(argv[++arg]); else if (! strcmp(argv[arg], "-im2")) im2 = ReadPGMFile(argv[++arg]); else if (! strcmp(argv[arg], "-k1")) k1 = ReadKeyFile(argv[++arg]); else if (! strcmp(argv[arg], "-k2")) k2 = ReadKeyFile(argv[++arg]); else FatalError("Invalid command line argument: %s", argv[arg]); } if (im1 == NULL || im2 == NULL || k1 == NULL || k2 == NULL) FatalError("Command line does not specify all images and keys."); FindMatches(im1, k1, im2, k2); exit(0); }
int main( int argc, char** argv ) { if (argc == 1) { std::cerr << "Usage: ./sift_detect -i image.pgm -o image.key " << "[-t warp.xfm -i2 warped.pgm -o2 warped.key] [options]\n" << " number of points to take: -p 800\n" << " scale upper bound 1: -ub1 6\n" << " scale lower bound 1: -lb1 2\n" << " scale upper bound 2: -ub2 9\n" << " scale lower bound 2: -lb2 2.8\n"; return 0; } char *image_file = NULL, *warped_file = NULL, *transform_file = NULL; int num_points = 800; std::string key_file = "source.key", warped_key_file = "warped.key"; float scale_ub1 = -1, scale_lb1 = -1, scale_ub2 = -1, scale_lb2 = -1; int arg = 0; while (++arg < argc) { if (! strcmp(argv[arg], "-i")) image_file = argv[++arg]; if (! strcmp(argv[arg], "-i2")) warped_file = argv[++arg]; if (! strcmp(argv[arg], "-t")) transform_file = argv[++arg]; if (! strcmp(argv[arg], "-o")) key_file = argv[++arg]; if (! strcmp(argv[arg], "-o2")) warped_key_file = argv[++arg]; if (! strcmp(argv[arg], "-p")) num_points = atoi(argv[++arg]); if (! strcmp(argv[arg], "-ub1")) scale_ub1 = atof(argv[++arg]); if (! strcmp(argv[arg], "-lb1")) scale_lb1 = atof(argv[++arg]); if (! strcmp(argv[arg], "-ub2")) scale_ub2 = atof(argv[++arg]); if (! strcmp(argv[arg], "-lb2")) scale_lb2 = atof(argv[++arg]); } assert(image_file); assert(!warped_file || transform_file); // Load the source image Image im = ReadPGMFile(image_file); int W = im->cols; int H = im->rows; // Find keypoints in source image LoweKeypoint lowe_keypts = NULL; { Timer t("SIFT detector"); lowe_keypts = GetKeypoints(im); } std::vector<KeypointFl> keypts; for (LoweKeypoint pt = lowe_keypts; pt != NULL; pt = pt->next) { keypts.push_back(KeypointFl(pt->col, pt->row, pt->scale, pt->strength)); } if (scale_ub1 > 0) keypts.erase(std::remove_if(keypts.begin(), keypts.end(), ScaleUpperBound(scale_ub1)), keypts.end()); if (scale_lb1 > 0) keypts.erase(std::remove_if(keypts.begin(), keypts.end(), ScaleLowerBound(scale_lb1)), keypts.end()); Image warped = NULL; CvMat *transform = NULL, *inv = NULL; if (warped_file) { warped = ReadPGMFile(warped_file); // Get inverse transform (warped -> source) transform = cvCreateMat(3, 3, CV_32FC1); ReadTransform(transform_file, transform); inv = cvCreateMat(3, 3, CV_32FC1); cvInvert(transform, inv); keypts.erase(std::remove_if(keypts.begin(), keypts.end(), OutsideSource(warped->cols, warped->rows, transform)), keypts.end()); } if ((int)keypts.size() < num_points) { num_points = keypts.size(); printf("WARNING: Only taking %d points!\n", num_points); std::sort(keypts.begin(), keypts.end()); } else { std::partial_sort(keypts.begin(), keypts.begin()+ num_points, keypts.end()); } if (warped_file) { // Find keypoints in warped image LoweKeypoint lowe_warp_keypts = NULL; { Timer t("SIFT detector (warped)"); lowe_warp_keypts = GetKeypoints(warped); } std::vector<KeypointFl> warp_keypts; for (LoweKeypoint pt = lowe_warp_keypts; pt != NULL; pt = pt->next) { warp_keypts.push_back(KeypointFl(pt->col, pt->row, pt->scale, pt->strength)); } if (scale_ub2 > 0) warp_keypts.erase(std::remove_if(warp_keypts.begin(), warp_keypts.end(), ScaleUpperBound(scale_ub2)), warp_keypts.end()); if (scale_lb2 > 0) warp_keypts.erase(std::remove_if(warp_keypts.begin(), warp_keypts.end(), ScaleLowerBound(scale_lb2)), warp_keypts.end()); warp_keypts.erase(std::remove_if(warp_keypts.begin(), warp_keypts.end(), OutsideSource(W, H, inv)), warp_keypts.end()); if ((int)warp_keypts.size() < num_points) { num_points = warp_keypts.size(); printf("WARNING: Only taking %d points!\n", num_points); std::sort(warp_keypts.begin(), warp_keypts.end()); } else { std::partial_sort(warp_keypts.begin(), warp_keypts.begin() + num_points, warp_keypts.end()); warp_keypts.erase(warp_keypts.begin() + num_points, warp_keypts.end()); } WriteKeypointsFl(warped_key_file, warp_keypts); } keypts.erase(keypts.begin() + num_points, keypts.end()); WriteKeypointsFl(key_file, keypts); cvReleaseMat(&inv); cvReleaseMat(&transform); delete warped; delete im; return 0; }
int main (int argc, char **argv) { srand(time(NULL)); int i, j, k; float minSize = 10000, maxSize = 1.0, minPeriod = 0.1, minStable = 0.1; PStack im2Regions = NewPStack(100); Image im2 = ReadPGMFile(argv[1]); Image out = ConvertImage1(CopyImage(im2)); fprintf(stderr,"Read in image %s with dimensions %d %d\n",argv[1],im2->rows,im2->cols); FindMSERegions(im2,im2Regions,minSize,maxSize,1,2,FALSE,TRUE); PStack dc = NewPStack(10); for(i=0;i<im2Regions->stacksize;i++) { Region re = im2Regions->items[i]; float area = PolygonArea(re->border); float numberOfSections = area / 44000; if ( numberOfSections >= 1 && numberOfSections < 5 ) { PolygonACD(re->border,0.06,dc); } } Region cc = im2Regions->items[i]; //DrawPolygon(cc->border,out,PIX3(0,255,0)); for(i=0;i<dc->stacksize;i++) { Polygon border = dc->items[i]; int area = PolygonArea(border); if ( area < 44000 || area > 44000 * 1.6 ) continue; PolygonVertexEvolution(border,4); int color = RandomColor(150); for(j=0;j<border->numberOfVertices;j++) { Ellipse e = NewEllipse(border->vertices[j].x,border->vertices[j].y,5,5,0); DrawEllipse(e,out,color); free(e); } DrawPolygon(border,out,color); } WritePPM("sections.ppm",out); //RegionsToSIFTDescriptors(im1Regions,im1Descriptors,4,8,41); //fprintf(stderr,"Created %d descriptors from %d regions in %2.2f seconds\n",im1Descriptors->stacksize,im1Regions->stacksize,CPUTIME-t0); //PrintSIFTDescriptors("csift1",im1Descriptors); /* PStack im2Regions = NewPStack(100); PStack im2Descriptors = NewPStack(100); t0 = CPUTIME; Image im2 = ReadPGMFile(argv[2]); FindMSERegions(im2,im2Regions,minSize,maxSize,minPeriod,minStable); RegionsToSIFTDescriptors(im2Regions,im2Descriptors,4,8,41); fprintf(stderr,"Created %d descriptors from %d regions in %2.2f seconds\n",im2Descriptors->stacksize,im2Regions->stacksize,CPUTIME-t0); PStack matches = NewPStack(100); double **transform = AllocDMatrix(3,3,0,0); FindMatches(im1Descriptors,im2Descriptors,matches,10); fprintf(stderr,"Found %d initial matches.\n",matches->stacksize); ScreenMatches(matches,transform); fprintf(stderr,"A1 = [ "); for(k=0;k<3;k++)fprintf(stderr,"%f %f %f;",transform[k][0],transform[k][1],transform[k][2]); fprintf(stderr,"]\n"); Image im3 = CreateImage(im1->rows,im1->cols); AffineTransformImage(im2,im3,NULL,transform); for (i=0;i<im1->rows;i++) { for (j=0;j<im1->cols;j++) { int rv = MAX(0,im1->pixels[i][j]); int bv = MAX(0,im3->pixels[i][j]); im3->pixels[i][j] = PIX3(rv,0,bv); }} WritePPM("affine.ppm",im3); */ return 0; }