JeVois  1.11
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...
 
std::string jevois::cvtypestr (unsigned int cvtype)
 Convert cv::Mat::type() code to to a string (e.g., CV_8UC1, CV_32SC3, etc) 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="\+")
 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::strip (std::string const &str)
 Strip white space (including CR, LF, tabs, etc) from the end of a string. 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, bool errtoo=true)
 Execute a command and grab stdout output to a string. More...
 

Macro Definition Documentation

◆ XIOCTL

◆ XIOCTL_QUIET

#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

◆ blackColor()

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

References jevois::fccstr(), and LFATAL.

Referenced by BOOST_PYTHON_MODULE().

◆ clamped_convert()

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

Clamped numerical conversion.

Definition at line 65 of file UtilsImpl.H.

◆ cvtypestr()

◆ fccstr()

◆ flushcache()

void jevois::flushcache ( )

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

Definition at line 236 of file Utils.C.

References LERROR.

Referenced by BOOST_PYTHON_MODULE().

◆ from_string()

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.

◆ join()

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

Referenced by jevois::Component::paramInfo().

◆ replaceWhitespace()

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

◆ sformat()

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

Create a string using printf style arguments.

Example:

std::string s = jevois::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 226 of file Utils.C.

Referenced by jevois::StdModule::sendSerialObjDetImg2D().

◆ split()

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

◆ strfcc()

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

Referenced by BOOST_PYTHON_MODULE(), jevois::VideoMapping::isSameAs(), and main().

◆ stringStartsWith()

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

Referenced by jevois::Serial::filePut(), jevois::Engine::mainLoop(), and jevois::Engine::postInit().

◆ strip()

std::string jevois::strip ( std::string const &  str)

Strip white space (including CR, LF, tabs, etc) from the end of a string.

Definition at line 180 of file Utils.C.

References LFATAL.

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

◆ system()

std::string jevois::system ( std::string const &  cmd,
bool  errtoo = true 
)

Execute a command and grab stdout output to a string.

If errtoo is true, we also grab errors by appending a 2>&1 to the command.

Definition at line 248 of file Utils.C.

References LFATAL.

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

◆ to_string()

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

◆ v4l2BytesPerPix()

unsigned int jevois::v4l2BytesPerPix ( unsigned int  fcc)

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

Definition at line 92 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().

◆ 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 108 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().

◆ whiteColor()

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

References jevois::fccstr(), and LFATAL.

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