Exemplo n.º 1
0
TEST(MatchDao, saveTeams){
    //precisa de um player, id 0
    auto connection = loadConnection();
    mm::Match match;
    vector<int> teamA;
    teamA.push_back(1);
    teamA.push_back(1);
    vector<int> teamB;
    teamB.push_back(1);
    match.addTeam(teamA);
    match.addTeam(teamB);

    auto matchDao = connection->matchDao();
    bool saved = matchDao->saveMatch(match);
    EXPECT_TRUE(saved);

    mm::Match loadedMatch;
    loadedMatch.setId(match.id());
    bool loaded = matchDao->loadMatch(loadedMatch);
    if(!loaded){
        std::cout << "ERRO: " << matchDao->getError() << std::endl;
    }

    EXPECT_TRUE(loaded);

    int playersCount = loadedMatch.playersCount();
    int teamsCount = loadedMatch.teamsCount();

    EXPECT_EQ(3, playersCount);
    EXPECT_EQ(2, teamsCount);

    bool removed = matchDao->removeMatch(match);
    EXPECT_FALSE(removed);//match_profile dependencies

}
Exemplo n.º 2
0
int main(int argc, char** argv)
{
    if(argc != 10) {
        std::cerr << "Usage: " << argv[0] << " w h match.txt good_match.txt ntrials verb noseed mode stop" <<std::endl;
        std::cerr << "w: width of image" <<std::endl;
        std::cerr << "h: height of image" <<std::endl;
        std::cerr << "match.txt: x1 y1 x2 y2 for each line" <<std::endl;
        std::cerr << "good_match.txt: good matchings (x1 y1 x2 y2 for each line)" <<std::endl;
        std::cerr << "ntrials: maximum number of ransac trials" <<std::endl;
        std::cerr << "verb: verbose mode (1 enabled, 0 disabled)" <<std::endl;
        std::cerr << "seed: random seed (0=reinitialize)" <<std::endl;
        std::cerr << "mode: 0=all 1=ransac 2=optimized ransac (ORSA) 3=automatic" <<std::endl;
        std::cerr << "stop: stop when first meaningful F is found (1 enabled, 0 disabled)" <<std::endl;
        return 1;
    }

    int width = 0, height = 0; // dimensions of image
    int ntrials = 0;           // maximum number of ransac trials
    bool verb = false;         // verbose
    unsigned long seed = 0;    // seed value (0=reinitialize)
    int mode = -1;    // 0=all 1=ransac 2=optimized ransac (ORSA) 3=automatic
    bool stop = false;         // stop when first meaningful F is found   

    if(! (std::istringstream(argv[1]) >> width).eof()) width = 0;
    if(! (std::istringstream(argv[2]) >> height).eof()) height = 0;
    if(width <=0 || height <= 0) {
        std::cerr << "Wrong dimensions of image" << std::endl;
        return 1;
    }

    std::vector<Match> match;
    if(! loadMatch(argv[3],match)) {
        std::cerr << "Failed reading " << argv[3] << std::endl;
        return 1;
    }

    if(! (std::istringstream(argv[5]) >> ntrials).eof() || ntrials <= 0) {
        std::cerr << "ntrials should be greater than 0" << std::endl;
        return 1;
    }

    if(! (std::istringstream(argv[6]) >> verb).eof()) {
        std::cerr << "verb can only be 0 or 1" << std::endl;
        return 1;
    }

    if(! (std::istringstream(argv[7]) >> seed).eof()) {
        std::cerr << "seed must be a non-negative integer value" << std::endl;
        return 1;
    }

    if(! (std::istringstream(argv[8]) >> mode).eof() || mode < 0 || mode > 3) {
        std::cerr << "mode can only be 0, 1, 2, or 3" << std::endl;
        return 1;
    }

    if(! (std::istringstream(argv[9]) >> stop).eof()) {
        std::cerr << "stop can only be 0 or 1" << std::endl;
        return 1;
    }

    // Initialize random seed if necessary
    if(seed == 0) {
        seed = (long int)time(NULL);
        if(verb)
            std::cout << "seed: " << seed << std::endl; // Useful for debugging
    }
    srand(seed);

    // Remove duplicates (frequent with SIFT)
    std::sort(match.begin(), match.end());
    std::vector<Match>::iterator end = std::unique(match.begin(), match.end());
    if(end != match.end()) {
        if(verb)
            std::cout << "Remove " << std::distance(end,match.end())
                      << "/" << match.size() << " duplicate matches"<<std::endl;
        match.erase(end, match.end());
    }

    // Normalize coordinates
    std::vector<Match> matchBackup(match);
    float nx = (float)width;
    float ny = (float)height;
    float norm = 1.0f/sqrt((float)(nx*ny));
    for(size_t i=0; i<match.size(); i++) {
        match[i].x1 =  (match[i].x1-0.5f*nx)*norm;
        match[i].y1 =  (match[i].y1-0.5f*ny)*norm;
        match[i].x2 =  (match[i].x2-0.5f*nx)*norm;
        match[i].y2 =  (match[i].y2-0.5f*ny)*norm;
    }
    libNumerics::matrix<float> N(3,3); // Normalization matrix
    N = 0;
    N(0,0) = N(1,1) = norm; N(2,2) = 1.0f;
    N(0,2) = -0.5f*nx*norm;
    N(1,2) = -0.5f*ny*norm;

    // log proba of a uniform point in image within a band of 1 pixel from line
    float logalpha0 = log10(2.0f)+0.5f*log10((nx*nx+ny*ny)/float(nx*ny));
    std::vector<size_t> inliers;
    float error;

	libNumerics::matrix<float> F = orsa(match, ntrials, verb, mode, stop, logalpha0, inliers, error);
    error /= norm;
    if(verb) {
        std::cout << "F= " << N.t()*F*N <<std::endl; // Denormalization
        std::cout << "Geometric error threshold: " << error <<std::endl;
    }

    // Write the good matchings into a file
    std::vector<Match> good_match;
    std::vector<size_t>::const_iterator it = inliers.begin();
    for(; it != inliers.end(); it++)
        good_match.push_back(matchBackup[*it]);

    if(! saveMatch(argv[4], good_match)) {
        std::cerr << "Failed saving good matchings into " <<argv[4] <<std::endl;
        return 1;
    }

    return 0;
}
Exemplo n.º 3
0
/// Usage: siftMatch imgIn imgIn2 fileOut [imgOut]
/// Output in text file fileOut the matches evaluated by SIFT method between
/// the images imgIn and imgIn2 (PNG format). If imgOut is in the argument list,
/// this is an image file where matches will be shown (PNG format).
int main(int argc, char **argv)
{	
    if(argc != 4 && argc != 5) {
        std::cerr << "Usage: " << argv[0] << " imgIn imgIn2 fileOut [imgOut]"
                  << std::endl;
        return 1;
    }

	//////////////////////////////////////////////// Input
	int w1, h1;
    float* ipixels1;
    if(! load(argv[1], ipixels1, w1, h1))
        return 1;

	//////////////////////////////////////////////// Input
    int w2, h2;
    float* ipixels2;
    if(! load(argv[2], ipixels2, w2, h2))
        return 1;

	///////////////////////////////////////// Applying Sift
	siftPar siftparameters;
	default_sift_parameters(siftparameters);
    siftparameters.DoubleImSize=0;

	keypointslist keyp1, keyp2;
	compute_sift_keypoints(ipixels1,keyp1,w1,h1,siftparameters);
    std::cout<< "siftMatch:: 1st image: " << keyp1.size() << " keypoints"<<std::endl;
	compute_sift_keypoints(ipixels2,keyp2,w2,h2,siftparameters);
    std::cout<< "siftMatch:: 2nd image: " << keyp2.size() << " keypoints"<<std::endl;

	matchingslist matchings;
	compute_sift_matches(keyp1,keyp2,matchings,siftparameters);	
    std::cout << "siftMatch:: matches: " << matchings.size() <<std::endl;

	//////////////////////////////////////////////////////////////// Save file with matches
    saveMatch(argv[3], matchings);

	//////////////////////////////////////////////// Output image containing line matches
    if(argc > 4) {
        int wo =  std::max(w1,w2);
        int ho = h1+h2;

        float *opixels = new float[wo*ho];
        for(int j = 0; j < h1; j++)
            for(int i = 0; i < w1; i++)  opixels[j*wo+i] = ipixels1[j*w1+i];
        for(int j = 0; j < h2; j++)
            for(int i = 0; i < w2; i++)  opixels[(h1 + j)*wo + i] = ipixels2[j*w2 + i];	

        //////////////////////////////////////////////////////////////////// Draw matches
        matchingslist::iterator ptr = matchings.begin();
        for(; ptr != matchings.end(); ++ptr)
            draw_line(opixels,
                      (int) ptr->x1, (int) ptr->y1,
                      (int) ptr->x2, (int) ptr->y2 + h1,
                      255.0f, wo, ho);

        ///////////////////////////////////////////////////////////////// Save imgOut	
        io_png_write_f32(argv[4], opixels, (size_t)wo, (size_t)ho, 1);
        delete[] opixels;
	}

	/////////////////////////////////////////////////////////////// Delete memory
	free(ipixels1);
	free(ipixels2);
    return 0;
}