Exemplo n.º 1
0
static void sum_leaf_centers( FidtrackerX *ft, Region *r, int width, int height )
{
  int i;
  float leaf_size;

  double radius = .5 + r->depth;
  double n = radius * radius * M_PI;  // weight according to depth circle area

  if( r->adjacent_region_count == 1 ) {
    float x, y;

    leaf_size = ((r->bottom-r->top) + (r->right-r->left)) * .5f;
    //printf("leaf: %f\n",leaf_size);
    ft->total_leaf_size += leaf_size;

    x = ((r->left + r->right) * .5f);
    y = ((r->top + r->bottom) * .5f);

    if( ft->pixelwarp ){
      int pixel = width*(int)y +(int)x;
      if ((pixel>=0) && (pixel<width*height)) {
	x = ft->pixelwarp[ pixel ].x;
	y = ft->pixelwarp[ pixel ].y;
      }

      if ((x>0) && (y>0)) {
	if( r->colour == 0 ){
	  ft->black_x_sum_warped += x * n;
	  ft->black_y_sum_warped += y * n;
	  ft->black_leaf_count_warped += n;
	}else{
	  ft->white_x_sum_warped += x * n;
	  ft->white_y_sum_warped += y * n;
	  ft->white_leaf_count_warped += n;
	}
      }
    }

    if( r->colour == 0 ){
      ft->black_x_sum += x * n;
      ft->black_y_sum += y * n;
      ft->black_leaf_count += n;
    }else{
      ft->white_x_sum += x * n;
      ft->white_y_sum += y * n;
      ft->white_leaf_count += n;
    }

    ft->total_leaf_count +=n;
  }else{
    for( i=0; i < r->adjacent_region_count; ++i ){
      Region *adjacent = r->adjacent_regions[i];
      if( adjacent->level == TRAVERSED
	  && adjacent->descendent_count < r->descendent_count )
	sum_leaf_centers( ft, adjacent, width, height );
    }
  }
}
Exemplo n.º 2
0
static void sum_leaf_centers( FidtrackerX *ft, Region *r, int width, int height )
{
    int i;

    double radius = .5 + r->depth;
    double n = radius * radius * M_PI;  // weight according to depth circle area

    if( r->adjacent_region_count == 1 ){
        float x, y;

		ft->total_leaf_size += ((r->bottom-r->top) + (r->right-r->left))/2.0f;

        x = ((r->left + r->right) * .5f);
        y = ((r->top + r->bottom) * .5f);

        if( ft->pixelwarp ){
            int xx = x;
            float xf = x - xx;
            int yy = y;
            float yf = y - yy;

            // bilinear interpolated pixel warp
            ShortPoint *a = &ft->pixelwarp[ width * yy + xx ];
            ShortPoint *b = &ft->pixelwarp[ width * yy + (xx+1) ];
            ShortPoint *c = &ft->pixelwarp[ width * (yy+1) + xx ];
            ShortPoint *d = &ft->pixelwarp[ width * (yy+1) + (xx+1) ];

            float x1 = a->x + ((b->x - a->x) * xf);
            float x2 = c->x + ((d->x - c->x) * xf);

            float y1 = a->y + ((c->y - a->y) * yf);
            float y2 = b->y + ((d->y - b->y) * yf);

            x = x1 + ((x2 - x1) * yf);
            y = y1 + ((y2 - y1) * xf);


            // truncated lookup of pixel warp:
            // x = ft->pixelwarp[ width * yy + xx ].x;
            // y = ft->pixelwarp[ width * yy + xx ].y;
        }

	ft->total_leaf_count ++;

        if( r->colour == 0 ){
            ft->black_x_sum += x * n;
            ft->black_y_sum += y * n;
            ft->black_leaf_count += n;
        }else{
            ft->white_x_sum += x * n;
            ft->white_y_sum += y * n;
            ft->white_leaf_count += n;
        }
    }else{
        for( i=0; i < r->adjacent_region_count; ++i ){
            Region *adjacent = r->adjacent_regions[i];
            if( adjacent->level == TRAVERSED
                    && adjacent->descendent_count < r->descendent_count )
                sum_leaf_centers( ft, adjacent, width, height );
        }
    }
}
Exemplo n.º 3
0
static void compute_fiducial_statistics( FidtrackerX *ft, FiducialX *f,
        Region *r, int width, int height )
{
    double all_x, all_y;
    double black_x, black_y;
    char *depth_string;

    ft->black_x_sum = 0.;
    ft->black_y_sum = 0.;
    ft->black_leaf_count = 0.;
    ft->white_x_sum = 0.;
    ft->white_y_sum = 0.;
    ft->white_leaf_count = 0.;

    ft->total_leaf_count = 0;
    ft->total_leaf_size = 0.;	
    ft->average_leaf_size = 0.;

//    ft->min_leaf_width_or_height = 0x7FFFFFFF;

    set_depth( r, 0 );

    sum_leaf_centers( ft, r, width, height );

    ft->average_leaf_size = ft->total_leaf_size / (double)(ft->total_leaf_count);

    all_x = (double)(ft->black_x_sum + ft->white_x_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count);
    all_y = (double)(ft->black_y_sum + ft->white_y_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count);

    black_x = (double)ft->black_x_sum / (double)ft->black_leaf_count;
    black_y = (double)ft->black_y_sum / (double)ft->black_leaf_count;

    f->x = all_x;
    f->y = all_y;
    f->angle = (M_PI * 2) - calculate_angle( all_x - black_x, all_y - black_y );
    f->leaf_size = (float)(ft->average_leaf_size);
	f->root_size = ((r->right-r->left)+(r->bottom-r->top))/2;

/*
    print_unordered_depth_string( r );
    printf( "\n" );
    fflush( stdout );
*/

/*
	// can differ due to fuzzy fiducial tracking
    assert( r->depth == 0 );
    assert( r->descendent_count >= ft->min_target_root_descendent_count );
    assert( r->descendent_count <= ft->max_target_root_descendent_count );
*/


	if(r->flags & LOST_SYMBOL_FLAG)  f->id = INVALID_FIDUCIAL_ID;
	else {
        ft->next_depth_string = 0;
        depth_string = build_left_heavy_depth_string( ft, r );
	
        ft->temp_coloured_depth_string[0] = (char)( r->colour ? 'w' : 'b' );
        ft->temp_coloured_depth_string[1] = '\0';
        strcat( ft->temp_coloured_depth_string, depth_string );

		f->id = treestring_to_id( ft->treeidmap, ft->temp_coloured_depth_string );
		/*if (f->id != INVALID_FIDUCIAL_ID) {
			if (!(check_leaf_variation(ft, r, width, height)))  {
				f->id = INVALID_FIDUCIAL_ID;
				printf("filtered %f\n",ft->average_leaf_size);
			}
		}*/
    }

}
Exemplo n.º 4
0
static void compute_fiducial_statistics( FidtrackerX *ft, FiducialX *f,
					 Region *r, int width, int height )
{
  double all_x = 0.;
  double all_y = 0.;
  double black_x = 0.;
  double black_y = 0.;

  double all_x_warped = 0.;
  double all_y_warped = 0.;
  double black_x_warped = 0.;
  double black_y_warped = 0.;
  char *depth_string;

  ft->black_x_sum = 0.;
  ft->black_y_sum = 0.;
  ft->black_leaf_count = 0.;
  ft->white_x_sum = 0.;
  ft->white_y_sum = 0.;
  ft->white_leaf_count = 0.;

  ft->black_x_sum_warped = 0.;
  ft->black_y_sum_warped = 0.;
  ft->black_leaf_count_warped = 0.;
  ft->white_x_sum_warped = 0.;
  ft->white_y_sum_warped = 0.;
  ft->white_leaf_count_warped = 0.;

  ft->total_leaf_count = 0;
  ft->total_leaf_size = 0.;
  ft->average_leaf_size = 0.;

  //    ft->min_leaf_width_or_height = 0x7FFFFFFF;

  set_depth( r, 0 );
  sum_leaf_centers( ft, r, width, height );
  if(ft->total_leaf_count<1 || ft->black_leaf_count<1 || ft->white_leaf_count<1) {
    //fprintf(stderr, "did not find any leafs (%d)!", ft->total_leaf_count);
    r->flags |= LOST_SYMBOL_FLAG;
    f->id = INVALID_FIDUCIAL_ID;
    return;
  }
  ft->average_leaf_size = ft->total_leaf_size / (double)(ft->total_leaf_count);

  all_x = (double)(ft->black_x_sum + ft->white_x_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count);
  all_y = (double)(ft->black_y_sum + ft->white_y_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count);

  black_x = (double)ft->black_x_sum / (double)ft->black_leaf_count;
  black_y = (double)ft->black_y_sum / (double)ft->black_leaf_count;

  if (ft->pixelwarp) {
    if (ft->total_leaf_count>(ft->black_leaf_count_warped+ft->white_leaf_count_warped)) {
      int pixel = width*(int)all_y+(int)all_x;

      if ((pixel>=0) && (pixel<width*height)) {
	all_x_warped = ft->pixelwarp[pixel].x;
	all_y_warped = ft->pixelwarp[pixel].y;
	if ((all_x_warped>0) || (all_y_warped>0)) {

	  pixel = (int)black_y*width+(int)black_x;
	  if ((pixel>=0) && (pixel<width*height)) {
	    black_x_warped = ft->pixelwarp[pixel].x;
	    black_y_warped = ft->pixelwarp[pixel].y;
	    if ((black_x_warped>0) || (black_y_warped>0)) {
	      f->angle = calculate_angle( all_x_warped - black_x_warped, all_y_warped - black_y_warped );
	    } else f->angle = 0.0f;
	  } else f->angle = 0.0f;

	  f->x = all_x_warped;
	  f->y = all_y_warped;
	} else {

	  f->x = 0.0f;
	  f->y = 0.0f;
	  f->angle = 0.0f;
	  r->flags |= LOST_SYMBOL_FLAG;
	}
      } else r->flags |= LOST_SYMBOL_FLAG;
    } else {
      all_x_warped = (double)(ft->black_x_sum_warped + ft->white_x_sum_warped) / (double)(ft->black_leaf_count_warped + ft->white_leaf_count_warped);
      all_y_warped = (double)(ft->black_y_sum_warped + ft->white_y_sum_warped) / (double)(ft->black_leaf_count_warped + ft->white_leaf_count_warped);

      black_x_warped = (double)ft->black_x_sum_warped / (double)ft->black_leaf_count_warped;
      black_y_warped = (double)ft->black_y_sum_warped / (double)ft->black_leaf_count_warped;

      f->x = all_x_warped;
      f->y = all_y_warped;
      f->angle = calculate_angle( all_x_warped - black_x_warped, all_y_warped - black_y_warped );
    }

  } else {
    f->x = all_x;
    f->y = all_y;
    f->angle = calculate_angle( all_x - black_x, all_y - black_y );
  }

  //f->a = black_x;
  //f->b = black_y;

  f->leaf_size = (float)(ft->average_leaf_size);
  f->root_size = r->right-r->left;
  if ((r->bottom-r->top)>f->root_size) f->root_size = r->bottom-r->top;
  f->root_colour=r->colour;
  f->node_count=r->descendent_count;

  /*
    print_unordered_depth_string( r );
    printf( "\n" );
    fflush( stdout );
  */

  /*
  // can differ due to fuzzy fiducial tracking
  assert( r->depth == 0 );
  assert( r->descendent_count >= ft->min_target_root_descendent_count );
  assert( r->descendent_count <= ft->max_target_root_descendent_count );
  */

  if (r->flags & LOST_SYMBOL_FLAG) f->id = INVALID_FIDUCIAL_ID;
  else {
    ft->next_depth_string = 0;
    depth_string = build_left_heavy_depth_string( ft, r );

    ft->temp_coloured_depth_string[0] = (char)( r->colour ? 'w' : 'b' );
    ft->temp_coloured_depth_string[1] = '\0';
    strcat( ft->temp_coloured_depth_string, depth_string );

    f->id = treestring_to_id( ft->treeidmap, ft->temp_coloured_depth_string );
    /*if (f->id != INVALID_FIDUCIAL_ID) {
      if (!(check_leaf_variation(ft, r, width, height)))  {
      f->id = INVALID_FIDUCIAL_ID;
      printf("filtered %f\n",ft->average_leaf_size);
      }
      }*/
  }

}
Exemplo n.º 5
0
void compute_fiducial_statistics( FidtrackerX *ft, FiducialX *f,
        Region *r, int width, int height )
{
    double all_x = 0.;
	double all_y = 0.;
    double black_x = 0.;
	double black_y = 0.;
	
    double all_x_warped = 0.;
	double all_y_warped = 0.;
    double black_x_warped = 0.;
	double black_y_warped = 0.;
    char *depth_string;

	double black_average = 0.;
	double white_average = 0.;

	double leaf_variation = 10.;
	double black_variation = 10.;
	double white_variation = 10.;

    ft->black_x_sum = 0.;
    ft->black_y_sum = 0.;
    ft->black_leaf_count = 0.;
    ft->white_x_sum = 0.;
    ft->white_y_sum = 0.;
    ft->white_leaf_count = 0.;

	ft->black_x_sum_warped = 0.;
    ft->black_y_sum_warped = 0.;
    ft->black_leaf_count_warped = 0.;
    ft->white_x_sum_warped = 0.;
    ft->white_y_sum_warped = 0.;
    ft->white_leaf_count_warped = 0.;
	
    ft->total_leaf_count = 0;
	
	ft->white_leaf_size = 0;
	ft->black_leaf_size = 0;
	ft->white_leaf_nodes = 0;
	ft->black_leaf_nodes = 0;
	
	ft->min_black = 0xFFFF;
	ft->min_white = 0xFFFF;
	ft->max_black = 0;
	ft->max_white = 0;
	
    set_depth( r, 0 );
    sum_leaf_centers( ft, r, width, height );

	all_x = (double)(ft->black_x_sum + ft->white_x_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count);
	all_y = (double)(ft->black_y_sum + ft->white_y_sum) / (double)(ft->black_leaf_count + ft->white_leaf_count);
	
	black_x = (double)ft->black_x_sum / (double)ft->black_leaf_count;
	black_y = (double)ft->black_y_sum / (double)ft->black_leaf_count;
	
	f->raw_x = all_x;
	f->raw_y = all_y;
	f->raw_a = calculate_angle( all_x - black_x, all_y - black_y );
	
	if (ft->pixelwarp) {
		if (ft->total_leaf_count>(ft->black_leaf_count_warped+ft->white_leaf_count_warped)) { 
			int pixel = width*(int)floor(all_y+.5f)+(int)floor(all_x+.5f);

			if ((pixel>=0) && (pixel<width*height)) {
				all_x_warped = ft->pixelwarp[pixel].x;
				all_y_warped = ft->pixelwarp[pixel].y;
				if ((all_x_warped>0) || (all_y_warped>0)) {

					pixel = width*(int)floor(black_y+.5f)+(int)floor(black_x+.5f);
					if ((pixel>=0) && (pixel<width*height)) {
						black_x_warped = ft->pixelwarp[pixel].x;
						black_y_warped = ft->pixelwarp[pixel].y;
						if ((black_x_warped>0) || (black_y_warped>0)) {
							f->angle = calculate_angle( all_x_warped - black_x_warped, all_y_warped - black_y_warped );
						} else f->angle = 0.0f;
					} else f->angle = 0.0f;
						
					f->x = all_x_warped;
					f->y = all_y_warped;	
				} else {

					f->x = 0.0f;
					f->y = 0.0f;
					f->angle = 0.0f;
					r->flags |= FUZZY_SYMBOL_FLAG;
				}
			} else r->flags |= FUZZY_SYMBOL_FLAG;
		} else {
			all_x_warped = (double)(ft->black_x_sum_warped + ft->white_x_sum_warped) / (double)(ft->black_leaf_count_warped + ft->white_leaf_count_warped);
			all_y_warped = (double)(ft->black_y_sum_warped + ft->white_y_sum_warped) / (double)(ft->black_leaf_count_warped + ft->white_leaf_count_warped);
			
			black_x_warped = (double)ft->black_x_sum_warped / (double)ft->black_leaf_count_warped;
			black_y_warped = (double)ft->black_y_sum_warped / (double)ft->black_leaf_count_warped;
						
			f->x = all_x_warped;
			f->y = all_y_warped;
			f->angle = calculate_angle( all_x_warped - black_x_warped, all_y_warped - black_y_warped );
		}
		
	} else {
		f->x = f->raw_x;
		f->y = f->raw_y;
		f->angle = f->raw_a;
	}
	
	f->root = r;
	
/*	
	print_unordered_depth_string( r );
    printf( "\n" );
    fflush( stdout );
*/


/*
	// can differ due to fuzzy fiducial tracking
    assert( r->depth == 0 );
    assert( r->descendent_count >= ft->min_target_root_descendent_count );
    assert( r->descendent_count <= ft->max_target_root_descendent_count );
*/
	
	if (ft->black_leaf_nodes>0) black_average=ft->black_leaf_size/ft->black_leaf_nodes;
	if (ft->white_leaf_nodes>0) white_average=ft->white_leaf_size/ft->white_leaf_nodes;
	
	if ((white_average>0) && (black_average>0)) {
		if (black_average>white_average) leaf_variation = black_average/white_average-1;
		else leaf_variation = white_average/black_average-1;
		
		if (ft->max_black>=ft->min_black) black_variation = (ft->max_black-ft->min_black)/black_average;
		//else printf("black %f %f\n",ft->max_black,ft->min_black);
		if (ft->max_white>=ft->min_white) white_variation = (ft->max_white-ft->min_white)/white_average;
		//else printf("white %f %f\n",ft->max_white,ft->min_white);
	}
	
	//printf("variation %f %f %f\n",leaf_variation,black_variation,white_variation);
	f->id = INVALID_FIDUCIAL_ID; // initialize
	
	if ((f->x<0) || (f->y<0)) return; // this can happen
	else if (r->flags & FUZZY_SYMBOL_FLAG) {
		// select fuzzy fiducials before decoding
		if ((ft->white_leaf_nodes>=ft->min_leafs) || (ft->black_leaf_nodes>=ft->min_leafs))
			f->id = FUZZY_FIDUCIAL_ID;
	} else if ((leaf_variation>1.0f) && ((black_variation>1.0f) || (white_variation>1.0f))) {
		// eliminate noise
		if ((ft->white_leaf_nodes>ft->min_leafs) || (ft->black_leaf_nodes>ft->min_leafs))
			f->id = FUZZY_FIDUCIAL_ID;
	} else {
		// decode valid fiducal candidates
		ft->next_depth_string = 0;
		depth_string = build_left_heavy_depth_string( ft, r );
				
		ft->temp_coloured_depth_string[0] = (char)( r->colour ? 'w' : 'b' );
		ft->temp_coloured_depth_string[1] = '\0';
		strcat( ft->temp_coloured_depth_string, depth_string );
		
		f->id = treestring_to_id( ft->treeidmap, ft->temp_coloured_depth_string );
		if (f->id != INVALID_FIDUCIAL_ID)
			r->flags |= ROOT_REGION_FLAG;
		else if ((ft->white_leaf_nodes>=ft->min_leafs) || (ft->black_leaf_nodes>=ft->min_leafs))
			f->id = FUZZY_FIDUCIAL_ID;
		
		//if (f->id != INVALID_FIDUCIAL_ID) printf("%d %s %f\n",f->id,ft->temp_coloured_depth_string,leaf_variation);
	}
}