ZED Open Capture  v0.6.0
Low level camera driver for the ZED stereo camera family
Classes | Typedefs | Enumerations | Functions | Variables
sl_oc::tools Namespace Reference

Classes

class  CSimpleIniTempl
 
struct  SI_GenericCase
 
struct  SI_GenericNoCase
 
class  SI_ConvertA
 
class  SI_ConvertW
 
struct  SI_NoCase
 
class  ConfManager
 
class  StereoSgbmPar
 The StereoSgbmPar class is used to store/retrieve the stereo matching parameters. More...
 
class  StopWatch
 Stop Timer used to measure time intervals. More...
 

Typedefs

typedef unsigned int UTF32
 
typedef unsigned short UTF16
 
typedef unsigned char UTF8
 
typedef CSimpleIniTempl< char, SI_NoCase< char >, SI_ConvertA< char > > CSimpleIniA
 
typedef CSimpleIniTempl< char, SI_Case< char >, SI_ConvertA< char > > CSimpleIniCaseA
 
typedef CSimpleIniTempl< UChar, SI_NoCase< UChar >, SI_ConvertW< UChar > > CSimpleIniW
 
typedef CSimpleIniTempl< UChar, SI_Case< UChar >, SI_ConvertW< UChar > > CSimpleIniCaseW
 

Enumerations

enum  SI_Error {
  SI_OK = 0 , SI_UPDATED = 1 , SI_INSERTED = 2 , SI_FAIL = -1 ,
  SI_NOMEM = -2 , SI_FILE = -3
}
 
enum  ConversionResult { conversionOK , sourceExhausted , targetExhausted , sourceIllegal }
 
enum  ConversionFlags { strictConversion = 0 , lenientConversion }
 

Functions

ConversionResult ConvertUTF8toUTF16 (const UTF8 **sourceStart, const UTF8 *sourceEnd, UTF16 **targetStart, UTF16 *targetEnd, ConversionFlags flags)
 
ConversionResult ConvertUTF16toUTF8 (const UTF16 **sourceStart, const UTF16 *sourceEnd, UTF8 **targetStart, UTF8 *targetEnd, ConversionFlags flags)
 
ConversionResult ConvertUTF8toUTF32 (const UTF8 **sourceStart, const UTF8 *sourceEnd, UTF32 **targetStart, UTF32 *targetEnd, ConversionFlags flags)
 
ConversionResult ConvertUTF32toUTF8 (const UTF32 **sourceStart, const UTF32 *sourceEnd, UTF8 **targetStart, UTF8 *targetEnd, ConversionFlags flags)
 
ConversionResult ConvertUTF16toUTF32 (const UTF16 **sourceStart, const UTF16 *sourceEnd, UTF32 **targetStart, UTF32 *targetEnd, ConversionFlags flags)
 
ConversionResult ConvertUTF32toUTF16 (const UTF32 **sourceStart, const UTF32 *sourceEnd, UTF16 **targetStart, UTF16 *targetEnd, ConversionFlags flags)
 
Boolean isLegalUTF8Sequence (const UTF8 *source, const UTF8 *sourceEnd)
 
std::vector< std::string > & split (const std::string &s, char delim, std::vector< std::string > &elems)
 
std::vector< std::string > split (const std::string &s, char delim)
 
bool checkFile (std::string path)
 
bool downloadCalibrationFile (unsigned int serial_number, std::string &calibration_file)
 
bool initCalibration (std::string calibration_file, cv::Size2i image_size, cv::Mat &map_left_x, cv::Mat &map_left_y, cv::Mat &map_right_x, cv::Mat &map_right_y, cv::Mat &cameraMatrix_left, cv::Mat &cameraMatrix_right, double *baseline=nullptr)
 
void showImage (std::string name, cv::UMat &img, sl_oc::video::RESOLUTION res, bool change_name=true, std::string info="")
 Rescale the OpenCV T-API images [cv::UMat] according to the selected resolution to better display them on screen and show. More...
 
void showImage (std::string name, cv::Mat &img, sl_oc::video::RESOLUTION res, bool change_name=true, std::string info="")
 Rescale the OpenCV images [cv::Mat] according to the selected resolution to better display them on screen and show. More...
 

Variables

const std::string STEREO_PAR_FILENAME = "zed_oc_stereo.yaml"
 STEREO_PAR_FILENAME default stereo parameter configuration file. More...
 

Typedef Documentation

◆ CSimpleIniA

Definition at line 3935 of file calibration.hpp.

◆ CSimpleIniCaseA

typedef CSimpleIniTempl<char,SI_Case<char>, SI_ConvertA<char> > sl_oc::tools::CSimpleIniCaseA

Definition at line 3937 of file calibration.hpp.

◆ CSimpleIniCaseW

typedef CSimpleIniTempl< wchar_t, SI_Case< wchar_t >, SI_ConvertW< wchar_t > > sl_oc::tools::CSimpleIniCaseW

Definition at line 3943 of file calibration.hpp.

◆ CSimpleIniW

typedef CSimpleIniTempl< wchar_t, SI_NoCase< wchar_t >, SI_ConvertW< wchar_t > > sl_oc::tools::CSimpleIniW

Definition at line 3941 of file calibration.hpp.

◆ UTF16

typedef unsigned short sl_oc::tools::UTF16

Definition at line 2769 of file calibration.hpp.

◆ UTF32

typedef unsigned int sl_oc::tools::UTF32

Definition at line 2768 of file calibration.hpp.

◆ UTF8

typedef unsigned char sl_oc::tools::UTF8

Definition at line 2770 of file calibration.hpp.

Enumeration Type Documentation

◆ ConversionFlags

Enumerator
strictConversion 
lenientConversion 

Definition at line 2786 of file calibration.hpp.

2786  {
2787  strictConversion = 0,
2789 } ConversionFlags;

◆ ConversionResult

Enumerator
conversionOK 
sourceExhausted 
targetExhausted 
sourceIllegal 

Definition at line 2779 of file calibration.hpp.

2779  {
2780  conversionOK, /* conversion successful */
2781  sourceExhausted, /* partial character in source, but hit end */
2782  targetExhausted, /* insuff. room in target for conversion */
2783  sourceIllegal /* source sequence is illegal/malformed */

◆ SI_Error

Enumerator
SI_OK 

No error.

SI_UPDATED 

An existing value was updated.

SI_INSERTED 

A new value was inserted.

SI_FAIL 

Generic failure.

SI_NOMEM 

Out of memory error.

SI_FILE 

File error (see errno for detail error)

Definition at line 93 of file calibration.hpp.

93  {
94  SI_OK = 0,
95  SI_UPDATED = 1,
96  SI_INSERTED = 2,
97 
98  // note: test for any error with (retval < 0)
99  SI_FAIL = -1,
100  SI_NOMEM = -2,
101  SI_FILE = -3
102 };
@ SI_NOMEM
Out of memory error.
@ SI_UPDATED
An existing value was updated.
Definition: calibration.hpp:95
@ SI_FAIL
Generic failure.
Definition: calibration.hpp:99
@ SI_OK
No error.
Definition: calibration.hpp:94
@ SI_FILE
File error (see errno for detail error)
@ SI_INSERTED
A new value was inserted.
Definition: calibration.hpp:96

Function Documentation

◆ checkFile()

bool sl_oc::tools::checkFile ( std::string  path)

Definition at line 4048 of file calibration.hpp.

4048  {
4049  std::ifstream f(path.c_str());
4050  return f.good();
4051 }

Referenced by downloadCalibrationFile(), and initCalibration().

◆ ConvertUTF16toUTF32()

ConversionResult sl_oc::tools::ConvertUTF16toUTF32 ( const UTF16 **  sourceStart,
const UTF16 sourceEnd,
UTF32 **  targetStart,
UTF32 targetEnd,
ConversionFlags  flags 
)

Definition at line 2893 of file calibration.hpp.

2895  {
2896  ConversionResult result = conversionOK;
2897  const UTF16* source = *sourceStart;
2898  UTF32* target = *targetStart;
2899  UTF32 ch, ch2;
2900  while (source < sourceEnd) {
2901  const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
2902  ch = *source++;
2903  /* If we have a surrogate pair, convert to UTF32 first. */
2904  if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
2905  /* If the 16 bits following the high surrogate are in the source buffer... */
2906  if (source < sourceEnd) {
2907  ch2 = *source;
2908  /* If it's a low surrogate, convert to UTF32. */
2909  if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
2910  ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
2911  + (ch2 - UNI_SUR_LOW_START) + halfBase;
2912  ++source;
2913  } else if (flags == strictConversion) { /* it's an unpaired high surrogate */
2914  --source; /* return to the illegal value itself */
2915  result = sourceIllegal;
2916  break;
2917  }
2918  } else { /* We don't have the 16 bits following the high surrogate. */
2919  --source; /* return to the high surrogate */
2920  result = sourceExhausted;
2921  break;
2922  }
2923  } else if (flags == strictConversion) {
2924  /* UTF-16 surrogate values are illegal in UTF-32 */
2925  if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
2926  --source; /* return to the illegal value itself */
2927  result = sourceIllegal;
2928  break;
2929  }
2930  }
2931  if (target >= targetEnd) {
2932  source = oldSource; /* Back up source pointer! */
2933  result = targetExhausted;
2934  break;
2935  }
2936  *target++ = ch;
2937  }
2938  *sourceStart = source;
2939  *targetStart = target;
2940 #ifdef CVTUTF_DEBUG
2941  if (result == sourceIllegal) {
2942  fprintf(stderr, "ConvertUTF16toUTF32 illegal seq 0x%04x,%04x\n", ch, ch2);
2943  fflush(stderr);
2944  }
2945 #endif
2946  return result;
2947  }
unsigned int UTF32
unsigned short UTF16

References conversionOK, sourceExhausted, sourceIllegal, strictConversion, and targetExhausted.

◆ ConvertUTF16toUTF8()

ConversionResult sl_oc::tools::ConvertUTF16toUTF8 ( const UTF16 **  sourceStart,
const UTF16 sourceEnd,
UTF8 **  targetStart,
UTF8 targetEnd,
ConversionFlags  flags 
)

Definition at line 2998 of file calibration.hpp.

3000  {
3001  ConversionResult result = conversionOK;
3002  const UTF16* source = *sourceStart;
3003  UTF8* target = *targetStart;
3004  while (source < sourceEnd) {
3005  UTF32 ch;
3006  unsigned short bytesToWrite = 0;
3007  const UTF32 byteMask = 0xBF;
3008  const UTF32 byteMark = 0x80;
3009  const UTF16* oldSource = source; /* In case we have to back up because of target overflow. */
3010  ch = *source++;
3011  /* If we have a surrogate pair, convert to UTF32 first. */
3012  if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_HIGH_END) {
3013  /* If the 16 bits following the high surrogate are in the source buffer... */
3014  if (source < sourceEnd) {
3015  UTF32 ch2 = *source;
3016  /* If it's a low surrogate, convert to UTF32. */
3017  if (ch2 >= UNI_SUR_LOW_START && ch2 <= UNI_SUR_LOW_END) {
3018  ch = ((ch - UNI_SUR_HIGH_START) << halfShift)
3019  + (ch2 - UNI_SUR_LOW_START) + halfBase;
3020  ++source;
3021  } else if (flags == strictConversion) { /* it's an unpaired high surrogate */
3022  --source; /* return to the illegal value itself */
3023  result = sourceIllegal;
3024  break;
3025  }
3026  } else { /* We don't have the 16 bits following the high surrogate. */
3027  --source; /* return to the high surrogate */
3028  result = sourceExhausted;
3029  break;
3030  }
3031  } else if (flags == strictConversion) {
3032  /* UTF-16 surrogate values are illegal in UTF-32 */
3033  if (ch >= UNI_SUR_LOW_START && ch <= UNI_SUR_LOW_END) {
3034  --source; /* return to the illegal value itself */
3035  result = sourceIllegal;
3036  break;
3037  }
3038  }
3039  /* Figure out how many bytes the result will require */
3040  if (ch < (UTF32) 0x80) {
3041  bytesToWrite = 1;
3042  } else if (ch < (UTF32) 0x800) {
3043  bytesToWrite = 2;
3044  } else if (ch < (UTF32) 0x10000) {
3045  bytesToWrite = 3;
3046  } else if (ch < (UTF32) 0x110000) {
3047  bytesToWrite = 4;
3048  } else {
3049  bytesToWrite = 3;
3050  ch = UNI_REPLACEMENT_CHAR;
3051  }
3052 
3053  target += bytesToWrite;
3054  if (target > targetEnd) {
3055  source = oldSource; /* Back up source pointer! */
3056  target -= bytesToWrite;
3057  result = targetExhausted;
3058  break;
3059  }
3060  switch (bytesToWrite) { /* note: everything falls through. */
3061  case 4: *--target = (UTF8) ((ch | byteMark) & byteMask);
3062  ch >>= 6;
3063  case 3: *--target = (UTF8) ((ch | byteMark) & byteMask);
3064  ch >>= 6;
3065  case 2: *--target = (UTF8) ((ch | byteMark) & byteMask);
3066  ch >>= 6;
3067  case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
3068  }
3069  target += bytesToWrite;
3070  }
3071  *sourceStart = source;
3072  *targetStart = target;
3073  return result;
3074  }
unsigned char UTF8

References conversionOK, sourceExhausted, sourceIllegal, strictConversion, and targetExhausted.

Referenced by sl_oc::tools::SI_ConvertW< SI_CHAR >::ConvertToStore().

◆ ConvertUTF32toUTF16()

ConversionResult sl_oc::tools::ConvertUTF32toUTF16 ( const UTF32 **  sourceStart,
const UTF32 sourceEnd,
UTF16 **  targetStart,
UTF16 targetEnd,
ConversionFlags  flags 
)

Definition at line 2842 of file calibration.hpp.

2844  {
2845  ConversionResult result = conversionOK;
2846  const UTF32* source = *sourceStart;
2847  UTF16* target = *targetStart;
2848  while (source < sourceEnd) {
2849  UTF32 ch;
2850  if (target >= targetEnd) {
2851  result = targetExhausted;
2852  break;
2853  }
2854  ch = *source++;
2855  if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
2856  /* UTF-16 surrogate values are illegal in UTF-32; 0xffff or 0xfffe are both reserved values */
2857  if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
2858  if (flags == strictConversion) {
2859  --source; /* return to the illegal value itself */
2860  result = sourceIllegal;
2861  break;
2862  } else {
2863  *target++ = UNI_REPLACEMENT_CHAR;
2864  }
2865  } else {
2866  *target++ = (UTF16) ch; /* normal case */
2867  }
2868  } else if (ch > UNI_MAX_LEGAL_UTF32) {
2869  if (flags == strictConversion) {
2870  result = sourceIllegal;
2871  } else {
2872  *target++ = UNI_REPLACEMENT_CHAR;
2873  }
2874  } else {
2875  /* target is a character in range 0xFFFF - 0x10FFFF. */
2876  if (target + 1 >= targetEnd) {
2877  --source; /* Back up source pointer! */
2878  result = targetExhausted;
2879  break;
2880  }
2881  ch -= halfBase;
2882  *target++ = (UTF16) ((ch >> halfShift) + UNI_SUR_HIGH_START);
2883  *target++ = (UTF16) ((ch & halfMask) + UNI_SUR_LOW_START);
2884  }
2885  }
2886  *sourceStart = source;
2887  *targetStart = target;
2888  return result;
2889  }

References conversionOK, sourceIllegal, strictConversion, and targetExhausted.

◆ ConvertUTF32toUTF8()

ConversionResult sl_oc::tools::ConvertUTF32toUTF8 ( const UTF32 **  sourceStart,
const UTF32 sourceEnd,
UTF8 **  targetStart,
UTF8 targetEnd,
ConversionFlags  flags 
)

Definition at line 3215 of file calibration.hpp.

3217  {
3218  ConversionResult result = conversionOK;
3219  const UTF32* source = *sourceStart;
3220  UTF8* target = *targetStart;
3221  while (source < sourceEnd) {
3222  UTF32 ch;
3223  unsigned short bytesToWrite = 0;
3224  const UTF32 byteMask = 0xBF;
3225  const UTF32 byteMark = 0x80;
3226  ch = *source++;
3227  if (flags == strictConversion) {
3228  /* UTF-16 surrogate values are illegal in UTF-32 */
3229  if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
3230  --source; /* return to the illegal value itself */
3231  result = sourceIllegal;
3232  break;
3233  }
3234  }
3235  /*
3236  * Figure out how many bytes the result will require. Turn any
3237  * illegally large UTF32 things (> Plane 17) into replacement chars.
3238  */
3239  if (ch < (UTF32) 0x80) {
3240  bytesToWrite = 1;
3241  } else if (ch < (UTF32) 0x800) {
3242  bytesToWrite = 2;
3243  } else if (ch < (UTF32) 0x10000) {
3244  bytesToWrite = 3;
3245  } else if (ch <= UNI_MAX_LEGAL_UTF32) {
3246  bytesToWrite = 4;
3247  } else {
3248  bytesToWrite = 3;
3249  ch = UNI_REPLACEMENT_CHAR;
3250  result = sourceIllegal;
3251  }
3252 
3253  target += bytesToWrite;
3254  if (target > targetEnd) {
3255  --source; /* Back up source pointer! */
3256  target -= bytesToWrite;
3257  result = targetExhausted;
3258  break;
3259  }
3260  switch (bytesToWrite) { /* note: everything falls through. */
3261  case 4: *--target = (UTF8) ((ch | byteMark) & byteMask);
3262  ch >>= 6;
3263  case 3: *--target = (UTF8) ((ch | byteMark) & byteMask);
3264  ch >>= 6;
3265  case 2: *--target = (UTF8) ((ch | byteMark) & byteMask);
3266  ch >>= 6;
3267  case 1: *--target = (UTF8) (ch | firstByteMark[bytesToWrite]);
3268  }
3269  target += bytesToWrite;
3270  }
3271  *sourceStart = source;
3272  *targetStart = target;
3273  return result;
3274  }

References conversionOK, sourceIllegal, strictConversion, and targetExhausted.

Referenced by sl_oc::tools::SI_ConvertW< SI_CHAR >::ConvertToStore().

◆ ConvertUTF8toUTF16()

ConversionResult sl_oc::tools::ConvertUTF8toUTF16 ( const UTF8 **  sourceStart,
const UTF8 sourceEnd,
UTF16 **  targetStart,
UTF16 targetEnd,
ConversionFlags  flags 
)

Definition at line 3134 of file calibration.hpp.

3136  {
3137  ConversionResult result = conversionOK;
3138  const UTF8* source = *sourceStart;
3139  UTF16* target = *targetStart;
3140  while (source < sourceEnd) {
3141  UTF32 ch = 0;
3142  unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
3143  if (source + extraBytesToRead >= sourceEnd) {
3144  result = sourceExhausted;
3145  break;
3146  }
3147  /* Do this check whether lenient or strict */
3148  if (!isLegalUTF8(source, extraBytesToRead + 1)) {
3149  result = sourceIllegal;
3150  break;
3151  }
3152  /*
3153  * The cases all fall through. See "Note A" below.
3154  */
3155  switch (extraBytesToRead) {
3156  case 5: ch += *source++;
3157  ch <<= 6; /* remember, illegal UTF-8 */
3158  case 4: ch += *source++;
3159  ch <<= 6; /* remember, illegal UTF-8 */
3160  case 3: ch += *source++;
3161  ch <<= 6;
3162  case 2: ch += *source++;
3163  ch <<= 6;
3164  case 1: ch += *source++;
3165  ch <<= 6;
3166  case 0: ch += *source++;
3167  }
3168  ch -= offsetsFromUTF8[extraBytesToRead];
3169 
3170  if (target >= targetEnd) {
3171  source -= (extraBytesToRead + 1); /* Back up source pointer! */
3172  result = targetExhausted;
3173  break;
3174  }
3175  if (ch <= UNI_MAX_BMP) { /* Target is a character <= 0xFFFF */
3176  /* UTF-16 surrogate values are illegal in UTF-32 */
3177  if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
3178  if (flags == strictConversion) {
3179  source -= (extraBytesToRead + 1); /* return to the illegal value itself */
3180  result = sourceIllegal;
3181  break;
3182  } else {
3183  *target++ = UNI_REPLACEMENT_CHAR;
3184  }
3185  } else {
3186  *target++ = (UTF16) ch; /* normal case */
3187  }
3188  } else if (ch > UNI_MAX_UTF16) {
3189  if (flags == strictConversion) {
3190  result = sourceIllegal;
3191  source -= (extraBytesToRead + 1); /* return to the start */
3192  break; /* Bail out; shouldn't continue */
3193  } else {
3194  *target++ = UNI_REPLACEMENT_CHAR;
3195  }
3196  } else {
3197  /* target is a character in range 0xFFFF - 0x10FFFF. */
3198  if (target + 1 >= targetEnd) {
3199  source -= (extraBytesToRead + 1); /* Back up source pointer! */
3200  result = targetExhausted;
3201  break;
3202  }
3203  ch -= halfBase;
3204  *target++ = (UTF16) ((ch >> halfShift) + UNI_SUR_HIGH_START);
3205  *target++ = (UTF16) ((ch & halfMask) + UNI_SUR_LOW_START);
3206  }
3207  }
3208  *sourceStart = source;
3209  *targetStart = target;
3210  return result;
3211  }

References conversionOK, sourceExhausted, sourceIllegal, strictConversion, and targetExhausted.

Referenced by sl_oc::tools::SI_ConvertW< SI_CHAR >::ConvertFromStore().

◆ ConvertUTF8toUTF32()

ConversionResult sl_oc::tools::ConvertUTF8toUTF32 ( const UTF8 **  sourceStart,
const UTF8 sourceEnd,
UTF32 **  targetStart,
UTF32 targetEnd,
ConversionFlags  flags 
)

Definition at line 3278 of file calibration.hpp.

3280  {
3281  ConversionResult result = conversionOK;
3282  const UTF8* source = *sourceStart;
3283  UTF32* target = *targetStart;
3284  while (source < sourceEnd) {
3285  UTF32 ch = 0;
3286  unsigned short extraBytesToRead = trailingBytesForUTF8[*source];
3287  if (source + extraBytesToRead >= sourceEnd) {
3288  result = sourceExhausted;
3289  break;
3290  }
3291  /* Do this check whether lenient or strict */
3292  if (!isLegalUTF8(source, extraBytesToRead + 1)) {
3293  result = sourceIllegal;
3294  break;
3295  }
3296  /*
3297  * The cases all fall through. See "Note A" below.
3298  */
3299  switch (extraBytesToRead) {
3300  case 5: ch += *source++;
3301  ch <<= 6;
3302  case 4: ch += *source++;
3303  ch <<= 6;
3304  case 3: ch += *source++;
3305  ch <<= 6;
3306  case 2: ch += *source++;
3307  ch <<= 6;
3308  case 1: ch += *source++;
3309  ch <<= 6;
3310  case 0: ch += *source++;
3311  }
3312  ch -= offsetsFromUTF8[extraBytesToRead];
3313 
3314  if (target >= targetEnd) {
3315  source -= (extraBytesToRead + 1); /* Back up the source pointer! */
3316  result = targetExhausted;
3317  break;
3318  }
3319  if (ch <= UNI_MAX_LEGAL_UTF32) {
3320  /*
3321  * UTF-16 surrogate values are illegal in UTF-32, and anything
3322  * over Plane 17 (> 0x10FFFF) is illegal.
3323  */
3324  if (ch >= UNI_SUR_HIGH_START && ch <= UNI_SUR_LOW_END) {
3325  if (flags == strictConversion) {
3326  source -= (extraBytesToRead + 1); /* return to the illegal value itself */
3327  result = sourceIllegal;
3328  break;
3329  } else {
3330  *target++ = UNI_REPLACEMENT_CHAR;
3331  }
3332  } else {
3333  *target++ = ch;
3334  }
3335  } else { /* i.e., ch > UNI_MAX_LEGAL_UTF32 */
3336  result = sourceIllegal;
3337  *target++ = UNI_REPLACEMENT_CHAR;
3338  }
3339  }
3340  *sourceStart = source;
3341  *targetStart = target;
3342  return result;
3343  }

References conversionOK, sourceExhausted, sourceIllegal, strictConversion, and targetExhausted.

Referenced by sl_oc::tools::SI_ConvertW< SI_CHAR >::ConvertFromStore().

◆ downloadCalibrationFile()

bool sl_oc::tools::downloadCalibrationFile ( unsigned int  serial_number,
std::string &  calibration_file 
)
Examples
zed_oc_depth_example.cpp, zed_oc_rectify_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 4101 of file calibration.hpp.

4101  {
4102 #ifndef _WIN32
4103  std::string path = getHiddenDir();
4104  char specific_name[128];
4105  sprintf(specific_name, "SN%d.conf", serial_number);
4106  calibration_file = path + specific_name;
4107  if (!checkFile(calibration_file)) {
4108  std::string cmd;
4109  int res;
4110 
4111  // Create download folder
4112  cmd = "mkdir -p " + path;
4113  res = system(cmd.c_str());
4114 
4115  // Download the file
4116  std::string url("'https://calib.stereolabs.com/?SN=");
4117 
4118  cmd = "wget " + url + std::to_string(serial_number) + "' -O " + calibration_file;
4119  std::cout << cmd << std::endl;
4120  res = system(cmd.c_str());
4121 
4122  if( res == EXIT_FAILURE )
4123  {
4124  std::cerr << "Error downloading the calibration file" << std::endl;
4125  return false;
4126  }
4127 
4128  if (!checkFile(calibration_file)) {
4129  std::cerr << "Invalid calibration file" << std::endl;
4130  return false;
4131  }
4132  }
4133 #else
4134  std::string path = getHiddenDir();
4135  char specific_name[128];
4136  sprintf(specific_name, "SN%d.conf", serial_number);
4137  calibration_file = path + specific_name;
4138  if (!checkFile(calibration_file)) {
4139  TCHAR *settingFolder = new TCHAR[path.size() + 1];
4140  settingFolder[path.size()] = 0;
4141  std::copy(path.begin(), path.end(), settingFolder);
4142  SHCreateDirectoryEx(NULL, settingFolder, NULL); //recursive creation
4143 
4144  std::string url("https://calib.stereolabs.com/?SN=");
4145  url += std::to_string(serial_number);
4146  TCHAR *address = new TCHAR[url.size() + 1];
4147  address[url.size()] = 0;
4148  std::copy(url.begin(), url.end(), address);
4149  TCHAR *calibPath = new TCHAR[calibration_file.size() + 1];
4150  calibPath[calibration_file.size()] = 0;
4151  std::copy(calibration_file.begin(), calibration_file.end(), calibPath);
4152 
4153  HRESULT hr = URLDownloadToFile(NULL, address, calibPath, 0, NULL);
4154  if (hr != 0) {
4155  std::cout << "Fail to download calibration file" << std::endl;
4156  return false;
4157  }
4158 
4159  if (!checkFile(calibration_file)) {
4160  std::cout << "Invalid calibration file" << std::endl;
4161  return false;
4162  }
4163  }
4164 #endif
4165 
4166  return true;
4167 }
bool checkFile(std::string path)

References checkFile().

Referenced by main().

◆ initCalibration()

bool sl_oc::tools::initCalibration ( std::string  calibration_file,
cv::Size2i  image_size,
cv::Mat &  map_left_x,
cv::Mat &  map_left_y,
cv::Mat &  map_right_x,
cv::Mat &  map_right_y,
cv::Mat &  cameraMatrix_left,
cv::Mat &  cameraMatrix_right,
double *  baseline = nullptr 
)
Examples
zed_oc_depth_example.cpp, zed_oc_rectify_example.cpp, and zed_oc_tune_stereo_sgbm.cpp.

Definition at line 4172 of file calibration.hpp.

4173  {
4174 
4175  if (!checkFile(calibration_file)) {
4176  std::cout << "Calibration file missing." << std::endl;
4177  return 0;
4178  }
4179 
4180  // Open camera configuration file
4181  ConfManager camerareader(calibration_file.c_str());
4182  if (!camerareader.isOpened())
4183  return 0;
4184 
4185  std::string resolution_str;
4186  switch ((int) image_size.width) {
4187  case 2208:
4188  resolution_str = "2k";
4189  break;
4190  case 1920:
4191  resolution_str = "fhd";
4192  break;
4193  case 1280:
4194  resolution_str = "hd";
4195  break;
4196  case 672:
4197  resolution_str = "vga";
4198  break;
4199  default:
4200  resolution_str = "hd";
4201  break;
4202  }
4203 
4204  // Get translations
4205  float T_[3];
4206  T_[0] = camerareader.getValue("stereo:baseline", 0.0f);
4207  T_[1] = camerareader.getValue("stereo:ty_" + resolution_str, 0.f);
4208  T_[2] = camerareader.getValue("stereo:tz_" + resolution_str, 0.f);
4209 
4210  if(baseline) *baseline=T_[0];
4211 
4212  // Get left parameters
4213  float left_cam_cx = camerareader.getValue("left_cam_" + resolution_str + ":cx", 0.0f);
4214  float left_cam_cy = camerareader.getValue("left_cam_" + resolution_str + ":cy", 0.0f);
4215  float left_cam_fx = camerareader.getValue("left_cam_" + resolution_str + ":fx", 0.0f);
4216  float left_cam_fy = camerareader.getValue("left_cam_" + resolution_str + ":fy", 0.0f);
4217  float left_cam_k1 = camerareader.getValue("left_cam_" + resolution_str + ":k1", 0.0f);
4218  float left_cam_k2 = camerareader.getValue("left_cam_" + resolution_str + ":k2", 0.0f);
4219  float left_cam_p1 = camerareader.getValue("left_cam_" + resolution_str + ":p1", 0.0f);
4220  float left_cam_p2 = camerareader.getValue("left_cam_" + resolution_str + ":p2", 0.0f);
4221  float left_cam_k3 = camerareader.getValue("left_cam_" + resolution_str + ":k3", 0.0f);
4222 
4223  // Get right parameters
4224  float right_cam_cx = camerareader.getValue("right_cam_" + resolution_str + ":cx", 0.0f);
4225  float right_cam_cy = camerareader.getValue("right_cam_" + resolution_str + ":cy", 0.0f);
4226  float right_cam_fx = camerareader.getValue("right_cam_" + resolution_str + ":fx", 0.0f);
4227  float right_cam_fy = camerareader.getValue("right_cam_" + resolution_str + ":fy", 0.0f);
4228  float right_cam_k1 = camerareader.getValue("right_cam_" + resolution_str + ":k1", 0.0f);
4229  float right_cam_k2 = camerareader.getValue("right_cam_" + resolution_str + ":k2", 0.0f);
4230  float right_cam_p1 = camerareader.getValue("right_cam_" + resolution_str + ":p1", 0.0f);
4231  float right_cam_p2 = camerareader.getValue("right_cam_" + resolution_str + ":p2", 0.0f);
4232  float right_cam_k3 = camerareader.getValue("right_cam_" + resolution_str + ":k3", 0.0f);
4233 
4234  // (Linux only) Safety check A: Wrong "." or "," reading in file conf.
4235 #ifndef _WIN32
4236  if (right_cam_k1 == 0 && left_cam_k1 == 0 && left_cam_k2 == 0 && right_cam_k2 == 0) {
4237  std::cout << "ZED File invalid" << std::endl;
4238 
4239  std::string cmd = "rm " + calibration_file;
4240  int res = system(cmd.c_str());
4241  if( res == EXIT_FAILURE )
4242  {
4243  exit(1);
4244  }
4245 
4246  exit(1);
4247  }
4248 #endif
4249 
4250  // Get rotations
4251  cv::Mat R_zed = (cv::Mat_<double>(1, 3) << camerareader.getValue("stereo:rx_" + resolution_str, 0.f), camerareader.getValue("stereo:cv_" + resolution_str, 0.f), camerareader.getValue("stereo:rz_" + resolution_str, 0.f));
4252  cv::Mat R;
4253 
4254  cv::Rodrigues(R_zed /*in*/, R /*out*/);
4255 
4256  cv::Mat distCoeffs_left, distCoeffs_right;
4257 
4258  // Left
4259  cameraMatrix_left = (cv::Mat_<double>(3, 3) << left_cam_fx, 0, left_cam_cx, 0, left_cam_fy, left_cam_cy, 0, 0, 1);
4260  distCoeffs_left = (cv::Mat_<double>(5, 1) << left_cam_k1, left_cam_k2, left_cam_p1, left_cam_p2, left_cam_k3);
4261 
4262  // Right
4263  cameraMatrix_right = (cv::Mat_<double>(3, 3) << right_cam_fx, 0, right_cam_cx, 0, right_cam_fy, right_cam_cy, 0, 0, 1);
4264  distCoeffs_right = (cv::Mat_<double>(5, 1) << right_cam_k1, right_cam_k2, right_cam_p1, right_cam_p2, right_cam_k3);
4265 
4266  // Stereo
4267  cv::Mat T = (cv::Mat_<double>(3, 1) << T_[0], T_[1], T_[2]);
4268  std::cout << " Camera Matrix L: \n" << cameraMatrix_left << std::endl << std::endl;
4269  std::cout << " Camera Matrix R: \n" << cameraMatrix_right << std::endl << std::endl;
4270 
4271  cv::Mat R1, R2, P1, P2, Q;
4272  cv::stereoRectify(cameraMatrix_left, distCoeffs_left, cameraMatrix_right, distCoeffs_right, image_size, R, T,
4273  R1, R2, P1, P2, Q, cv::CALIB_ZERO_DISPARITY, 0, image_size);
4274 
4275  //Precompute maps for cv::remap()
4276  initUndistortRectifyMap(cameraMatrix_left, distCoeffs_left, R1, P1, image_size, CV_32FC1, map_left_x, map_left_y);
4277  initUndistortRectifyMap(cameraMatrix_right, distCoeffs_right, R2, P2, image_size, CV_32FC1, map_right_x, map_right_y);
4278 
4279  cameraMatrix_left = P1;
4280  cameraMatrix_right = P2;
4281 
4282  return 1;
4283 }

References checkFile(), sl_oc::tools::ConfManager::getValue(), and sl_oc::tools::ConfManager::isOpened().

Referenced by main().

◆ isLegalUTF8Sequence()

bool sl_oc::tools::isLegalUTF8Sequence ( const UTF8 source,
const UTF8 sourceEnd 
)

Definition at line 3124 of file calibration.hpp.

3124  {
3125  int length = trailingBytesForUTF8[*source] + 1;
3126  if (source + length > sourceEnd) {
3127  return false;
3128  }
3129  return isLegalUTF8(source, length);
3130  }

◆ showImage() [1/2]

void sl_oc::tools::showImage ( std::string  name,
cv::Mat &  img,
sl_oc::video::RESOLUTION  res,
bool  change_name = true,
std::string  info = "" 
)

Rescale the OpenCV images [cv::Mat] according to the selected resolution to better display them on screen and show.

Parameters
nameName of the display window
imgImage to be displayed
resImage resolution
change_nameAdd rescaling information in window name if true
infooptional info string

Definition at line 64 of file ocv_display.hpp.

65 {
66  cv::Mat resized;
67  switch(res)
68  {
69  default:
71  resized = img;
72  break;
74  if(change_name) name += " [Resize factor 0.6]";
75  cv::resize( img, resized, cv::Size(), 0.6, 0.6 );
76  break;
79  if(change_name) name += " [Resize factor 0.4]";
80  cv::resize( img, resized, cv::Size(), 0.4, 0.4 );
81  break;
82  }
83 
84  if(!info.empty())
85  {
86  cv::putText( resized, info, cv::Point(20,40),cv::FONT_HERSHEY_SIMPLEX, 0.75,
87  cv::Scalar(100,100,100), 2);
88  }
89 
90  cv::imshow( name, resized );
91 }

References sl_oc::video::HD1080, sl_oc::video::HD2K, sl_oc::video::HD720, and sl_oc::video::VGA.

◆ showImage() [2/2]

void sl_oc::tools::showImage ( std::string  name,
cv::UMat &  img,
sl_oc::video::RESOLUTION  res,
bool  change_name = true,
std::string  info = "" 
)

Rescale the OpenCV T-API images [cv::UMat] according to the selected resolution to better display them on screen and show.

Parameters
nameName of the display window
imgImage to be displayed
resImage resolution
change_nameAdd rescaling information in window name if true
infooptional info string
Examples
zed_oc_depth_example.cpp, zed_oc_rectify_example.cpp, zed_oc_tune_stereo_sgbm.cpp, and zed_oc_video_example.cpp.

Definition at line 27 of file ocv_display.hpp.

28 {
29  cv::UMat resized;
30  switch(res)
31  {
32  default:
34  resized = img;
35  break;
37  if(change_name) name += " [Resize factor 0.6]";
38  cv::resize( img, resized, cv::Size(), 0.6, 0.6 );
39  break;
42  if(change_name) name += " [Resize factor 0.4]";
43  cv::resize( img, resized, cv::Size(), 0.4, 0.4 );
44  break;
45  }
46 
47  if(!info.empty())
48  {
49  cv::putText( resized, info, cv::Point(20,40),cv::FONT_HERSHEY_SIMPLEX, 0.75,
50  cv::Scalar(100,100,100), 2);
51  }
52 
53  cv::imshow( name, resized );
54 }

References sl_oc::video::HD1080, sl_oc::video::HD2K, sl_oc::video::HD720, and sl_oc::video::VGA.

Referenced by applyStereoMatching(), and main().

◆ split() [1/2]

std::vector<std::string> sl_oc::tools::split ( const std::string &  s,
char  delim 
)
inline

Definition at line 3997 of file calibration.hpp.

3997  {
3998  std::vector<std::string> elems;
3999  split(s, delim, elems);
4000  return elems;
4001 }
std::vector< std::string > split(const std::string &s, char delim)

References split().

◆ split() [2/2]

std::vector<std::string>& sl_oc::tools::split ( const std::string &  s,
char  delim,
std::vector< std::string > &  elems 
)
inline

Definition at line 3988 of file calibration.hpp.

3988  {
3989  std::stringstream ss(s);
3990  std::string item;
3991  while (getline(ss, item, delim)) {
3992  elems.push_back(item);
3993  }
3994  return elems;
3995 }

Referenced by sl_oc::tools::ConfManager::getValue(), sl_oc::tools::ConfManager::setValue(), and split().

Variable Documentation

◆ STEREO_PAR_FILENAME

const std::string sl_oc::tools::STEREO_PAR_FILENAME = "zed_oc_stereo.yaml"

STEREO_PAR_FILENAME default stereo parameter configuration file.

Definition at line 14 of file stereo.hpp.

Referenced by sl_oc::tools::StereoSgbmPar::load(), and sl_oc::tools::StereoSgbmPar::save().