Пример #1
0
void EdgeRoberts::prepareMatrices()
{
    g_x = math::matrix<double>(3,3);
    g_y = math::matrix<double>(3,3);

    g_x(0,0) = 1;
    g_x(0,1) = 0;
    g_x(1,0) = 0;
    g_x(1,1) = -1;

    g_y(0,0) = 0;
    g_y(0,1) = 1;
    g_y(1,0) = -1;
    g_y(1,1) = 0;
}
void EdgeSobel::prepareMatrices()
{
	g_x = math::matrix<double>(3,3);
	g_x(0,0)=-1;
	g_x(0,1)=0;
	g_x(0,2)=1;
	g_x(1,0)=-2;
	g_x(1,1)=0;
	g_x(1,2)=2;
	g_x(2,0)=-1;
	g_x(2,1)=0;
	g_x(2,2)=1;

	g_y = math::matrix<double>(3,3);
	g_y(0,0)=-1;
	g_y(0,1)=-2;
	g_y(0,2)=-1;
	g_y(1,0)=0;
	g_y(1,1)=0;
	g_y(1,2)=0;
	g_y(2,0)=1;
	g_y(2,1)=2;
	g_y(2,2)=1;
}
Пример #3
0
int main(int argc, char *argv[])
{
  if (argc != 4)
  {
    cout << "Usage: " << argv[0] << " cpu|gpu out_func out_prefix" << endl;
    return 1;
  }

  ImageParam input(UInt(8), 3, "input");
  Func clamped("clamped"), grayscale("grayscale");
  Func g_x("g_x"), g_y("g_y"), g_mag("g_mag");
  Func sobel("sobel");
  Var c("c"), x("x"), y("y");

  // Algorithm
  clamped(x, y, c) = input(
    clamp(x, 0, input.width()-1),
    clamp(y, 0, input.height()-1),
    c) / 255.f;
  grayscale(x, y) =
    clamped(x, y, 0)*0.299f +
    clamped(x, y, 1)*0.587f +
    clamped(x, y, 2)*0.114f;

  Image<int16_t> kernel(3, 3);
  kernel(0, 0) = -1;
  kernel(0, 1) = -2;
  kernel(0, 2) = -1;
  kernel(1, 0) = 0;
  kernel(1, 1) = 0;
  kernel(1, 2) = 0;
  kernel(2, 0) = 1;
  kernel(2, 1) = 2;
  kernel(2, 2) = 1;

  RDom r(kernel);
  g_x(x, y) += kernel(r.x, r.y) * grayscale(x + r.x - 1, y + r.y - 1);
  g_y(x, y) += kernel(r.y, r.x) * grayscale(x + r.x - 1, y + r.y - 1);
  g_mag(x, y) = sqrt(g_x(x, y)*g_x(x, y) + g_y(x, y)*g_y(x, y));
  sobel(x, y, c) = select(c==3, 255, u8(clamp(g_mag(x, y), 0, 1)*255));

  // Channel order
  input.set_stride(0, 4);
  input.set_extent(2, 4);
  sobel.reorder_storage(c, x, y);
  sobel.output_buffer().set_stride(0, 4);
  sobel.output_buffer().set_extent(2, 4);

  // Schedules
  if (!strcmp(argv[1], "cpu"))
  {
    sobel.parallel(y).vectorize(c, 4);
  }
  else if (!strcmp(argv[1], "gpu"))
  {
    sobel.cuda_tile(x, y, 16, 4);
  }
  else
  {
    cout << "Invalid schedule type '" << argv[1] << "'" << endl;
    return 1;
  }

  compile(sobel, input, argv[2], argv[3]);

  return 0;
}
Пример #4
0
template <typename PointInT, typename IntensityT> void
pcl::tracking::PyramidalKLTTracker<PointInT, IntensityT>::computePyramids (const PointCloudInConstPtr& input,
                                                                    std::vector<FloatImageConstPtr>& pyramid,
                                                                    pcl::InterpolationType border_type) const
{
  int step = 3;
  pyramid.resize (step * nb_levels_);

  FloatImageConstPtr previous;
  FloatImagePtr tmp (new FloatImage (input->width, input->height));
#ifdef _OPENMP
#pragma omp parallel for num_threads (threads_)
#endif
  for (int i = 0; i < static_cast<int> (input->size ()); ++i)
    tmp->points[i] = intensity_ (input->points[i]);
  previous = tmp;

  FloatImagePtr img (new FloatImage (previous->width + 2*track_width_,
                                     previous->height + 2*track_height_));

  pcl::copyPointCloud (*tmp, *img, track_height_, track_height_, track_width_, track_width_,
                       border_type, 0.f);
  pyramid[0] = img;

  // compute first level gradients
  FloatImagePtr g_x (new FloatImage (input->width, input->height));
  FloatImagePtr g_y (new FloatImage (input->width, input->height));
  derivatives (*img, *g_x, *g_y);
  // copy to bigger clouds
  FloatImagePtr grad_x (new FloatImage (previous->width + 2*track_width_,
                                        previous->height + 2*track_height_));
  pcl::copyPointCloud (*g_x, *grad_x, track_height_, track_height_, track_width_, track_width_,
                       pcl::BORDER_CONSTANT, 0.f);
  pyramid[1] = grad_x;

  FloatImagePtr grad_y (new FloatImage (previous->width + 2*track_width_,
                                        previous->height + 2*track_height_));
  pcl::copyPointCloud (*g_y, *grad_y, track_height_, track_height_, track_width_, track_width_,
                       pcl::BORDER_CONSTANT, 0.f);
  pyramid[2] = grad_y;

  for (int level = 1; level < nb_levels_; ++level)
  {
    // compute current level and current level gradients
    FloatImageConstPtr current;
    FloatImageConstPtr g_x;
    FloatImageConstPtr g_y;
    downsample (previous, current, g_x, g_y);
    // copy to bigger clouds
    FloatImagePtr image (new FloatImage (current->width + 2*track_width_,
                                         current->height + 2*track_height_));
    pcl::copyPointCloud (*current, *image, track_height_, track_height_, track_width_, track_width_,
                         border_type, 0.f);
    pyramid[level*step] = image;
    FloatImagePtr gradx (new FloatImage (g_x->width + 2*track_width_, g_x->height + 2*track_height_));
    pcl::copyPointCloud (*g_x, *gradx, track_height_, track_height_, track_width_, track_width_,
                         pcl::BORDER_CONSTANT, 0.f);
    pyramid[level*step + 1] = gradx;
    FloatImagePtr grady (new FloatImage (g_y->width + 2*track_width_, g_y->height + 2*track_height_));
    pcl::copyPointCloud (*g_y, *grady, track_height_, track_height_, track_width_, track_width_,
                         pcl::BORDER_CONSTANT, 0.f);
    pyramid[level*step + 2] = grady;
    // set the new level
    previous = current;
  }
}
Пример #5
0
// Funktion berechnet, ob ein Feuersystem aufgrund der Position des Schiffes, der Position des Systems auf dem Schiff und
// dessen Feuerwinkel auch feuern kann.
// @param arc Zeiger auf Schussfeld
// @return Wahrheitswert
bool CCombatShip::AllowFire(const CFireArc* arc)
{
	if (m_pShip->IsStation())
		return true;
	/*
	Ich fasse nochmal zusammen was benötigt wird und was mittels Variablen festgehalten werden müsste:

	- Ausrichtung des Schiffes (kann schnell berechnet werden)
	- Feuerwinkel jeder einzelnen Waffe (müsste noch als Attribut hinzugefügt werden -> Änderung des ShipEditors und der data Datei,
	  horizontaler == vertikaler Winkel?)
	- Position des gegnerischen Schiffes (ist vorhanden)
	-> aus diesen Variablen muss ein boolescher Wert berechnet werden, ob ein Feuern gestattet ist
	*/
	int dirarc_V = arc->GetPosition();
	int firearc_V = arc->GetAngle();
	bool allow = false;
    //int m=2; //"Regelkonstante"

	vec3<float> v;
	// Besitzt das Schiff eine Flugroute, so ist dessen Ausrichtung der Vektor zwischen aktueller Position und dem
	// nächsten Punkt auf der Flugroute
	if (!m_lRoute.empty())
	{
		vec3i p = m_lRoute[0] - m_KO;
		v.Set((float)p.x, (float)p.y, (float)p.z);
		v /= v.Length();
	}
	// Ohne Flugziel richtet sich das Schiff automatisch zum Zentrum aus P(0,0,0)
	else
	{
		v.Set((float)-m_KO.x, (float)-m_KO.y, (float)-m_KO.z);
		v /= v.Length();
	}

	// Vektor zwischen Schiff und Ziel
	vec3<float> diff;
	if (m_pTarget != 0)
	{
		vec3i p = m_pTarget->m_KO - m_KO;
		diff.Set((float)p.x, (float)p.y, (float)p.z);
		diff /= diff.Length();
	}

	int diffarc = 0;
	// new_z =(v)x(diff)=(v2*diff3 - v3*diff2, v3*diff1 - v1*diff3, v1*diff2 - v2*diff1);
	vec3<float> new_z = v / diff; // Kreuzprodukt geht auch mit v ^ diff und ^-Operator
	// If (new_z=0)    #Der Nullvektor, d.h. v=k*diff (k wäre ein Skalar)
	if (new_z.IsNull())
	{
	  // If Skalar(v,diff)>=0 then diffarc=0 else diffarc=180; #ginge auch über norm(diff+v)>norm(diff)
	  if (v * diff >= 0)
		diffarc = 0;
	  else
		diffarc = 180;
	}
	else
	{
		//Regeln für Verhindern der positiven Achsenausrichtung und damit immer gleiche Seite beim Feuern
		vec3<float> g_x;
		vec3<float> g_z;
		vec3<float> g_y(diff / diff.Length()); //unser g_y bleibt immer gleich, man hätte auch g_y verändern können, ich hab mich für g_x entschieden
		vec3<float> gYTemp((v * g_y) * g_y); //damit bleibt auch gYTemp immer gleich

		/*if (firepower_centroid > m)
		{
			g_x = ((gYTemp - v) / (gYTemp - v).Length());
			g_z = ((-new_z) / new_z.Length());
		}
		else if (firepower_centroid < m)
		{
			g_x = ((v - gYTemp) / (v - gYTemp).Length());
			g_z((new_z) new_z.Length());
		}
		else*/
		if (diff.y < 0)
		{
			if (diff * v < 0)
			{
				g_x = ((gYTemp - v) / (gYTemp - v).Length());
				g_z = ((-new_z) / new_z.Length());
			}
			else
			{
				g_x = ((v - gYTemp) / (v - gYTemp).Length());
				g_z = (new_z / new_z.Length());
			}
		}
		else if (diff.y > 0)
		{
			if (diff * v < 0)
			{
				g_x = ((v - gYTemp) / (v - gYTemp).Length());
				g_z = (new_z / new_z.Length());
			}
			else
			{
				g_x = ((gYTemp - v) / (gYTemp - v).Length());
				g_z = ((-new_z) / new_z.Length());
			}
		}
		else if (diff.x < 0)
		{
			 if (diff * v < 0)
			 {
				 g_x = ((gYTemp - v) / (gYTemp - v).Length());
				 g_z = ((-new_z) / new_z.Length());
			 }
			 else
			 {
				 g_x = ((v - gYTemp) / (v - gYTemp).Length());
				 g_z = (new_z / new_z.Length());
			 }
		}
		else if (diff.x > 0)
		{
			 if (diff * v < 0)
			 {
				 g_x = ((v - gYTemp) / (v - gYTemp).Length());
				 g_z = (new_z / new_z.Length());
			 }
			 else
			 {
				 g_x = ((gYTemp - v) / (gYTemp - v).Length());
				 g_z = ((-new_z) / new_z.Length());
			 }
		}
		else if (diff.z < 0)
		{
			 if (diff * v < 0)
			 {
				 g_x = ((gYTemp - v) / (gYTemp -v).Length());
				 g_z = ((-new_z) / new_z.Length());
			 }
			 else
			 {
				 g_x = ((v - gYTemp) / (v - gYTemp).Length());
				 g_z = (new_z / new_z.Length());
			 }
		}
		else if (diff.z > 0)
		{
			 if (diff * v < 0)
			 {
				 g_x = ((v - gYTemp) / (v - gYTemp).Length());
				 g_z = (new_z / new_z.Length());
			 }
			 else
			 {
				 g_x = ((gYTemp - v) / (gYTemp - v).Length());
				 g_z = ((-new_z) / new_z.Length());
			 }
		}
		else
		{
			g_x = ((v - gYTemp) / (v - gYTemp).Length());
			g_z = ((new_z) / new_z.Length());
		}

		// v=Matrixprodukt((a1,a2,a3;b1,b2,b3;c1,c2,c3),(v1,v2,v3))
		vec3<float> V(g_x.x * v.x + g_x.y * v.y + g_x.z * v.z, g_y.x * v.x + g_y.y * v.y + g_y.z * v.z, g_z.x * v.x + g_z.y * v.y + g_z.z * v.z);
		// diff=Matrixprodukt((a1,a2,a3;b1,b2,b3;c1,c2,c3),(diff1,diff2,diff3))
		vec3<float> DIFF(g_x.x * diff.x + g_x.y * diff.y + g_x.z * diff.z, g_y.x * diff.x + g_y.y * diff.y + g_y.z * diff.z, g_z.x * diff.x + g_z.y * diff.y + g_z.z * diff.z);

		// diffv_arcdiff=(Skalarprodukt(diff_new,v_new),diff_new2*v_new1 - diff_new1*v_new2) #als komplex-konjugiert-multiplizierte komplexe Zahl und die wiederum als 2D-Vektor dargestellt. Der Fall    dass diffv_arcdiff1 und diffv_arcdiff2 0 sind, also der gesamte Vektor der Nullvektor darstellt, kann nicht auftreten, den haben wir mit der If-Abfrage oben schon rausgenommen.
		vec3<float> diffv_arcdiff(DIFF * V / V.Length(), DIFF.y * V.x / V.Length(), 0); //DIFF.x = 0 ! d.h. es steht eigentlich nur DIFF.y*V.X und das ist 1*1=1
		// diffarc_bogenmaß=arg(z)={arctan(y/x) für x<0, Pi/2 für x=0 und y>0, Pi + arctan(y/x) für x>0, 3/2 Pi für x=0, y<0} oder auch diffarc_bogenmaß=arg(z)={arccos(a/r) für y>=0, 2pi - arccos(a/r) für y<0}
		float diffarc_bogenmass;
		if (diffv_arcdiff.y < 0) //zweite Komponente kleiner 0, d.h. Vektor in unterer Halbebene und damit das Feindschiff links vom eigenen Schiff aus gesehen
			diffarc_bogenmass = (float)PI * 2 - acos((float)diffv_arcdiff.x / (float)diffv_arcdiff.Length());
		else
			diffarc_bogenmass = acos((float)diffv_arcdiff.x / (float)diffv_arcdiff.Length());
		//diffarc=diffarc_bogenmaß*180/Pi
		diffarc = (int)(diffarc_bogenmass * 180 / (float)PI);
	}

	if ( (dirarc_V - firearc_V/2 < diffarc - 360) || ((dirarc_V - firearc_V/2 < diffarc) && (diffarc < dirarc_V + firearc_V/2))
	  || (diffarc + 360 < dirarc_V + firearc_V/2) )
	  allow = true;

	return allow;
}