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:

Public Member Functions

 Image ()
 Default constructor. More...
 
 Image (const Image &alt)
 Copy constructor. More...
 
 Image (Image &&other) noexcept
 Move constructor. More...
 
Imageoperator= (const Image &alt)
 Assignment operator. More...
 
Imageoperator= (Image &&other) noexcept
 Move assignment operator. More...
 
 ~Image () override
 Destructor. 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...
 
bool read (yarp::os::ConnectionReader &connection) override
 Read image from a connection. More...
 
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...
 
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)
 

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. More...
 

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.

Constructor & Destructor Documentation

◆ Image() [1/3]

Image::Image ( )

Default constructor.

Creates an empty image.

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

◆ Image() [3/3]

Image::Image ( Image &&  other)
noexcept

Move constructor.

Parameters
otherthe Image to be moved

Definition at line 817 of file Image.cpp.

◆ ~Image()

Image::~Image ( )
override

Destructor.

Definition at line 441 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 842 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 892 of file Image.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

Definition at line 553 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 557 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 192 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 227 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

Definition at line 454 of file Image.cpp.

◆ getPixelSize()

size_t Image::getPixelSize ( ) const
virtual

Gets pixel size in memory in bytes.

Returns
the size of the pixels stored in the image, in bytes

Definition at line 449 of file Image.cpp.

◆ 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 186 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 534 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 543 of file Image.cpp.

◆ getReadType()

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

Reimplemented from yarp::os::PortReader.

Definition at line 365 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 203 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 215 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 361 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 179 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)

Definition at line 159 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 237 of file Image.h.

◆ 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 833 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 824 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 665 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 262 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)

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

◆ setPixelCode()

void Image::setPixelCode ( int  imgPixelCode)
protected

Definition at line 504 of file Image.cpp.

◆ setPixelSize()

void Image::setPixelSize ( size_t  imgPixelSize)
protected

Definition at line 496 of file Image.cpp.

◆ setQuantum()

void Image::setQuantum ( size_t  imgQuantum)

Definition at line 510 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 352 of file Image.h.

◆ 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 340 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)

Definition at line 153 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 561 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 772 of file Image.cpp.

◆ zero()

void Image::zero ( )

Set all pixels to 0.

Definition at line 459 of file Image.cpp.


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