Пример #1
0
void extrema_locator::locate(void)
{
	find_extrema();
	find_objects();
	merge_objects();
	ex_points_from_objects();
}
Пример #2
0
///////////////////////////
// Author: Brian Fehrman
// Creates a mosaic given a p and p_prime image. Assumes P image is to the
// left and P_prime is to the right (this may not be a needed assumption)
// Assumes H matrix takes p to p_prime.
///////////////////////////
void stitcher::create_mosaic( Mat& dst_mat)
{
   double curr_tran_x = 0.0, curr_tran_y = 0.0;
   Mat scaled_mat;
   Mat H_matrix_inv = H_matrix.inv();
   double scale_val = 0.0;
   Vec3d extrema;
   Vec3d point_offsets;
   Mat temp_mat;
   
   find_extrema( extrema, point_offsets );
   
   temp_mat.create( (int) extrema[1], (int) extrema[0], CV_8UC3 );

   for( int curr_row = 0; curr_row < temp_mat.rows; curr_row++)
   {
      for( int curr_col = 0; curr_col < temp_mat.cols; curr_col++)
      {
         temp_mat.at<Vec3b>( curr_row, curr_col) = Vec3b( 0, 0, 0);
      }
   }

   for(double curr_x = 0; curr_x < p_prime_image.cols - 1; curr_x += 1 )
   {   
      for( double curr_y = 0; curr_y < p_prime_image.rows - 1; curr_y += 1 )
      {
         scale_val = curr_x * H_matrix_inv.at<double>(2,0)  + curr_y * H_matrix_inv.at<double>(2,1) + H_matrix_inv.at<double>(2,2);
         curr_tran_x = (curr_x * H_matrix_inv.at<double>(0,0) + curr_y * H_matrix_inv.at<double>(0,1) + H_matrix_inv.at<double>(0,2))/scale_val;
         curr_tran_y = (curr_x * H_matrix_inv.at<double>(1,0) + curr_y * H_matrix_inv.at<double>(1,1) + H_matrix_inv.at<double>(1,2))/scale_val;
         
         if( curr_tran_y > 0 && curr_tran_x > 0 && curr_tran_y < temp_mat.rows && curr_tran_x < temp_mat.cols)
         temp_mat.at<Vec3b>( curr_tran_y, curr_tran_x) = p_prime_image.at<Vec3b>( curr_y, curr_x );
   
      }
   }
   
   for(double curr_x = 0; curr_x < temp_mat.cols - 1; curr_x += 1 )
   {   
      for( double curr_y = 0; curr_y < temp_mat.rows - 1; curr_y += 1 )
      {
         scale_val = curr_x * H_matrix.at<double>(2,0)  + curr_y * H_matrix.at<double>(2,1) + H_matrix.at<double>(2,2);
         curr_tran_x = (curr_x * H_matrix.at<double>(0,0) + curr_y * H_matrix.at<double>(0,1) + H_matrix.at<double>(0,2))/scale_val;
         curr_tran_y = (curr_x * H_matrix.at<double>(1,0) + curr_y * H_matrix.at<double>(1,1) + H_matrix.at<double>(1,2))/scale_val;
         
         if( curr_tran_y > 0 && curr_tran_x > 0 && curr_tran_y < p_prime_image.rows && curr_tran_x < p_prime_image.cols)
            temp_mat.at<Vec3b>( curr_y, curr_x) = p_prime_image.at<Vec3b>( curr_tran_y, curr_tran_x );
   
      }
   }

   for(double curr_x = 0; curr_x < p_image.cols - 1; curr_x += 1 )
   {   
      for( double curr_y = 0; curr_y < p_image.rows - 1; curr_y += 1 )
      {
         temp_mat.at<Vec3b>( curr_y, curr_x) = p_image.at<Vec3b>( curr_y, curr_x );
      }
   }

   temp_mat.copyTo( dst_mat);
   
   imwrite(output_mosaic_name, temp_mat);
}
Пример #3
0
static void determine_hand(struct hand *const best_hand, const unsigned long long HAND){
        enum hand_t type = HIGH_CARD;

        const unsigned CLUB = HAND & 0x1FFF;
        const unsigned DIAMOND = HAND>>13 & 0x1FFF;
        const unsigned HEART = HAND>>26 & 0x1FFF;
        const unsigned SPADE = HAND>>39 & 0x1FFF;

        const unsigned CLUB_ACED = CLUB | (CLUB & 0x1) << 13;
        const unsigned DIAMOND_ACED = DIAMOND | (DIAMOND & 0x1) << 13;
        const unsigned HEART_ACED = HEART | (HEART & 0x1) << 13;
        const unsigned SPADE_ACED = SPADE | (SPADE & 0x1) << 13;

        const unsigned LUMP = CLUB_ACED | DIAMOND_ACED | HEART_ACED | SPADE_ACED;

        unsigned rank;
        for(unsigned i = 0; i < 10; i++){
                const unsigned SMASK = 0x3E00 >> i;

                // check for straight
                if(is_straight(LUMP, SMASK)){
                        // check for straight-flush
                        if(is_straight_flush(CLUB_ACED, DIAMOND_ACED, HEART_ACED, SPADE_ACED, SMASK)){
                                type = STRAIGHT_FLUSH;
                        }else{
                                type = STRAIGHT;
                        }

                        rank = 9 - i;

                        break;
                }
        }

        const unsigned CLUB_NORMALIZED = CLUB_ACED >> 1;
        const unsigned DIAMOND_NORMALIZED = DIAMOND_ACED >> 1;
        const unsigned HEART_NORMALIZED = HEART_ACED >> 1;
        const unsigned SPADE_NORMALIZED = SPADE_ACED >> 1;
        const unsigned LUMP_NORMALIZED = LUMP >> 1;

        unsigned pairs = 0;
        unsigned triplet = 0;
        unsigned quadruplet = 0;

        unsigned chits = 0;
        unsigned dhits = 0;
        unsigned hhits = 0;
        unsigned shits = 0;

        for(unsigned i = 0; type < FOUR_OF_A_KIND && i < 13; i++){
                const unsigned C = CLUB_NORMALIZED & 1<<i;
                const unsigned D = DIAMOND_NORMALIZED & 1<<i;
                const unsigned H = HEART_NORMALIZED & 1<<i;
                const unsigned S = SPADE_NORMALIZED & 1<<i;

                const unsigned C_HIT = (C > 0);
                const unsigned D_HIT = (D > 0);
                const unsigned H_HIT = (H > 0);
                const unsigned S_HIT = (S > 0);

                switch(C_HIT + D_HIT + H_HIT + S_HIT){
                        case 4:
                                quadruplet = 1<<i;
                                type = FOUR_OF_A_KIND;
                                continue;
                        case 3:
                                triplet = 1<<i;
                                if(type < THREE_OF_A_KIND){
                                        type = THREE_OF_A_KIND;
                                }
                        case 2:
                                pairs |= 1<<i;
                                if(type < ONE_PAIR){
                                        type = ONE_PAIR;
                                }
                                break;
                }

                chits += C_HIT;
                dhits += D_HIT;
                hhits += H_HIT;
                shits += S_HIT;
        }

        unsigned suit;
        // check for full-house, flush, and two pair
        if(type < FULL_HOUSE && is_full_house(triplet, &pairs)){
                type = FULL_HOUSE;
        }else if(type < FLUSH && (suit = is_flush(chits, dhits, hhits, shits))){
                switch(suit){
                        case 1:
                                rank = CLUB_NORMALIZED;
                                break;
                        case 2:
                                rank = DIAMOND_NORMALIZED;
                                break;
                        case 3:
                                rank = HEART_NORMALIZED;
                                break;
                        case 4:
                                rank = SPADE_NORMALIZED;
                                break;
                }

                type = FLUSH;
        }else if(type < TWO_PAIR && is_two_pair(&pairs)){
                type = TWO_PAIR;
        }

        switch(type){
                case HIGH_CARD:
                        rank = find_extrema(LUMP_NORMALIZED, 5);
                        break;
                case ONE_PAIR:
                        rank = find_extrema(LUMP_NORMALIZED & (~pairs), 3);
                        break;
                case TWO_PAIR:
                        rank = find_extrema(LUMP_NORMALIZED & (~pairs), 1);
                        break;
                case THREE_OF_A_KIND:
                        rank = find_extrema(LUMP_NORMALIZED & (~triplet), 2);
                        break;
                case FLUSH:
                        rank = find_extrema(rank, 5);
                        break;
                case FOUR_OF_A_KIND:
                        rank = find_extrema(LUMP_NORMALIZED & (~quadruplet), 1);
                        break;
        }

        best_hand->category = type;
        best_hand->quadruplet = quadruplet;
        best_hand->triplet = triplet;
        best_hand->pairs = pairs;
        best_hand->rank = rank;
}