YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
yarp::sig::Image Class Reference

Base class for storing images. More...

#include <yarp/sig/Image.h>

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

Public Member Functions

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

Protected Member Functions

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

Additional Inherited Members

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

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 79 of file Image.h.

Constructor & Destructor Documentation

◆ Image() [1/3]

Image::Image ( )

Default constructor.

Creates an empty image.

Definition at line 411 of file Image.cpp.

◆ Image() [2/3]

Image::Image ( const Image alt)

Copy constructor.

Clones the content of another image.

Parameters
altthe image to clone

Definition at line 692 of file Image.cpp.

◆ Image() [3/3]

Image::Image ( Image &&  other)
noexcept

Move constructor.

Parameters
otherthe Image to be moved

Definition at line 698 of file Image.cpp.

◆ ~Image()

Image::~Image ( )
override

Destructor.

Definition at line 428 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 722 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 803 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 202 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 237 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< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, yarp::sig::ImageOf< yarp::sig::PixelRgb >, yarp::sig::ImageOf< T >, yarp::sig::ImageOf< CellFlagData >, yarp::sig::ImageOf< CellOccupancyData >, yarp::sig::ImageOf< float >, yarp::sig::ImageOf< PixelRgb >, yarp::sig::ImageOf< yarp::sig::PixelFloat >, yarp::sig::ImageOf< yarp::sig::PixelMono >, and yarp::sig::ImageOf< yarp::sig::PixelRgb >.

Definition at line 441 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 196 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 542 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 551 of file Image.cpp.

◆ getReadType()

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

Reimplemented from yarp::os::PortReader.

Definition at line 336 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 213 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 225 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 332 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 189 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
imagemagick/main.cpp, and opencv/main.cpp.

Definition at line 169 of file Image.h.

◆ 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 247 of file Image.h.

◆ move()

bool Image::move ( Image &&  alt)
noexcept

move operator.

Moves the content of another image.

Parameters
altthe image to move

Definition at line 760 of file Image.cpp.

◆ operator=() [1/2]

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

Assignment operator.

Clones the content of another image.

Parameters
altthe image to clone

Definition at line 713 of file Image.cpp.

◆ operator=() [2/2]

Image & Image::operator= ( Image &&  other)
noexcept

Move assignment operator.

Parameters
otherthe Image to be moved
Returns
this object

Definition at line 704 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 560 of file Image.cpp.

◆ resize() [1/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 272 of file Image.h.

◆ resize() [2/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, and opencv/main.cpp.

Definition at line 453 of file Image.cpp.

◆ 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 789 of file Image.cpp.

◆ setPixelCode()

void Image::setPixelCode ( int  imgPixelCode)
protected

Definition at line 491 of file Image.cpp.

◆ setPixelSize()

void Image::setPixelSize ( size_t  imgPixelSize)
protected

Definition at line 483 of file Image.cpp.

◆ setQuantum()

void Image::setQuantum ( size_t  imgQuantum)

Definition at line 502 of file Image.cpp.

◆ setTopIsLowIndex()

void Image::setTopIsLowIndex ( bool  flag)

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 512 of file Image.cpp.

◆ swap()

bool Image::swap ( Image alt)

swap operator.

Swap the content with another image.

Parameters
altthe image to swap with

Definition at line 774 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 313 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
imagemagick/main.cpp, and opencv/main.cpp.

Definition at line 163 of file Image.h.

◆ 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 671 of file Image.cpp.

◆ zero()

void Image::zero ( )

Set all pixels to 0.

Examples
opencv/main.cpp.

Definition at line 446 of file Image.cpp.


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