YARP  2.3.70.1
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...
 
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, int w, int h)
 Scaled copy. More...
 
int width () const
 Gets width of image in pixels. More...
 
int height () const
 Gets height of image in pixels. More...
 
virtual int getPixelSize () const
 Gets pixel size in memory in bytes. More...
 
virtual int getPixelCode () const
 Gets pixel type identifier. More...
 
int getRowSize () const
 Size of the underlying image buffer rows. More...
 
int getQuantum () const
 The size of a row is constrained to be a multiple of the "quantum". More...
 
int getPadding () const
 Returns the number of padding bytes. More...
 
unsigned char * getRow (int r)
 Get the address of a the first byte of a row in memory. More...
 
const unsigned char * getRow (int r) const
 Get the address of a the first byte of a row in memory, const versions. More...
 
unsigned char * getPixelAddress (int x, int y) const
 Get address of a pixel in memory. More...
 
bool isPixel (int x, int y) const
 Check whether a coordinate lies within the image. More...
 
void zero ()
 Set all pixels to 0. More...
 
void resize (int imgWidth, int 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, int imgWidth, int imgHeight)
 Use this to wrap an external image. More...
 
unsigned char * getRawImage () const
 Access to the internal image buffer. More...
 
int 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) YARP_OVERRIDE
 Read image from a connection. More...
 
virtual bool write (yarp::os::ConnectionWriter &connection) YARP_OVERRIDE
 Write image to a connection. More...
 
void setQuantum (int 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 () YARP_OVERRIDE
 
- Public Member Functions inherited from yarp::os::Portable
virtual Type getType ()
 
- 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 ()
 This is called when the port has finished all writing operations. More...
 
virtual void onCommencement ()
 This is called when the port is about to begin writing operations. More...
 
virtual Type getWriteType ()
 

Protected Member Functions

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

Private Member Functions

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

Private Attributes

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

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

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

Constructor & Destructor Documentation

◆ Image() [1/2]

Image::Image ( )

Default constructor.

Creates an empty image.

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

◆ ~Image()

Image::~Image ( )
virtual

Destructor.

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

◆ copy() [2/2]

bool Image::copy ( const Image alt,
int  w,
int  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 1054 of file Image.cpp.

◆ copyPixels()

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

Definition at line 586 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
Examples:
cuda/cuda_gpu.cpp, and opencv/main.cpp.

Definition at line 743 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

Definition at line 747 of file Image.cpp.

◆ getPadding()

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

Returns the number of padding bytes.

Returns
number of bytes of the row padding.

Definition at line 140 of file Image.h.

◆ getPixelAddress()

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

Get address of a pixel in memory.

Parameters
xx coordinate
yy coordinate
Returns
address of pixel in memory

Definition at line 175 of file Image.h.

◆ getPixelCode()

◆ getPixelSize()

◆ getQuantum()

int 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 134 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 725 of file Image.cpp.

◆ getRawImageSize()

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

◆ getReadType()

virtual yarp::os::Type yarp::sig::Image::getReadType ( )
inlinevirtual

Reimplemented from yarp::os::PortReader.

Definition at line 308 of file Image.h.

◆ getRow() [1/2]

unsigned char* yarp::sig::Image::getRow ( int  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 151 of file Image.h.

◆ getRow() [2/2]

const unsigned char* yarp::sig::Image::getRow ( int  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 163 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 304 of file Image.h.

◆ getRowSize()

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

◆ height()

int 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:
cuda/cuda_gpu.cpp, dev/file_grabber.cpp, dev/grabber_client.cpp, imagemagick/main.cpp, and opencv/main.cpp.

Definition at line 107 of file Image.h.

◆ initialize()

void Image::initialize ( )
private

Definition at line 618 of file Image.cpp.

◆ isPixel()

bool yarp::sig::Image::isPixel ( int  x,
int  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 185 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 1000 of file Image.cpp.

◆ read()

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

Read image from a connection.

Returns
true iff image was read correctly

Implements yarp::os::Portable.

Definition at line 854 of file Image.cpp.

◆ resize() [1/2]

void Image::resize ( int  imgWidth,
int  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 656 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 210 of file Image.h.

◆ setExternal()

void Image::setExternal ( const void *  data,
int  imgWidth,
int  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 1040 of file Image.cpp.

◆ setPixelCode()

void Image::setPixelCode ( int  imgPixelCode)
protected

Definition at line 692 of file Image.cpp.

◆ setPixelSize()

void Image::setPixelSize ( int  imgPixelSize)
protected

Definition at line 697 of file Image.cpp.

◆ setQuantum()

void Image::setQuantum ( int  imgQuantum)

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

◆ synchronize()

void Image::synchronize ( )
private

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

◆ width()

int 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:
cuda/cuda_gpu.cpp, 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 101 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 751 of file Image.cpp.

◆ write()

bool Image::write ( yarp::os::ConnectionWriter connection)
virtual

Write image to a connection.

Returns
true iff image was written correctly

Implements yarp::os::Portable.

Definition at line 955 of file Image.cpp.

◆ zero()

void Image::zero ( )

Set all pixels to 0.

Examples:
os/image_source.cpp.

Definition at line 649 of file Image.cpp.

Member Data Documentation

◆ data

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

Definition at line 324 of file Image.h.

◆ imgHeight

int yarp::sig::Image::imgHeight
private

Definition at line 321 of file Image.h.

◆ imgPixelCode

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

Definition at line 321 of file Image.h.

◆ imgPixelSize

int yarp::sig::Image::imgPixelSize
private

Definition at line 321 of file Image.h.

◆ imgQuantum

int yarp::sig::Image::imgQuantum
private

Definition at line 321 of file Image.h.

◆ imgRowSize

int yarp::sig::Image::imgRowSize
private

Definition at line 321 of file Image.h.

◆ imgWidth

int yarp::sig::Image::imgWidth
private

Definition at line 321 of file Image.h.

◆ implementation

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

Definition at line 325 of file Image.h.

◆ topIsLow

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

Definition at line 322 of file Image.h.


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