Visual Servoing Platform  version 3.5.0 under development (2022-02-15)
vpUeyeGrabber.cpp
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2019 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See http://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  *
31  * Description:
32  * IDS uEye interface.
33  *
34  *****************************************************************************/
35 
36 #include <visp3/core/vpConfig.h>
37 
38 #if defined(VISP_HAVE_UEYE)
39 
40 #include <string.h>
41 
42 #include <visp3/core/vpImageConvert.h>
43 #include <visp3/core/vpIoTools.h>
44 #include <visp3/sensor/vpUeyeGrabber.h>
45 
46 #include <ueye.h>
47 
48 #include "vpUeyeGrabber_impl.h"
49 
50 #ifndef DOXYGEN_SHOULD_SKIP_THIS
51 
54 #define IMAGE_COUNT 5
55 
56 #define CAMINFO BOARDINFO
57 #define EVENTTHREAD_WAIT_TIMEOUT 1000
58 
59 #define CAP(val, min, max) \
60 { \
61  if (val < min) { \
62  val = min; \
63  } else if (val > max) { \
64  val = max; \
65  } \
66 }
67 
69 struct sBufferProps
70 {
71  int width;
72  int height;
73  int bitspp;
74 };
75 
77 struct sCameraProps
78 {
79  bool bUsesImageFormats;
80  int nImgFmtNormal;
81  int nImgFmtDefaultNormal;
82  int nImgFmtTrigger;
83  int nImgFmtDefaultTrigger;
84 };
85 
89 typedef struct _UEYE_IMAGE
90 {
91  char *pBuf;
92  INT nImageID;
93  INT nImageSeqNum;
94  INT nBufferSize;
95 } UEYE_IMAGE, *PUEYE_IMAGE;
96 
97 class vpUeyeGrabber::vpUeyeGrabberImpl
98 {
99 public:
100  vpUeyeGrabberImpl()
101  : m_hCamera((HIDS)0), m_nMemoryId(0), m_nColorMode(0), m_nBitsPerPixel(0), m_activeCameraSelected(-1),
102  m_pLastBuffer(NULL), m_cameraList(NULL), m_bLive(true), m_bLiveStarted(false), m_verbose(false), m_I_temp()
103  {
104  ZeroMemory (&m_SensorInfo, sizeof(SENSORINFO));
105  ZeroMemory (&m_CamInfo, sizeof(CAMINFO));
106  ZeroMemory (&m_CamListInfo, sizeof(UEYE_CAMERA_INFO));
107  ZeroMemory (m_Images, sizeof(m_Images));
108 
109  m_BufferProps.width = 0;
110  m_BufferProps.height = 0;
111  m_BufferProps.bitspp = 8;
112 
113  m_event = 0;
114 #ifndef __linux__
115  m_hEvent = 0;
116 #endif
117 
118  // Active camera is the first one that is found
119  m_activeCameraSelected = setActiveCamera(0);
120  }
121 
122  ~vpUeyeGrabberImpl()
123  {
124  close();
125  }
126 
127  void acquire(vpImage<unsigned char> &I, double *timestamp_camera, std::string *timestamp_system)
128  {
129  INT ret = IS_SUCCESS;
130 
131  if (! m_hCamera) {
132  open(I);
133  }
134 
135  if (m_hCamera) {
136  if (! m_bLive) {
137  ret = is_FreezeVideo(m_hCamera, IS_WAIT);
138  }
139  else {
140  if (! m_bLiveStarted) {
141  ret = is_CaptureVideo(m_hCamera, IS_DONT_WAIT);
142  m_bLiveStarted = true;
143  }
144  }
145 
146  ret = waitEvent();
147 
148  if (ret == IS_SUCCESS) {
149  INT dummy = 0;
150  char *pLast = NULL, *pMem = NULL;
151 
152  is_GetActSeqBuf (m_hCamera, &dummy, &pMem, &pLast);
153  m_pLastBuffer = pLast;
154 
155  if (!m_pLastBuffer || m_BufferProps.width < 1 || m_BufferProps.height < 1)
156  return;
157 
158  int nNum = getImageNum (m_pLastBuffer);
159  if (timestamp_camera != NULL || timestamp_system != NULL) {
160  int nImageID = getImageID(m_pLastBuffer);
161  UEYEIMAGEINFO ImageInfo;
162  if (is_GetImageInfo(m_hCamera, nImageID, &ImageInfo, sizeof (ImageInfo)) == IS_SUCCESS) {
163  if (timestamp_camera != NULL) {
164  *timestamp_camera = static_cast<double>(ImageInfo.u64TimestampDevice) / 10000.;
165  }
166  if (timestamp_system != NULL) {
167  std::stringstream ss;
168  ss << ImageInfo.TimestampSystem.wYear << ":"
169  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wMonth << ":"
170  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wDay << ":"
171  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wHour << ":"
172  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wMinute << ":"
173  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wSecond << ":"
174  << std::setfill('0') << std::setw(3) << ImageInfo.TimestampSystem.wMilliseconds;
175  *timestamp_system = ss.str();
176  }
177  }
178  }
179 
180  helper::LockUnlockSeqBuffer lock(m_hCamera, nNum, m_pLastBuffer);
181 
182  if (lock.OwnsLock()) {
183  // get current colormode
184  int colormode = is_SetColorMode(m_hCamera, IS_GET_COLOR_MODE);
185 
186  switch (colormode) {
187  default:
188  case IS_CM_MONO8:
189  memcpy(reinterpret_cast<unsigned char*>(I.bitmap), reinterpret_cast<unsigned char*>(m_pLastBuffer), m_BufferProps.width * m_BufferProps.height * m_BufferProps.bitspp / 8);
190  break;
191  case IS_CM_SENSOR_RAW8:
192  m_I_temp.resize( m_BufferProps.height, m_BufferProps.width ),
193  vpImageConvert::demosaicRGGBToRGBaBilinear( reinterpret_cast< unsigned char * >( m_pLastBuffer ),
194  reinterpret_cast< unsigned char * >( m_I_temp.bitmap ),
195  m_BufferProps.width, m_BufferProps.height );
196  vpImageConvert::RGBaToGrey( reinterpret_cast< unsigned char * >( m_I_temp.bitmap ),
197  reinterpret_cast< unsigned char * >( I.bitmap ), m_BufferProps.width,
198  m_BufferProps.height );
199  break;
200  case IS_CM_BGR565_PACKED:
201  throw(vpException(vpException::fatalError, "vpUeyeGrabber doesn't support BGR565 format"));
202 
203  case IS_CM_RGB8_PACKED:
204  vpImageConvert::RGBToGrey(reinterpret_cast<unsigned char*>(m_pLastBuffer), reinterpret_cast<unsigned char*>(I.bitmap),
205  m_BufferProps.width, m_BufferProps.height);
206  break;
207  case IS_CM_BGR8_PACKED:
208  vpImageConvert::BGRToGrey(reinterpret_cast<unsigned char*>(m_pLastBuffer), reinterpret_cast<unsigned char*>(I.bitmap),
209  m_BufferProps.width, m_BufferProps.height);
210  break;
211  case IS_CM_RGBA8_PACKED:
212  vpImageConvert::RGBaToGrey(reinterpret_cast<unsigned char*>(m_pLastBuffer), reinterpret_cast<unsigned char*>(I.bitmap),
213  m_BufferProps.width, m_BufferProps.height);
214  break;
215  case IS_CM_BGRA8_PACKED:
216  vpImageConvert::BGRaToGrey(reinterpret_cast<unsigned char*>(m_pLastBuffer), reinterpret_cast<unsigned char*>(I.bitmap),
217  m_BufferProps.width, m_BufferProps.height);
218  break;
219  }
220  }
221  }
222  }
223  }
224 
225  void acquire(vpImage<vpRGBa> &I, double *timestamp_camera, std::string *timestamp_system)
226  {
227  INT ret = IS_SUCCESS;
228 
229  if (! m_hCamera) {
230  open(I);
231  }
232 
233  if (m_hCamera) {
234  if (! m_bLive) {
235  ret = is_FreezeVideo(m_hCamera, IS_WAIT);
236  }
237  else {
238  if (! m_bLiveStarted) {
239  // ret = is_CaptureVideo(m_hCamera, IS_DONT_WAIT);
240  ret = is_CaptureVideo(m_hCamera, IS_WAIT);
241  m_bLiveStarted = true;
242  }
243  }
244 
245  ret = waitEvent();
246 
247  if (ret == IS_SUCCESS) {
248  INT dummy = 0;
249  char *pLast = NULL, *pMem = NULL;
250 
251  is_GetActSeqBuf (m_hCamera, &dummy, &pMem, &pLast);
252  m_pLastBuffer = pLast;
253 
254  if (!m_pLastBuffer || m_BufferProps.width < 1 || m_BufferProps.height < 1)
255  return;
256 
257  int nNum = getImageNum (m_pLastBuffer);
258  if (timestamp_camera != NULL || timestamp_system != NULL) {
259  int nImageID = getImageID(m_pLastBuffer);
260  UEYEIMAGEINFO ImageInfo;
261  if (is_GetImageInfo(m_hCamera, nImageID, &ImageInfo, sizeof (ImageInfo)) == IS_SUCCESS) {
262  if (timestamp_camera != NULL) {
263  *timestamp_camera = static_cast<double>(ImageInfo.u64TimestampDevice) / 10000.;
264  }
265  if (timestamp_system != NULL) {
266  std::stringstream ss;
267  ss << ImageInfo.TimestampSystem.wYear << ":"
268  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wMonth << ":"
269  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wDay << ":"
270  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wHour << ":"
271  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wMinute << ":"
272  << std::setfill('0') << std::setw(2) << ImageInfo.TimestampSystem.wSecond << ":"
273  << std::setfill('0') << std::setw(3) << ImageInfo.TimestampSystem.wMilliseconds;
274  *timestamp_system = ss.str();
275  }
276  }
277  }
278 
279  helper::LockUnlockSeqBuffer lock(m_hCamera, nNum, m_pLastBuffer);
280 
281  if (lock.OwnsLock()) {
282  // get current colormode
283  int colormode = is_SetColorMode(m_hCamera, IS_GET_COLOR_MODE);
284 
285  switch (colormode) {
286  default:
287  case IS_CM_MONO8:
288  vpImageConvert::GreyToRGBa(reinterpret_cast<unsigned char*>(m_pLastBuffer), reinterpret_cast<unsigned char*>(I.bitmap),
289  m_BufferProps.width, m_BufferProps.height);
290  break;
291  case IS_CM_SENSOR_RAW8:
292  vpImageConvert::demosaicRGGBToRGBaBilinear( reinterpret_cast< unsigned char * >( m_pLastBuffer ),
293  reinterpret_cast< unsigned char * >( I.bitmap ),
294  m_BufferProps.width, m_BufferProps.height );
295  break;
296  case IS_CM_BGR565_PACKED:
297  throw(vpException(vpException::fatalError, "vpUeyeGrabber doesn't support BGR565 format"));
298 
299  case IS_CM_RGB8_PACKED:
300  vpImageConvert::RGBToRGBa(reinterpret_cast<unsigned char*>(m_pLastBuffer), reinterpret_cast<unsigned char*>(I.bitmap),
301  m_BufferProps.width, m_BufferProps.height);
302  break;
303  case IS_CM_BGR8_PACKED:
304  vpImageConvert::BGRToRGBa(reinterpret_cast<unsigned char*>(m_pLastBuffer), reinterpret_cast<unsigned char*>(I.bitmap),
305  m_BufferProps.width, m_BufferProps.height);
306  break;
307  case IS_CM_RGBA8_PACKED:
308  memcpy(reinterpret_cast<unsigned char*>(I.bitmap), reinterpret_cast<unsigned char*>(m_pLastBuffer), m_BufferProps.width * m_BufferProps.height * m_BufferProps.bitspp / 8);
309  break;
310  case IS_CM_BGRA8_PACKED:
311  vpImageConvert::BGRaToRGBa(reinterpret_cast<unsigned char*>(m_pLastBuffer), reinterpret_cast<unsigned char*>(I.bitmap),
312  m_BufferProps.width, m_BufferProps.height);
313  break;
314  }
315  }
316  }
317  }
318  }
319 
320  bool allocImages()
321  {
322  m_pLastBuffer = NULL;
323  int nWidth = 0;
324  int nHeight = 0;
325 
326  UINT nAbsPosX;
327  UINT nAbsPosY;
328 
329  is_AOI(m_hCamera, IS_AOI_IMAGE_GET_POS_X_ABS, (void*)&nAbsPosX , sizeof(nAbsPosX));
330  is_AOI(m_hCamera, IS_AOI_IMAGE_GET_POS_Y_ABS, (void*)&nAbsPosY , sizeof(nAbsPosY));
331 
332  is_ClearSequence(m_hCamera);
333  freeImages();
334 
335  for (unsigned int i = 0; i < sizeof(m_Images) / sizeof(m_Images[0]); i++) {
336  nWidth = m_BufferProps.width;
337  nHeight = m_BufferProps.height;
338 
339  if (nAbsPosX) {
340  m_BufferProps.width = nWidth = m_SensorInfo.nMaxWidth;
341  }
342  if (nAbsPosY) {
343  m_BufferProps.height = nHeight = m_SensorInfo.nMaxHeight;
344  }
345 
346  if (is_AllocImageMem (m_hCamera, nWidth, nHeight, m_BufferProps.bitspp, &m_Images[i].pBuf,
347  &m_Images[i].nImageID) != IS_SUCCESS)
348  return false;
349  if (is_AddToSequence (m_hCamera, m_Images[i].pBuf, m_Images[i].nImageID) != IS_SUCCESS)
350  return false;
351 
352  m_Images[i].nImageSeqNum = i + 1;
353  m_Images[i].nBufferSize = nWidth * nHeight * m_BufferProps.bitspp / 8;
354  }
355 
356  return true;
357  }
358 
359  int cameraInitialized()
360  {
361  int ret = 0;
362  unsigned int uInitialParameterSet = IS_CONFIG_INITIAL_PARAMETERSET_NONE;
363 
364  if ((ret=is_GetCameraInfo (m_hCamera, &m_CamInfo)) != IS_SUCCESS) {
365  throw(vpException(vpException::fatalError, "uEye error: GetCameraInfo failed"));
366  }
367  else if ((ret=is_GetSensorInfo (m_hCamera, &m_SensorInfo)) != IS_SUCCESS) {
368  throw(vpException(vpException::fatalError, "uEye error: GetSensorInfo failed"));
369  }
370  else if ((ret = is_Configuration(IS_CONFIG_INITIAL_PARAMETERSET_CMD_GET, &uInitialParameterSet, sizeof(unsigned int))) != IS_SUCCESS) {
371  throw(vpException(vpException::fatalError, "uEye error: querying 'initial parameter set' failed"));
372  }
373  else
374  {
375  //m_nWidth = m_SensorInfo.nMaxWidth;
376  //m_nHeight = m_SensorInfo.nMaxHeight;
377 
378  // restore all defaults
379  // do this only if there is no 'initial parameter set' installed.
380  // if an 'initial parameter set' is installed we must not overwrite this setup!
381  if (uInitialParameterSet == IS_CONFIG_INITIAL_PARAMETERSET_NONE)
382  {
383  ret = is_ResetToDefault (m_hCamera);
384  }
385 
386  int colormode = 0;
387  if (m_SensorInfo.nColorMode >= IS_COLORMODE_BAYER) {
388  colormode = IS_CM_BGRA8_PACKED;
389  }
390  else {
391  colormode = IS_CM_MONO8;
392  }
393 
394  if (is_SetColorMode (m_hCamera, colormode) != IS_SUCCESS) {
395  throw(vpException(vpException::fatalError, "uEye error: SetColorMode failed"));
396  }
397 
398  /* get some special camera properties */
399  ZeroMemory (&m_CameraProps, sizeof(m_CameraProps));
400 
401  // If the camera does not support a continuous AOI -> it uses special image formats
402  m_CameraProps.bUsesImageFormats = false;
403  INT nAOISupported = 0;
404  if (is_ImageFormat(m_hCamera, IMGFRMT_CMD_GET_ARBITRARY_AOI_SUPPORTED, (void*)&nAOISupported,
405  sizeof(nAOISupported)) == IS_SUCCESS) {
406  m_CameraProps.bUsesImageFormats = (nAOISupported == 0);
407  }
408 
409  /* set the default image format, if used */
410  if (m_CameraProps.bUsesImageFormats) {
411  // search the default formats
412  m_CameraProps.nImgFmtNormal = searchDefImageFormats(CAPTMODE_FREERUN | CAPTMODE_SINGLE);
413  m_CameraProps.nImgFmtDefaultNormal = m_CameraProps.nImgFmtNormal;
414  m_CameraProps.nImgFmtTrigger = searchDefImageFormats(CAPTMODE_TRIGGER_SOFT_SINGLE);
415  m_CameraProps.nImgFmtDefaultTrigger = m_CameraProps.nImgFmtTrigger;
416  // set the default formats
417  if ((ret=is_ImageFormat(m_hCamera, IMGFRMT_CMD_SET_FORMAT, (void*)&m_CameraProps.nImgFmtNormal,
418  sizeof(m_CameraProps.nImgFmtNormal))) == IS_SUCCESS) {
419  //m_nImageFormat = nFormat;
420  //bRet = TRUE;
421  }
422  }
423 
424  /* setup the capture parameter */
425  setupCapture();
426 
427  enableEvent(IS_SET_EVENT_FRAME);
428  }
429 
430  m_pLastBuffer = NULL;
431 
432  return ret;
433  }
434 
435  void close()
436  {
437  if (m_hCamera == IS_INVALID_HIDS)
438  return;
439 
440  if (m_hCamera) {
441  if (m_bLive && m_bLiveStarted) {
442  INT nRet = 1;
443  double t = vpTime::measureTimeSecond();
444  while (nRet != IS_SUCCESS && (vpTime::measureTimeSecond() - t) <= 2. ) {
445  nRet = is_StopLiveVideo(m_hCamera, IS_WAIT);
446  }
447  m_bLiveStarted = false;
448  }
449 
450  is_ClearSequence(m_hCamera);
451  freeImages();
452 
453  if (is_ExitCamera(m_hCamera) != IS_SUCCESS) {
454  throw(vpException(vpException::fatalError, "Cannot logoff camera"));
455  }
456 
457  disableEvent();
458 
459  m_hCamera = (HIDS)0;
460  }
461  }
462 
463  void disableEvent()
464  {
465  is_DisableEvent (m_hCamera, m_event);
466 #ifndef __linux__
467  is_ExitEvent(m_hCamera, m_event);
468  CloseHandle(m_hEvent);
469 #endif
470  }
471 
472 
473  int enableEvent(int event)
474  {
475  int ret = 0;
476  m_event = event;
477 #ifndef __linux__
478  m_hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
479  if (m_hEvent == NULL) {
480  return -1;
481  }
482  ret = is_InitEvent(m_hCamera, m_hEvent, m_event);
483 #endif
484  ret = is_EnableEvent (m_hCamera, m_event);
485 
486  return ret;
487  }
488 
489  int waitEvent()
490  {
491 #ifdef __linux__
492  if (is_WaitEvent (m_hCamera, m_event, EVENTTHREAD_WAIT_TIMEOUT) == IS_SUCCESS) {
493 #else
494  if (WaitForSingleObject(m_hEvent, EVENTTHREAD_WAIT_TIMEOUT) == WAIT_OBJECT_0) {
495 #endif
496  return IS_SUCCESS;
497  }
498  else {
499  return IS_TIMED_OUT;
500  }
501  }
502 
503  void freeImages()
504  {
505  m_pLastBuffer = NULL;
506  //printf ("freeing image buffers\n");
507  for (unsigned int i = 0; i < sizeof(m_Images) / sizeof(m_Images[0]); i++) {
508  if (NULL != m_Images[i].pBuf) {
509  is_FreeImageMem (m_hCamera, m_Images[i].pBuf, m_Images[i].nImageID);
510  }
511 
512  m_Images[i].pBuf = NULL;
513  m_Images[i].nImageID = 0;
514  m_Images[i].nImageSeqNum = 0;
515  }
516  }
517 
518  std::string getActiveCameraModel() const
519  {
520  return m_CamListInfo.Model;
521  }
522 
523  std::string getActiveCameraSerialNumber() const
524  {
525  return m_CamListInfo.SerNo;
526  }
527 
528  int getBitsPerPixel(int colormode)
529  {
530  switch (colormode)
531  {
532  default:
533  case IS_CM_MONO8:
534  case IS_CM_SENSOR_RAW8:
535  return 8; // occupies 8 Bit
536  case IS_CM_MONO12:
537  case IS_CM_MONO16:
538  case IS_CM_SENSOR_RAW12:
539  case IS_CM_SENSOR_RAW16:
540  case IS_CM_BGR5_PACKED:
541  case IS_CM_BGR565_PACKED:
542  case IS_CM_UYVY_PACKED:
543  case IS_CM_CBYCRY_PACKED:
544  return 16; // occupies 16 Bit
545  case IS_CM_RGB8_PACKED:
546  case IS_CM_BGR8_PACKED:
547  return 24;
548  case IS_CM_RGBA8_PACKED:
549  case IS_CM_BGRA8_PACKED:
550  case IS_CM_RGBY8_PACKED:
551  case IS_CM_BGRY8_PACKED:
552  case IS_CM_RGB10_PACKED:
553  case IS_CM_BGR10_PACKED:
554  return 32;
555  }
556  }
557 
558  std::vector<unsigned int> getCameraIDList() const
559  {
560  CameraList camera_list;
561  return camera_list.getCameraIDList();
562  }
563 
564  std::vector<std::string> getCameraModelList() const
565  {
566  CameraList camera_list;
567  return camera_list.getCameraModelList();
568  }
569 
570  std::vector<std::string> getCameraSerialNumberList() const
571  {
572  CameraList camera_list;
573  return camera_list.getCameraSerialNumberList();
574  }
575 
576  unsigned int getFrameHeight() const
577  {
578  if (!isConnected()) {
579  throw(vpException(vpException::fatalError, "Unable to get frame height. Camera connexion is not opened"));
580  }
581  return static_cast<unsigned int>(m_BufferProps.height);
582  }
583 
584  unsigned int getFrameWidth() const
585  {
586  if (!isConnected()) {
587  throw(vpException(vpException::fatalError, "Unable to get frame width. Camera connexion is not opened"));
588  }
589  return static_cast<unsigned int>(m_BufferProps.width);
590  }
591 
592  double getFramerate() const
593  {
594  if (! m_hCamera) {
595  return 0;
596  }
597  double fps;
598 
599  // Get framerate
600  if (is_GetFramesPerSecond (m_hCamera, &fps) != IS_SUCCESS) {
601  if (m_verbose) {
602  std::cout << "Unable to get acquisition frame rate" << std::endl;
603  }
604  }
605  return fps;
606  }
607 
608  INT getImageID (char* pbuf)
609  {
610  if (!pbuf)
611  return 0;
612 
613  for (unsigned int i = 0; i < sizeof(m_Images) / sizeof(m_Images[0]); i++)
614  if (m_Images[i].pBuf == pbuf)
615  return m_Images[i].nImageID;
616 
617  return 0;
618  }
619 
620  INT getImageNum(char* pbuf)
621  {
622  if (!pbuf)
623  return 0;
624 
625  for (unsigned int i = 0; i < sizeof(m_Images) / sizeof(m_Images[0]); i++)
626  if (m_Images[i].pBuf == pbuf)
627  return m_Images[i].nImageSeqNum;
628 
629  return 0;
630  }
631 
632  bool isConnected() const
633  {
634  return (m_hCamera != (HIDS) 0);
635  }
636 
637  void loadParameters(const std::string &filename)
638  {
639  if (! vpIoTools::checkFilename(filename)) {
640  throw(vpException(vpException::fatalError, "Camera parameters file doesn't exist: %s", filename.c_str()));
641  }
642 
643  const std::wstring filename_(filename.begin(), filename.end());
644  int ret = is_ParameterSet(m_hCamera, IS_PARAMETERSET_CMD_LOAD_FILE, (void*) filename_.c_str(), 0);
645 
646  if (ret == IS_INVALID_CAMERA_TYPE) {
647  throw(vpException(vpException::fatalError, "The camera parameters file %s belong to a different camera", filename.c_str()));
648  }
649  else if (ret == IS_INCOMPATIBLE_SETTING) {
650  throw(vpException(vpException::fatalError, "Because of incompatible settings, cannot load parameters from file %s", filename.c_str()));
651  }
652  else if (ret != IS_SUCCESS) {
653  throw(vpException(vpException::fatalError, "Cannot load parameters from file %s", filename.c_str()));
654  }
655  else {
656  std::cout << "Parameters loaded sucessfully" << std::endl;
657  }
658 
659  setupCapture();
660  }
661 
662  void open()
663  {
664  if (m_hCamera) {
665  if (is_ExitCamera(m_hCamera) != IS_SUCCESS) {
666  throw(vpException(vpException::fatalError, "Cannot logoff camera"));
667  }
668  }
669 
670  // open the selected camera
671  m_hCamera = (HIDS) (m_CamListInfo.dwDeviceID | IS_USE_DEVICE_ID); // open camera
672 
673  if (is_InitCamera(&m_hCamera, 0) != IS_SUCCESS) { // init camera - no window handle required
674  throw(vpException(vpException::fatalError, "Cannot open connexion with IDS uEye camera"));
675  }
676 
677  int ret = cameraInitialized();
678  if (ret != IS_SUCCESS) {
679  throw(vpException(vpException::fatalError, "Unable to initialize uEye camera"));
680  }
681  }
682 
683  template <class Type>
684  void open(vpImage<Type> &I)
685  {
686  open();
687  I.resize(m_SensorInfo.nMaxHeight, m_SensorInfo.nMaxWidth);
688  }
689 
695  int searchDefImageFormats(int suppportMask)
696  {
697  int ret = IS_SUCCESS;
698  int nNumber;
699  int format = 0;
700  IMAGE_FORMAT_LIST *pFormatList;
701  IS_RECT rectAOI;
702 
703  if ((ret=is_ImageFormat(m_hCamera, IMGFRMT_CMD_GET_NUM_ENTRIES, (void*)&nNumber, sizeof(nNumber))) == IS_SUCCESS &&
704  (ret=is_AOI(m_hCamera, IS_AOI_IMAGE_GET_AOI, (void*)&rectAOI, sizeof(rectAOI))) == IS_SUCCESS) {
705  int i = 0;
706  int nSize = sizeof(IMAGE_FORMAT_LIST) + (nNumber - 1) * sizeof(IMAGE_FORMAT_LIST);
707  pFormatList = (IMAGE_FORMAT_LIST*)(new char[nSize]);
708  pFormatList->nNumListElements = nNumber;
709  pFormatList->nSizeOfListEntry = sizeof(IMAGE_FORMAT_INFO);
710 
711  if((ret=is_ImageFormat(m_hCamera, IMGFRMT_CMD_GET_LIST, (void*)pFormatList, nSize)) == IS_SUCCESS) {
712  for(i=0; i<nNumber; i++) {
713  if ((pFormatList->FormatInfo[i].nSupportedCaptureModes & suppportMask) &&
714  pFormatList->FormatInfo[i].nHeight == (UINT)rectAOI.s32Height &&
715  pFormatList->FormatInfo[i].nWidth == (UINT)rectAOI.s32Width) {
716  format = pFormatList->FormatInfo[i].nFormatID;
717  break;
718  }
719  }
720  }
721  else {
722  throw(vpException(vpException::fatalError, "uEye error: is_ImageFormat returned %d", ret));
723  }
724 
725  delete (pFormatList);
726  }
727  else
728  {
729  throw(vpException(vpException::fatalError, "uEye error: is_ImageFormat returned %d", ret));
730  }
731  return format;
732  }
733 
734  int setActiveCamera(unsigned int cam_index)
735  {
736  m_cameraList = new CameraList;
737  m_activeCameraSelected = m_cameraList->setActiveCamera(cam_index);
738  if (! m_activeCameraSelected) {
739  m_CamListInfo = m_cameraList->getCameraInfo();
740  }
741  delete m_cameraList;
742  return m_activeCameraSelected;
743  }
744 
745  std::string toUpper(const std::basic_string<char>& s)
746  {
747  std::string s_upper = s;
748  for (std::basic_string<char>::iterator p = s_upper.begin(); p != s_upper.end(); ++p) {
749  *p = toupper(*p);
750  }
751  return s_upper;
752  }
753 
754  int setColorMode(const std::string &color_mode)
755  {
756  if (! isConnected()) {
757  throw(vpException(vpException::fatalError, "Cannot set color mode. Connection to active uEye camera is not opened"));
758  }
759 
760  std::string color_mode_upper = toUpper(color_mode);
761  int cm = IS_CM_MONO8;
762  if (color_mode_upper == "MONO8") {
763  cm = IS_CM_MONO8;
764  }
765  else if (color_mode_upper == "RGB24") {
766  cm = IS_CM_BGR8_PACKED;
767  }
768  else if (color_mode_upper == "RGB32") {
769  cm = IS_CM_RGBA8_PACKED;
770  }
771  else if ( color_mode_upper == "BAYER8" ) {
772  cm = IS_CM_SENSOR_RAW8;
773  }
774  else {
775  throw(vpException(vpException::fatalError, "Unsupported color mode %s", color_mode.c_str()));
776  }
777 
778  INT ret = IS_SUCCESS;
779  if ((ret = is_SetColorMode(m_hCamera, cm)) != IS_SUCCESS) {
780  std::cout << "Could not set color mode of " << m_CamListInfo.Model << " to " << color_mode << std::endl;
781  }
782  else {
783  setupCapture();
784  }
785  return ret;
786  }
787 
788  int setFrameRate(bool auto_frame_rate, double frame_rate_hz)
789  {
790  if (! isConnected()) {
791  throw(vpException(vpException::fatalError, "Cannot set frame rate. Connection to active uEye camera is not opened"));
792  }
793 
794  INT ret = IS_SUCCESS;
795 
796  // Auto
797  if (auto_frame_rate) {
798  double pval1 = 0, pval2 = 0;
799 
800  // Make sure that auto shutter is enabled before enabling auto frame rate
801  bool autoShutterOn = false;
802  is_SetAutoParameter(m_hCamera, IS_GET_ENABLE_AUTO_SENSOR_SHUTTER, &pval1, &pval2);
803  autoShutterOn |= (pval1 != 0);
804  is_SetAutoParameter(m_hCamera, IS_GET_ENABLE_AUTO_SHUTTER, &pval1, &pval2);
805  autoShutterOn |= (pval1 != 0);
806  if (!autoShutterOn) {
807  if (m_verbose) {
808  std::cout << "Auto shutter mode is not supported for " << m_CamListInfo.Model << std::endl;
809  }
810  return IS_NO_SUCCESS;
811  }
812 
813  // Set frame rate / auto
814  pval1 = auto_frame_rate;
815  if ((ret = is_SetAutoParameter(m_hCamera, IS_SET_ENABLE_AUTO_SENSOR_FRAMERATE,
816  &pval1, &pval2)) != IS_SUCCESS) {
817  if ((ret = is_SetAutoParameter(m_hCamera, IS_SET_ENABLE_AUTO_FRAMERATE,
818  &pval1, &pval2)) != IS_SUCCESS) {
819  if (m_verbose) {
820  std::cout << "Auto frame rate mode is not supported for " << m_CamListInfo.Model << std::endl;
821  }
822  return IS_NO_SUCCESS;
823  }
824  }
825  }
826  else { // Manual
827  double minFrameTime, maxFrameTime, intervalFrameTime, newFrameRate;
828  // Make sure that user-requested frame rate is achievable
829  if ((ret = is_GetFrameTimeRange(m_hCamera, &minFrameTime,
830  &maxFrameTime, &intervalFrameTime)) != IS_SUCCESS) {
831  if (m_verbose) {
832  std::cout << "Failed to query valid frame rate range from " << m_CamListInfo.Model << std::endl;
833  }
834  return ret;
835  }
836  CAP(frame_rate_hz, 1.0/maxFrameTime, 1.0/minFrameTime);
837 
838  // Update frame rate
839  if ((ret = is_SetFrameRate(m_hCamera, frame_rate_hz, &newFrameRate)) != IS_SUCCESS) {
840  if (m_verbose) {
841  std::cout << "Failed to set frame rate to " << frame_rate_hz <<
842  " MHz for " << m_CamListInfo.Model << std::endl;
843  }
844  return ret;
845  } else if (frame_rate_hz != newFrameRate) {
846  frame_rate_hz = newFrameRate;
847  }
848  }
849 
850  if (m_verbose) {
851  std::cout << "Updated frame rate for " << m_CamListInfo.Model << ": " <<
852  ((auto_frame_rate) ? "auto" : std::to_string(frame_rate_hz)) << " Hz" << std::endl;
853  }
854 
855  return ret;
856  }
857 
858  int setExposure(bool auto_exposure, double exposure_ms)
859  {
860  if (! isConnected()) {
861  throw(vpException(vpException::fatalError, "Cannot set exposure. Connection to active uEye camera is not opened"));
862  }
863 
864  INT err = IS_SUCCESS;
865 
866  double minExposure, maxExposure;
867 
868  // Set auto exposure
869  if (auto_exposure) {
870  double pval1 = auto_exposure, pval2 = 0;
871  if ((err = is_SetAutoParameter(m_hCamera, IS_SET_ENABLE_AUTO_SENSOR_SHUTTER,
872  &pval1, &pval2)) != IS_SUCCESS) {
873  if ((err = is_SetAutoParameter(m_hCamera, IS_SET_ENABLE_AUTO_SHUTTER,
874  &pval1, &pval2)) != IS_SUCCESS) {
875  std::cout << "Auto exposure mode is not supported for " << m_CamListInfo.Model << std::endl;
876  return IS_NO_SUCCESS;
877  }
878  }
879  }
880 
881  else { // Set manual exposure timing
882  // Make sure that user-requested exposure rate is achievable
883  if (((err = is_Exposure(m_hCamera, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN,
884  (void*) &minExposure, sizeof(minExposure))) != IS_SUCCESS) ||
885  ((err = is_Exposure(m_hCamera, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX,
886  (void*) &maxExposure, sizeof(maxExposure))) != IS_SUCCESS)) {
887  std::cout << "Failed to query valid exposure range from " << m_CamListInfo.Model << std::endl;
888  return err;
889  }
890  CAP(exposure_ms, minExposure, maxExposure);
891 
892  // Update exposure
893  if ((err = is_Exposure(m_hCamera, IS_EXPOSURE_CMD_SET_EXPOSURE,
894  (void*) &(exposure_ms), sizeof(exposure_ms))) != IS_SUCCESS) {
895  std::cout << "Failed to set exposure to " << exposure_ms <<
896  " ms for " << m_CamListInfo.Model << std::endl;
897  return err;
898  }
899  }
900 
901  if (m_verbose) {
902  std::cout << "Updated exposure: " << ((auto_exposure) ? "auto" : std::to_string(exposure_ms) + " ms") <<
903  " for " << m_CamListInfo.Model << std::endl;
904  }
905 
906  return err;
907  }
908 
909  int setGain(bool auto_gain, int master_gain, bool gain_boost)
910  {
911  if (! isConnected()) {
912  throw(vpException(vpException::fatalError, "Cannot set gain. Connection to active uEye camera is not opened"));
913  }
914 
915  INT err = IS_SUCCESS;
916 
917  // Validate arguments
918  CAP(master_gain, 0, 100);
919 
920  double pval1 = 0, pval2 = 0;
921 
922  if (auto_gain) {
923  // Set auto gain
924  pval1 = 1;
925  if ((err = is_SetAutoParameter(m_hCamera, IS_SET_ENABLE_AUTO_SENSOR_GAIN,
926  &pval1, &pval2)) != IS_SUCCESS) {
927  if ((err = is_SetAutoParameter(m_hCamera, IS_SET_ENABLE_AUTO_GAIN,
928  &pval1, &pval2)) != IS_SUCCESS) {
929  if (m_verbose) {
930  std::cout << m_CamListInfo.Model << " does not support auto gain mode" << std::endl;
931  }
932  return IS_NO_SUCCESS;
933  }
934  }
935  } else {
936  // Disable auto gain
937  if ((err = is_SetAutoParameter(m_hCamera, IS_SET_ENABLE_AUTO_SENSOR_GAIN,
938  &pval1, &pval2)) != IS_SUCCESS) {
939  if ((err = is_SetAutoParameter(m_hCamera, IS_SET_ENABLE_AUTO_GAIN,
940  &pval1, &pval2)) != IS_SUCCESS) {
941  std::cout << m_CamListInfo.Model << " does not support auto gain mode" << std::endl;
942  }
943  }
944 
945  // Set gain boost
946  if (is_SetGainBoost(m_hCamera, IS_GET_SUPPORTED_GAINBOOST) != IS_SET_GAINBOOST_ON) {
947  gain_boost = false;
948  } else {
949  if ((err = is_SetGainBoost(m_hCamera,
950  (gain_boost) ? IS_SET_GAINBOOST_ON : IS_SET_GAINBOOST_OFF))
951  != IS_SUCCESS) {
952  std::cout << "Failed to " << ((gain_boost) ? "enable" : "disable") <<
953  " gain boost for " << m_CamListInfo.Model << std::endl;
954  }
955  }
956 
957  // Set manual gain parameters
958  if ((err = is_SetHardwareGain(m_hCamera, master_gain,
959  IS_IGNORE_PARAMETER, IS_IGNORE_PARAMETER, IS_IGNORE_PARAMETER)) != IS_SUCCESS) {
960  std::cout << "Failed to set manual master gain: " << master_gain << " for " << m_CamListInfo.Model << std::endl;
961  return IS_NO_SUCCESS;
962  }
963  }
964 
965  if (m_verbose) {
966  if (auto_gain) {
967  std::cout << "Updated gain for " << m_CamListInfo.Model << ": auto" << std::endl;
968  } else {
969  std::cout << "Updated gain for " << m_CamListInfo.Model << ": manual master gain " << master_gain << std::endl;
970 
971  }
972  std::cout << "\n gain boost: " << (gain_boost ? "enabled" : "disabled") << std::endl;;
973  }
974 
975  return err;
976  }
977 
978  void applySubsamplingSettings(int subsamplingMode, int nMode)
979  {
980  INT ret = IS_SUCCESS;
981  int currentSubsampling = is_SetSubSampling(m_hCamera, IS_GET_SUBSAMPLING);
982  if ((ret = is_SetSubSampling (m_hCamera, subsamplingMode | nMode)) != IS_SUCCESS) {
983  throw(vpException(vpException::fatalError, "Unable to apply subsampling factor"));
984  }
985 
986  int newSubsampling = is_SetSubSampling(m_hCamera, IS_GET_SUBSAMPLING);
987  if((nMode == IS_SUBSAMPLING_DISABLE) && (currentSubsampling == newSubsampling)) {
988  // the subsampling nMode IS_SUBSAMPLING_DISABLE was expected, but the device
989  // did not changed the format, disable subsampling.
990  if ((ret = is_SetSubSampling (m_hCamera, IS_SUBSAMPLING_DISABLE)) != IS_SUCCESS) {
991  throw(vpException(vpException::fatalError, "Unable to apply subsampling factor"));
992  }
993  }
994  }
995 
996  void setSubsampling(int factor)
997  {
998  if (! isConnected()) {
999  throw(vpException(vpException::fatalError, "Cannot set sub sampling factor. Connection to active uEye camera is not opened"));
1000  }
1001 
1002  INT hMode = IS_SUBSAMPLING_DISABLE, vMode = IS_SUBSAMPLING_DISABLE;
1003 
1004  switch(factor) {
1005  case 2:
1006  hMode = IS_SUBSAMPLING_2X_HORIZONTAL;
1007  vMode = IS_SUBSAMPLING_2X_VERTICAL;
1008  break;
1009  case 3:
1010  hMode = IS_SUBSAMPLING_3X_HORIZONTAL;
1011  vMode = IS_SUBSAMPLING_3X_VERTICAL;
1012  break;
1013  case 4:
1014  hMode = IS_SUBSAMPLING_4X_HORIZONTAL;
1015  vMode = IS_SUBSAMPLING_4X_VERTICAL;
1016  break;
1017  case 5:
1018  hMode = IS_SUBSAMPLING_5X_HORIZONTAL;
1019  vMode = IS_SUBSAMPLING_5X_VERTICAL;
1020  break;
1021  case 6:
1022  hMode = IS_SUBSAMPLING_6X_HORIZONTAL;
1023  vMode = IS_SUBSAMPLING_6X_VERTICAL;
1024  break;
1025  case 8:
1026  hMode = IS_SUBSAMPLING_8X_HORIZONTAL;
1027  vMode = IS_SUBSAMPLING_8X_VERTICAL;
1028  break;
1029  case 16:
1030  hMode = IS_SUBSAMPLING_16X_HORIZONTAL;
1031  vMode = IS_SUBSAMPLING_16X_VERTICAL;
1032  break;
1033  default:
1034  hMode = IS_SUBSAMPLING_DISABLE;
1035  vMode = IS_SUBSAMPLING_DISABLE;
1036  }
1037 
1038  if (m_bLive && m_bLiveStarted) {
1039  is_StopLiveVideo (m_hCamera, IS_WAIT);
1040  }
1041 
1042  INT subsamplingModeH = is_SetSubSampling (m_hCamera, IS_GET_SUBSAMPLING) & IS_SUBSAMPLING_MASK_VERTICAL;
1043  applySubsamplingSettings(subsamplingModeH, hMode);
1044 
1045  INT subsamplingModeV = is_SetSubSampling (m_hCamera, IS_GET_SUBSAMPLING) & IS_SUBSAMPLING_MASK_HORIZONTAL;
1046  applySubsamplingSettings(subsamplingModeV, vMode);
1047 
1048  setupCapture();
1049  }
1050 
1051  void setWhiteBalance(bool auto_wb)
1052  {
1053  if (! isConnected()) {
1054  throw(vpException(vpException::fatalError, "Cannot set white balance. Connection to active uEye camera is not opened"));
1055  }
1056 
1057  double dblAutoWb = 0.0;
1058 
1059  if (auto_wb) {
1060  dblAutoWb = 0.0;
1061  is_SetAutoParameter (m_hCamera, IS_SET_AUTO_WB_ONCE, &dblAutoWb, NULL);
1062 
1063  dblAutoWb = 1.0;
1064  is_SetAutoParameter (m_hCamera, IS_SET_ENABLE_AUTO_WHITEBALANCE, &dblAutoWb, NULL);
1065  }
1066  else {
1067  dblAutoWb = 0.0;
1068  is_SetAutoParameter (m_hCamera, IS_SET_AUTO_WB_ONCE, &dblAutoWb, NULL);
1069  is_SetAutoParameter (m_hCamera, IS_SET_ENABLE_AUTO_WHITEBALANCE, &dblAutoWb, NULL);
1070  }
1071  }
1072 
1073  int setupCapture()
1074  {
1075  int width, height;
1076  // init the memorybuffer properties
1077  ZeroMemory(&m_BufferProps, sizeof(m_BufferProps));
1078 
1079  IS_RECT rectAOI;
1080  INT nRet = is_AOI(m_hCamera, IS_AOI_IMAGE_GET_AOI, (void*)&rectAOI, sizeof(rectAOI));
1081 
1082  if (nRet == IS_SUCCESS) {
1083  width = rectAOI.s32Width;
1084  height = rectAOI.s32Height;
1085 
1086  // get current colormode
1087  int colormode = is_SetColorMode(m_hCamera, IS_GET_COLOR_MODE);
1088 
1089  if(colormode == IS_CM_BGR5_PACKED) {
1090  is_SetColorMode(m_hCamera, IS_CM_BGR565_PACKED);
1091  colormode = IS_CM_BGR565_PACKED;
1092  std::cout << "uEye color format 'IS_CM_BGR5_PACKED' actually not supported by vpUeyeGrabber, patched to 'IS_CM_BGR565_PACKED'" << std::endl;
1093  }
1094 
1095  // fill memorybuffer properties
1096  ZeroMemory (&m_BufferProps, sizeof(m_BufferProps));
1097  m_BufferProps.width = width;
1098  m_BufferProps.height = height;
1099  m_BufferProps.bitspp = getBitsPerPixel(colormode);
1100 
1101  // Reallocate image buffers
1102  allocImages();
1103 
1104  if (m_verbose) {
1105  std::cout << "Capture ready set up." << std::endl;
1106  }
1107  }
1108  return 0;
1109  }
1110 
1111  void setVerbose(bool verbose)
1112  {
1113  m_verbose = verbose;
1114  }
1115 
1116 private:
1117  HIDS m_hCamera; // handle to camera
1118  INT m_nMemoryId; // grabber memory - buffer ID
1119  INT m_nColorMode; // Y8/RGB16/RGB24/REG32
1120  INT m_nBitsPerPixel; // number of bits needed store one pixel
1121  int m_activeCameraSelected;
1122  SENSORINFO m_SensorInfo; // sensor information struct
1123  CAMINFO m_CamInfo; // Camera (Board)info
1124  UEYE_CAMERA_INFO m_CamListInfo;
1125  char *m_pLastBuffer;
1126  CameraList *m_cameraList;
1127  struct sBufferProps m_BufferProps;
1128  struct sCameraProps m_CameraProps;
1129  UEYE_IMAGE m_Images[IMAGE_COUNT]; // uEye frame buffer array
1130  bool m_bLive; // live or snapshot indicator
1131  bool m_bLiveStarted; // live mode is started
1132  bool m_verbose;
1133  /* event waiting for */
1134  int m_event;
1135 #ifndef __linux__
1136  /* on windows we need an Event handle member */
1137  HANDLE m_hEvent;
1138 #endif
1139  vpImage< vpRGBa > m_I_temp; // Temp image used for Bayer conversion
1140 };
1141 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
1142 
1143 /*
1144  **********************************************************************************************
1145  */
1146 
1153  : m_impl(new vpUeyeGrabberImpl())
1154 {
1155 
1156 }
1157 
1162 {
1163  delete m_impl;
1164 }
1165 
1187 void vpUeyeGrabber::acquire(vpImage<unsigned char> &I, double *timestamp_camera, std::string *timestamp_system)
1188 {
1189  m_impl->acquire(I, timestamp_camera, timestamp_system);
1190 }
1191 
1212 void vpUeyeGrabber::acquire(vpImage<vpRGBa> &I, double *timestamp_camera, std::string *timestamp_system)
1213 {
1214  m_impl->acquire(I, timestamp_camera, timestamp_system);
1215 }
1216 
1223 {
1224  return m_impl->getActiveCameraModel();
1225 }
1226 
1233 {
1234  return m_impl->getActiveCameraSerialNumber();
1235 }
1236 
1244 std::vector<unsigned int> vpUeyeGrabber::getCameraIDList() const
1245 {
1246  return m_impl->getCameraIDList();
1247 }
1248 
1256 std::vector<std::string> vpUeyeGrabber::getCameraModelList() const
1257 {
1258  return m_impl->getCameraModelList();
1259 }
1260 
1268 std::vector<std::string> vpUeyeGrabber::getCameraSerialNumberList() const
1269 {
1270  return m_impl->getCameraSerialNumberList();
1271 }
1272 
1280 {
1281  return m_impl->getFramerate();
1282 }
1283 
1291 unsigned int vpUeyeGrabber::getFrameHeight() const
1292 {
1293  return m_impl->getFrameHeight();
1294 }
1295 
1303 unsigned int vpUeyeGrabber::getFrameWidth() const
1304 {
1305  return m_impl->getFrameWidth();
1306 }
1307 
1308 
1313 {
1314  return m_impl->isConnected();
1315 }
1316 
1322 void vpUeyeGrabber::loadParameters(const std::string &filename)
1323 {
1324  m_impl->loadParameters(filename);
1325 }
1326 
1332 {
1333  m_impl->open(I);
1334 }
1335 
1341 {
1342  m_impl->open(I);
1343 }
1344 
1350 bool vpUeyeGrabber::setActiveCamera(unsigned int cam_index)
1351 {
1352  return (m_impl->setActiveCamera(cam_index) ? false : true);
1353 }
1354 
1370 bool vpUeyeGrabber::setColorMode(const std::string &color_mode)
1371 {
1372  return (m_impl->setColorMode(color_mode) ? false : true);
1373 }
1374 
1388 bool vpUeyeGrabber::setExposure(bool auto_exposure, double exposure_ms)
1389 {
1390  return (m_impl->setExposure(auto_exposure, exposure_ms) ? false : true);
1391 }
1392 
1423 bool vpUeyeGrabber::setFrameRate(bool auto_frame_rate, double manual_frame_rate_hz)
1424 {
1425  return (m_impl->setFrameRate(auto_frame_rate, manual_frame_rate_hz) ? false : true);
1426 }
1427 
1444 bool vpUeyeGrabber::setGain(bool auto_gain, int master_gain, bool gain_boost)
1445 {
1446  return (m_impl->setGain(auto_gain, master_gain, gain_boost) ? false : true);
1447 }
1448 
1460 {
1461  m_impl->setSubsampling(factor);
1462 }
1463 
1475 {
1476  m_impl->setWhiteBalance(auto_wb);
1477 }
1478 
1484 void vpUeyeGrabber::setVerbose(bool verbose)
1485 {
1486  m_impl->setVerbose(verbose);
1487 }
1488 
1489 #elif !defined(VISP_BUILD_SHARED_LIBS)
1490 // Work arround to avoid warning: libvisp_sensor.a(vpUeyeGrabber.cpp.o) has no symbols
1491 void dummy_vpUeyeGrabber(){};
1492 
1493 #endif
static void BGRToRGBa(unsigned char *bgr, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
void loadParameters(const std::string &filename)
void setWhiteBalance(bool auto_wb)
std::vector< std::string > getCameraSerialNumberList() const
void open(vpImage< unsigned char > &I)
void setSubsampling(int factor)
std::string getActiveCameraModel() const
bool setFrameRate(bool auto_frame_rate, double manual_frame_rate_hz=-1)
void resize(unsigned int h, unsigned int w)
resize the image : Image initialization
Definition: vpImage.h:800
static void RGBToRGBa(unsigned char *rgb, unsigned char *rgba, unsigned int size)
Type * bitmap
points toward the bitmap
Definition: vpImage.h:143
VISP_EXPORT double measureTimeSecond()
Definition: vpTime.cpp:158
static void BGRaToRGBa(unsigned char *bgra, unsigned char *rgba, unsigned int width, unsigned int height, bool flip=false)
error that can be emited by ViSP classes.
Definition: vpException.h:71
bool setColorMode(const std::string &color_mode)
bool setGain(bool auto_gain, int master_gain=-1, bool gain_boost=false)
static void GreyToRGBa(unsigned char *grey, unsigned char *rgba, unsigned int width, unsigned int height)
unsigned int getFrameWidth() const
static void RGBToGrey(unsigned char *rgb, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false)
unsigned int getFrameHeight() const
bool setActiveCamera(unsigned int cam_index)
std::vector< unsigned int > getCameraIDList() const
void setVerbose(bool verbose)
static void RGBaToGrey(unsigned char *rgba, unsigned char *grey, unsigned int width, unsigned int height, unsigned int nThreads=0)
static void demosaicRGGBToRGBaBilinear(const uint8_t *rggb, uint8_t *rgba, unsigned int width, unsigned int height, unsigned int nThreads=0)
void acquire(vpImage< unsigned char > &I, double *timestamp_camera=NULL, std::string *timestamp_system=NULL)
static void BGRToGrey(unsigned char *bgr, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
static void BGRaToGrey(unsigned char *bgra, unsigned char *grey, unsigned int width, unsigned int height, bool flip=false, unsigned int nThreads=0)
bool isConnected() const
virtual ~vpUeyeGrabber()
static bool checkFilename(const std::string &filename)
Definition: vpIoTools.cpp:802
double getFramerate() const
bool setExposure(bool auto_exposure, double exposure_ms=-1)
std::string getActiveCameraSerialNumber() const
std::vector< std::string > getCameraModelList() const