JeVois  1.0
JeVois Smart Embedded Machine Vision Toolkit
Misc utilities

Miscellaneous utility and helper functions.

Collaboration diagram for Misc utilities:

Modules

 Miscellaneous preprocessor utilities related to controlling compilation
 
 Helper functions to convert coordiantes from camera resolution to standardized
 
 Name demangling functions
 

Macros

#define XIOCTL(dev, req, mem)
 Helper macro to execute an ioctl, ignore interruptions, and, if error, issue a fatal message and throw. More...
 
#define XIOCTL_QUIET(dev, req, mem)
 Helper macro to execute an ioctl, ignore interruptions, and, if error throw quietly. More...
 

Functions

std::string jevois::fccstr (unsigned int fcc)
 Convert a V4L2 four-cc code (V4L2_PIX_FMT_...) to a 4-char string. More...
 
unsigned int jevois::v4l2BytesPerPix (unsigned int fcc)
 Return the number of bytes per pixel for a given V4L2_PIX_FMT_... More...
 
unsigned int jevois::v4l2ImageSize (unsigned int fcc, unsigned int width, unsigned int height)
 Return the image size in bytes for a given V4L2_PIX_FMT_..., width, height. More...
 
std::vector< std::string > jevois::split (std::string const &input, std::string const &regex="\\s+")
 Split string into vector of tokens using a regex to specify what to split on; default regex splits by whitespace. More...
 
std::string jevois::join (std::vector< std::string > const &strings, std::string const &delimiter)
 Concatenate a vector of tokens into a string. More...
 
bool jevois::stringStartsWith (std::string const &str, std::string const &prefix)
 Return true if str starts with prefix (including if both strings are equal) More...
 
template<typename T >
jevois::from_string (std::string const &str)
 Convert from string to a type. More...
 
template<typename T >
std::string jevois::to_string (T const &val)
 Convert from type to string. More...
 
template<typename dest_type , typename source_type >
dest_type jevois::clamped_convert (source_type source)
 Clamped numerical conversion. More...
 
void jevois::flushcache ()
 Flush the caches, may sometimes be useful when running the cemare in turbo mode. More...
 

Macro Definition Documentation

#define XIOCTL (   dev,
  req,
  mem 
)
#define XIOCTL_QUIET (   dev,
  req,
  mem 
)

Helper macro to execute an ioctl, ignore interruptions, and, if error throw quietly.

This is useful, e.g., for V4L2 camera enumeration of formats, where one is supposed to call an ioctl with increasing format number until it fails. When that happens we don't want to display any fatal error message as XIOCTL() does. This macro assumes that req is an identifier for the corresponding ioctl number.

Referenced by jevois::Camera::Camera(), jevois::Camera::queryControl(), jevois::Camera::queryMenu(), jevois::Gadget::setFormat(), jevois::Camera::setFormat(), jevois::Camera::streamOff(), jevois::Gadget::streamOff(), and jevois::VideoBuffers::~VideoBuffers().

Function Documentation

template<typename dest_type , typename source_type >
dest_type jevois::clamped_convert ( source_type  source)
inline

Clamped numerical conversion.

Definition at line 58 of file UtilsImpl.H.

void jevois::flushcache ( )

Flush the caches, may sometimes be useful when running the cemare in turbo mode.

Definition at line 93 of file Utils.C.

References LERROR.

template<typename T >
T jevois::from_string ( std::string const &  str)

Convert from string to a type.

For integral types, internally uses std::stoll() for that type, which supports prefixes like 0 (for octal) and 0x (hex). Beware of that octal convention and do not pass leading zeros unless you mean it. For non-integral types, internally uses operator>> for that type, so it works with any type that supports it.

std::string jevois::join ( std::vector< std::string > const &  strings,
std::string const &  delimiter 
)

Concatenate a vector of tokens into a string.

Definition at line 73 of file Utils.C.

std::vector< std::string > jevois::split ( std::string const &  input,
std::string const &  regex = "\\s+" 
)

Split string into vector of tokens using a regex to specify what to split on; default regex splits by whitespace.

Definition at line 63 of file Utils.C.

bool jevois::stringStartsWith ( std::string const &  str,
std::string const &  prefix 
)

Return true if str starts with prefix (including if both strings are equal)

Note that if str is shorter than prefix, return is false (like in strncmp()).

Definition at line 87 of file Utils.C.

Referenced by jevois::Engine::postInit().

template<typename T >
std::string jevois::to_string ( T const &  val)
inline

Convert from type to string.

This internally uses operator>> for that type, so it works with any type that supports it.

Definition at line 51 of file UtilsImpl.H.

Referenced by jevois::getSysInfoCPU(), main(), TutorialEdgeDetection::onParamChange(), jevois::paramValToString(), jevois::paramValToString< unsigned char >(), jevois::Engine::parseCommand(), and jevois::Engine::runScriptFromFile().

unsigned int jevois::v4l2BytesPerPix ( unsigned int  fcc)

Return the number of bytes per pixel for a given V4L2_PIX_FMT_...

Definition at line 43 of file Utils.C.

References jevois::fccstr(), and LFATAL.

Referenced by jevois::RawImage::bytesize(), jevois::RawImage::bytesperpix(), jevois::rawimage::cvImage(), and jevois::v4l2ImageSize().

unsigned int jevois::v4l2ImageSize ( unsigned int  fcc,
unsigned int  width,
unsigned int  height 
)

Return the image size in bytes for a given V4L2_PIX_FMT_..., width, height.

Definition at line 59 of file Utils.C.

References jevois::v4l2BytesPerPix().

Referenced by jevois::VideoMapping::csize(), jevois::VideoMapping::osize(), jevois::Camera::streamOn(), and jevois::Gadget::streamOn().