|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
10 #ifndef YARP_SIG_IMAGE_H
11 #define YARP_SIG_IMAGE_H
28 template <
class T>
class ImageOf;
37 const size_t rem = len % pad;
38 return (rem != 0) ? (pad - rem) : rem;
146 bool copy(
const Image& alt,
size_t w,
size_t h);
153 inline size_t width()
const {
return imgWidth; }
159 inline size_t height()
const {
return imgHeight; }
194 const size_t ret=imgRowSize-imgWidth*imgPixelSize;
206 return reinterpret_cast<unsigned char *
>(data[r]);
215 inline const unsigned char *
getRow(
size_t r)
const
218 return reinterpret_cast<const unsigned char *
>(data[r]);
228 return reinterpret_cast<unsigned char *
>(data[y] + x*imgPixelSize);
237 inline bool isPixel(
size_t x,
size_t y)
const {
238 return (x<imgWidth && y<imgHeight);
255 void resize(
size_t imgWidth,
size_t imgHeight);
271 void setExternal(
const void *data,
size_t imgWidth,
size_t imgHeight);
285 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2.0
302 const
void *getIplImage() const;
316 void wrapIplImage(
void *iplImage);
317 #endif // YARP_NO_DEPRECATED
381 static const std::map<YarpVocabPixelTypesEnum, size_t> pixelCode2Size;
382 size_t imgWidth, imgHeight, imgPixelSize, imgRowSize, imgQuantum;
392 void copyPixels(
const unsigned char *src,
size_t id1,
393 unsigned char *dest,
size_t id2,
size_t w,
size_t h,
394 size_t imageSize,
size_t quantum1,
size_t quantum2,
395 bool topIsLow1,
bool topIsLow2);
531 PixelBgr(
unsigned char n_r,
unsigned char n_g,
unsigned char n_b) :
663 inline T&
pixel(
size_t x,
size_t y) {
664 return *(
reinterpret_cast<T*
>(getPixelAddress(x,y)));
667 inline T&
pixel(
size_t x,
size_t y)
const {
668 return *(
reinterpret_cast<T*
>(getPixelAddress(x,y)));
680 if (!isPixel(x,y)) {
return nullPixel; }
681 return *(
reinterpret_cast<T*
>(getPixelAddress(x,y)));
685 if (!isPixel(x,y)) {
return nullPixel; }
686 return *(
reinterpret_cast<T*
>(getPixelAddress(x,y)));
765 return -(
static_cast<int>(
sizeof(T)));
771 #endif // YARP_SIG_IMAGE_H
void setPixelCode(int imgPixelCode)
bool write(yarp::os::ConnectionWriter &connection) const override
Write image to a connection.
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
This is a base class for objects that can be both read from and be written to the YARP network.
void setPixelSize(size_t imgPixelSize)
::cv::Mat toCvMat(yarp::sig::ImageOf< T > &yarpImage)
Convert a yarp::sig::ImageOf to a cv::Mat object.
PixelRgba(unsigned char n_r, unsigned char n_g, unsigned char n_b, unsigned char n_a)
bool isPixel(size_t x, size_t y) const
Check whether a coordinate lies within the image.
#define YARP_END_PACK
Ends 1 byte packing for structs/classes.
void zero()
Set all pixels to 0.
Image & operator=(const Image &alt)
Assignment operator.
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR16
PixelRgbFloat(float n_r, float n_g, float n_b)
#define YARP_BEGIN_PACK
Starts 1 byte packing for structs/classes.
size_t getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
char PixelMonoSigned
Signed byte pixel type.
T & pixel(size_t x, size_t y) const
#define YARP_SUPPRESS_DLL_INTERFACE_WARNING
Suppress MSVC C4251 warning for the next line.
size_t PAD_BYTES(size_t len, size_t pad)
computes the padding of YARP images.
Packed RGB pixel type, with pixels stored in reverse order.
Signed, packed RGB pixel type.
bool copy(const Image &alt)
Copy operator.
~Image() override
Destructor.
Floating point HSV pixel type.
bool read(yarp::os::ConnectionReader &connection) override
Read image from a connection.
virtual size_t getPixelSize() const
Gets pixel size in memory in bytes.
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB8
Image()
Default constructor.
size_t getRowSize() const
Size of the underlying image buffer rows.
size_t width() const
Gets width of image in pixels.
void setExternal(const void *data, size_t imgWidth, size_t imgHeight)
Use this to wrap an external image.
bool topIsLowIndex() const
T & safePixel(size_t x, size_t y)
void setQuantum(size_t imgQuantum)
T & operator()(size_t x, size_t y)
const T & safePixel(size_t x, size_t y) const
static Type byName(const char *name)
const T & operator()(size_t x, size_t y) const
unsigned char PixelMono
Monochrome pixel type.
float PixelFloat
Floating point pixel type.
An interface for writing to a network connection.
PixelRgb(unsigned char n_r, unsigned char n_g, unsigned char n_b)
Image class with user control of representation details.
@ VOCAB_PIXEL_ENCODING_BAYER_RGGB16
unsigned char * getPixelAddress(size_t x, size_t y) const
Get address of a pixel in memory.
void setPixelCode(int imgPixelCode)
const unsigned char * getRow(size_t r) const
Get the address of a the first byte of a row in memory, const versions.
yarp::os::NetInt32 PixelInt
32-bit integer pixel type.
unsigned char * getRow(size_t r)
Get the address of a the first byte of a row in memory.
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG16
PixelBgr(unsigned char n_r, unsigned char n_g, unsigned char n_b)
yarp::sig::ImageOf< T > fromCvMat(::cv::Mat &cvImage)
Convert a cv::Mat to a yarp::sig::ImageOf object.
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
size_t height() const
Gets height of image in pixels.
Packed HSV (hue/saturation/value pixel type.
void setTopIsLowIndex(bool flag)
control whether image has origin at top left (default) or bottom left.
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG16
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG8
@ VOCAB_PIXEL_MONO_SIGNED
T & pixel(size_t x, size_t y)
An interface for reading from a network connection.
PixelRgbInt(int n_r, int n_g, int n_b)
Floating point RGB pixel type.
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
yarp::os::NetUint16 PixelMono16
16-bit monochrome pixel type.
std::uint16_t NetUint16
Definition of the NetUint16 type.
The main, catch-all namespace for YARP.
size_t getPadding() const
Returns the number of padding bytes.
Base class for storing images.
yarp::os::Type getReadType() const override
int getPixelCode() const override
RandScalar * implementation(void *t)
char ** getRowArray()
Get an array of pointers to the rows of the image.
void resize(const Image &alt)
Reallocate the size of the image to match another, throwing away the actual content of the image.
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR8
PixelBgra(unsigned char n_r, unsigned char n_g, unsigned char n_b, unsigned char n_a)
void setPixelSize(size_t imgPixelSize)
unsigned char * getRawImage() const
Access to the internal image buffer.
size_t getPixelSize() const override
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG8
void setQuantum(size_t imgQuantum)
std::int32_t NetInt32
Definition of the NetInt32 type.
virtual int getPixelCode() const
Gets pixel type identifier.