コード例 #1
0
int main( int argc , char **argv )
{
    if( argc < 2 )
        throw std::runtime_error("[directory]");

    char *nameDirectory = argv[1];

    char filename[1024];

    printf("directory name: %s\n",nameDirectory);

    for( int i = 1; i <= 6; i++ ) {
        sprintf(filename,"%s/img%d.pgm",nameDirectory,i);
        ImLoad ImageLoader;
        Image *img=ImageLoader.readImage(filename);
        if( img == NULL ) {
            fprintf(stderr,"Couldn't open image file: %s\n",filename);
            throw std::runtime_error("Failed to open");
        }

        sprintf(filename,"%s/DETECTED_img%d_%s.txt",nameDirectory,i,"SURF_REFERENCE");
        FILE *output = fopen(filename,"w");
        if( output == NULL ) {
            fprintf(stderr,"Couldn't open file: %s\n",filename);
            throw std::runtime_error("Failed to open");
        }

        printf("Processing %s\n",filename);
        process(img,output);
    }

}
コード例 #2
0
int main(int argc, char **argv) {
	Image *im1, *im2;

	ImLoad ImageLoader;
	vector< Ipoint > ipts1, ipts2, ConS1, ConS2, ConSRough1, ConSRough2; //Min 
	bool drawc = false;
	bool usesym = false;
	bool printAllDist = false;
	double abs_thre = 0.3;
	double ratio_thre = 0.7;
	
	char ofname[100];

	im1 = im2 = NULL;
	ofname[0] = 0;

	// Read the arguments
	int arg = 0;
	while (++arg < argc) { 
		if (! strcmp(argv[arg], "-k1"))
			loadIpoints(argv[++arg], ipts1);
		if (! strcmp(argv[arg], "-k2"))
			loadIpoints(argv[++arg], ipts2);
		//Min -------------------------------------
		if (! strcmp(argv[arg], "-S1")) 
			loadIpoints(argv[++arg], ConS1);
		if (! strcmp(argv[arg], "-S2"))
			loadIpoints(argv[++arg], ConS2);
		if (! strcmp(argv[arg], "-RS1")) 
			loadIpoints(argv[++arg], ConSRough1);
		if (! strcmp(argv[arg], "-RS2"))
			loadIpoints(argv[++arg], ConSRough2);
		//Min -------------------------------------

		if (! strcmp(argv[arg], "-im1"))
			im1 = ImageLoader.readImage(argv[++arg]); 
		if (! strcmp(argv[arg], "-im2"))
			im2 = ImageLoader.readImage(argv[++arg]); 
		if (! strcmp(argv[arg], "-o"))
			strcpy(ofname, argv[++arg]);
		if (! strcmp(argv[arg], "-c"))
			drawc = true;
		if (! strcmp(argv[arg], "-s"))
			usesym = true;
		if (! strcmp(argv[arg], "-d"))
			printAllDist = true;
		if (! strcmp(argv[arg], "-abs"))
			abs_thre = strtod( argv[++arg], NULL);
		if (! strcmp(argv[arg], "-ratio"))
			ratio_thre = strtod( argv[++arg], NULL);

	}
	

	if (ipts1.size() == 0 || ipts2.size() == 0) {
		cout << "Usage:" << endl;
		cout << " match [-s] -k1 out1.surf -k2 out2.surf -im1 img1.pgm -im2 img2.pgm -o out.pgm" << endl << endl;
		cout << "For each feature in first descriptor file, find best in second according to "
			<< "nearest neighbor ratio strategy. Display matches in out.pgm, generated "
			<< "from img1.pgm and img2.pgm. Use -c to draw crosses at interest points." << endl;

		cout << "use -s to require that the best match be symetric."<<endl;
		cout << "use -d to print out all of the n*m distances between points instead of matching."<<endl;
		cout << "use -abs to set absolute threshould and -ratio to set rative threshould."<<endl;
		return 1;
	}

	vector< int > matches;
	  
	if (usesym) {
	  cerr << "Using symmetricConS matches, using descriptor length " << vlen << ConSRough1[0].ivec[3] << abs_thre << ratio_thre<< endl;
//	  cout << "test CONSRough" << ConSRough1[1].ivec[1] << endl;
		matches = symMatches(ipts1, ipts2, ConS1, ConS2, ConSRough1, ConSRough2, abs_thre, ratio_thre);//Min
	} else if (printAllDist){
	  printAllDistances(ipts1, ipts2);
	} else {
	  matches = findMatches(ipts1, ipts2);
	}


	if (im1 != NULL && im2 != NULL && ofname[0] != 0) {
		Image res(max(im1->getWidth(), im2->getWidth()), im1->getHeight() + im2->getHeight());
		for (int x = 0; x < im1->getWidth(); x++)
			for (int y = 0; y < im1->getHeight(); y++)
				res.setPix(x, y, im1->getPix(x, y));
		for (int x = 0; x < im2->getWidth(); x++)
			for (int y = 0; y < im2->getHeight(); y++)
				res.setPix(x, y + im1->getHeight(), im2->getPix(x, y));

		// Draw lines for matches
		for (unsigned i = 0; i < matches.size(); i++) {
			if (matches[i] != -1) {
				drawLine(&res, (int)ipts1[i].x, (int)ipts1[i].y,
					(int)ipts2[matches[i]].x, (int)(ipts2[matches[i]].y + im1->getHeight()));
			}
		}

		// Draw crosses at interest point locations
		if (drawc) {
			for (unsigned i = 0; i < ipts1.size(); i++)
				drawCross(&res, (int)ipts1[i].x, (int)ipts1[i].y);
			for (unsigned i = 0; i < ipts2.size(); i++)
				drawCross(&res, (int)ipts2[i].x, (int)ipts2[i].y + im1->getHeight());
		}

		ImageLoader.saveImage(ofname, &res);
	}

	
	return 0;
}
コード例 #3
0
int main(int argc, char **argv) {
	Image *im1, *im2;

	ImLoad ImageLoader;
	vector< Ipoint > ipts1, ipts2;
	bool drawc = false;
	bool usesym = false;
	bool printAllDist = false;

	double *fundMatrix;
	fundMatrix = new double[9];
	bool isDense = false;
	
	char ofname[100];

	im1 = im2 = NULL;
	ofname[0] = 0;

	// Read the arguments
	int arg = 0;
	while (++arg < argc) { 
		if (! strcmp(argv[arg], "-k1"))
			loadIpoints(argv[++arg], ipts1);
		if (! strcmp(argv[arg], "-k2"))
			loadIpoints(argv[++arg], ipts2);
		
		if (! strcmp(argv[arg], "-F"))
			isDense = readFundamentalMatrix(argv[++arg], fundMatrix);

		if (! strcmp(argv[arg], "-im1"))
			im1 = ImageLoader.readImage(argv[++arg]); 
		if (! strcmp(argv[arg], "-im2"))
			im2 = ImageLoader.readImage(argv[++arg]); 
		if (! strcmp(argv[arg], "-o"))
			strcpy(ofname, argv[++arg]);
		if (! strcmp(argv[arg], "-c"))
			drawc = true;
		if (! strcmp(argv[arg], "-s"))
			usesym = true;
		if (! strcmp(argv[arg], "-d"))
			printAllDist = true;

	}

	if (ipts1.size() == 0 || ipts2.size() == 0) {
		cout << "Usage:" << endl;
		cout << " match [-s] -k1 out1.surf -k2 out2.surf -im1 img1.pgm -im2 img2.pgm -o out.pgm [-F fundamentalMatrixFilename]" << endl << endl;
		cout << "For each feature in first descriptor file, find best in second according to "
			<< "nearest neighbor ratio strategy. Display matches in out.pgm, generated "
			<< "from img1.pgm and img2.pgm. Use -c to draw crosses at interest points." << endl;

		cout << "use -s to require that the best match be symetric."<<endl;
		cout << "use -d to print out all of the n*m distances between points instead of matching."<<endl;
		return 1;
	}

	vector< int > matches;
	if (usesym) {
	  cerr << "Using symmetric Dense matches, descriptor length " << vlen << endl;
		matches = symMatches(ipts1, ipts2, isDense, fundMatrix);
	} else if (printAllDist){
	  printAllDistances(ipts1, ipts2);
	} else {
	  matches = findMatches(ipts1, ipts2, isDense, fundMatrix);
	}


	if (im1 != NULL && im2 != NULL && ofname[0] != 0) {
		Image res(max(im1->getWidth(), im2->getWidth()), im1->getHeight() + im2->getHeight());
		for (int x = 0; x < im1->getWidth(); x++)
			for (int y = 0; y < im1->getHeight(); y++)
				res.setPix(x, y, im1->getPix(x, y));
		for (int x = 0; x < im2->getWidth(); x++)
			for (int y = 0; y < im2->getHeight(); y++)
				res.setPix(x, y + im1->getHeight(), im2->getPix(x, y));

		// Draw lines for matches
		for (unsigned i = 0; i < matches.size(); i++) {
			if (matches[i] != -1) {
				drawLine(&res, (int)ipts1[i].x, (int)ipts1[i].y,
					(int)ipts2[matches[i]].x, (int)(ipts2[matches[i]].y + im1->getHeight()));
			}
		}

		// Draw crosses at interest point locations
		if (drawc) {
			for (unsigned i = 0; i < ipts1.size(); i++)
				drawCross(&res, (int)ipts1[i].x, (int)ipts1[i].y);
			for (unsigned i = 0; i < ipts2.size(); i++)
				drawCross(&res, (int)ipts2[i].x, (int)ipts2[i].y + im1->getHeight());
		}

		ImageLoader.saveImage(ofname, &res);
	}

	
	return 0;
}
コード例 #4
0
ファイル: match.cpp プロジェクト: yimingyanged/youbot
int main(int argc, char **argv) {
    Image *im1, *im2;
#ifdef GRAPHICS
    ImLoad ImageLoader;
    vector< Ipoint > ipts1, ipts2;
    bool drawc = false;
#endif
    char ofname[100];

    im1 = im2 = NULL;
    ofname[0] = 0;

    // Read the arguments
    int arg = 0;
    while (++arg < argc) { 
        if (! strcmp(argv[arg], "-k1"))
            loadIpoints(argv[++arg], ipts1);
        if (! strcmp(argv[arg], "-k2"))
            loadIpoints(argv[++arg], ipts2);
#ifdef GRAPHICS
        if (! strcmp(argv[arg], "-im1"))
            im1 = ImageLoader.readImage(argv[++arg]); 
        if (! strcmp(argv[arg], "-im2"))
            im2 = ImageLoader.readImage(argv[++arg]); 
        if (! strcmp(argv[arg], "-o"))
            strcpy(ofname, argv[++arg]);
        if (! strcmp(argv[arg], "-c"))
            drawc = true;
#endif
    }

    if (ipts1.size() == 0 || ipts2.size() == 0) {
        cout << "Usage:" << endl;
        cout << " match -k1 out1.surf -k2 out2.surf -im1 img1.pgm -im2 img2.pgm -o out.pgm" << endl << endl;
        cout << "For each feature in first descriptor file, find best in second according to "
            << "nearest neighbor ratio strategy. Display matches in out.pgm, generated "
            << "from img1.pgm and img2.pgm. Use -c to draw crosses at interest points." << endl;
        return 1;
    }

    vector< int > matches = findMatches(ipts1, ipts2);

#ifdef GRAPHICS
    if (im1 != NULL && im2 != NULL && ofname[0] != 0) {
        Image res(max(im1->getWidth(), im2->getWidth()), im1->getHeight() + im2->getHeight());
        for (int x = 0; x < im1->getWidth(); x++)
            for (int y = 0; y < im1->getHeight(); y++)
                res.setPix(x, y, im1->getPix(x, y));
        for (int x = 0; x < im2->getWidth(); x++)
            for (int y = 0; y < im2->getHeight(); y++)
                res.setPix(x, y + im1->getHeight(), im2->getPix(x, y));

        // Draw lines for matches
        for (unsigned i = 0; i < matches.size(); i++) {
            if (matches[i] != -1) {
                drawLine(&res, (int)ipts1[i].x, (int)ipts1[i].y,
                    (int)ipts2[matches[i]].x, (int)(ipts2[matches[i]].y + im1->getHeight()));
            }
        }

        // Draw crosses at interest point locations
        if (drawc) {
            for (unsigned i = 0; i < ipts1.size(); i++)
                drawCross(&res, (int)ipts1[i].x, (int)ipts1[i].y);
            for (unsigned i = 0; i < ipts2.size(); i++)
                drawCross(&res, (int)ipts2[i].x, (int)ipts2[i].y + im1->getHeight());
        }

        ImageLoader.saveImage(ofname, &res);
    }
#endif
    
    return 0;
}