void
  fastnc_detector<A>::new_particles(F& feature, PS& pset, const cpu&)
  {
    SCOPE_PROF(fastnc_new_particles_detector);
    memset(new_points_, 0);
    typename PS::kernel_type pset_ = pset;
    mt_apply2d(sizeof(i_float1), saliency_.domain() - border(8),
               [this, &feature, &pset_] (i_int2 p)
               {
                 if (pset_.has(p)) return;
                 if (saliency_(p) == 0) return;

                 for (int i = 0; i < 8; i++)
                 {
                   i_int2 n(p + i_int2(c8_h[i]));
                   if (saliency_(p) < saliency_(n) || pset_.has(n))
                     return;
                 }

                 new_points_(p) = p;
               }, cpu());

    st_apply2d(sizeof(i_float1), saliency_.domain() - border(8),
               [this, &feature, &pset] (i_int2 p)
               {
                 if (new_points_(p) != i_short2(0,0)) pset.add(p, feature(p));
               }, cpu());

  }
    inline __host__ __device__
    gl8u compute_contrast(i_short2 p, const I& input)
    {
      const int d = 5;
      return ::abs(int(input(p + i_int2(0,d))) - int(input(p + i_int2(0,-d)))) +
	::abs(int(input(p + i_int2(-d,0))) - int(input(p + i_int2(d,0))));
    }
Exemple #3
0
 bc2s64_feature<A>::bc2s64_feature(const obox2d& d)
   : bc2s_feature<A>(d)
 {
   for (unsigned i = 0; i < 16; i += 4)
   {
     point2d<int> p(10,10);
     this->offsets_s1_[i/4] = (long(&this->s1_(p + i_int2(circle_r3[i]))) - long(&this->s1_(p))) / sizeof(V);
     this->offsets_s2_[i/4] = (long(&this->s2_(p + i_int2(circle_r3[i])*2)) - long(&this->s2_(p))) / sizeof(V);
   }
 }
Exemple #4
0
 i_int2 host_image2d<V>::index_to_point(int idx) const
 {
   assert(!(pitch_ % sizeof(V)));
   int r = (idx * int(sizeof(V))) / pitch_;
   int c = idx - r * (pitch_ / int(sizeof(V)));
   return i_int2(r, c);
 }
inline __host__ __device__
i_short2 gradient_descent_match2(i_short2 prediction, F f, FI& feature_img, float& distance, unsigned scale = 1)
{
    i_short2 match = prediction;
    float match_distance = feature_img.distance(f, prediction);
    unsigned match_i = 8;
    box2d domain = feature_img.domain() - border(7);

    if (!domain.has(prediction)) return prediction;
    assert(domain.has(prediction));
    for (int search = 0; search < 7; search++)
    {
        for(int i = 0; i != 25; i++)
        {
            i_int2 n(prediction + i_int2(c25_h[i]));
            {
                float d = feature_img.distance(f, n, scale);
                if (d < match_distance)
                {
                    match = n;
                    match_i = i;
                    match_distance = d;
                }
            }
        }

        if (i_int2(prediction) == i_int2(match) || !domain.has(match))
            break;
        else
            prediction = match;

    }

    distance = match_distance;
    return match;

}
Exemple #6
0
    __global__ void convolve_kernel(I, kernel_image2d<O> out, unsigned kernelsize)
    {
      i_int2 p = thread_pos2d();

      if (!out.has(p))
        return;

      bt_change_vtype(O, type_mult(bt_vtype(O), float)) r  = zero();
      for(int i = 0; i < kernelsize; i++)
      {
        float w = tex1Dfetch(tex_weights, i);
        point2d<int> n = i_int2(tex1Dfetch(tex_dpoints, i)) + p;
        if (out.has(n))
          r += O(tex2D(conv_input_tex<I>::tex(), n)) * w;
      }
      out(p) = r;
    }
inline __host__ __device__
i_int2 naive_local_match(i_short2 prediction,
                         const S& sample,
                         const F& feature_img)
{
    i_short2 match = prediction;
    float match_distance = feature_img.distance(sample, prediction);

    for_all_in_static_neighb2d(prediction, n, c49)
    if (n->row() > 10 && n->row() < (feature_img.domain().nrows() - 10) &&
            n->col() > 10 && n->col() < (feature_img.domain().ncols() - 10))
    {
        float d = feature_img.distance_linear(sample, n);
        if (d < match_distance)
        {
            match = i_int2(n);
            match_distance = d;
        }
    }

    return match;
}
    inline __host__ __device__
    gl8u compute_saliency(i_short2 p, I& input_, int n_, int fast_th_, const A&)
    {

      unsigned max_n = 0;
      unsigned n_bright = 0;
      unsigned n_dark = 0;
      gl8u vp = input_(p);
      unsigned sum_bright = 0;
      unsigned sum_dark = 0;

      for (int i = 0; i < 16; i++)
      {
	gl8u vn = input_(p + i_int2(arch_neighb2d<A>::get(circle_r3_h, circle_r3, i)));
	unsigned char dist = ::abs(int(vn) - int(vp));
	if (dist > fast_th_)
	{
	  if (int(vn) >= int(vp))
	  {
	    n_bright++;
	    sum_bright += dist;
	  }
	  else
	  {
	  n_dark++;
	  sum_dark += dist;
	  }
	}
      }
      max_n = std::max(n_dark, n_bright);

      if (max_n < n_)
	return 0;
      else
	return max(sum_bright, sum_dark);

    }
  __host__ __device__ void benchmark_matcher_kernel(thread_info<target> ti,
                                                  i_short2* particles_vec,
                                                  unsigned n_particles,
                                                  F f,
                                                  kernel_image2d<T> particles,
                                                  kernel_image2d<T> new_particles,
                                                  kernel_image2d<i_short2> matches,
                                                  kernel_image2d<typename F::feature_t> states,
                                                  const kernel_image2d<i_short2> ls_matches,
                                                  i_short2 mvt,
                                                  T* compact_particles
                                                  ,kernel_image2d<i_float4> dist
                                                  )
  {
    unsigned threadid = ti.blockIdx.x * ti.blockDim.x + ti.threadIdx.x;
    if (threadid >= n_particles) return;
    point2d<int> p = particles_vec[threadid];

    if (!particles.has(p))
      return;

    matches(p) = i_short2(-1, -1);

    if (p.row() < 6 || p.row() >= particles.domain().nrows() - 6 ||
        p.col() < 6 || p.col() >= particles.domain().ncols() - 6)
    {
      new_particles(p).age = 0;
      return;
    }

    if (particles(p).age == 0)
      return;

    // Search for the best match in the neighborhood.
    short p_age = particles(p).age;
    float p_pertinence = particles(p).pertinence;
    typename F::feature_t p_state = states(p);

    point2d<int> match = p;

    bool ls_p_found = false;

    float match_distance;
    point2d<int> prediction = i_int2(p);
    if (p_age == 1)
    {
      point2d<int> lsp(p.row() / 2, p.col() / 2);
      point2d<int> ls_pred;
      {for_all_in_static_neighb2d(lsp, n, c25)
        {
          if (ls_matches(n).x != -1)
          {
            ls_pred = point2d<int>(ls_matches(n).x * 2,
                                   ls_matches(n).y * 2);
            ls_p_found = true;
          }
        }
      }

      match = p;

      match_distance = f.distance_linear(p_state, p);
    }
 void neighb_iterator2d<N>::start()
 {
   i_ = 0;
   p_ = i_int2(cur_) + i_int2(n_[i_]);
   i_++;
 }
 void neighb_iterator2d<N>::next()
 {
     p_ = i_int2(cur_) + i_int2(n_[i_]);
     i_++;
 }
Exemple #12
0
    inline __host__ __device__
    gl8u compute_saliency(i_short2 p, I& input_, int n_, int fast_th_, const A&)
    {
      unsigned max_n = 0;
      unsigned n = 0;
      int status = 2;
      gl8u vp = input_(p);
      unsigned sum_bright = 0;
      unsigned sum_dark = 0;

      // if (n_ == 15)
      // {
      // 	int to_test[3] = {0, 4, 12, 0};
      // 	for (int i = 0; i < 3; i++)
      // 	{
      // 		gl8u vn = input_(p + i_int2(arch_neighb2d<A>::get(circle_r3_h, circle_r3, to_test[i])));
      // 		int sign = int(vn) > int(vp);
      // 		unsigned char dist = ::abs(int(vn) - int(vp));

      // 		if (dist > fast_th_)
      // 			if (sign == status) n++;
      // 			else
      // 			{
      // 				if (n > max_n)
      // 					max_n = n;
      // 				status = sign;
      // 				n = 1;
      // 			}
      // 		else
      // 		{
      // 			if (n > max_n)
      // 				max_n = n;
      // 			status = 2;
      // 		}
      // 	}
      // 	if (n < 3) return 0;
      // }

      if (n_ >= 9)
      {
      	int to_test[6] = {0, 4, 8, 12, 0, 4};
      	int equals = 0;
      	for (int i = 0; i < 6; i++)
      	{
      	  gl8u vn = input_(p + i_int2(arch_neighb2d<A>::get(circle_r3_h, circle_r3, to_test[i])));
      	  int sign = int(vn) > int(vp);
      	  unsigned char dist = ::abs(int(vn) - int(vp));

      	  if (dist > fast_th_)
      	    if (sign == status) { n++; }
      	    else
      	    {
      	      if (n > max_n)
      		max_n = n;
      	      status = sign;
      	      n = 1;
      	    }
      	  else
      	  {
      	    if (n > max_n)
      	      max_n = n;
      	    status = 2;
      	    equals++;
      	    if (i < 4 && n_ >= 12 && equals >= 2) return 0;
      	  }
      	}
      	if (n > max_n)
      	  max_n = n;
      	if (n_ >= 12 && max_n < 3) return 0;
      	else if (n_ >= 8 && max_n < 2) return 0;
      }

      n = 0;
      status = 2;
      max_n = 0;
      for (int i = 0; i < 16; i++)
      {
	gl8u vn = input_(p + i_int2(arch_neighb2d<A>::get(circle_r3_h, circle_r3, i)));
	int sign = int(vn) > int(vp);
	unsigned char dist = ::abs(int(vn) - int(vp));
	if (dist > fast_th_)
	{
	  if (sign == status) n++;
	  else
	  {
	    if (n > max_n)
	      max_n = n;
	    status = sign;
	    n = 1;
	  }

	  if (vn < vp)
	    sum_dark += dist;
	  else
	    sum_bright += dist;
	}
	else
	{
	  if (n > max_n)
	    max_n = n;
	  status = 2;
	}
      }

      if (n != 16 && status != 2)
      {
	int i = 0;
	while (true)
	{
	  gl8u vn = input_(p + i_int2(arch_neighb2d<A>::get(circle_r3_h, circle_r3, i)));
	  int sign = int(vn) > int(vp);
	  unsigned char dist = ::abs(int(vn) - int(vp));

	  if (dist <= fast_th_ || sign != status) break;

	  n++;
	  i++;
	  assert(i < 16);
	}

      }

      if (n > max_n)
	max_n = n;

      if (max_n < n_)
	return 0;
      else
	return max(sum_bright, sum_dark);
	// return sum_bright;
    }
inline __host__ __device__
std::pair<i_short2, float> gradient_descent_match(i_short2 prediction_, F f, FI& feature_img, unsigned scale = 1)
{
    typedef std::pair<i_short2, float> ret;
    i_short2 prediction = prediction_;
    typedef typename FI::architecture A;
    i_short2 match = prediction;
    float match_distance = feature_img.distance(f, prediction);
    unsigned match_i = 8;
    box2d domain = feature_img.domain() - border(0);

    if (!domain.has(prediction))
    {
        return ret(prediction, 999999.f);
    }

    assert(domain.has(prediction));
    for (int search = 0; search < 10; search++)
    {
        int i = arch_neighb2d<A>::get(c8_it_h, c8_it, match_i)[0];
        int end = arch_neighb2d<A>::get(c8_it_h, c8_it, match_i)[1];
        {
            i_int2 n(prediction + i_int2(arch_neighb2d<A>::get(c8_h, c8, i)));
            if (feature_img.domain().has(n))
            {
                float d = feature_img.distance(f, n, scale);
                if (d < match_distance)
                {
                    match = n;
                    match_i = i;
                    match_distance = d;
                }
            }
            i = (i + 1) & 7;
        }



#pragma unroll 4
        for(; i != end; i = (i + 1) & 7)
        {
            i_int2 n(prediction + i_int2(arch_neighb2d<A>::get(c8_h, c8, i)));
            if (feature_img.domain().has(n))
            {
                float d = feature_img.distance(f, n, scale);
                if (d < match_distance)
                {
                    match = n;
                    match_i = i;
                    match_distance = d;
                }
            }
        }

        if (i_int2(prediction) == i_int2(match) || !domain.has(match))
            break;
        else
            prediction = match;

    }

    // if (scale == 2)
    //   match = prediction + 2 * (match - prediction);
    // match_distance = feature_img.distance(f, match, scale);

    return ret(match, match_distance);
}