Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048 #ifndef UEYE_CAM_DRIVER_HPP_
00049 #define UEYE_CAM_DRIVER_HPP_
00050
00051
00052 #include <ueye.h>
00053 #include <string>
00054 #include <thread>
00055 #include <functional>
00056 #include "logging_macros.hpp"
00057
00058
00059 namespace ueye_cam {
00060
00061
00062 #define CAP(val, min, max) \
00063 if (val < min) { \
00064 val = min; \
00065 } else if (val > max) { \
00066 val = max; \
00067 }
00068
00069 #define IS_SUBSAMPLING_2X (IS_SUBSAMPLING_2X_VERTICAL | IS_SUBSAMPLING_2X_HORIZONTAL)
00070 #define IS_SUBSAMPLING_4X (IS_SUBSAMPLING_4X_VERTICAL | IS_SUBSAMPLING_4X_HORIZONTAL)
00071 #define IS_SUBSAMPLING_8X (IS_SUBSAMPLING_8X_VERTICAL | IS_SUBSAMPLING_8X_HORIZONTAL)
00072 #define IS_SUBSAMPLING_16X (IS_SUBSAMPLING_16X_VERTICAL | IS_SUBSAMPLING_16X_HORIZONTAL)
00073
00074 #define IS_BINNING_2X (IS_BINNING_2X_VERTICAL | IS_BINNING_2X_HORIZONTAL)
00075 #define IS_BINNING_4X (IS_BINNING_4X_VERTICAL | IS_BINNING_4X_HORIZONTAL)
00076 #define IS_BINNING_8X (IS_BINNING_8X_VERTICAL | IS_BINNING_8X_HORIZONTAL)
00077 #define IS_BINNING_16X (IS_BINNING_16X_VERTICAL | IS_BINNING_16X_HORIZONTAL)
00078
00079
00083 class UEyeCamDriver {
00084 public:
00085 constexpr static int ANY_CAMERA = 0;
00086
00087
00091 UEyeCamDriver(int cam_ID = ANY_CAMERA, std::string cam_name = "camera");
00092
00096 virtual ~UEyeCamDriver();
00097
00105 virtual INT connectCam(int new_cam_ID = -1);
00106
00112 virtual INT disconnectCam();
00113
00122 INT loadCamConfig(std::string filename, bool ignore_load_failure = true);
00123
00137 INT setColorMode(std::string& mode, bool reallocate_buffer = true);
00138
00157 INT setResolution(INT& image_width, INT& image_height, INT& image_left,
00158 INT& image_top, bool reallocate_buffer = true);
00159
00170 INT setSubsampling(int& rate, bool reallocate_buffer = true);
00171
00182 INT setBinning(int& rate, bool reallocate_buffer = true);
00183
00194 INT setSensorScaling(double& rate, bool reallocate_buffer = true);
00195
00213 INT setGain(bool& auto_gain, INT& master_gain_prc, INT& red_gain_prc,
00214 INT& green_gain_prc, INT& blue_gain_prc, bool& gain_boost);
00215
00227 INT setExposure(bool& auto_exposure, double& exposure_ms);
00228
00240 INT setWhiteBalance(bool& auto_white_balance, INT& red_offset, INT& blue_offset);
00241
00256 INT setFrameRate(bool& auto_frame_rate, double& frame_rate_hz);
00257
00266 INT setPixelClockRate(INT& clock_rate_mhz);
00267
00277 INT setFlashParams(INT& delay_us, UINT& duration_us);
00278
00298 INT setFreeRunMode();
00299
00314 INT setExtTriggerMode();
00315
00322 INT setStandbyMode();
00323
00330 INT setMirrorUpsideDown(bool flip_horizontal);
00331
00338 INT setMirrorLeftRight(bool flip_vertical);
00339
00353 const char* processNextFrame(INT timeout_ms);
00354
00355 inline bool isConnected() { return (cam_handle_ != (HIDS) 0); }
00356
00357 inline bool freeRunModeActive() {
00358 return ((cam_handle_ != (HIDS) 0) &&
00359 (is_SetExternalTrigger(cam_handle_, IS_GET_EXTERNALTRIGGER) == IS_SET_TRIGGER_OFF) &&
00360 (is_CaptureVideo(cam_handle_, IS_GET_LIVE) == TRUE));
00361 }
00362
00363 inline bool extTriggerModeActive() {
00364 return ((cam_handle_ != (HIDS) 0) &&
00365 (is_SetExternalTrigger(cam_handle_, IS_GET_EXTERNALTRIGGER) == IS_SET_TRIGGER_HI_LO) &&
00366 (is_CaptureVideo(cam_handle_, IS_GET_LIVE) == TRUE));
00367 }
00368
00369 inline bool isCapturing() {
00370 return ((cam_handle_ != (HIDS) 0) &&
00371 (is_CaptureVideo(cam_handle_, IS_GET_LIVE) == TRUE));
00372 }
00373
00377 const static char* err2str(INT error);
00378
00382 const static char* colormode2str(INT mode);
00383
00387 const static std::string colormode2img_enc(INT mode);
00388
00392 const static INT colormode2bpp(INT mode);
00393
00397 const static bool isSupportedColorMode(INT mode);
00398
00402 const static INT name2colormode(const std::string& name);
00403 const static std::string colormode2name(INT mode);
00404
00409 const static std::function<void*(void*, void*, size_t)> getUnpackCopyFunc(INT color_mode);
00410 static void* unpackRGB10(void* dst, void* src, size_t num);
00411 static void* unpack10u(void* dst, void* src, size_t num);
00412 static void* unpack12u(void* dst, void* src, size_t num);
00413
00417 bool getTimestamp(UEYETIME *timestamp);
00418
00422 bool getClockTick(uint64_t *tick);
00423
00424
00425 protected:
00444 virtual INT syncCamConfig(std::string dft_mode_str = "mono8");
00445
00446
00447 virtual void handleTimeout() {};
00448
00449
00456 INT reallocateCamBuffer();
00457
00458 const static std::map<std::string, INT> COLOR_DICTIONARY;
00459
00460 HIDS cam_handle_;
00461 SENSORINFO cam_sensor_info_;
00462 char* cam_buffer_;
00463 int cam_buffer_id_;
00464 INT cam_buffer_pitch_;
00465 unsigned int cam_buffer_size_;
00466 std::string cam_name_;
00467 int cam_id_;
00468 IS_RECT cam_aoi_;
00469 unsigned int cam_subsampling_rate_;
00470 unsigned int cam_binning_rate_;
00471 double cam_sensor_scaling_rate_;
00472 INT color_mode_;
00473 INT bits_per_pixel_;
00474 };
00475
00476
00477 }
00478
00479
00480 #endif