JeVois  1.3
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Misc utilities

Miscellaneous utility and helper functions.

Collaboration diagram for Misc utilities:

Modules

 Miscellaneous preprocessor utilities related to controlling compilation
 
 Helper functions to convert coordinates 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::strfcc (std::string const &str)
 Convert a JeVois video format string to V4L2 four-cc code (V4L2_PIX_FMT_...) 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...
 
unsigned int jevois::blackColor (unsigned int fcc)
 Return a value that corresponds to black for the given video format. More...
 
unsigned int jevois::whiteColor (unsigned int fcc)
 Return a value that corresponds to white for the given video format. 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...
 
std::string jevois::replaceWhitespace (std::string const &str, char rep= '_')
 Replace white space characters in a string with underscore (default) or another characters. More...
 
std::string jevois::sformat (char const *fmt,...) __attribute__((format(__printf__
 Create a string using printf style arguments. More...
 
template<typename T >
std::string 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 camera in turbo mode. More...
 
std::string jevois::system (std::string const &cmd)
 Execute a command and grab stdout output to a string. 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

unsigned int jevois::blackColor ( unsigned int  fcc)

Return a value that corresponds to black for the given video format.

The returned value is appropriate to use as the color value for the image drawing functions in Minimalistic support for images in the core JeVois library and may not always be zero.

Definition at line 83 of file Utils.C.

References jevois::fccstr(), and LFATAL.

Referenced by BOOST_PYTHON_MODULE().

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 camera in turbo mode.

Definition at line 199 of file Utils.C.

References LERROR.

Referenced by BOOST_PYTHON_MODULE().

template<typename T >
std::string 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 123 of file Utils.C.

std::string jevois::replaceWhitespace ( std::string const &  str,
char  rep = '_' 
)

Replace white space characters in a string with underscore (default) or another characters.

Definition at line 143 of file Utils.C.

Referenced by jevois::StdModule::sendSerialContour2D(), jevois::StdModule::sendSerialStd1Dx(), jevois::StdModule::sendSerialStd1Dy(), jevois::StdModule::sendSerialStd2D(), and jevois::StdModule::sendSerialStd3D().

std::string jevois::sformat ( char const *  fmt,
  ... 
)

Create a string using printf style arguments.

Example:

std::string s = nrt::sformat("MyString_%f_%d", 1.0, 2);

One should normally refrain from using sformat(), and instead use streaming operators of C++, one exception is when issuing serial messages that have float numbers in them, the printf-like sytnax of sformat is useful to quickly and easily specify a numerical precision.

Definition at line 189 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 113 of file Utils.C.

Referenced by jevois::drawErrorImage(), jevois::warnAndIgnoreException(), and jevois::warnAndRethrowException().

unsigned int jevois::strfcc ( std::string const &  str)

Convert a JeVois video format string to V4L2 four-cc code (V4L2_PIX_FMT_...)

Throws a runtime_error if str is not one of: BAYER, YUYV, GREY, GRAY, MJPG, RGB565, BGR24 or NONE.

Definition at line 50 of file Utils.C.

Referenced by BOOST_PYTHON_MODULE(), and main().

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 137 of file Utils.C.

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

std::string jevois::system ( std::string const &  cmd)

Execute a command and grab stdout output to a string.

Definition at line 211 of file Utils.C.

References LFATAL.

Referenced by BOOST_PYTHON_MODULE(), jevois::Engine::parseCommand(), jevois::MovieOutput::run(), jevois::MovieOutput::streamOff(), and jevois::MovieOutput::~MovieOutput().

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 63 of file Utils.C.

References jevois::fccstr(), and LFATAL.

Referenced by BOOST_PYTHON_MODULE(), 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 79 of file Utils.C.

References jevois::v4l2BytesPerPix().

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

unsigned int jevois::whiteColor ( unsigned int  fcc)

Return a value that corresponds to white for the given video format.

The returned value is appropriate to use as the color value for the image drawing functions in Minimalistic support for images in the core JeVois library.

Definition at line 98 of file Utils.C.

References jevois::fccstr(), and LFATAL.

Referenced by BOOST_PYTHON_MODULE(), and jevois::drawErrorImage().