Esempio n. 1
0
void test_optim(YARPImageOf<YarpPixelBGR>& src, 
		YARPImageOf<YarpPixelBGR>& dest)
{
  SatisfySize(src,dest);

  static Graph::node_id nodes[DIM][DIM];
  Graph *g = new Graph();
  
  for (int i=0; i<DIM; i++)
    {
      for (int j=0; j<DIM; j++)
	{
	  nodes[i][j] = g->add_node();
	}
    }

  YARPImageOf<YarpPixelFloat> src_motion, src_variance;
  SatisfySize(src,src_motion);
  SatisfySize(src,src_variance);
  src_motion.Zero();
  src_variance.Zero();
  IMGFOR(src,x,y)
    {
      YarpPixelBGR& pix = src(x,y);
      if (pix.r>128)
	{
	  src_motion(x,y) = 255;
	}
      if (pix.g>128)
	{
	  src_variance(x,y) = 255;
	}
    }
Esempio n. 2
0
float YARPObjectAnalysis::SpotInternals(YARPImageOf<YarpPixelBGR>& src_seg,
					YARPImageOf<YarpPixelMono>& in_mask,
					YARPImageOf<YarpPixelMono>& out_mask,
					YARPImageOf<YarpPixelBGR>& dest)
{
  YARPShapeBoundary sb;
  sb.SetFromMask(in_mask);
  sb.ScaleAboutCenter(shrink);
  YARPImageOf<YarpPixelMono> mask_small;
  SatisfySize(src_seg,mask_small);
  sb.GetMask(mask_small);
  ColorMap color_map, color_map2, color_id;
  YARPImageOf<YarpPixelInt> cluster0, cluster1;
  SatisfySize(src_seg,cluster0);
  SatisfySize(src_seg,cluster1);

  int iid = 1;
  IMGFOR(src_seg,x,y)
    {
      NetInt32 addr = HashColor(src_seg(x,y));
      ColorMap::iterator it = color_id.find(addr);
      
      if (it == color_id.end())
	{
	  color_id[addr] = iid;
	  it = color_id.find(addr);
	  iid++;
	}
      cluster0(x,y) = (*it).second;
    }
Esempio n. 3
0
int main(int argc, const char *argv[])
{
  const char *name = DEFAULT_NAME;
  char buf[256];
  if (argc>1)
    {
      name = argv[1];
    }
  sprintf(buf, "%s/i:img", name);
  in_img.Register(buf);
  sprintf(buf, "%s/o:img", name);
  out_img.Register(buf);

  sprintf(buf, "%s/i:mix", name);
  in_mix.Register(buf);
  sprintf(buf, "%s/o:box", name);
  out_data.Register(buf);
  
  box_thread.Begin();
  
  while(1)
    {
      in_img.Read();
      YARPImageOf<YarpPixelBGR> in;
      YARPImageOf<YarpPixelBGR> out;
      in.Refer(in_img.Content());
      out_img.Content().SetID(YARP_PIXEL_BGR);
      SatisfySize(in,out_img.Content());
      out.Refer(out_img.Content());
      Filter(in,out);
      out_img.Write();
//      YARPTime::DelayInSeconds(1000000);
    }
  return 0;
}
Esempio n. 4
0
static float GetMotion(YARPImageOf<YarpPixelBGR>& src, 
		       YARPImageOf<YarpPixelBGR>& dest,
		       YARPImageOf<YarpPixelFloat>& response)
{
  static int first = 1;
  static YARPImageOf<YarpPixelRGBFoo> record_x[NOISE_GAP];
  static YARPImageOf<YarpPixelFloat> record_x_gray[NOISE_GAP];
  static YARPImageOf<YarpPixelRGBFoo> record_x2[NOISE_GAP];
  static YARPImageOf<YarpPixelRGBFoo> total_x;
  static YARPImageOf<YarpPixelRGBFoo> total_x2;  
  static YARPImageOf<YarpPixelRGBFoo> wide_mean;  
  static YARPImageOf<YarpPixelRGBFoo> wide_var;  
  static YARPImageOf<YarpPixelFloat> src_gray;
  static int index_first = -1;
  static int index_last = -1;
  static int index_count = 0;


  if (force_first)
    {
      first = 1;
      index_first = -1;
      index_last = -1;
      index_count = 0;
    }

  SatisfySize(src,dest);
  SatisfySize(src,response);
  if (first)
    {
      SatisfySize(src,total_x);
      SatisfySize(src,total_x2);
      SatisfySize(src,wide_mean);
      SatisfySize(src,wide_var);      
      for (int k=0; k<NOISE_GAP; k++)
	{
	  SatisfySize(src,record_x[k]);
	  SatisfySize(src,record_x_gray[k]);
	  SatisfySize(src,record_x2[k]);
	}
      IMGFOR(src,x,y)
	{
	  YarpPixelRGBFoo zero = {0,0.0};
	  total_x(x,y) = zero;
	  total_x2(x,y) = zero;
	}
    }
void YARPFineOrientation::Apply(YARPImageOf<YarpPixelBGR>& src,
				YARPImageOf<YarpPixelBGR>& dest,
				YARPImageOf<YarpPixelFloat>& xdata, 
				YARPImageOf<YarpPixelFloat>& ydata, 
				YARPImageOf<YarpPixelFloat>& mdata)
{
  int view = (dest.GetWidth()>0);
  YARPImageOf<YarpPixelFloat>& orient = fine_orientation_data.Orient();
  static YARPImageOf<YarpPixelMono> mask;
  static IntegralImageTool ii;
  if (view)
    {
      SatisfySize(src,dest);
    }
  for (int i=0;i<SHIFTS;i++)
    {
      SatisfySize(src,shifts[i]);
    }
  SatisfySize(src,mean);
  static int shifts_x[SHIFTS], shifts_y[SHIFTS];
  
  int ct = 0;
  for (int dx=-1; dx<=2; dx++)
    {
      for (int dy=-1; dy<=2; dy++)
	{
	  assert(ct<SHIFTS);
	  ii.Offset(src,shifts[ct],dx,dy,1);
	  shifts_x[ct] = dx;
	  shifts_y[ct] = dy;
	  ct++;
	}
    }

  static YARPImageOf<YarpPixelFloat> mean, var, lx, ly, agree;
  YARPImageOf<YarpPixelBGR>& mono = src;
  SatisfySize(mono,mean);
  SatisfySize(mono,var);
  SatisfySize(mono,lx);
  SatisfySize(mono,ly);
  SatisfySize(mono,agree);
  SatisfySize(mono,xdata);
  SatisfySize(mono,ydata);
  SatisfySize(mono,mdata);
  int response_ct = 0;
  IMGFOR(mono,x,y)
    {
      float total = 0;
      float total2 = 0;
      YarpPixelBGR& pix0 = src(x,y);
      for (int k=0; k<SHIFTS; k++)
	{
	  YarpPixelBGR& pix1 = shifts[k](x,y);
	  float v = pdist(pix0,pix1);
	  total += v;
#ifdef USE_LUMINANCE_FILTER
	  total2 += v*v;
#endif
	}
      mean(x,y) = total/SHIFTS;
#ifdef USE_LUMINANCE_FILTER
      var(x,y) = total2/SHIFTS - (total/SHIFTS)*(total/SHIFTS);
#endif
    }