JeVois  1.5
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
jevois::VideoMapping Struct Reference

#include <jevois/Core/VideoMapping.H>

Simple struct to hold video mapping definitions for the processing Engine.

This struct specifies an output video format, resolution, and frame rate (to be send to the end user over USB), the corresponding camera capture video format, resolution and frame rate, and the Module to use to process the camera frames and generate the corresponding output frames. This class also provides conversion functions between frame rate and frame interval periods for both USB and V4L2, which use different units.

Operation of JeVois is based on a list of available VideoMapping definitions, which is configured in a file called JEVOIS:config/videomappings.cfg on the microSD card. The video mappings indicate which output formats are exposed to the host computer connected over USB, and which corresponding camera format and vision processing module should be used when a given output format is selected by video capture software running on the host computer.

See User guide to video modes and mappings for explanations about how to organize videomappings.cfg

Definition at line 41 of file VideoMapping.H.

Collaboration diagram for jevois::VideoMapping:

Public Member Functions

std::string sopath () const
 Return the full absolute path and file name of the module's .so or .py file. More...
 
unsigned int osize () const
 Return the size in bytes of an output image. More...
 
unsigned int csize () const
 Return the size in bytes of a camera image. More...
 
bool match (unsigned int oformat, unsigned int owidth, unsigned int oheight, float oframespersec) const
 Return true if this VideoMapping's output format is a match to the given output parameters. More...
 
std::string ostr () const
 Convenience function to print out FCC WxH @ fps, for the output (UVC) format. More...
 
std::string cstr () const
 Convenience function to print out FCC WxH @ fps, for the input (camera) format. More...
 
std::string str () const
 Convenience function to print out the whole mapping in a human-friendly way. More...
 
bool hasSameSpecsAs (VideoMapping const &other) const
 Equality operator for specs but not vendor or module name. More...
 
bool isSameAs (VideoMapping const &other) const
 Equality operator for specs and also vendor or module name. More...
 
void setModuleType ()
 Determine whether module is C++ or python and set ispython flag accordingly. More...
 

Static Public Member Functions

static float uvcToFps (unsigned int interval)
 Convert from USB/UVC interval to fps. More...
 
static unsigned int fpsToUvc (float fps)
 Convert from fps to USB/UVC interval. More...
 
static float v4l2ToFps (struct v4l2_fract const &interval)
 Convert from V4L2 interval to fps. More...
 
static struct v4l2_fract fpsToV4l2 (float fps)
 Convert from fps to V4L2 interval. More...
 

Public Attributes

unsigned int ofmt
 output pixel format, or 0 for no output over USB More...
 
unsigned int ow
 output width More...
 
unsigned int oh
 output height More...
 
float ofps
 output frame rate in frames/sec More...
 
unsigned int cfmt
 camera pixel format More...
 
unsigned int cw
 camera width More...
 
unsigned int ch
 camera height More...
 
float cfps
 camera frame rate in frames/sec More...
 
unsigned int uvcformat
 USB-UVC format number (1-based) More...
 
unsigned int uvcframe
 USB UVC frame number (1-based) More...
 
std::string vendor
 Module creator name, used as a directory to organize the modules. More...
 
std::string modulename
 Name of the Module that will process this mapping. More...
 
bool ispython
 True if the module is written in Python; affects behavior of sopath() only. More...
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &out, VideoMapping const &m)
 Stream a VideoMapping out, intended for machines. More...
 
std::istream & operator>> (std::istream &in, VideoMapping &m)
 Stream a VideoMapping in, intended for machines. More...
 
std::vector< VideoMappingloadVideoMappings (size_t &defidx, bool checkso=true)
 Load all the video mappings from the default config file. More...
 
std::vector< VideoMappingvideoMappingsFromStream (std::istream &is, size_t &defidx, bool checkso=true)
 Parse all the mappings in a config file and also indicate which one is the default. More...
 

Member Function Documentation

◆ csize()

unsigned int jevois::VideoMapping::csize ( ) const

Return the size in bytes of a camera image.

Definition at line 41 of file VideoMapping.C.

References cfmt, ch, cw, and jevois::v4l2ImageSize().

Referenced by jevois::MovieInput::get().

◆ cstr()

std::string jevois::VideoMapping::cstr ( ) const

Convenience function to print out FCC WxH @ fps, for the input (camera) format.

Definition at line 79 of file VideoMapping.C.

References cfmt, cfps, ch, cw, and jevois::fccstr().

Referenced by str().

◆ fpsToUvc()

unsigned int jevois::VideoMapping::fpsToUvc ( float  fps)
static

Convert from fps to USB/UVC interval.

Definition at line 52 of file VideoMapping.C.

Referenced by main(), and jevois::Gadget::setFormat().

◆ fpsToV4l2()

struct v4l2_fract jevois::VideoMapping::fpsToV4l2 ( float  fps)
static

Convert from fps to V4L2 interval.

Definition at line 65 of file VideoMapping.C.

Referenced by jevois::Gadget::setFormat(), and jevois::Camera::setFormat().

◆ hasSameSpecsAs()

bool jevois::VideoMapping::hasSameSpecsAs ( VideoMapping const &  other) const

Equality operator for specs but not vendor or module name.

Note that two mappings will be declared to match if their fps values are within 0.01fps, to avoid mismatches due to floating point representation and rounding.

Definition at line 99 of file VideoMapping.C.

References cfmt, cfps, ch, cw, ofmt, ofps, oh, and ow.

Referenced by isSameAs(), and main().

◆ isSameAs()

bool jevois::VideoMapping::isSameAs ( VideoMapping const &  other) const

Equality operator for specs and also vendor or module name.

Note that two mappings will be declared to match if their fps values are within 0.01fps, to avoid mismatches due to floating point representation and rounding.

Definition at line 106 of file VideoMapping.C.

References cfmt, cfps, ch, cw, jevois::fccstr(), hasSameSpecsAs(), ispython, isSameAs(), LDEBUG, LERROR, LFATAL, modulename, ofmt, ofps, oh, ow, PERROR, setModuleType(), jevois::split(), str(), jevois::strfcc(), uvcformat, uvcframe, and vendor.

Referenced by isSameAs().

◆ match()

bool jevois::VideoMapping::match ( unsigned int  oformat,
unsigned int  owidth,
unsigned int  oheight,
float  oframespersec 
) const

Return true if this VideoMapping's output format is a match to the given output parameters.

Definition at line 302 of file VideoMapping.C.

References ofmt, ofps, oh, and ow.

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

◆ osize()

unsigned int jevois::VideoMapping::osize ( ) const

Return the size in bytes of an output image.

Definition at line 37 of file VideoMapping.C.

References ofmt, oh, ow, and jevois::v4l2ImageSize().

Referenced by jevois::MovieOutput::get(), jevois::VideoOutputNone::setFormat(), jevois::VideoDisplay::setFormat(), and jevois::Gadget::setFormat().

◆ ostr()

std::string jevois::VideoMapping::ostr ( ) const

Convenience function to print out FCC WxH @ fps, for the output (UVC) format.

Definition at line 71 of file VideoMapping.C.

References jevois::fccstr(), ofmt, ofps, oh, and ow.

Referenced by str().

◆ setModuleType()

void jevois::VideoMapping::setModuleType ( )

Determine whether module is C++ or python and set ispython flag accordingly.

The other fields should have been initialized already. operator>> and loadVideoMappings use this function insternally, so no need to call it after making a VideoMapping from sream. This function throws if neither a .so nor .py file is found in the appropriate place given module vendor and name.

Definition at line 310 of file VideoMapping.C.

References ispython, and sopath().

Referenced by isSameAs().

◆ sopath()

std::string jevois::VideoMapping::sopath ( ) const

Return the full absolute path and file name of the module's .so or .py file.

Definition at line 30 of file VideoMapping.C.

References ispython, modulename, and vendor.

Referenced by jevois::PythonModule::PythonModule(), jevois::Engine::setFormat(), and setModuleType().

◆ str()

std::string jevois::VideoMapping::str ( ) const

Convenience function to print out the whole mapping in a human-friendly way.

Definition at line 87 of file VideoMapping.C.

References cstr(), modulename, ostr(), and vendor.

Referenced by isSameAs(), jevois::Engine::parseCommand(), jevois::Gadget::setFormat(), and jevois::Engine::setFormat().

◆ uvcToFps()

float jevois::VideoMapping::uvcToFps ( unsigned int  interval)
static

Convert from USB/UVC interval to fps.

This function rounds to the nearest 1/100 fps.

Definition at line 45 of file VideoMapping.C.

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

◆ v4l2ToFps()

float jevois::VideoMapping::v4l2ToFps ( struct v4l2_fract const &  interval)
static

Convert from V4L2 interval to fps.

This function rounds to the nearest 1/100 fps.

Definition at line 58 of file VideoMapping.C.

Friends And Related Function Documentation

◆ loadVideoMappings()

std::vector< VideoMapping > loadVideoMappings ( size_t &  defidx,
bool  checkso = true 
)
related

Load all the video mappings from the default config file.

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
VideoMapping const &  m 
)
related

Stream a VideoMapping out, intended for machines.

Note that no std::endl is issued at the end.

◆ operator>>()

std::istream & operator>> ( std::istream &  in,
VideoMapping m 
)
related

Stream a VideoMapping in, intended for machines.

Note that the assumption is that the mapping is clean (no extra garbage).

◆ videoMappingsFromStream()

std::vector< VideoMapping > videoMappingsFromStream ( std::istream &  is,
size_t &  defidx,
bool  checkso = true 
)
related

Parse all the mappings in a config file and also indicate which one is the default.

The contents of the file are sorted so that the resulting vector is ordered by increasing 1) format fcc, then 2) resolution (from large to small, looking at x first), and 3) framerate (from high to low).

In case of duplicate output formats, frame rates will be decreased by 1fps for each additional duplicate. This is because we need to present the host computer with distinct video formats so that users can select the one they want. For example:

YUYV 320 240 60.0 YUYV 320 240 60.0 JeVois SaveVideo
YUYV 320 240 60.0 YUYV 320 240 60.0 VendorX MyModule
YUYV 320 240 60.0 YUYV 320 240 60.0 VendorY MyModule
YUYV 320 240 60.0 YUYV 320 240 60.0 VendorZ MyModule

will be disambiguated into:

YUYV 320 240 60.0 YUYV 320 240 60.0 JeVois SaveVideo
YUYV 320 240 59.0 YUYV 320 240 60.0 VendorX MyModule
YUYV 320 240 58.0 YUYV 320 240 60.0 VendorY MyModule
YUYV 320 240 57.0 YUYV 320 240 60.0 VendorZ MyModule

and in guvcview or similar program running on a host computer, these 4 mappings will be available since they correspond to 4 different framerates. It is recommended that you issue a listmapping command in the JeVois command-line interface to confirm the final mappings that are used at runtime after any adjustments; see Command-line interface user guide for details.

defidx is the index of the default format in the resulting vector of mappings. If several default formats are specified, the first one prevails.

See User guide to video modes and mappings for explanations about how to organize videomappings.cfg

Member Data Documentation

◆ cfmt

unsigned int jevois::VideoMapping::cfmt

camera pixel format

Definition at line 48 of file VideoMapping.H.

Referenced by csize(), cstr(), jevois::MovieInput::get(), hasSameSpecsAs(), isSameAs(), main(), and jevois::Camera::setFormat().

◆ cfps

float jevois::VideoMapping::cfps

camera frame rate in frames/sec

Definition at line 51 of file VideoMapping.H.

Referenced by cstr(), jevois::MovieInput::get(), hasSameSpecsAs(), isSameAs(), main(), and jevois::Camera::setFormat().

◆ ch

unsigned int jevois::VideoMapping::ch

camera height

Definition at line 50 of file VideoMapping.H.

Referenced by csize(), cstr(), jevois::MovieInput::get(), hasSameSpecsAs(), isSameAs(), main(), and jevois::Camera::setFormat().

◆ cw

unsigned int jevois::VideoMapping::cw

camera width

Definition at line 49 of file VideoMapping.H.

Referenced by csize(), cstr(), jevois::MovieInput::get(), hasSameSpecsAs(), isSameAs(), main(), and jevois::Camera::setFormat().

◆ ispython

bool jevois::VideoMapping::ispython

True if the module is written in Python; affects behavior of sopath() only.

Definition at line 60 of file VideoMapping.H.

Referenced by isSameAs(), jevois::PythonModule::PythonModule(), jevois::Engine::setFormat(), setModuleType(), and sopath().

◆ modulename

std::string jevois::VideoMapping::modulename

Name of the Module that will process this mapping.

Definition at line 58 of file VideoMapping.H.

Referenced by isSameAs(), main(), jevois::PythonModule::PythonModule(), jevois::Engine::setFormat(), sopath(), and str().

◆ ofmt

◆ ofps

◆ oh

◆ ow

◆ uvcformat

unsigned int jevois::VideoMapping::uvcformat

USB-UVC format number (1-based)

Definition at line 53 of file VideoMapping.H.

Referenced by jevois::Engine::getVideoMappingIdx(), isSameAs(), and jevois::Gadget::setFormat().

◆ uvcframe

unsigned int jevois::VideoMapping::uvcframe

USB UVC frame number (1-based)

Definition at line 54 of file VideoMapping.H.

Referenced by jevois::Engine::getVideoMappingIdx(), isSameAs(), and jevois::Gadget::setFormat().

◆ vendor

std::string jevois::VideoMapping::vendor

Module creator name, used as a directory to organize the modules.

Definition at line 56 of file VideoMapping.H.

Referenced by isSameAs(), main(), sopath(), and str().


The documentation for this struct was generated from the following files: