24 #include "VideoSource_uEye.hh"
25 #include <Base/Image/ImageIO.hh>
27 #include <Base/Image/ImageBase.hh>
36 #ifdef USE_PROJECTOR_MODE
37 # define UEYE_THREAD_DELAY 5000
39 # define UEYE_THREAD_DELAY 1000
44 template <
typename T> T number_from_string(std::string
const & s)
46 std::stringstream ss(s);
99 std::cout <<
"VideoSource_uEye::OpenDevice() : Open device " << resource <<
"..." << std::endl;
103 if (
cams_.size()==0) {
107 long long deviceId = number_from_string<long long>(resource);
109 for (
unsigned int i=0;i<
cams_.size();i++) {
110 if (deviceId ==
cams_[i].deviceId) {
118 for (
unsigned int i=0;i<
cams_.size();i++) {
119 long long curId = number_from_string<long long>(
cams_[i].serNo);
121 std::cout <<
"- checking if camera " <<
cams_[i].serNo <<
" (#" << (curId % 10000)
122 <<
") has device ID " << deviceId << std::endl << std::flush;
124 if (deviceId == curId || deviceId == (curId % 10000)) {
127 std::cout <<
"- found " <<
cam_.
hCam << std::endl << std::flush;
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)
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);
155 ret = is_SetColorMode(
cam_.
hCam, IS_CM_RGB8_PACKED);
156 if (ret != IS_SUCCESS) {
160 ret = is_SetColorMode(
cam_.
hCam, IS_CM_SENSOR_RAW8);
161 if (ret != IS_SUCCESS) {
165 case BAYER_PIXEL_RED:
168 case BAYER_PIXEL_GREEN:
171 case BAYER_PIXEL_BLUE:
181 memset(nRange, 0,
sizeof(UINT)*3);
184 ret = is_PixelClock(
cam_.
hCam, IS_PIXELCLOCK_CMD_GET_RANGE, (
void*)nRange,
sizeof(nRange));
185 if (ret == IS_SUCCESS) {
191 if (ret == IS_SUCCESS) {
202 <<
", val. " <<
pixelClock_ << std::endl << std::flush;
207 ret = is_Exposure(
cam_.
hCam, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MIN, &val,
sizeof(
double));
209 ret = is_Exposure(
cam_.
hCam, IS_EXPOSURE_CMD_GET_EXPOSURE_RANGE_MAX, &val,
sizeof(
double));
213 if (ret == IS_SUCCESS) {
216 BIASERR(
"Failed to initialize camera!");
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);
227 INT nRet = is_Gamma(
cam_.
hCam, IS_GAMMA_CMD_SET, (
void*) &nGamma,
sizeof(nGamma));
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);
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);
236 if (nRet != IS_SUCCESS) { ret = 1; }
238 #ifdef USE_PROJECTOR_MODE
240 long long curId = number_from_string<long long>(
cam_.
serNo);
242 if (curId % 10000 == 9309) {
244 is_SetExternalTrigger(
cam_.
hCam, IS_SET_TRIGGER_SOFTWARE);
246 std::cout <<
"- found TESTO master camera : Software trigger, flash pulse for"
247 <<
" projector and slave camera sync" << std::endl << std::flush;
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));
257 else if (curId % 10000 == 6321) {
259 std::cout <<
"- found TESTO slave camera : Triggered by flash signal of"
260 <<
" master camera" << std::endl << std::flush;
262 is_SetExternalTrigger(
cam_.
hCam, IS_SET_TRIGGER_LO_HI);
282 is_SetExternalTrigger(
cam_.
hCam, IS_SET_TRIGGER_OFF);
295 BIASERR(
"Trigger mode " << mode <<
" is not supported!");
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));
322 double val = (double)exptime;
323 return is_Exposure(
cam_.
hCam, IS_EXPOSURE_CMD_SET_EXPOSURE, (
void*)&val,
sizeof(
double));
329 is_Exposure(
cam_.
hCam, IS_EXPOSURE_CMD_GET_EXPOSURE, (
void*)&val,
sizeof(
double));
345 double dEnable = 0.0;
349 is_SetAutoParameter(
cam_.
hCam, IS_SET_ENABLE_AUTO_GAIN, &dEnable, 0);
351 is_SetAutoParameter (
cam_.
hCam, IS_SET_AUTO_REFERENCE, &soll, 0);
383 rvalue = (1.0f-rvalue) * bmin + rvalue * bmax;
384 is_SetHWGainFactor (
cam_.
hCam, IS_SET_RED_GAIN_FACTOR, (
int)rvalue);
387 bvalue = (1.0f-bvalue) * bmin + bvalue * bmax;
388 is_SetHWGainFactor (
cam_.
hCam, IS_SET_BLUE_GAIN_FACTOR, (
int)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);
400 is_SetAutoParameter(
cam_.
hCam, IS_SET_ENABLE_AUTO_WHITEBALANCE, &enable, 0);
401 is_SetAutoParameter(
cam_.
hCam, IS_SET_AUTO_WB_ONCE, &enable, 0);
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);
417 int nGamma = (int)bright;
418 int ret = is_Gamma(
cam_.
hCam, IS_GAMMA_CMD_SET, (
void*) &nGamma,
sizeof(
int));
425 is_Gamma(
cam_.
hCam, IS_GAMMA_CMD_GET, (
void*) &nGamma,
sizeof(nGamma));
426 return (
float)nGamma;
431 min = 100.0f; max = 260.0f;
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) );
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);
448 is_SetHardwareGamma (
cam_.
hCam, IS_SET_HW_GAMMA_OFF);
455 #ifdef USE_PROJECTOR_MODE
457 if (is_FreezeVideo(
cam_.
hCam, IS_DONT_WAIT) != 0) {
458 BIASWARN(
"Master camera soft trigger failed!");
465 consBufferIdx_ = (consBufferIdx_ + 1) %
imageBuffer_.size();
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;
497 for (
unsigned int i = 0; i <
imageBuffer_.size(); i++) {
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);
505 is_EnableEvent(
cam_.
hCam, IS_SET_EVENT_FRAME);
508 if (is_CaptureVideo(
cam_.
hCam, IS_WAIT) != 0) {
509 BIASERR(
"Failed to start capture!");
518 is_DisableEvent(
cam_.
hCam, IS_SET_EVENT_FRAME);
519 is_ExitEvent(
cam_.
hCam, IS_SET_EVENT_FRAME);
520 CloseHandle(hEvent_);
522 is_DisableEvent(
cam_.
hCam, IS_SET_EVENT_FRAME);
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!");
551 return number_from_string<long long>(a.
serNo) > number_from_string<long long>(b.
serNo);
557 std::cout <<
"VideoSource_uEye::ScanBus() : Retrieving cameras..." << std::endl;
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++) {
568 int Type = (pucl->uci[i].dwDeviceID >= 1000);
571 if (pucl->uci[i].dwInUse == 0) {
573 if ((pucl->uci[i].dwStatus & DEVSTS_INCLUDED_STARTER_FIRMWARE_INCOMPATIBLE) != 0) {
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;
587 if(pucl->uci[i].dwInUse == 0) {
588 if(FirmwareDownloadSupported && InterfaceSpeedSupported) {
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;
604 std::cout <<
"- found camera " << cam.
model <<
" "<< cam.
serNo <<
" with ID "
607 cams_.push_back(cam);
610 BIASERR(
"Failed to retrieve camera list!");
616 BIASERR(
"Failed to retrieve number of cameras!");
626 BIASERR(
"No uEye cameras found!");
629 std::vector<std::string> ret;
630 for (
unsigned int i=0;i<
cams_.size();i++) {
631 ret.push_back(
cams_[i].name);
662 sem_post(&parent_->conssem_);
663 pthread_join(*thread_, NULL);
679 DWORD dwRet = WaitForSingleObject(parent_->hEvent_, UEYE_THREAD_DELAY);
680 if (dwRet == WAIT_TIMEOUT) {
682 }
else if (dwRet == WAIT_OBJECT_0) {
686 INT nRet = is_WaitEvent(cam->
cam_.
hCam, IS_SET_EVENT_FRAME, UEYE_THREAD_DELAY);
687 if (nRet == IS_TIMED_OUT) {
690 }
else if (nRet == IS_SUCCESS) {
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.
virtual bool HasControlShutter()
virtual bool GetAutoBrightness()
unsigned int pixelClockDefault_
virtual void SetExternalTriggerMode(unsigned int mode)
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
void CopyIn_NoInit(void *data)
Take some data and fill it into the Image.
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)
int SetEdgeEnhancement(int mode)
Use mode 0 to disable, 1 for weak, and 2 for strong enhancement.
int InitImage(BIAS::ImageBase &Image)
virtual bool GetAutoGain()
Bayer_RGGB, 1 channel RGB image Bayer tile.
virtual bool HasControlBrightness()
virtual bool HasControlGain()
virtual int SetGain(float g)
Set gain in dB.
unsigned int pixelClockInc_
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()
std::vector< std::string > GetDevices()
Bayer_BGGR, 1 channel RGB image Bayer tile.
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]. */.
unsigned int pixelClockMax_
color values, 3 channels, order: red,green,blue
Defines a structure describing a uEye camera instance.
unsigned int pixelClockMin_
UeyeGrabThread(VideoSource_uEye *parent)
virtual void GetWhiteBalanceRange(float &bmin, float &bmax)
double minContrast_
Feature ranges.
VideoSource_uEye * parent_
The image template class for specific storage types.
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...
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.
virtual int SetWhiteBalance(float rvalue, float bvalue)
Set white balance as values in interval [0, 100]. */.
int SetExposure(float exptime)
static void * run(void *parent)
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
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)
UeyeGrabThread grabThread_
virtual float GetShutter()
Get shutter (exposure time) in seconds.
int GetPixelClock_() const
This is the base class for images in BIAS.
virtual void SetExternalTriggerDelay(unsigned int delay)
virtual bool HasControlWhiteBalance()
std::vector< char * > imageBuffer_
virtual ~UeyeGrabThread()
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.