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

}
Exemple #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;
}
Exemple #3
0
int main(int argc, char** argv)
{
    if(argc != 6) {
        std::cerr << "Usage: " << argv[0]
                  << " in.png out.png match.txt left|right H.txt" <<std::endl;
        return 1;
    }

    // Read image
    size_t nx, ny;
    LWImage<unsigned char> in(0,0,0);
    in.data = read_png_u8_rgb(argv[1], &nx, &ny);
    in.w = static_cast<int>(nx); in.h = static_cast<int>(ny); in.comps=3;
    if(! in.data) {
        std::cerr << "Error reading image " << argv[1] << std::endl;
        return 1;
    }

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

    // Read left/right image
    bool bLeft = (strcmp(argv[4],"left")==0);
    if(!bLeft && strcmp(argv[4], "right")!=0) {
        std::cerr << "Error: arg 4 must be 'left' or 'right'" << std::endl;
        return 1;
    }

    // Read homography
    libNumerics::Homography H;
    std::ifstream f(argv[5]);
    if((f >> H.mat()).fail()) {
        std::cerr << "Error reading homography file " << argv[2] << std::endl;
        return 1;
    }

    // Drawing lines
    int delta = in.h/(NUM_LINES+1);
    if(delta==0) delta=1;
    for(int i=delta; i < in.h; i+=delta)
        draw_horizontal_dashed_line(in.data, in.w, in.h, i,
                                    LENGTH_ON, LENGTH_OFF, CYAN);

    // Drawing SIFT
    std::vector<Match>::const_iterator it=match.begin();
    for(; it != match.end(); ++it) {
        double x=it->x1, y=it->y1;
        if(! bLeft) {
            x = it->x2; y=it->y2;
        }
        H(x,y);
        int ix = static_cast<int>(std::floor(x+0.5));
        int iy = static_cast<int>(std::floor(y+0.5));
        if(0<=ix && ix<in.w && 0<=iy && iy<in.h)
            draw_cross(in.data, in.w, in.h, ix, iy, CROSS_HALF_LENGTH, RED);
    }

    // Write image
    if(write_png_u8(argv[2], in.data, in.w, in.h, in.comps) != 0) {
        std::cerr << "Error writing file " << argv[3] << std::endl;
        return 1;
    }
    return 0;
}