Ejemplo n.º 1
0
void displayResult(CImgDisplay display, CImg<unsigned char> map_image, Solution solution)
{
	double hue = 0.0;
	unsigned char color [3] = {0,0,0};
	hue_to_rgb(hue, color);
	
	CImg<unsigned char> allMoves = map_image;

	for (int i = 0; i < solution.num_routes; i++)
	{
		Point from, to;
		for (int city = 0; city < solution.routes[i].num_cities - 1; city++)
		{
			from = solution.routes[i].cities[city].location;
			to = solution.routes[i].cities[city+1].location;

			allMoves.draw_line(from.x,from.y,to.x,to.y,color,1.0);			
		}

		hue += (1.0/(double)solution.num_routes);
		hue_to_rgb(hue, color);

	}

	display.display(allMoves);
	
	while(!display.is_closed())display.wait();
}
Ejemplo n.º 2
0
void PlotData(const char *title, const char *xaxis, const char *yaxis,
	double xmin, double xmax, std::vector<double> &values)
{
	CImg<double> y(values.data(), values.size());

	const unsigned int plot_type = 1;
	const unsigned int vertex_type = 0;

	if (y.is_empty()) return;

	CImgDisplay disp;
	disp.assign(cimg_fitscreen(640,480,1),0,0).set_title(title);
	show_graph(disp, y, plot_type, vertex_type, xaxis, xmin, xmax, yaxis);
}
Ejemplo n.º 3
0
void Scope2(const char *title, std::vector<double> &values)
{
	CImg<double> y(values.data(), values.size());

	float x0 =    0.0f;
	float x1 =  1.25f * values.size();
	const unsigned int plot_type = 1;
	const unsigned int vertex_type = 0;

	if (y.is_empty()) return;

	CImgDisplay disp;
	disp.assign(cimg_fitscreen(640,480,1),0,0).set_title(title);
	show_graph(disp, y, plot_type, vertex_type, "t / ns", x0, x1, "adc units");

//	y.display_graph(title ,plot_type, vertex_type, "t / ns", x0,x1, "adc units");
}
Ejemplo n.º 4
0
void displayResultAnimated(CImgDisplay display, CImg<unsigned char> thisRoute, Solution solution)
{
	double hue = 0.0;
	unsigned char color [3] = {0,0,0};
	unsigned char green [3] = {0,255,0};
	unsigned char red [3] = {255,0,0};
	hue_to_rgb(hue, color);

	CImg<unsigned char> cleanMap = thisRoute;
	CImg<unsigned char> allMoves = thisRoute;

	for (int i = 0; i < solution.num_routes; i++)
	{
		Point from, to;
		for (int city = 0; city < solution.routes[i].num_cities - 1; city++)
		{
			from = solution.routes[i].cities[city].location;
			to = solution.routes[i].cities[city+1].location;

			CImg<unsigned char> thisMove = thisRoute;
			thisRoute.draw_line(from.x,from.y,to.x,to.y,color,1.0);
			allMoves.draw_line(from.x,from.y,to.x,to.y,color,1.0);			
			thisMove.draw_arrow(from.x,from.y,to.x,to.y,red,1.0);


			display.display(thisMove);
			Sleep(10);
		}

		display.display(thisRoute);
		thisRoute = cleanMap;

		Sleep(250);

		hue += (1.0/(double)solution.num_routes);
		hue_to_rgb(hue, color);
	}

	display.display(allMoves);
	//all.display(display);
	while(!display.is_closed())display.wait();
}
Ejemplo n.º 5
0
int main( int argc, char** argv )
{
	CImg<unsigned char> img;
	CImgDisplay disp;
	int skip_frames = 0;
	bool release_video = false;
	std::string filename;

	if(argc < 2) {
		std::cerr << "One argument must be provided\n";
		exit(0);
	}
	filename = argv[1];

	std::cout << "Press Key to exit.\n";
	for (int k = 0; 1 ; k++){
		//Get next frame from video
		img.load_video( filename, skip_frames, release_video);
		if ( img.is_empty() ) {
			if (k == 0) {//Video not found
				std::cerr << "Could not read from video " << filename << "\n";
				exit(0);
			}
			else
				break; //End of video
		}

		disp.display(img).set_title("CImg-camera: %d", k);
		if ( disp.is_key() )
			break;
	}

	//Release video
	release_video = true;
	img.load_video( filename, skip_frames, release_video);
	return 0;
}
Ejemplo n.º 6
0
void show_graph2(CImgDisplay &disp, CImg<double> &data,
	const unsigned int plot_type, const unsigned int vertex_type,
	const char *const labelx, const double xmin, const double xmax,
	const char *const labely, const double ymin, const double ymax)
{
	if (data.is_empty()) return;

	if (!disp) disp.assign(cimg_fitscreen(640,480,1),0,0).set_title("CImg<%s>", data.pixel_type());

	const unsigned long siz = (unsigned long)data._width*data._height*data._depth, siz1 = cimg::max(1U,siz-1);
	disp.normalization();

	disp.show().flush()._normalization = 0;

	double y0 = ymin, y1 = ymax, nxmin = xmin, nxmax = xmax;
	if (nxmin==nxmax) { nxmin = 0; nxmax = siz1; }
	int x0 = 0, x1 = data.width()*data.height()*data.depth() - 1;




	x0 = 0; x1 = data.width()*data.height()*data.depth()-1; y0 = ymin; y1 = ymax;

	CImg<double> zoom(x1-x0+1,1,1,data.spectrum());
	cimg_forC(data,c) zoom.get_shared_channel(c) = CImg<double>(data.data(x0,0,0,c),x1-x0+1,1,1,1,true);

	if (y0==y1) { y0 = zoom.min_max(y1); const double dy = y1 - y0; y0-=dy/20; y1+=dy/20; }
	if (y0==y1) { --y0; ++y1; }
	const CImg<int> selection = zoom.get_select_graph(disp,plot_type,vertex_type,
                                                       labelx,
                                                       nxmin + x0*(nxmax-nxmin)/siz1,
                                                       nxmin + x1*(nxmax-nxmin)/siz1,
                                                       labely,y0,y1);

	while (!disp.key() && !disp.is_closed())
	{
	    disp.wait();
	}

}
Ejemplo n.º 7
0
int main() {

    const std::string folder_name = "35mm_focallength/scene_forwards/slow/left/";

    std::string im_path("/home/vertensj/Training_data/Blender/object_index/" + folder_name);
    //std::string im_rendered_path("/home/vertensj/Training_data/Blender/frames_finalpass/" + folder_name); // Finalpass
    std::string im_rendered_path("/home/vertensj/Training_data/Blender/frames_cleanpass/" + folder_name); // Cleanpass

    std::set<size_t> car_set (cars, cars+32);
    std::set<size_t> moving_car_set (moving_cars, moving_cars+8);

    // load object index images
    std::vector<std::string> object_file_list;
    listImagesInDir(im_path, object_file_list);
    std::sort (object_file_list.begin(), object_file_list.end());

    // load rendered images
    std::vector<std::string> rendered_file_list;
    listImagesInDir(im_rendered_path, rendered_file_list);
    std::sort (rendered_file_list.begin(), rendered_file_list.end());

    std::cout << "Object index size: " << object_file_list.size() << " rendered size: " << rendered_file_list.size() << std::endl;
    assert(object_file_list.size() == rendered_file_list.size());

    for(auto i = 0; i < object_file_list.size(); i++){
        std::cout << "File name nr: " << i << " is: " << object_file_list.at(i) << std::endl;
    }

    const char *const keycode_next = "ARROWRIGHT";
    const char *const keycode_esc = "ESC";
    const char *const keycode_enter = "ENTER";

#ifdef SHOW
    CImgDisplay disp;
    disp.show_mouse();
    for(auto i = 0; i < object_file_list.size(); i++){
        std::cout << "Displaying image nr: " << i << std::endl;
        // get object index image
        CImg<unsigned int> object_image(object_file_list.at(i).c_str());
        // filter image for cars
        //filterImageForIndex<unsigned int>(object_image, car_set);  // all cars
        filterImageForIndex<unsigned int>(object_image, moving_car_set);  // moving cars

        // get rendered image
        CImg<unsigned int> rendered_image(rendered_file_list.at(i).c_str());

        // create image list
        CImgList<unsigned char> list;
        list.push_back<unsigned char>(object_image);
        list.push_back<unsigned char>(rendered_image);

        // show object index image and rendered image
        disp.display(list, 'y');
        while (!disp.is_closed()) {

            if(disp.button()&1){
                int x = disp.mouse_x();
                int y = disp.mouse_y();
                const unsigned int index = object_image(x,y);
                std::cout << "Current index: " << std::to_string(index) << std::endl;
                disp.wait(100);
            }

            if (disp.is_key(keycode_next)) {
                break;
            }
            if(disp.is_key(keycode_esc)) return 0;

        }
        disp.wait(50);
    }

#endif

#ifdef SAVE

    const std::string save_folder = "/home/vertensj/Training_data/Blender/filtered_images/"  + folder_name;

    boost::filesystem::path dir(save_folder);
    if(boost::filesystem::create_directories(dir)) {
        std::cout << "Created save folder" << "\n";
    }

    for(auto i = 0; i < object_file_list.size(); i++){
        std::cout << "Saving image nr: " << i << " of " << object_file_list.size() <<  std::endl;
        CImg<unsigned int> object_image(object_file_list.at(i).c_str());
        // filter image for cars
        //filterImageForIndex<unsigned int>(object_image, car_set);  // all cars
        filterImageForIndex<unsigned int>(object_image, moving_car_set);  // moving cars
        object_image.save((save_folder + "img" + std::to_string(i) +".bmp").c_str());
    }

#endif

    return 0;
}
Ejemplo n.º 8
0
int main(int argc, char *argv[]) {

  if ( !argv[1] ){
    cerr<<"ERROR: No se ha especificado un archivo imagen.\n";
    cout<<argv[0]<<": Aplica efecto 'emboss' sobre la imagen.\n";
    cout<<"uso: "<<argv[0]<<" <archivo_imagen>"<<endl;
    return 1;
  }

  CImg<float> original( argv[1] );
  CImg<float> mod( original );
  CImgDisplay disp;

  short x=0, y=0;
  bool invertir = false;
  mod.display(disp);

  while (! disp.is_closed() ) {
    disp.wait();
    if ( disp.is_keyARROWUP() ) { y +=1; disp.flush(); }
    if ( disp.is_keyARROWDOWN() ) { y -=1; disp.flush(); }
    if ( disp.is_keyARROWLEFT() ) { x -=1; disp.flush(); }
    if ( disp.is_keyARROWRIGHT() ) { x +=1; disp.flush(); }
    if ( disp.is_keyI() ) { invertir = !invertir; disp.flush(); }

    mod = emboss( original, x, y, invertir);
    disp.resize(mod);
    mod.display( disp );

  }

  return 0;
}
Ejemplo n.º 9
0
int main( int argc, char** argv )
{
	unsigned char yellow[] = { 255, 255, 0};
	unsigned char white[] = { 255, 255, 255};
	unsigned char black[] = { 0, 0, 0};

	float opacity = 1.0;
	unsigned int pattern = ~0L; //32 bits are equal to 1

	float fraction_size = 1/4.0;
	float sigma = 3.0;

	CImgDisplay cdisplay;
	CImgDisplay viewfinder_display;

	if( argc < 2 )
	{
		std::cout << "No video filename given \n" ;
		return -1;
	}

	VideoCapture capture( argv[1] );
	if( !capture.isOpened() )
	{
		std::cerr << "Could not open video file:  " << argv[1] << "\n";
		exit(0);
	}
	Mat cv_image;

	CImg<unsigned char> best_focus_img;
	float Emax = -1.0;
	int kmax = -1;
	char txt[100];

	std::vector <float> energies;
	int k = 0;
	clock_t totalTicks = 0;
	while( capture.read(cv_image) ) {

		CImg<unsigned char> input(cv_image);
		CImg<unsigned char> output;
		int xmin = (0.5 - fraction_size / 2.0) * input.width();
		int xmax = (0.5 + fraction_size / 2.0) * input.width();
		int ymin = (0.5 - fraction_size / 2.0) * input.height();
		int ymax = (0.5 + fraction_size / 2.0) * input.height();

		CImg<unsigned char> viewer_image = input.get_resize_halfXY().resize_halfXY();

		//This is the function that you have to implement in linfilters.cpp
		clock_t t0 = clock();
		float E = highFrequencyEnergy(input, sigma, xmin, xmax, ymin, ymax);
		clock_t t1 = clock();
		totalTicks += (t1-t0);
		energies.push_back(E);

		//Draw rectangle on input image
		input.draw_rectangle (xmin, ymin, xmax, ymax, yellow, opacity, pattern);
		if( E > Emax ) {
			Emax = E;
			best_focus_img = input;
			kmax = k;
		}
		//Draw Energy text
		sprintf( txt, "%.2f", E);
		input.draw_text(xmin, ymax, txt, black, white);

		//Displays
		cdisplay.display(input).set_title("Focus Meter");
		viewfinder_display.display( viewer_image).set_title("ViewFinder");
		k++;
	}

	float totalTime = totalTicks;
	totalTime /= CLOCKS_PER_SEC;
	totalTime /= k;

	std::cout << "Average Time per image: " << totalTime << "\n";


	//Save Energies of every frame into file
	CImg<float> cimg_energies( energies.size() );

	for (int k=0; k < energies.size(); k++){
		cimg_energies[k] = energies[k];
	}
	cimg_energies.save_dlm("energies.dlm");
	std::cout << "energies.dlm saved. Open in MATLAB\n";


	//Display best focus image
	sprintf( txt, "Best focus at frame %d", kmax);
	best_focus_img.display(txt,false);


	return 0;
}
Ejemplo n.º 10
0
void show_graph(CImgDisplay &disp, CImg<double> &data,
	const unsigned int plot_type, const unsigned int vertex_type,
	const char *const labelx, const double xmin, const double xmax,
	const char *const labely, const double ymin, const double ymax)
{
  if (data.is_empty()) return;

  if (!disp) disp.assign(cimg_fitscreen(640,480,1),0,0).set_title("CImg<%s>", data.pixel_type());

  const unsigned long siz = (unsigned long)data._width*data._height*data._depth, siz1 = cimg::max(1U,siz-1);
  const unsigned int old_normalization = disp.normalization();

  disp.show().flush()._normalization = 0;

  double y0 = ymin, y1 = ymax, nxmin = xmin, nxmax = xmax;
  if (nxmin==nxmax) { nxmin = 0; nxmax = siz1; }
  int x0 = 0, x1 = data.width()*data.height()*data.depth() - 1, key = 0;

  for (bool reset_view = true, resize_disp = false; !key && !disp.is_closed(); )
  {
    if (reset_view) { x0 = 0; x1 = data.width()*data.height()*data.depth()-1; y0 = ymin; y1 = ymax; reset_view = false; }

    CImg<double> zoom(x1-x0+1,1,1,data.spectrum());
    cimg_forC(data,c) zoom.get_shared_channel(c) = CImg<double>(data.data(x0,0,0,c),x1-x0+1,1,1,1,true);

    if (y0==y1) { y0 = zoom.min_max(y1); const double dy = y1 - y0; y0-=dy/20; y1+=dy/20; }
    if (y0==y1) { --y0; ++y1; }
    const CImg<int> selection = zoom.get_select_graph(disp,plot_type,vertex_type,
                                                       labelx,
                                                       nxmin + x0*(nxmax-nxmin)/siz1,
                                                       nxmin + x1*(nxmax-nxmin)/siz1,
                                                       labely,y0,y1);

    const int mouse_x = disp.mouse_x(), mouse_y = disp.mouse_y();
    if (selection[0]>=0)
	{
      if (selection[2]<0) reset_view = true;
      else
	  {
        x1 = x0 + selection[2]; x0+=selection[0];
        if (selection[1]>=0 && selection[3]>=0)
		{
          y0 = y1 - selection[3]*(y1-y0)/(disp.height()-32);
          y1-=selection[1]*(y1-y0)/(disp.height()-32);
        }
      }
    }
	else
	{
      bool go_in = false, go_out = false, go_left = false, go_right = false, go_up = false, go_down = false;

      switch (key = disp.key())
	  {
      case cimg::keyHOME : reset_view = resize_disp = true; key = 0; disp.set_key(); break;
      case cimg::keyPADADD : go_in = true; go_out = false; key = 0; disp.set_key(); break;
      case cimg::keyPADSUB : go_out = true; go_in = false; key = 0; disp.set_key(); break;
      case cimg::keyARROWLEFT : case cimg::keyPAD4 : go_left = true; go_right = false; key = 0; disp.set_key(); break;
      case cimg::keyARROWRIGHT : case cimg::keyPAD6 : go_right = true; go_left = false; key = 0; disp.set_key(); break;
      case cimg::keyARROWUP : case cimg::keyPAD8 : go_up = true; go_down = false; key = 0; disp.set_key(); break;
      case cimg::keyARROWDOWN : case cimg::keyPAD2 : go_down = true; go_up = false; key = 0; disp.set_key(); break;
      case cimg::keyPAD7 : go_left = true; go_up = true; key = 0; disp.set_key(); break;
      case cimg::keyPAD9 : go_right = true; go_up = true; key = 0; disp.set_key(); break;
      case cimg::keyPAD1 : go_left = true; go_down = true; key = 0; disp.set_key(); break;
      case cimg::keyPAD3 : go_right = true; go_down = true; key = 0; disp.set_key(); break;
      }

	  if (disp.wheel())
	  {
        if (disp.is_keyCTRLLEFT() || disp.is_keyCTRLRIGHT()) go_out = !(go_in = disp.wheel()>0);
        else if (disp.is_keySHIFTLEFT() || disp.is_keySHIFTRIGHT()) go_left = !(go_right = disp.wheel()>0);
        else go_up = !(go_down = disp.wheel()<0);
        key = 0;
      }

      if (go_in)
	  {
        const int
          xsiz = x1 - x0,
          mx = (mouse_x-16)*xsiz/(disp.width()-32),
          cx = x0 + (mx<0?0:(mx>=xsiz?xsiz:mx));
        if (x1-x0>4)
		{
          x0 = cx - 7*(cx-x0)/8; x1 = cx + 7*(x1-cx)/8;
          if (disp.is_keyCTRLLEFT() || disp.is_keyCTRLRIGHT())
		  {
            const double
              ysiz = y1 - y0,
              my = (mouse_y-16)*ysiz/(disp.height()-32),
              cy = y1 - (my<0?0:(my>=ysiz?ysiz:my));
              y0 = cy - 7*(cy-y0)/8; y1 = cy + 7*(y1-cy)/8;
          } else y0 = y1 = 0;
        }
      }

	  if (go_out)
	  {
        if (x0>0 || x1<(int)siz1)
		{
          const int delta_x = (x1-x0)/8, ndelta_x = delta_x?delta_x:(siz>1?1:0);
          const double ndelta_y = (y1-y0)/8;
          x0-=ndelta_x; x1+=ndelta_x;
          y0-=ndelta_y; y1+=ndelta_y;
          if (x0<0) { x1-=x0; x0 = 0; if (x1>=(int)siz) x1 = (int)siz1; }
          if (x1>=(int)siz) { x0-=(x1-siz1); x1 = (int)siz1; if (x0<0) x0 = 0; }
        }
      }

	  if (go_left)
	  {
        const int delta = (x1-x0)/5, ndelta = delta?delta:1;
        if (x0-ndelta>=0) { x0-=ndelta; x1-=ndelta; }
        else { x1-=x0; x0 = 0; }
        go_left = false;
      }

	  if (go_right)
	  {
        const int delta = (x1-x0)/5, ndelta = delta?delta:1;
        if (x1+ndelta<(int)siz) { x0+=ndelta; x1+=ndelta; }
        else { x0+=(siz1-x1); x1 = siz1; }
        go_right = false;
      }

	  if (go_up)
	  {
        const double delta = (y1-y0)/10, ndelta = delta?delta:1;
        y0+=ndelta; y1+=ndelta;
        go_up = false;
      }

      if (go_down)
	  {
        const double delta = (y1-y0)/10, ndelta = delta?delta:1;
        y0-=ndelta; y1-=ndelta;
        go_down = false;
      }
    }
  }
  disp._normalization = old_normalization;
}