Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_uEye.cpp
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2015 (see file CONTACT for details)
5 Multimediale Systeme der Informationsverarbeitung
6 Institut fuer Informatik
7 Christian-Albrechts-Universitaet Kiel
8 
9 BIAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation; either version 2.1 of the License, or
12 (at your option) any later version.
13 
14 BIAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18 
19 You should have received a copy of the GNU Lesser General Public License
20 along with BIAS; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 
24 #include "VideoSource_uEye.hh"
25 #include <Base/Image/ImageIO.hh>
26 #include <stdio.h>
27 #include <Base/Image/ImageBase.hh>
28 #include <sstream>
29 #include <string>
30 
31 using namespace BIAS;
32 using namespace std;
33 
34 //#define USE_PROJECTOR_MODE
35 
36 #ifdef USE_PROJECTOR_MODE
37 # define UEYE_THREAD_DELAY 5000
38 #else
39 # define UEYE_THREAD_DELAY 1000
40 #endif
41 
42 std::vector<VideoSource_uEye::CuEye> VideoSource_uEye::cams_;
43 
44 template <typename T> T number_from_string(std::string const & s)
45 {
46  std::stringstream ss(s);
47  T result;
48  ss >> result;
49  return result;
50 }
51 
53 {
54  // use default values for uEye camera
55  SetSize(1280, 1024, 1);
57 
58  IsControllable_ = true;
59 
60  pixelClock_ = 0;
62 
63  imageBuffer_.resize(3, (char*)NULL);
64 
65  minContrast_ = 0; // [?]
66  maxContrast_ = 40;
67  minGain_= 0; // [dB]
68  maxGain_ = 56;
69  minShutter_ = 0; // [us]
70  maxShutter_ = 1000;
71 
72  camBufferId_ = 0;
73  camBuffer_ = NULL;
74 
75  consBufferIdx_ = 0;
76  prodBufferIdx_ = 0;
77 
78  bytesize_ = 0;
79 
80  triggerMode_ = IS_SET_TRIGGER_LO_HI;
81 
82  isMaster_ = false;
83  sem_init(&prodsem_, true, 0);
84  sem_init(&conssem_, true, 3);
85 }
86 
88 {
89 }
90 
92 {
93  return -1;
94 }
95 
96 int VideoSource_uEye::OpenDevice(const char *resource)
97 {
98 #ifdef BIAS_DEBUG
99  std::cout << "VideoSource_uEye::OpenDevice() : Open device " << resource << "..." << std::endl;
100 #endif
101  //int pNumCameras = 0;
102  int ret = -1;
103  if (cams_.size()==0) {
104  ScanBus();
105  }
106  bool found = false;
107  long long deviceId = number_from_string<long long>(resource);
108 
109  for (unsigned int i=0;i<cams_.size();i++) {
110  if (deviceId == cams_[i].deviceId) {
111  cam_ = cams_[i];
112  found = true;
113  break;
114  }
115  }
116  // Search for serial number
117  if (!found) {
118  for (unsigned int i=0;i<cams_.size();i++) {
119  long long curId = number_from_string<long long>(cams_[i].serNo);
120 #ifdef BIAS_DEBUG
121  std::cout << "- checking if camera " << cams_[i].serNo << " (#" << (curId % 10000)
122  << ") has device ID " << deviceId << std::endl << std::flush;
123 #endif
124  if (deviceId == curId || deviceId == (curId % 10000)) {
125  cam_ = cams_[i];
126 #ifdef BIAS_DEBUG
127  std::cout << "- found " << cam_.hCam << std::endl << std::flush;
128 #endif
129  found = true;
130  break;
131  }
132  }
133  }
134  if (found) {
135  HIDS camid = (HIDS) ((INT)cam_.hCam | IS_USE_DEVICE_ID);
136  ret = is_InitCamera (&camid, NULL);
137  if (ret == IS_STARTER_FW_UPLOAD_NEEDED)
138  {
139  // Time for the firmware upload = 25 seconds by default
140  INT nUploadTime = 25000;
141  is_GetDuration (cam_.hCam, IS_STARTER_FW_UPLOAD, &nUploadTime);
142  camid = (HIDS) ((INT)camid | IS_ALLOW_STARTER_FW_UPLOAD);
143  ret = is_InitCamera (&camid, NULL);
144  }
145  cam_.hCam = camid;
146  is_GetCameraInfo( cam_.hCam, &cam_.CamInfo);
147 
148  // Retrieve original image size
149  is_GetSensorInfo( cam_.hCam, &cam_.SensorInfo);
150 
151  SetSize(cam_.SensorInfo.nMaxWidth, cam_.SensorInfo.nMaxHeight, 1 );
152 
153  /** @todo Not all RGB modes are tested yet! */
154  if (GetColorModel() == ImageBase::CM_RGB) {
155  ret = is_SetColorMode(cam_.hCam, IS_CM_RGB8_PACKED);
156  if (ret != IS_SUCCESS) {
157  return ret;
158  }
159  } else {
160  ret = is_SetColorMode(cam_.hCam, IS_CM_SENSOR_RAW8);
161  if (ret != IS_SUCCESS) {
162  return ret;
163  }
164  switch (cam_.SensorInfo.nUpperLeftBayerPixel) {
165  case BAYER_PIXEL_RED:
167  break;
168  case BAYER_PIXEL_GREEN:
170  break;
171  case BAYER_PIXEL_BLUE:
173  break;
174  default:
176  break;
177  }
178  }
179 
180  UINT nRange[3];
181  memset(nRange, 0, sizeof(UINT)*3);
182 
183  // Get pixel clock range
184  ret = is_PixelClock(cam_.hCam, IS_PIXELCLOCK_CMD_GET_RANGE, (void*)nRange, sizeof(nRange));
185  if (ret == IS_SUCCESS) {
186  pixelClockMin_ = nRange[0];
187  pixelClockMax_ = nRange[1];
188  pixelClockInc_ = nRange[2];
189  }
190  ret = is_PixelClock(cam_.hCam, IS_PIXELCLOCK_CMD_GET_DEFAULT, (void*)&pixelClockDefault_, sizeof(UINT));
191  if (ret == IS_SUCCESS) {
192  if (pixelClock_ == 0) {
194  }
196  ret = is_PixelClock(cam_.hCam, IS_PIXELCLOCK_CMD_SET, (void*)&pixelClock_, sizeof(UINT));
197  }
198  ret = is_PixelClock(cam_.hCam, IS_PIXELCLOCK_CMD_GET, (void*)&pixelClock_, sizeof(UINT));
199 #ifdef BIAS_DEBUG
200  std::cout << "- clocks : min. " << pixelClockMin_ << ", max. " << pixelClockMax_
201  << ", def. " << pixelClockDefault_ << ", inc. " << pixelClockInc_
202  << ", val. " << pixelClock_ << std::endl << std::flush;
203 #endif
204  }
205 
206  double val;
207  ret = is_Exposure(cam_.hCam, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN, &val, sizeof(double));
208  minShutter_ = (float)val;
209  ret = is_Exposure(cam_.hCam, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX, &val, sizeof(double));
210  maxShutter_ = (float)val;
211 
212  /** @todo This depends only on exposure setting! */
213  if (ret == IS_SUCCESS) {
214  Active_ = true;
215  } else {
216  BIASERR("Failed to initialize camera!");
217  }
218 
219  // Apply default settings
220  double disable = 0.0;
221  is_SetAutoParameter(cam_.hCam, IS_SET_ENABLE_AUTO_FRAMERATE, &disable, 0);
222  is_SetAutoParameter(cam_.hCam, IS_SET_ENABLE_AUTO_GAIN, &disable, 0);
223  is_SetAutoParameter(cam_.hCam, IS_SET_ENABLE_AUTO_SHUTTER, &disable, 0);
224  is_SetAutoParameter(cam_.hCam, IS_SET_ENABLE_AUTO_WHITEBALANCE, &disable, 0);
225 
226  INT nGamma = 160;
227  INT nRet = is_Gamma(cam_.hCam, IS_GAMMA_CMD_SET, (void*) &nGamma, sizeof(nGamma));
228 
229  nRet = is_SetHWGainFactor (cam_.hCam, IS_SET_MASTER_GAIN_FACTOR, 100);
230  if (nRet != IS_SUCCESS) { ret = 1; }
231  nRet = is_SetHWGainFactor (cam_.hCam, IS_SET_RED_GAIN_FACTOR, 100); // 114
232  if (nRet != IS_SUCCESS) { ret = 1; }
233  nRet = is_SetHWGainFactor (cam_.hCam, IS_SET_GREEN_GAIN_FACTOR, 100);
234  if (nRet != IS_SUCCESS) { ret = 1; }
235  nRet = is_SetHWGainFactor (cam_.hCam, IS_SET_BLUE_GAIN_FACTOR, 100); // 229
236  if (nRet != IS_SUCCESS) { ret = 1; }
237 
238 #ifdef USE_PROJECTOR_MODE
239  // Set trigger settings for projector
240  long long curId = number_from_string<long long>(cam_.serNo);
241  // HACK : master camera
242  if (curId % 10000 == 9309) {
243  isMaster_ = true;
244  is_SetExternalTrigger(cam_.hCam, IS_SET_TRIGGER_SOFTWARE);
245 #ifdef BIAS_DEBUG
246  std::cout << "- found TESTO master camera : Software trigger, flash pulse for"
247  << " projector and slave camera sync" << std::endl << std::flush;
248 #endif
249  IO_FLASH_PARAMS flashparam;
250  flashparam.s32Delay = 0;
251  flashparam.u32Duration = 0;
252  is_IO(cam_.hCam, IS_IO_CMD_FLASH_SET_PARAMS, (void*) &flashparam, sizeof(IO_FLASH_PARAMS));
253  unsigned int flashmode = IO_FLASH_MODE_TRIGGER_HI_ACTIVE;
254  is_IO(cam_.hCam, IS_IO_CMD_FLASH_SET_MODE, (void*) &flashmode, sizeof(flashmode));
255  }
256  // slave camera
257  else if (curId % 10000 == 6321) {
258 #ifdef BIAS_DEBUG
259  std::cout << "- found TESTO slave camera : Triggered by flash signal of"
260  << " master camera" << std::endl << std::flush;
261 #endif
262  is_SetExternalTrigger(cam_.hCam, IS_SET_TRIGGER_LO_HI);
263  }
264 #endif
265 
266  return ret;
267 }
268 
270 {
271  int ret = is_ExitCamera(cam_.hCam);
272  Active_ = false;
273  return ret;
274 }
275 
277 {
279  if (trigger) {
280  is_SetExternalTrigger(cam_.hCam, triggerMode_);
281  } else {
282  is_SetExternalTrigger(cam_.hCam, IS_SET_TRIGGER_OFF);
283  }
284 }
285 
287  switch (mode) {
288  case 0:
289  triggerMode_ = IS_SET_TRIGGER_LO_HI;
290  break;
291  case 1:
292  triggerMode_ = IS_SET_TRIGGER_HI_LO;
293  break;
294  default:
295  BIASERR("Trigger mode " << mode << " is not supported!");
296  break;
297  }
298 }
299 
301 {
302  int ret = is_SetTriggerDelay (cam_.hCam, delay);
303  if (ret != IS_SUCCESS) {
304  BIASERR("Valid delay range is [" << is_SetTriggerDelay(cam_.hCam, IS_GET_MIN_TRIGGER_DELAY)
305  << ", " << is_SetTriggerDelay(cam_.hCam, IS_GET_MAX_TRIGGER_DELAY)
306  << "] with step " << is_SetTriggerDelay(cam_.hCam, IS_GET_TRIGGER_DELAY_GRANULARITY));
307  }
308 }
309 
311 {
312  return SetExposure(exptime);
313 }
314 
316 {
317  return GetExposure();
318 }
319 
321 {
322  double val = (double)exptime;
323  return is_Exposure(cam_.hCam, IS_EXPOSURE_CMD_SET_EXPOSURE, (void*)&val, sizeof(double));
324 }
325 
327 {
328  double val;
329  is_Exposure(cam_.hCam, IS_EXPOSURE_CMD_GET_EXPOSURE, (void*)&val, sizeof(double));
330  return (float)val;
331 }
332 
334 {
335  return true;
336 }
337 
339 {
340  return false; // true;
341 }
342 
343 void VideoSource_uEye::SetAutoGain(bool autoGain)
344 {
345  double dEnable = 0.0;
346  if (autoGain) {
347  dEnable = 1.0;
348  }
349  is_SetAutoParameter(cam_.hCam, IS_SET_ENABLE_AUTO_GAIN, &dEnable, 0);
350  double soll = 128;
351  is_SetAutoParameter (cam_.hCam, IS_SET_AUTO_REFERENCE, &soll, 0);
352 }
353 
355  return false;
356 }
357 
359 {
360  //double gain = (double)g;
361  //ret = is_SetAutoParameter (cam_.hCam, IS_SET_AUTO_REFERENCE, &gain, 0);
362  return 0;
363 }
364 
366 {
367  float gain = 0.0f;
368  //if (m_bIsInited)
369  // gain = (float)m_ueye.GetGain();
370  //else
371  // gain = 0.0f;
372  return gain;
373 }
374 
376  return true;
377 }
378 
379 int VideoSource_uEye::SetWhiteBalance(float rvalue,float bvalue) {
380  float bmin,bmax;
381  GetWhiteBalanceRange(bmin,bmax);
382  rvalue += 0.5f; // now in 0..1
383  rvalue = (1.0f-rvalue) * bmin + rvalue * bmax;
384  is_SetHWGainFactor (cam_.hCam, IS_SET_RED_GAIN_FACTOR, (int)rvalue);
385  //is_SetHWGainFactor (cam_.hCam, IS_SET_GREEN_GAIN_FACTOR, 100);
386  bvalue += 0.5f; // now in 0..1
387  bvalue = (1.0f-bvalue) * bmin + bvalue * bmax;
388  is_SetHWGainFactor (cam_.hCam, IS_SET_BLUE_GAIN_FACTOR, (int)bvalue);
389  return 0;
390 }
391 
392 int VideoSource_uEye::GetWhiteBalance(float &rvalue,float &bvalue) {
393  rvalue = (float)is_SetHWGainFactor (cam_.hCam, IS_GET_RED_GAIN_FACTOR, 0);
394  bvalue = (float)is_SetHWGainFactor (cam_.hCam, IS_GET_BLUE_GAIN_FACTOR, 0);
395  return 0;
396 }
397 
399  double enable = 1.0;
400  is_SetAutoParameter(cam_.hCam, IS_SET_ENABLE_AUTO_WHITEBALANCE, &enable, 0);
401  is_SetAutoParameter(cam_.hCam, IS_SET_AUTO_WB_ONCE, &enable, 0);
402 }
403 
404 void VideoSource_uEye::GetWhiteBalanceRange(float &bmin, float &bmax)
405 {
406  bmin = (float)is_SetHWGainFactor (cam_.hCam, IS_INQUIRE_RED_GAIN_FACTOR, 0);
407  bmax = (float)is_SetHWGainFactor (cam_.hCam, IS_INQUIRE_RED_GAIN_FACTOR, 100);
408 }
409 
411 {
412  return true;
413 }
414 
416 {
417  int nGamma = (int)bright;
418  int ret = is_Gamma(cam_.hCam, IS_GAMMA_CMD_SET, (void*) &nGamma, sizeof(int));
419  return ret;
420 }
421 
423 {
424  int nGamma;
425  is_Gamma(cam_.hCam, IS_GAMMA_CMD_GET, (void*) &nGamma, sizeof(nGamma));
426  return (float)nGamma;
427 }
428 
429 void VideoSource_uEye::GetBrightnessRange(float &min, float &max)
430 {
431  min = 100.0f; max = 260.0f;
432 }
433 
435 {
436  if (IS_SET_HW_GAMMA_ON == is_SetHardwareGamma(cam_.hCam, IS_GET_HW_SUPPORTED_GAMMA)) {
437  return ( IS_SET_HW_GAMMA_ON == is_SetHardwareGamma (cam_.hCam, IS_GET_HW_GAMMA) );
438  }
439  return false;
440 }
441 
442 void VideoSource_uEye::SetAutoBrightness(bool autoBrightness)
443 {
444  if (IS_SET_HW_GAMMA_ON == is_SetHardwareGamma(cam_.hCam, IS_GET_HW_SUPPORTED_GAMMA)) {
445  if (autoBrightness) {
446  is_SetHardwareGamma (cam_.hCam, IS_SET_HW_GAMMA_ON);
447  } else {
448  is_SetHardwareGamma (cam_.hCam, IS_SET_HW_GAMMA_OFF);
449  }
450  }
451 }
452 
454 {
455 #ifdef USE_PROJECTOR_MODE
456  if (isMaster_) {
457  if (is_FreezeVideo(cam_.hCam, IS_DONT_WAIT) != 0) {
458  BIASWARN("Master camera soft trigger failed!");
459  }
460  biassleep(2); // wait for 2 sec to prevent hardware damage
461  }
462 #endif
463  sem_wait(&prodsem_);
465  consBufferIdx_ = (consBufferIdx_ + 1) % imageBuffer_.size();
466  sem_post(&conssem_);
467  return 0;
468 }
469 
471 {
472  if (!Image.IsEmpty()) {
473  Image.Release();
474  }
476  Image.SetColorModel(GetColorModel());
477  return 0;
478 }
479 
481 {
482  switch (mode) {
483  case 0: mode = IS_EDGE_EN_DISABLE; break;
484  case 1: mode = IS_EDGE_EN_WEAK; break;
485  case 2: mode = IS_EDGE_EN_STRONG; break;
486  default: mode = IS_EDGE_EN_DISABLE;
487  }
488  return 0; // m_ueye.SetEdgeEnhancement(mode);
489 }
490 
492 {
493  bytesize_ = GetWidth() * GetHeight();
494  camBuffer_ = new char[bytesize_];
495  is_SetAllocatedImageMem(cam_.hCam, GetWidth(), GetHeight(), 8, camBuffer_, &camBufferId_);
496  is_SetImageMem(cam_.hCam, camBuffer_, camBufferId_);
497  for (unsigned int i = 0; i < imageBuffer_.size(); i++) {
498  imageBuffer_[i] = new char[ bytesize_ ];
499  }
500 #ifdef WIN32
501  hEvent_ = CreateEvent(NULL, FALSE, FALSE, NULL);
502  is_InitEvent(cam_.hCam, hEvent_, IS_SET_EVENT_FRAME);
503  is_EnableEvent(cam_.hCam, IS_SET_EVENT_FRAME);
504 #else
505  is_EnableEvent(cam_.hCam, IS_SET_EVENT_FRAME);
506 #endif
507  grabThread_.start();
508  if (is_CaptureVideo(cam_.hCam, IS_WAIT) != 0) {
509  BIASERR("Failed to start capture!");
510  }
511  return 0;
512 }
513 
515 {
516  grabThread_.stop();
517 #ifdef WIN32
518  is_DisableEvent(cam_.hCam, IS_SET_EVENT_FRAME);
519  is_ExitEvent(cam_.hCam, IS_SET_EVENT_FRAME);
520  CloseHandle(hEvent_);
521 #else
522  is_DisableEvent(cam_.hCam, IS_SET_EVENT_FRAME);
523 #endif
524  if (is_CaptureVideo(cam_.hCam, IS_GET_LIVE) != 0) {
525  if (is_StopLiveVideo(cam_.hCam, IS_FORCE_VIDEO_STOP) != 0) {
526  BIASERR("Failed to stop capture!");
527  }
528  }
529  delete[] camBuffer_;
530  camBuffer_ = NULL;
531  for (unsigned int i = 0; i <imageBuffer_.size(); i++) {
532  delete[] imageBuffer_[i];
533  imageBuffer_[i] = NULL;
534  }
535  return 0;
536 }
537 
539 {
540  return pixelClock_;
541 }
542 
544 {
545  pixelClock_ = value;
546 }
547 
550 {
551  return number_from_string<long long>(a.serNo) > number_from_string<long long>(b.serNo);
552 }
553 
555 {
556 #ifdef BIAS_DEBUG
557  std::cout << "VideoSource_uEye::ScanBus() : Retrieving cameras..." << std::endl;
558 #endif
559  cams_.clear();
560  int nCameraCount = 0;
561  if (is_GetNumberOfCameras(&nCameraCount) == IS_SUCCESS) {
562  PUEYE_CAMERA_LIST pucl = (PUEYE_CAMERA_LIST)new char[sizeof(DWORD) + nCameraCount * sizeof(UEYE_CAMERA_INFO)];
563  pucl->dwCount = nCameraCount;
564  if (is_GetCameraList(pucl) == IS_SUCCESS) {
565  for (int i = 0; i < nCameraCount; i++) {
566  CuEye cam;
567  // Type = 0 -> USB, Type = 1 -> ETH
568  int Type = (pucl->uci[i].dwDeviceID >= 1000);
569  // If ETH camera
570  if (Type == 1) {
571  if (pucl->uci[i].dwInUse == 0) {
572  // Check if starter firmware is compatible to the driver (only SE)
573  if ((pucl->uci[i].dwStatus & DEVSTS_INCLUDED_STARTER_FIRMWARE_INCOMPATIBLE) != 0) {
574  cam.available = true;
575  } else {
576  cam.available = true;
577  }
578  } else {
579  cam.available = false;
580  }
581  }
582  // If USB camera
583  else if (Type == 0) {
584  bool FirmwareDownloadSupported = (pucl->uci[i].dwStatus & FIRMWARE_DOWNLOAD_NOT_SUPPORTED) == 0;
585  bool InterfaceSpeedSupported = (pucl->uci[i].dwStatus & INTERFACE_SPEED_NOT_SUPPORTED) == 0;
586  // If device is not used
587  if(pucl->uci[i].dwInUse == 0) {
588  if(FirmwareDownloadSupported && InterfaceSpeedSupported) {
589  cam.available = true;
590  } else {
591  cam.available = false;
592  }
593  } else {
594  cam.available = false;
595  }
596  }
597  cam.camId = pucl->uci[i].dwCameraID;
598  cam.deviceId = pucl->uci[i].dwDeviceID;
599  cam.model = pucl->uci[i].Model;
600  cam.serNo = pucl->uci[i].SerNo;
601  cam.name = cam.serNo; // QString::number(cam.deviceId);
602  cam.hCam = cam.deviceId;
603 #ifdef BIAS_DEBUG
604  std::cout << "- found camera " << cam.model << " "<< cam.serNo << " with ID "
605  << cam.deviceId << " " << cam.camId << std::endl;
606 #endif
607  cams_.push_back(cam);
608  }
609  } else {
610  BIASERR("Failed to retrieve camera list!");
611  }
612  // sort cameras according to their serial number
613  std::sort(cams_.begin(), cams_.end(), sortBySerial_);
614  delete pucl;
615  } else {
616  BIASERR("Failed to retrieve number of cameras!");
617  }
618  return nCameraCount;
619 }
620 
621 std::vector<std::string> VideoSource_uEye::GetDevices()
622 {
623  if (cams_.empty()) {
624  int numCams = ScanBus();
625  if (numCams == 0) {
626  BIASERR("No uEye cameras found!");
627  }
628  }
629  std::vector<std::string> ret;
630  for (unsigned int i=0;i<cams_.size();i++) {
631  ret.push_back(cams_[i].name);
632  }
633  return ret;
634 }
635 
637 {
638  stopRequest_ = false;
639  isRunning_ = false;
640  parent_ = parent;
641  thread_= new pthread_t;
642 }
643 
645 {
646  if (isRunning()) {
647  stop();
648  }
649  delete thread_;
650 }
651 
653 {
654  isRunning_ = true;
655  stopRequest_= false;
656  pthread_create(thread_, NULL, VideoSource_uEye::UeyeGrabThread::run, (void*)this);
657 }
658 
660 {
661  stopRequest_ = true;
662  sem_post(&parent_->conssem_);
663  pthread_join(*thread_, NULL);
664  isRunning_ = false;
665 }
666 
668 {
669  return isRunning_;
670 }
671 
673 {
675  VideoSource_uEye *cam = p->parent_;
676  while (!p->stopRequest_) {
677  bool grabOk = false;
678 #ifdef WIN32
679  DWORD dwRet = WaitForSingleObject(parent_->hEvent_, UEYE_THREAD_DELAY);
680  if (dwRet == WAIT_TIMEOUT) {
681  BIASWARN("Timeout");
682  } else if (dwRet == WAIT_OBJECT_0) {
683  grabOk = true;
684  }
685 #else
686  INT nRet = is_WaitEvent(cam->cam_.hCam, IS_SET_EVENT_FRAME, UEYE_THREAD_DELAY);
687  if (nRet == IS_TIMED_OUT) {
688  BIASWARN("Timeout");
689  //is_ForceTrigger(cam->cam_.hCam);
690  } else if (nRet == IS_SUCCESS) {
691  grabOk = true;
692  }
693 #endif
694  grabOk = true; // HACK : grab even when timeout occurred
695  if (grabOk) {
696  sem_wait(&cam->conssem_);
697  memcpy(cam->imageBuffer_[cam->prodBufferIdx_], cam->camBuffer_, cam->bytesize_);
698  cam->prodBufferIdx_ = (cam->prodBufferIdx_ + 1) % cam->imageBuffer_.size();
699  sem_post(&cam->prodsem_);
700  }
701  }
702  return NULL;
703 }
virtual void SetSize(int w, int h, int bytesperpixel=1)
Set image size and number of bytes per pixel (e.g.
Bayer_GRBG, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:145
virtual bool HasControlShutter()
virtual bool GetAutoBrightness()
virtual void SetExternalTriggerMode(unsigned int mode)
gray values, 1 channel
Definition: ImageBase.hh:130
int OpenDevice()
selects the first available device to open (e.g.
bool IsControllable_
Must be initialized be the derived classes.
virtual void OnePushWhiteBalance()
bool IsEmpty() const
check if ImageData_ points to allocated image buffer or not
Definition: ImageBase.hh:245
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
Definition: ImageBase.cpp:827
virtual float GetBrightness()
Get brightness as value in interval [0, 100]. */.
virtual void SetExternalTrigger(bool trigger=true)
Specify if there is an external trigger to be used.
void SetColorModel(EColorModel Model)
Definition: ImageBase.hh:561
int SetEdgeEnhancement(int mode)
Use mode 0 to disable, 1 for weak, and 2 for strong enhancement.
int InitImage(BIAS::ImageBase &Image)
Bayer_RGGB, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:143
virtual bool HasControlBrightness()
virtual int SetGain(float g)
Set gain in dB.
int PreGrab()
Do last preparations before grabbing (e.g. start ISO transfer)
virtual int SetBrightness(float bright)
Set brightness as value in interval [0, 100]. */.
int PostGrab()
Stop anything started in PreGrab()
int GetHeight() const
std::vector< std::string > GetDevices()
Bayer_BGGR, 1 channel RGB image Bayer tile.
Definition: ImageBase.hh:146
virtual int SetColorModel(BIAS::ImageBase::EColorModel mode)
Select colormodel to use.
virtual int GetWhiteBalance(float &rvalue, float &bvalue)
Get white balance as values in interval [0, 100]. */.
color values, 3 channels, order: red,green,blue
Definition: ImageBase.hh:131
Defines a structure describing a uEye camera instance.
UeyeGrabThread(VideoSource_uEye *parent)
virtual void GetWhiteBalanceRange(float &bmin, float &bmax)
double minContrast_
Feature ranges.
The image template class for specific storage types.
Definition: Image.hh:78
static bool sortBySerial_(const VideoSource_uEye::CuEye a, const VideoSource_uEye::CuEye b)
bool Active_
Active flag is set in PreGrab() und unset in PostGrab()
Defines a thread for asynchronous uEye camera capturing.
void Release(const bool reset_storage_type=false)
Free the allocated data structures Hands off: Do !!NOT!! change the default of reset_storage_type: Im...
Definition: ImageBase.cpp:350
static std::vector< CuEye > cams_
void Init(unsigned int width, unsigned int height, unsigned int nChannels=1, enum EStorageType storageType=ST_unsignedchar, const bool interleaved=true)
Initialize image size and channels.
Definition: ImageBase.cpp:229
virtual int SetWhiteBalance(float rvalue, float bvalue)
Set white balance as values in interval [0, 100]. */.
int SetExposure(float exptime)
virtual void SetAutoBrightness(bool autoBrightness)
virtual void SetExternalTrigger(bool trigger=true)
Specify if there is an external trigger to be used.
(8bit) unsigned char image storage type
Definition: ImageBase.hh:112
BIAS::ImageBase::EColorModel GetColorModel() const
virtual void SetAutoGain(bool autoGain)
This class extends VideoSource for the use of IDS uEye devices.
int GrabSingle(BIAS::Camera< unsigned char > &image)
void SetPixelClock_(int value)
virtual float GetShutter()
Get shutter (exposure time) in seconds.
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
virtual void SetExternalTriggerDelay(unsigned int delay)
virtual bool HasControlWhiteBalance()
std::vector< char * > imageBuffer_
virtual void GetBrightnessRange(float &min, float &max)
virtual int SetShutter(float exptime)
Set shutter (exposure time) in seconds.
virtual float GetGain()
Get gain in dB.