37 #include "../XIMEA/examples/xiSample/stdafx.h" 
   38 #include "../XIMEA/include/xiApi.h" 
   39 #include "../XIMEA/include/xiExt.h" 
   40 #define FORMAT XI_MONO8 
   45 template<
typename Timg> 
 
   51     CImgList<double> m_time;
 
   52     CImg<unsigned char> m_cam_get;
 
   54     int m_image_exposure, m_frame;
 
   55     int m_image_width, m_image_height, m_offset_x, m_offset_y;
 
   65       this->class_name = 
"Image : grab";
 
   74         xiStopAcquisition(m_xiH);
 
   82     virtual void load_paths(CParameterNetCDF &fp)
 
   91       std::string att_name = 
"exposure";
 
   92       error = fp.loadAttribute(att_name,m_image_exposure);
 
   93       att_name = 
"offset_x";
 
   94       error = fp.loadAttribute(att_name,m_offset_x);
 
   95       att_name = 
"offset_y";
 
   96       error = fp.loadAttribute(att_name,m_offset_y);
 
   98       error = fp.loadAttribute(att_name,m_image_width);
 
  100       error = fp.loadAttribute(att_name,m_image_height);
 
  102       error = fp.loadAttribute(att_name,m_fps);
 
  105       if (open_device(m_xiH, m_image))
 
  109         error = set_device(m_xiH, m_image_exposure, m_offset_x, m_offset_y, m_image_width, m_image_height, m_fps);
 
  112         m_cam_get.assign(m_image_width, m_image_height, 1, 1, 0);
 
  114         this->m_img.assign(this->m_dim_image, m_image_width, m_image_height, 1, 1, 0);
 
  115         m_time.assign(3,this->m_dim_sample,1,1,1,0);
 
  122         printf(
"Warning : device no opened");
 
  127     int open_device(HANDLE &xiH, XI_IMG &image)
 
  130       image.size = 
sizeof(XI_IMG);
 
  138       DWORD dwNumberOfDevices = 0;
 
  139       DWORD m_get_delay = 10000;
 
  141       if (!xiGetNumberDevices(&dwNumberOfDevices))
 
  143         printf(
"number of devices detected : %i",dwNumberOfDevices);
 
  145         xiOpenDevice(0, &xiH);
 
  149         printf(
"xiGetNumberDevices (no camera found)");
 
  157     int set_device(HANDLE &xiH, 
int &exposure, 
int &offset_x, 
int &offset_y, 
int &width, 
int &height, 
float &fps)
 
  160       int error(0), tmpW(0), tmpH(0);
 
  161       float min_fps(0), max_fps(0);
 
  163       xiSetParamInt(xiH, XI_PRM_EXPOSURE, exposure);
 
  165       xiGetParamInt( xiH, XI_PRM_WIDTH, &tmpW);
 
  166       xiGetParamInt( xiH, XI_PRM_HEIGHT, &tmpH);
 
  167       printf(
"\nFullFrame resolution -> [%i, %i]\n",tmpW, tmpH);
 
  170       xiSetParamInt( xiH, XI_PRM_OFFSET_X, offset_x);
 
  171       xiSetParamInt( xiH, XI_PRM_OFFSET_Y, offset_y);
 
  172       xiSetParamInt( xiH, XI_PRM_WIDTH, width);
 
  173       xiSetParamInt( xiH, XI_PRM_HEIGHT, height);
 
  175       xiGetParamInt( xiH, XI_PRM_WIDTH, &width);
 
  176       xiGetParamInt( xiH, XI_PRM_HEIGHT, &height);
 
  178       printf(
"\nCaptured image -> offset [%i, %i] - dimensions [%i, %i]\n", offset_x, offset_y, width, height);
 
  180       xiSetParamInt( xiH, XI_PRM_BUFFERS_QUEUE_SIZE, 2);
 
  182       xiSetParamInt( xiH, XI_PRM_IMAGE_DATA_FORMAT, FORMAT);
 
  187         std::cerr<<
"Information: use internal trigger.\n";
 
  189         xiGetParamFloat( xiH, XI_PRM_FRAMERATE XI_PRM_INFO_MIN, &min_fps);
 
  190         xiGetParamFloat( xiH, XI_PRM_FRAMERATE XI_PRM_INFO_MAX, &max_fps);
 
  192         if (fps>max_fps or fps<min_fps)
 
  194           printf(
"Warning ! : required fps isn't in the appropriate range, its value will be set to (min_fps + max_fps)/2\n");
 
  195           fps = (min_fps + max_fps)/2;
 
  198         xiSetParamFloat( xiH, XI_PRM_FRAMERATE, fps);
 
  199         xiGetParamFloat( xiH, XI_PRM_FRAMERATE, &fps);
 
  201         printf(
"\nFPS settings [min: %f, max: %f, current: %f]\n", min_fps, max_fps, fps);
 
  207         std::cerr<<
"Information: use external trigger.\n";
 
  208         xiSetParamInt( xiH, XI_PRM_TRG_SOURCE, XI_TRG_EDGE_RISING);
 
  209         xiSetParamInt( xiH, XI_PRM_GPI_SELECTOR, 1);
 
  210         xiSetParamInt( xiH, XI_PRM_GPI_MODE, XI_GPI_TRIGGER);
 
  214       xiStartAcquisition(xiH);
 
  220     void grab(HANDLE &xiH, XI_IMG &image, CImg<unsigned char> &buffer, CImgList<double> &time, 
int const &bframe, 
int &frame)
 
  228         xiGetImage(xiH, 10000, &image);
 
  231         if(frame){lastFrame = time[0][frame-1];}
 
  234       while ( image.nframe == lastFrame );
 
  236       memcpy( buffer.data(), image.bp, image.width*image.height);
 
  239       time[0][frame] = image.nframe;
 
  240       time[1][frame] = (double)image.tsSec + (
double)image.tsUSec/1e6;
 
  241       if (!frame){time[2][frame] = 1.0/(time[1][frame]-time[1][frame-1]);}
else{time[2][frame] = 1.0/time[1][frame];}
 
  243       printf(
"image : %i, frame %f, at time %f, with a frequency of %f\n",bframe, m_time[0][frame], m_time[1][frame], m_time[2][frame]);
 
  248     virtual void load_images(CImg<char> &list, std::string &dir, 
const int &sample)
 
  252       for (
int bframe = 0; bframe<this->m_dim_image; bframe++)
 
  255         grab(m_xiH, m_image, m_cam_get, m_time, bframe, m_frame);
 
  259         this->m_img[bframe] = m_cam_get;
 
Definition: Cimage_file.h:38
load image and mask from cdl and store fields. It also creates a resized version of data in the case ...
virtual void load_images(CImg< char > &list, std::string &dir, const int &sample)
Definition: Cimage_grab.h:248
Definition: Cimage_grab.h:46
virtual void load_paths(CParameterNetCDF &fp)
Definition: Cimage_file.h:59