Example #1
0
int main(int argc, char ** argv) {
	
	std::string path, 
				rgbFilename("RGB_%07d.ppm"), 
				depthFilename("depth_%07d.pfm"),
				timeFilename("TimeSampling.dat");

	if (argc>1){
		path = argv[1];
	}
	else {
		std::cerr << "ERROR Usage : " << argv[0] << " pathname" << std::endl;
		return -1;
	}
	
	try {
    	Freenect::Freenect freenect;
    
    	vpKinect & kinect = freenect.createDevice<vpKinect>(0);
    	// Start acquisition thread with a depth map resolution of 480x640
    	kinect.start(vpKinect::DMAP_MEDIUM_RES); 
    
    	vpImage<unsigned char> Idmap(480,640);//for medium resolution
    	vpImage<float> dmap(480,640);//for medium resolution
    	vpImage<vpRGBa> Irgb(480,640);
    	
		  vpDisplayX display, displayRgb;
		  display.init(Idmap, 100, 200,"Depth map");
		  displayRgb.init(Irgb, 900, 200,"Color Image");

      //init val
      int index(0);
      struct timeval now ;
      
      //open time file
      std::string timeFullPath = path + "/"+ timeFilename; 
      std::ofstream file(timeFullPath.c_str(), std::ios::out);
      int precision(15);
       
      // A click to stop acquisition
      std::cout << "Click in one image to stop acquisition" << std::endl;
      while(!vpDisplay::getClick(Idmap,false) && !vpDisplay::getClick(Irgb,false)){
        kinect.getDepthMap(dmap);
        kinect.getDepthMap(dmap, Idmap);
        kinect.getRGB(Irgb);
        
        // get the current time
        gettimeofday(&now,NULL);
        double kinectTime = now.tv_sec + ((double)now.tv_usec)/1000000.0;
        
        if(file){
	  			    file << index << "\t";
              file << std::setprecision(precision) <<kinectTime << "\n";	 
			      }
 
        
        vpDisplay::display(Idmap);
        vpDisplay::flush(Idmap);
        vpDisplay::display(Irgb);
        vpDisplay::flush(Irgb);
        
        // save the depth image
        std::string depthPath = path+"/"+depthFilename;
        char buf[100];
        sprintf(buf,depthPath.c_str(),index);
        std::string depthFullPath(buf);
        std::cout << "Write in : " << depthFullPath << std::endl;
        try{
          vpImageIo::writePFM(dmap,depthFullPath.c_str());
        }
        catch(...){
              std::cout << "Catch an exception when writing image " << depthFullPath << std::endl;
        }
        //save the color image
        std::string rgbPath = path+"/"+rgbFilename;
        sprintf(buf,rgbPath.c_str(),index);
        std::string rgbFullPath(buf);
        std::cout << "Write in : " << rgbFullPath << std::endl;
        try{
          vpImageIo::writePPM(Irgb,rgbFullPath.c_str());
        }
        catch(...){
              std::cout << "Catch an exception when writing image " << rgbFullPath << std::endl;
        }
        
      index++;
		}
    
		std::cout << "Stop acquisition" << std::endl;
		kinect.stop(); // Stop acquisition thread
    if  (file) file.close();
		return 0;
	}	
	catch(vpException e) {
		std::cout << "Catch an exception: " << e << std::endl;
		return 1;
	}
	catch(...){
		std::cout << "Catch an exception " << std::endl;
		return 1;
	}
}
Example #2
0
int main() {
  try {
    // Init Kinect
#ifdef VISP_HAVE_LIBFREENECT_OLD
    // This is the way to initialize Freenect with an old version of libfreenect packages under ubuntu lucid 10.04
    Freenect::Freenect<vpKinect> freenect;
    vpKinect & kinect = freenect.createDevice(0);
#else
    Freenect::Freenect freenect;
    vpKinect & kinect = freenect.createDevice<vpKinect>(0);
#endif

    // Set tilt angle in degrees
    if (0) {
      float angle = -3;
      kinect.setTiltDegrees(angle);
    }

    // Init display
#if 1
    kinect.start(vpKinect::DMAP_MEDIUM_RES); // Start acquisition thread with a depth map resolution of 480x640
    vpImage<unsigned char> Idmap(480,640);//for medium resolution
    vpImage<float> dmap(480,640);//for medium resolution
#else
    kinect.start(vpKinect::DMAP_LOW_RES); // Start acquisition thread with a depth map resolution of 240x320 (default resolution)
    vpImage<unsigned char> Idmap(240,320);//for low resolution
    vpImage<float> dmap(240,320);//for low resolution
#endif
    vpImage<vpRGBa> Irgb(480,640),Iwarped(480,640);

#if defined VISP_HAVE_X11
    vpDisplayX display, displayRgb, displayRgbWarped;
#elif defined VISP_HAVE_GTK
    vpDisplayGTK display;
    vpDisplayGTK displayRgb;
    vpDisplayGTK displayRgbWarped;
#elif defined VISP_HAVE_OPENCV
    vpDisplayOpenCV display;
    vpDisplayOpenCV displayRgb;
    vpDisplayOpenCV displayRgbWarped;
#elif defined VISP_HAVE_GDI
    vpDisplayGDI display;
    vpDisplayGDI displayRgb;
    vpDisplayGDI displayRgbWarped;
#endif

    display.init(Idmap, 100, 200,"Depth map");
    displayRgb.init(Irgb, 900, 200,"Color Image");
    displayRgbWarped.init(Iwarped,900,700,"Warped Color Image");

    // A click to stop acquisition
    std::cout << "Click in one image to stop acquisition" << std::endl;

    while(!vpDisplay::getClick(Idmap,false) && !vpDisplay::getClick(Irgb,false))
    {
      kinect.getDepthMap(dmap);
      kinect.getDepthMap(dmap, Idmap);
      kinect.getRGB(Irgb);

      vpDisplay::display(Idmap);
      vpDisplay::flush(Idmap);
      vpDisplay::display(Irgb);
      vpDisplay::flush(Irgb);

      //Warped RGB image:
      kinect.warpRGBFrame(Irgb,dmap, Iwarped);
      vpDisplay::display(Iwarped);
      vpDisplay::flush(Iwarped);
    }
    std::cout << "Stop acquisition" << std::endl;
    kinect.stop(); // Stop acquisition thread
    return 0;
  }
  catch(vpException &e) {
    std::cout << "Catch an exception: " << e << std::endl;
    return 1;
  }
  catch(...) {
    std::cout << "Catch an exception " << std::endl;
    return 1;
  }
}