YARP
Yet Another Robot Platform
yarp::sig::Image Class Reference

Base class for storing images. More...

#include <yarp/sig/Image.h>

+ Inheritance diagram for yarp::sig::Image:

Detailed Description

Base class for storing images.

You actually want to use ImageOf or FlexImage. This is a minimal class, designed to be as interoperable as possible with other image classes in other libraries, particularly IPL-derived libraries such as OpenCV.

Definition at line 85 of file Image.h.

Public Member Functions

 Image ()
 Default constructor. More...
 
 Image (const Image &alt)
 Copy constructor. More...
 
virtual ~Image ()
 Destructor. More...
 
const Imageoperator= (const Image &alt)
 Assignment operator. More...
 
bool copy (const Image &alt)
 Copy operator. More...
 
bool copy (const Image &alt, size_t w, size_t h)
 Scaled copy. More...
 
size_t width () const
 Gets width of image in pixels. More...
 
size_t height () const
 Gets height of image in pixels. More...
 
virtual size_t getPixelSize () const
 Gets pixel size in memory in bytes. More...
 
virtual int getPixelCode () const
 Gets pixel type identifier. More...
 
size_t getRowSize () const
 Size of the underlying image buffer rows. More...
 
size_t getQuantum () const
 The size of a row is constrained to be a multiple of the "quantum". More...
 
size_t getPadding () const
 Returns the number of padding bytes. More...
 
unsigned char * getRow (size_t r)
 Get the address of a the first byte of a row in memory. More...
 
const unsigned char * getRow (size_t r) const
 Get the address of a the first byte of a row in memory, const versions. More...
 
unsigned char * getPixelAddress (size_t x, size_t y) const
 Get address of a pixel in memory. More...
 
bool isPixel (size_t x, size_t y) const
 Check whether a coordinate lies within the image. More...
 
void zero ()
 Set all pixels to 0. More...
 
void resize (size_t imgWidth, size_t imgHeight)
 Reallocate an image to be of a desired size, throwing away its current contents. More...
 
void resize (const Image &alt)
 Reallocate the size of the image to match another, throwing away the actual content of the image. More...
 
void setExternal (const void *data, size_t imgWidth, size_t imgHeight)
 Use this to wrap an external image. More...
 
unsigned char * getRawImage () const
 Access to the internal image buffer. More...
 
size_t getRawImageSize () const
 Access to the internal buffer size information (this is how much memory has been allocated for the image). More...
 
void * getIplImage ()
 Returns IPL/OpenCV view of image, if possible. More...
 
const void * getIplImage () const
 Returns IPL/OpenCV view of image, if possible. More...
 
void wrapIplImage (void *iplImage)
 Act as a wrapper around an IPL/OpenCV image. More...
 
virtual bool read (yarp::os::ConnectionReader &connection) override
 Read image from a connection. More...
 
virtual bool write (yarp::os::ConnectionWriter &connection) const override
 Write image to a connection. More...
 
void setQuantum (size_t imgQuantum)
 
bool topIsLowIndex () const
 
void setTopIsLowIndex (bool flag)
 control whether image has origin at top left (default) or bottom left. More...
 
char ** getRowArray ()
 Get an array of pointers to the rows of the image. More...
 
virtual yarp::os::Type getReadType () const override
 
- Public Member Functions inherited from yarp::os::Portable
virtual Type getType () const
 
- Public Member Functions inherited from yarp::os::PortReader
virtual ~PortReader ()
 Destructor. More...
 
- Public Member Functions inherited from yarp::os::PortWriter
virtual ~PortWriter ()
 Destructor. More...
 
virtual void onCompletion () const
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement () const
 This is called when the port is about to begin writing operations. More...
 
virtual yarp::os::Type getWriteType () const
 

Protected Member Functions

void setPixelCode (int imgPixelCode)
 
void setPixelSize (size_t imgPixelSize)
 

Private Member Functions

void synchronize ()
 
void initialize ()
 
void copyPixels (const unsigned char *src, size_t id1, unsigned char *dest, size_t id2, size_t w, size_t h, size_t imageSize, size_t quantum1, size_t quantum2, bool topIsLow1, bool topIsLow2)
 

Private Attributes

size_t imgWidth
 
size_t imgHeight
 
size_t imgPixelSize
 
size_t imgRowSize
 
size_t imgQuantum
 
int imgPixelCode
 
bool topIsLow
 
char ** data
 
void * implementation
 

Static Private Attributes

static const std::map< YarpVocabPixelTypesEnum, size_t > pixelCode2Size
 

Additional Inherited Members

- Static Public Member Functions inherited from yarp::os::Portable
static bool copyPortable (PortWriter &writer, PortReader &reader)
 Copy one portable to another, via writing and reading. More...
 

Constructor & Destructor Documentation

◆ Image() [1/2]

Image::Image ( )

Default constructor.

Creates an empty image.

Definition at line 420 of file Image.cpp.

◆ Image() [2/2]

Image::Image ( const Image alt)

Copy constructor.

Clones the content of another image.

Parameters
altthe image to clone

Definition at line 795 of file Image.cpp.

◆ ~Image()

Image::~Image ( )
virtual

Destructor.

Definition at line 437 of file Image.cpp.

Member Function Documentation

◆ copy() [1/2]

bool Image::copy ( const Image alt)

Copy operator.

Clones the content of another image.

Parameters
altthe image to clone

Definition at line 807 of file Image.cpp.

◆ copy() [2/2]

bool Image::copy ( const Image alt,
size_t  w,
size_t  h 
)

Scaled copy.

Clones the content of another image, and resizes in a fast but low-quality way.

Parameters
altthe image to copy
wtarget width for image
htarget height for image

Definition at line 855 of file Image.cpp.

◆ copyPixels()

void Image::copyPixels ( const unsigned char *  src,
size_t  id1,
unsigned char *  dest,
size_t  id2,
size_t  w,
size_t  h,
size_t  imageSize,
size_t  quantum1,
size_t  quantum2,
bool  topIsLow1,
bool  topIsLow2 
)
private

Definition at line 1227 of file ImageCopy.cpp.

◆ getIplImage() [1/2]

void * Image::getIplImage ( )

Returns IPL/OpenCV view of image, if possible.

Not possible if the image is the wrong size, with no padding. This method is currently not well documented.

Returns
pointer to an IplImage structure or nullptr
Examples:
opencv/main.cpp.

Definition at line 544 of file Image.cpp.

◆ getIplImage() [2/2]

const void * Image::getIplImage ( ) const

Returns IPL/OpenCV view of image, if possible.

Not possible if the image is the wrong size, with no padding. This method is currently not well documented.

Returns
pointer to an IplImage structure or nullptr

Definition at line 548 of file Image.cpp.

◆ getPadding()

size_t yarp::sig::Image::getPadding ( ) const
inline

Returns the number of padding bytes.

Returns
number of bytes of the row padding.

Definition at line 177 of file Image.h.

◆ getPixelAddress()

unsigned char* yarp::sig::Image::getPixelAddress ( size_t  x,
size_t  y 
) const
inline

Get address of a pixel in memory.

Parameters
xx coordinate
yy coordinate
Returns
address of pixel in memory

Definition at line 212 of file Image.h.

◆ getPixelCode()

int Image::getPixelCode ( ) const
virtual

Gets pixel type identifier.

Images have an associated type identifier to permit automatic casting between different image types.

Returns
the image type identifier

Reimplemented in yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< CellData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, and yarp::sig::ImageOf< yarp::sig::PixelRgb >.

Definition at line 450 of file Image.cpp.

◆ getPixelSize()

size_t Image::getPixelSize ( ) const
virtual

◆ getQuantum()

size_t yarp::sig::Image::getQuantum ( ) const
inline

The size of a row is constrained to be a multiple of the "quantum".

Returns
size of the current quantum (0 means no constraint)

Definition at line 171 of file Image.h.

◆ getRawImage()

unsigned char * Image::getRawImage ( ) const

Access to the internal image buffer.

Returns
pointer to the internal image buffer.

Definition at line 526 of file Image.cpp.

◆ getRawImageSize()

size_t Image::getRawImageSize ( ) const

Access to the internal buffer size information (this is how much memory has been allocated for the image).

Returns
size of the internal buffer in bytes including padding.

Definition at line 535 of file Image.cpp.

◆ getReadType()

virtual yarp::os::Type yarp::sig::Image::getReadType ( ) const
inlineoverridevirtual

Reimplemented from yarp::os::PortReader.

Definition at line 345 of file Image.h.

◆ getRow() [1/2]

unsigned char* yarp::sig::Image::getRow ( size_t  r)
inline

Get the address of a the first byte of a row in memory.

Parameters
rrow number (starting from 0)
Returns
address of the r-th row

Definition at line 188 of file Image.h.

◆ getRow() [2/2]

const unsigned char* yarp::sig::Image::getRow ( size_t  r) const
inline

Get the address of a the first byte of a row in memory, const versions.

Parameters
rrow number (starting from 0)
Returns
address of the r-th row

Definition at line 200 of file Image.h.

◆ getRowArray()

char** yarp::sig::Image::getRowArray ( )
inline

Get an array of pointers to the rows of the image.

Returns
an array of pointers to the rows of the image.

Definition at line 341 of file Image.h.

◆ getRowSize()

size_t yarp::sig::Image::getRowSize ( ) const
inline

Size of the underlying image buffer rows.

Returns
size of the underlying image buffer rows in bytes.

Definition at line 164 of file Image.h.

◆ height()

size_t yarp::sig::Image::height ( ) const
inline

Gets height of image in pixels.

Returns
the height of the image in pixels (0 if no image present)
Examples:
dev/file_grabber.cpp, dev/grabber_client.cpp, imagemagick/main.cpp, and opencv/main.cpp.

Definition at line 144 of file Image.h.

◆ initialize()

void Image::initialize ( )
private

Definition at line 424 of file Image.cpp.

◆ isPixel()

bool yarp::sig::Image::isPixel ( size_t  x,
size_t  y 
) const
inline

Check whether a coordinate lies within the image.

Parameters
xx coordinate
yy coordinate
Returns
true iff there is a pixel at the given coordinate

Definition at line 222 of file Image.h.

◆ operator=()

const Image & Image::operator= ( const Image alt)

Assignment operator.

Clones the content of another image.

Parameters
altthe image to clone

Definition at line 801 of file Image.cpp.

◆ read()

bool Image::read ( yarp::os::ConnectionReader connection)
overridevirtual

Read image from a connection.

Returns
true iff image was read correctly

Implements yarp::os::Portable.

Definition at line 655 of file Image.cpp.

◆ resize() [1/2]

void Image::resize ( size_t  imgWidth,
size_t  imgHeight 
)

Reallocate an image to be of a desired size, throwing away its current contents.

If the desired size is the same as the current size, then no reallocation is done. But the resulting image should always be assumed to have undefined content. To rescale an image, maintaining its content, see the Image::copy methods.

Parameters
imgWidththe desired width (the number of possible x values)
imgHeightthe desired height (the number of possible y values)
Examples:
imagemagick/main.cpp, opencv/main.cpp, and os/image_source.cpp.

Definition at line 462 of file Image.cpp.

◆ resize() [2/2]

void yarp::sig::Image::resize ( const Image alt)
inline

Reallocate the size of the image to match another, throwing away the actual content of the image.

Parameters
altthe image whose size we should match.

Definition at line 247 of file Image.h.

◆ setExternal()

void Image::setExternal ( const void *  data,
size_t  imgWidth,
size_t  imgHeight 
)

Use this to wrap an external image.

Make sure to that pixel type and padding quantum are synchronized (you can set these in the FlexImage class).

Definition at line 841 of file Image.cpp.

◆ setPixelCode()

void Image::setPixelCode ( int  imgPixelCode)
protected

Definition at line 499 of file Image.cpp.

◆ setPixelSize()

void Image::setPixelSize ( size_t  imgPixelSize)
protected

Definition at line 491 of file Image.cpp.

◆ setQuantum()

void Image::setQuantum ( size_t  imgQuantum)

Definition at line 505 of file Image.cpp.

◆ setTopIsLowIndex()

void yarp::sig::Image::setTopIsLowIndex ( bool  flag)
inline

control whether image has origin at top left (default) or bottom left.

Parameters
flagtrue if image has origin at top left (default), false if image has origin at bottom left.

Definition at line 332 of file Image.h.

◆ synchronize()

void Image::synchronize ( )
private

Definition at line 510 of file Image.cpp.

◆ topIsLowIndex()

bool yarp::sig::Image::topIsLowIndex ( ) const
inline
Returns
true if image has origin at top left (default); in other words when the y index is low, we are near the top of the image.

Definition at line 320 of file Image.h.

◆ width()

size_t yarp::sig::Image::width ( ) const
inline

Gets width of image in pixels.

Returns
the width of the image in pixels (0 if no image present)
Examples:
dev/file_grabber.cpp, dev/grabber_client.cpp, imagemagick/main.cpp, opencv/main.cpp, os/image_process.cpp, and os/image_process_module.cpp.

Definition at line 138 of file Image.h.

◆ wrapIplImage()

void Image::wrapIplImage ( void *  iplImage)

Act as a wrapper around an IPL/OpenCV image.

The wrapped image needs to exist for the rest of the lifetime of this oboject. Be careful if you use this method on objects read from or written to a BufferedPort, since the lifetime of such objects can be longer than you expect (see the documentation for yarp::os::BufferedPort::read, yarp::os::BufferedPort::prepare, and yarp::os::BufferedPort::write).

Parameters
iplImagepointer to an IplImage structure

Definition at line 552 of file Image.cpp.

◆ write()

bool Image::write ( yarp::os::ConnectionWriter connection) const
overridevirtual

Write image to a connection.

Returns
true iff image was written correctly

Implements yarp::os::Portable.

Definition at line 756 of file Image.cpp.

◆ zero()

void Image::zero ( )

Set all pixels to 0.

Examples:
os/image_source.cpp.

Definition at line 455 of file Image.cpp.

Member Data Documentation

◆ data

char** yarp::sig::Image::data
private

Definition at line 366 of file Image.h.

◆ imgHeight

size_t yarp::sig::Image::imgHeight
private

Definition at line 362 of file Image.h.

◆ imgPixelCode

int yarp::sig::Image::imgPixelCode
private

Definition at line 363 of file Image.h.

◆ imgPixelSize

size_t yarp::sig::Image::imgPixelSize
private

Definition at line 362 of file Image.h.

◆ imgQuantum

size_t yarp::sig::Image::imgQuantum
private

Definition at line 362 of file Image.h.

◆ imgRowSize

size_t yarp::sig::Image::imgRowSize
private

Definition at line 362 of file Image.h.

◆ imgWidth

size_t yarp::sig::Image::imgWidth
private

Definition at line 362 of file Image.h.

◆ implementation

void* yarp::sig::Image::implementation
private

Definition at line 367 of file Image.h.

◆ pixelCode2Size

◆ topIsLow

bool yarp::sig::Image::topIsLow
private

Definition at line 364 of file Image.h.


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