JeVois  1.3
JeVois Smart Embedded Machine Vision Toolkit
Share this page:
Minimalistic support for images in the core JeVois library

The main purpose of the classes and functions that support images is to allow handling of image buffers whose memory is mapped onto hardware (camera or USB drivers) without having to copy the data over. Many other libraries and frameworks are available that define more complete image classes and associated image processing and machine vision functions. Functions are here provided to allow you to reinterpret the raw image buffers as, e.g., OpenCV cv::Mat images without copying the image pixel data. For the purposes of creating demo displays, simple image copy, paste, drawing, text, etc into raw YUYV image buffers (which would typically be obtained from the USB driver and need to be filled with some pixel data to send over the USB link) are also provided.

The class that represents an image with a pixel buffer that the camera or USB hardware has direct memory access to (see VideoBuf) is called RawImage. To avoid defining pixel types yet again, as most image-related libraries already do, in RawImage we just use the definitions provided by Video4Linux2.

The functions that operate on RawImage are thus mostly intented for two purposes: 1) get pixel data out of RawImage and into another format like OpenCV, or from some other format into RawImage; 2) Allow simple drawings of lines, circles, rectangles, etc to make simple demo displays directly in the RawImage buffer that will be sent over the USB link.

Collaboration diagram for Minimalistic support for images in the core JeVois library:

Classes

class  jevois::RawImage
 A raw image as coming from a V4L2 Camera and/or being sent out to a USB Gadget. More...
 

Namespaces

 jevois::yuyv
 Helper YUYV colors.
 
 jevois::rgb565
 Helper RGB565 colors.
 

Modules

 Jpeg-related classes and functions
 

Enumerations

enum  jevois::rawimage::Font {
  jevois::rawimage::Font5x7, jevois::rawimage::Font6x10, jevois::rawimage::Font7x13, jevois::rawimage::Font8x13bold,
  jevois::rawimage::Font9x15bold, jevois::rawimage::Font10x20, jevois::rawimage::Font11x22, jevois::rawimage::Font12x22,
  jevois::rawimage::Font14x26, jevois::rawimage::Font15x28, jevois::rawimage::Font16x29, jevois::rawimage::Font20x38
}
 Available fonts for writeText() More...
 

Functions

void convertYUYVtoRGB24 (unsigned int w, unsigned int h, unsigned char const *src, unsigned char *dst)
 Convert from YUYV to RGB, mostly intended for internal use. Use RawImage functions instead in most cases. More...
 
void convertYUYVtoRGBYL (unsigned int w, unsigned int h, unsigned char const *src, int *dstrg, int *dstby, int *dstlum, int thresh, int inputbits)
 Convert from YUYV to RG, BY, and luminance for use by Saliency module in jevoisbase. For internal use. More...
 
cv::Mat jevois::rawimage::cvImage (RawImage const &src)
 Create an OpenCV image from the existing RawImage data, sharing the pixel memory rather than copying it. More...
 
cv::Mat jevois::rawimage::convertToCvGray (RawImage const &src)
 Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV gray byte. More...
 
cv::Mat jevois::rawimage::convertToCvBGR (RawImage const &src)
 Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV BGR byte. More...
 
cv::Mat jevois::rawimage::convertToCvRGB (RawImage const &src)
 Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB byte. More...
 
cv::Mat jevois::rawimage::convertToCvRGBA (RawImage const &src)
 Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB-A byte. More...
 
void jevois::rawimage::byteSwap (RawImage &img)
 Swap pairs of bytes in a RawImage. More...
 
void jevois::rawimage::paste (RawImage const &src, RawImage &dest, int dx, int dy)
 Paste an image within another of same pixel type. More...
 
void jevois::rawimage::pasteGreyToYUYV (cv::Mat const &src, RawImage &dest, int dx, int dy)
 Paste a grey byte image into a YUYV image. More...
 
void jevois::rawimage::pasteBGRtoYUYV (cv::Mat const &src, RawImage &dst, int dx, int dy)
 Paste a BGR byte image into a YUYV image. More...
 
void jevois::rawimage::roipaste (RawImage const &src, int x, int y, unsigned int w, unsigned int h, RawImage &dest, int dx, int dy)
 Paste an ROI from an image to within another of same pixel type. More...
 
void jevois::rawimage::drawDisk (RawImage &img, int x, int y, unsigned int rad, unsigned int col)
 Draw a disk in a YUYV image. More...
 
void jevois::rawimage::drawCircle (RawImage &img, int x, int y, unsigned int rad, unsigned int thick, unsigned int col)
 Draw a circle in a YUYV image. More...
 
void jevois::rawimage::drawLine (RawImage &img, int x1, int y1, int x2, int y2, unsigned int thick, unsigned int col)
 Draw a line in a YUYV image. More...
 
void jevois::rawimage::drawRect (RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int thick, unsigned int col)
 Draw a rectangle in a YUYV image. More...
 
void jevois::rawimage::drawRect (RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int col)
 Draw a rectangle in a YUYV image. More...
 
void jevois::rawimage::drawFilledRect (RawImage &img, int x, int y, unsigned int w, unsigned int h, unsigned int col)
 Draw a filled rectangle in a YUYV image. More...
 
void jevois::rawimage::writeText (RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
 Write some text in an image. More...
 
void jevois::rawimage::writeText (RawImage &img, char const *txt, int x, int y, unsigned int col, Font font=Font6x10)
 Write some text in an image. More...
 
void jevois::rawimage::convertCvBGRtoRawImage (cv::Mat const &src, RawImage &dst, int quality)
 Convert a BGR cv::Mat to RawImage with already-allocated pixels and pixel type. More...
 
void jevois::rawimage::convertCvRGBtoRawImage (cv::Mat const &src, RawImage &dst, int quality)
 Convert a RGB cv::Mat to RawImage with already-allocated pixels and pixel type. More...
 
void jevois::rawimage::convertCvRGBAtoRawImage (cv::Mat const &src, RawImage &dst, int quality)
 Convert an RGBA cv::Mat to RawImage with already-allocated pixels and pixel type. More...
 
void jevois::rawimage::convertCvGRAYtoRawImage (cv::Mat const &src, RawImage &dst, int quality)
 Convert a Gray cv::Mat to RawImage with already-allocated pixels and pixel type. More...
 
void jevois::rawimage::unpackCvRGBAtoGrayRawImage (cv::Mat const &src, RawImage &dst)
 Split an RGBA cv::Mat into a 4x taller grey RawImage with already-allocated pixels. More...
 

Enumeration Type Documentation

Available fonts for writeText()

Enumerator
Font5x7 
Font6x10 
Font7x13 
Font8x13bold 
Font9x15bold 
Font10x20 
Font11x22 
Font12x22 
Font14x26 
Font15x28 
Font16x29 
Font20x38 

Definition at line 140 of file RawImageOps.H.

Function Documentation

void jevois::rawimage::byteSwap ( jevois::RawImage img)

Swap pairs of bytes in a RawImage.

This should never be needed, except maybe for RGB565 images, mainly for internal debugging, or to directly pass an RGB565 camera image (which is big endian) to USB (which assumes little endian when using RGBP UVC format). This function is NEON-accelerated when compiled for the platform hardware.

Definition at line 306 of file RawImageOps.C.

References jevois::RawImage::bytesize(), jevois::RawImage::bytesperpix(), jevois::RawImage::height, LFATAL, jevois::RawImage::pixelsw(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE().

void jevois::rawimage::convertCvBGRtoRawImage ( cv::Mat const &  src,
RawImage dst,
int  quality 
)

Convert a BGR cv::Mat to RawImage with already-allocated pixels and pixel type.

This is used to output video frames over USB from internally computed results in opencv BGR format. dst should already have an allocated pixel buffer (typically, it should be obtained from the USB gadget), and its size must match that of the src image.

Supported dst pixel formats:

  • V4L2_PIX_FMT_YUYV
  • V4L2_PIX_FMT_GREY
  • V4L2_PIX_FMT_SRGGB8 (Bayer)
  • V4L2_PIX_FMT_RGB565
  • V4L2_PIX_FMT_MJPG
  • V4L2_PIX_FMT_BGR24

quality is used only when dst is MJPG and should be between 1 and 100.

Definition at line 1072 of file RawImageOps.C.

References jevois::RawImage::bytesperpix(), jevois::compressBGRtoJpeg(), jevois::rawimage::cvImage(), jevois::fccstr(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, jevois::RawImage::pixelsw(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), jevois::MovieInput::get(), TutorialConvert::process(), and jevois::OutputFrame::sendCvBGR().

void jevois::rawimage::convertCvGRAYtoRawImage ( cv::Mat const &  src,
RawImage dst,
int  quality 
)

Convert a Gray cv::Mat to RawImage with already-allocated pixels and pixel type.

This is used to output video frames over USB from internally computed results in opencv Gray format. dst should already have an allocated pixel buffer (typically, it should be obtained from the USB gadget), and its size must match that of the src image.

Supported dst pixel formats:

  • V4L2_PIX_FMT_YUYV
  • V4L2_PIX_FMT_GREY
  • V4L2_PIX_FMT_SRGGB8 (Bayer)
  • V4L2_PIX_FMT_RGB565
  • V4L2_PIX_FMT_MJPG
  • V4L2_PIX_FMT_BGR24

quality is used only when dst is MJPG and should be between 1 and 100.

Definition at line 1158 of file RawImageOps.C.

References jevois::RawImage::bytesperpix(), jevois::compressGRAYtoJpeg(), jevois::rawimage::cvImage(), jevois::fccstr(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, jevois::RawImage::pixelsw(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), and jevois::OutputFrame::sendCvGRAY().

void jevois::rawimage::convertCvRGBAtoRawImage ( cv::Mat const &  src,
RawImage dst,
int  quality 
)

Convert an RGBA cv::Mat to RawImage with already-allocated pixels and pixel type.

This is used to output video frames over USB from internally computed results in opencv RGB-A format (which is often the format of choice for NEON or OpenGL processing). dst should already have an allocated pixel buffer (typically, it should be obtained from the USB gadget), and its size must match that of the src image.

Supported dst pixel formats:

  • V4L2_PIX_FMT_YUYV
  • V4L2_PIX_FMT_GREY
  • V4L2_PIX_FMT_SRGGB8 (Bayer)
  • V4L2_PIX_FMT_RGB565
  • V4L2_PIX_FMT_MJPG
  • V4L2_PIX_FMT_BGR24

quality is used only when dst is MJPG and should be between 1 and 100.

Definition at line 1138 of file RawImageOps.C.

References jevois::compressRGBAtoJpeg(), jevois::rawimage::cvImage(), jevois::fccstr(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), and jevois::OutputFrame::sendCvRGBA().

void jevois::rawimage::convertCvRGBtoRawImage ( cv::Mat const &  src,
RawImage dst,
int  quality 
)

Convert a RGB cv::Mat to RawImage with already-allocated pixels and pixel type.

This is used to output video frames over USB from internally computed results in opencv BGR format. dst should already have an allocated pixel buffer (typically, it should be obtained from the USB gadget), and its size must match that of the src image.

Supported dst pixel formats:

  • V4L2_PIX_FMT_YUYV
  • V4L2_PIX_FMT_GREY
  • V4L2_PIX_FMT_SRGGB8 (Bayer)
  • V4L2_PIX_FMT_RGB565
  • V4L2_PIX_FMT_MJPG
  • V4L2_PIX_FMT_BGR24

quality is used only when dst is MJPG and should be between 1 and 100.

Definition at line 1093 of file RawImageOps.C.

References jevois::compressRGBtoJpeg(), jevois::rawimage::cvImage(), jevois::fccstr(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), and jevois::OutputFrame::sendCvRGB().

cv::Mat jevois::rawimage::convertToCvBGR ( jevois::RawImage const &  src)

Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV BGR byte.

For historical reasons, BGR is the "native" color format of OpenCV, check whether your algorithm needs RGB or BGR and use the appropriate conversion for it.

Supported RawImage pixel formats:

  • V4L2_PIX_FMT_YUYV
  • V4L2_PIX_FMT_GREY
  • V4L2_PIX_FMT_SRGGB8 (Bayer)
  • V4L2_PIX_FMT_RGB565
  • V4L2_PIX_FMT_BGR24

Definition at line 226 of file RawImageOps.C.

References jevois::rawimage::cvImage(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), jevois::InputFrame::getCvBGR(), TutorialConvert::process(), and jevois::MovieOutput::send().

cv::Mat jevois::rawimage::convertToCvGray ( jevois::RawImage const &  src)

Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV gray byte.

Supported RawImage pixel formats:

  • V4L2_PIX_FMT_YUYV
  • V4L2_PIX_FMT_GREY
  • V4L2_PIX_FMT_SRGGB8 (Bayer)
  • V4L2_PIX_FMT_RGB565
  • V4L2_PIX_FMT_BGR24

Definition at line 203 of file RawImageOps.C.

References jevois::rawimage::cvImage(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), jevois::InputFrame::getCvGRAY(), TutorialEdgeDetection::process(), and TutorialEdgeDetectionX4::process().

cv::Mat jevois::rawimage::convertToCvRGB ( jevois::RawImage const &  src)

Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB byte.

For historical reasons, BGR is the "native" color format of OpenCV, not RGB as created here, check whether your algorithm needs RGB or BGR and use the appropriate conversion for it.

Supported RawImage pixel formats:

  • V4L2_PIX_FMT_YUYV
  • V4L2_PIX_FMT_GREY
  • V4L2_PIX_FMT_SRGGB8 (Bayer)
  • V4L2_PIX_FMT_RGB565
  • V4L2_PIX_FMT_BGR24

Definition at line 249 of file RawImageOps.C.

References jevois::rawimage::cvImage(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), and jevois::InputFrame::getCvRGB().

cv::Mat jevois::rawimage::convertToCvRGBA ( jevois::RawImage const &  src)

Convert RawImage to OpenCV doing color conversion from any RawImage source pixel to OpenCV RGB-A byte.

RGBA is seldom used by OpenCV itself, but is useful for many NEON and OpenGL (GPU) algorithms. For these algorithms, we here just use cv::Mat as a convenient container for raw pixel data.

Supported RawImage pixel formats:

  • V4L2_PIX_FMT_YUYV
  • V4L2_PIX_FMT_GREY
  • V4L2_PIX_FMT_SRGGB8 (Bayer)
  • V4L2_PIX_FMT_RGB565
  • V4L2_PIX_FMT_BGR24

Definition at line 272 of file RawImageOps.C.

References jevois::rawimage::cvImage(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), and jevois::InputFrame::getCvRGBA().

void convertYUYVtoRGB24 ( unsigned int  w,
unsigned int  h,
unsigned char const *  src,
unsigned char *  dst 
)

Convert from YUYV to RGB, mostly intended for internal use. Use RawImage functions instead in most cases.

This code is modified from here: http://pastebin.com/mDcwqJV3 Memory should have been allocated by caller.

Definition at line 23 of file ColorConversion.c.

References CLAMP.

void convertYUYVtoRGBYL ( unsigned int  w,
unsigned int  h,
unsigned char const *  src,
int *  dstrg,
int *  dstby,
int *  dstlum,
int  thresh,
int  inputbits 
)

Convert from YUYV to RG, BY, and luminance for use by Saliency module in jevoisbase. For internal use.

Definition at line 89 of file ColorConversion.c.

References convertYUYVtoRGBYLinternal().

cv::Mat jevois::rawimage::cvImage ( jevois::RawImage const &  src)

Create an OpenCV image from the existing RawImage data, sharing the pixel memory rather than copying it.

The pixel data is not copied, just pointed to, and no pixel format conversion is done. You should destroy the cv::Mat before the RawImage to avoid that your cv::Mat ends up with de-allocated pixel memory.

Definition at line 30 of file RawImageOps.C.

References jevois::RawImage::buf, jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, jevois::v4l2BytesPerPix(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE(), jevois::rawimage::convertCvBGRtoRawImage(), jevois::rawimage::convertCvGRAYtoRawImage(), jevois::rawimage::convertCvRGBAtoRawImage(), jevois::rawimage::convertCvRGBtoRawImage(), jevois::rawimage::convertToCvBGR(), jevois::rawimage::convertToCvGray(), jevois::rawimage::convertToCvRGB(), jevois::rawimage::convertToCvRGBA(), and TutorialEdgeDetection::process().

void jevois::rawimage::drawCircle ( jevois::RawImage img,
int  x,
int  y,
unsigned int  rad,
unsigned int  thick,
unsigned int  col 
)

Draw a circle in a YUYV image.

Definition at line 421 of file RawImageOps.C.

References jevois::rawimage::drawDisk().

Referenced by BOOST_PYTHON_MODULE().

void jevois::rawimage::drawDisk ( jevois::RawImage img,
int  x,
int  y,
unsigned int  rad,
unsigned int  col 
)
void jevois::rawimage::drawFilledRect ( jevois::RawImage img,
int  x,
int  y,
unsigned int  w,
unsigned int  h,
unsigned int  col 
)

Draw a filled rectangle in a YUYV image.

This is really not flexible and is optimized for speed only. col will be used for both YU and YV pixels. For more demanding drawings, use openCV functions.

Definition at line 516 of file RawImageOps.C.

References jevois::RawImage::height, jevois::RawImage::pixelsw(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE().

void jevois::rawimage::drawLine ( jevois::RawImage img,
int  x1,
int  y1,
int  x2,
int  y2,
unsigned int  thick,
unsigned int  col 
)
void jevois::rawimage::drawRect ( jevois::RawImage img,
int  x,
int  y,
unsigned int  w,
unsigned int  h,
unsigned int  thick,
unsigned int  col 
)

Draw a rectangle in a YUYV image.

Definition at line 482 of file RawImageOps.C.

References jevois::rawimage::drawLine().

Referenced by BOOST_PYTHON_MODULE().

void jevois::rawimage::drawRect ( jevois::RawImage img,
int  x,
int  y,
unsigned int  w,
unsigned int  h,
unsigned int  col 
)

Draw a rectangle in a YUYV image.

This is really not flexible and is optimized for speed only. col will be used for both YU and YV pixels. For more demanding drawings, use openCV functions.

Definition at line 496 of file RawImageOps.C.

References jevois::RawImage::height, jevois::RawImage::pixelsw(), and jevois::RawImage::width.

void jevois::rawimage::paste ( jevois::RawImage const &  src,
jevois::RawImage dest,
int  dx,
int  dy 
)

Paste an image within another of same pixel type.

To keep this function fast, throws if the source image does not fully fit within the destination image, or if the two images do not have the same pixel format.

Definition at line 341 of file RawImageOps.C.

References jevois::RawImage::bytesperpix(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, jevois::RawImage::pixels(), jevois::RawImage::pixelsw(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE().

void jevois::rawimage::pasteBGRtoYUYV ( cv::Mat const &  src,
jevois::RawImage dst,
int  dx,
int  dy 
)

Paste a BGR byte image into a YUYV image.

Definition at line 888 of file RawImageOps.C.

References jevois::RawImage::bytesperpix(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, jevois::RawImage::pixelsw(), and jevois::RawImage::width.

void jevois::rawimage::pasteGreyToYUYV ( cv::Mat const &  src,
jevois::RawImage dest,
int  dx,
int  dy 
)

Paste a grey byte image into a YUYV image.

Definition at line 386 of file RawImageOps.C.

References jevois::RawImage::bytesperpix(), jevois::RawImage::height, LFATAL, jevois::RawImage::pixelsw(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE().

void jevois::rawimage::roipaste ( jevois::RawImage const &  src,
int  x,
int  y,
unsigned int  w,
unsigned int  h,
jevois::RawImage dest,
int  dx,
int  dy 
)

Paste an ROI from an image to within another of same pixel type.

To keep this function fast, throws if the source image does not fully fit within the destination image or if the pixel formats differ.

Definition at line 363 of file RawImageOps.C.

References jevois::RawImage::bytesperpix(), jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, jevois::RawImage::pixels(), jevois::RawImage::pixelsw(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE().

void jevois::rawimage::unpackCvRGBAtoGrayRawImage ( cv::Mat const &  src,
RawImage dst 
)

Split an RGBA cv::Mat into a 4x taller grey RawImage with already-allocated pixels.

This is used to run GPU shaders that apply different filters to an image and store their results separately into the R, G, B and A components of an RGBA output image. Here, we just unpack the 4 components and stuff them into the output image one above the other: R on top, then G below it, then B below it, then A below it. The destination RawImage must be at least as wide as src and at least 4 times as tall as src, and must have V4L2_PIX_FMT_GREY pixels.

Definition at line 1114 of file RawImageOps.C.

References jevois::RawImage::fmt, jevois::RawImage::height, LFATAL, jevois::RawImage::pixelsw(), and jevois::RawImage::width.

Referenced by BOOST_PYTHON_MODULE().

void jevois::rawimage::writeText ( jevois::RawImage img,
std::string const &  txt,
int  x,
int  y,
unsigned int  col,
Font  font = Font6x10 
)

Write some text in an image.

Definition at line 557 of file RawImageOps.C.

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