|
YARP
Yet Another Robot Platform
|
|
Go to the documentation of this file.
56 printf(
"There is a problem reading an image\n");
57 printf(
"incoming: width %zu, height %zu, code %zu, quantum %zu, size %zu\n",
58 static_cast<size_t>(header.
width),
59 static_cast<size_t>(header.
height),
60 static_cast<size_t>(header.
id),
61 static_cast<size_t>(header.
quantum),
62 static_cast<size_t>(header.
imgSize));
63 printf(
"my space: width %zu, height %zu, code %d, quantum %zu, size %zu\n",
67 bool ok = connection.
expectBlock(
reinterpret_cast<char*
>(mem), allocatedBytes);
68 return (!connection.
isError() && ok);
96 void _alloc_extern (
const void *buf);
101 void _make_independent();
102 bool _set_ipl_header(
size_t x,
size_t y,
int pixel_type,
size_t quantum,
104 void _free_ipl_header();
105 void _alloc_complete(
size_t x,
size_t y,
int pixel_type,
size_t quantum,
107 void _free_complete();
111 int _pad_bytes (
size_t linesize,
size_t align)
const;
127 extern_type_quantum = -1;
134 void resize(
size_t x,
size_t y,
int pixel_type,
135 size_t quantum,
bool topIsLow);
137 void _alloc_complete_extern(
const void *buf,
size_t x,
size_t y,
int pixel_type,
138 size_t quantum,
bool topIsLow);
145 size_t quantum,
bool topIsLow) {
146 int need_recreation = 1;
152 if (need_recreation) {
154 DBGPF1 printf(
"HIT recreation for %p %p: %zu %zu %d\n",
static_cast<void*
>(
this),
static_cast<void*
>(pImage), x, y, pixel_type);
155 _alloc_complete (x, y, pixel_type, quantum, topIsLow);
157 extern_type_id = pixel_type;
158 extern_type_quantum = quantum;
193 if (pImage !=
nullptr) {
194 if (pImage->imageData !=
nullptr) {
200 pImage->imageData =
const_cast<char*
>(
reinterpret_cast<const char*
>(buf));
209 DBGPF1 printf(
"alloc_data1\n"), fflush(stdout);
214 char **ptr =
new char *[pImage->height];
220 yAssert(pImage->imageData !=
nullptr);
222 int height = pImage->height;
224 char * DataArea = pImage->imageData;
226 for (
int r = 0; r < height; r++)
231 Data[height-r-1] = DataArea;
233 DataArea += pImage->widthStep;
235 DBGPF1 printf(
"alloc_data4\n");
240 if (pImage !=
nullptr) {
241 if (pImage->imageData !=
nullptr) {
251 pImage->imageData =
nullptr;
285 _set_ipl_header(x, y, pixel_type, quantum, topIsLow);
340 if (pImage !=
nullptr) {
347 printf (
"*** Trying to allocate an invalid pixel type image\n");
362 pImage =
iplCreateImageHeader(param.
nChannels, 0, param.
depth,
const_cast<char*
>(param.
colorModel),
const_cast<char*
>(param.
channelSeq),
IPL_DATA_ORDER_PIXEL, origin, quantum, x, y,
nullptr,
nullptr,
nullptr,
nullptr);
364 type_id = pixel_type;
365 this->quantum = quantum;
366 this->topIsLow = topIsLow;
375 this->quantum = quantum;
376 this->topIsLow = topIsLow;
380 _set_ipl_header(x, y, pixel_type, quantum, topIsLow);
394 const std::map<YarpVocabPixelTypesEnum, size_t> Image::pixelCode2Size = {
428 void Image::initialize() {
431 imgWidth = imgHeight = 0;
432 imgPixelSize = imgRowSize = 0;
460 if (getRawImage()!=
nullptr) {
461 memset(getRawImage(),0,getRawImageSize());
468 int code = getPixelCode();
470 if (code!=imgPixelCode) {
481 if (imgWidth!=width()||imgHeight!=height()) {
501 setPixelCode(-imgPixelSize);
505 this->imgPixelCode = imgPixelCode;
506 this->imgPixelSize = (imgPixelCode < 0) ? -imgPixelCode : pixelCode2Size.at(
static_cast<YarpVocabPixelTypesEnum>(imgPixelCode));
511 this->imgQuantum = imgQuantum;
515 void Image::synchronize() {
518 if (impl->pImage!=
nullptr) {
519 imgWidth = impl->pImage->width;
520 imgHeight = impl->pImage->height;
522 imgQuantum = impl->quantum;
523 imgRowSize = impl->pImage->widthStep;
524 setPixelCode(impl->getTypeId());
537 if (impl->pImage!=
nullptr) {
538 return reinterpret_cast<unsigned char*
>(impl->pImage->imageData);
546 if (impl->pImage!=
nullptr) {
547 return impl->pImage->imageSize;
552 #ifndef YARP_NO_DEPRECATED // Since YARP 3.2.0
563 auto* p =
static_cast<IplImage *
>(iplImage);
567 if (str==
"rgb"||str==
"RGB"||
568 str==
"bgr"||str==
"BGR"||
569 str==
"gray"||str==
"GRAY"||
570 str==
"graygray"||str==
"GRAYGRAY") {
572 if (str==
"rgb"||str==
"RGB") {
574 }
else if (str==
"bgr"||str==
"BGR") {
576 }
else if (str==
"gray"||str==
"GRAY"||
577 str==
"graygray"||str==
"GRAYGRAY") {
580 printf(
"specific IPL RGB order (%s) is not yet supported\n",
582 printf(
"Try RGB, BGR, or \n");
583 printf(
"Or fix code at %s line %d\n",__FILE__,__LINE__);
593 switch (color_code) {
605 switch (color_code) {
611 fprintf(stderr,
"No translation currently available for this pixel type\n");
616 switch (color_code) {
626 switch (color_code) {
638 fprintf(stderr,
"IPL pixel type / depth combination is not yet supported\n");
639 fprintf(stderr,
"Please email a YARP developer to complain, quoting this:\n");
640 fprintf(stderr,
" %s:%d\n", __FILE__, __LINE__);
643 if (getPixelCode()!=code && getPixelCode()!=-1) {
644 printf(
"your specific IPL format (%s depth %d -> %s) does not match your YARP format (%s)\n",
649 printf(
"Making a copy instead of just wrapping...\n");
656 setQuantum(p->align);
658 setExternal(p->imageData,p->width,p->height);
662 #endif // YARP_NO_DEPRECATED
672 bool ok = connection.
expectBlock(
reinterpret_cast<char*
>(&header),
sizeof(header));
684 setPixelCode(header.
id);
686 size_t q = getQuantum();
692 if (q !=
static_cast<size_t>(header.
quantum)) {
700 if (getPixelCode() == header.
id && q ==
static_cast<size_t>(header.
quantum) && imgPixelSize ==
static_cast<size_t>(header.
depth))
793 connection.
appendBlock(
reinterpret_cast<char*
>(&header),
sizeof(header));
794 unsigned char *mem = getRawImage();
820 other.implementation =
nullptr;
826 Image moved(std::move(other));
882 (
static_cast<ImageStorage*
>(implementation))->_alloc_complete_extern(data,
900 return copy(img,w,h);
908 return copy(img,w,h);
919 float di = (
static_cast<float>(h))/nh;
920 float dj = (
static_cast<float>(w))/nw;
922 for (
size_t i=0; i<nh; i++)
924 auto i0 =
static_cast<size_t>(di*i);
925 for (
size_t j=0; j<nw; j++)
927 auto j0 =
static_cast<size_t>(dj*j);
void setPixelCode(int imgPixelCode)
#define IPL_BORDER_CONSTANT
bool write(yarp::os::ConnectionWriter &connection) const override
Write image to a connection.
#define IPL_DATA_ORDER_PIXEL
virtual void appendBlock(const char *data, size_t len)=0
Send a block of data to the network connection.
This is a base class for objects that can be both read from and be written to the YARP network.
void _alloc_extern(const void *buf)
void setPixelSize(size_t imgPixelSize)
bool deBayer_GRBG8_TO_RGB(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize)
size_t extern_type_quantum
bool _set_ipl_header(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
void _alloc_complete_extern(const void *buf, size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
void iplDeallocateImage(IplImage *image)
void zero()
Set all pixels to 0.
Image & operator=(const Image &alt)
Assignment operator.
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR16
const pixelTypeIplParams iplPixelTypeMono
size_t getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
char PixelMonoSigned
Signed byte pixel type.
void iplDeallocate(IplImage *image, int flag)
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.
void _alloc_complete(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
int _pad_bytes(size_t linesize, size_t align) const
void resize(size_t x, size_t y, int pixel_type, size_t quantum, bool topIsLow)
void wrapIplImage(void *iplImage)
Act as a wrapper around an IPL/OpenCV image.
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
void iplAllocateImage(IplImage *image, int doFill, int fillValue)
Image()
Default constructor.
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
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
void setQuantum(size_t imgQuantum)
int nChannels
Most of OpenCV functions support 1,2,3 or 4 channels.
virtual bool isError() const =0
ImageStorage(Image &owner)
#define YARP_FIXME_NOTIMPLEMENTED(what)
unsigned char PixelMono
Monochrome pixel type.
float PixelFloat
Floating point pixel type.
An interface for writing to a network connection.
Image class with user control of representation details.
const pixelTypeIplParams iplPixelTypeMono16
@ 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)
virtual bool isError() const =0
yarp::os::NetInt32 PixelInt
32-bit integer pixel type.
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG16
bool readFromConnection(Image &dest, ImageNetworkHeader &header, ConnectionReader &connection)
This helper function groups code to avoid duplication.
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.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
bool deBayer_GRBG8_TO_BGR(yarp::sig::Image &source, yarp::sig::Image &dest, int pixelSize)
char colorModel[4]
ignored by OpenCV
Packed HSV (hue/saturation/value pixel type.
const std::map< int, pixelTypeIplParams > pixelCode2iplParams
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG16
@ VOCAB_PIXEL_ENCODING_BAYER_GBRG8
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
@ VOCAB_PIXEL_MONO_SIGNED
void * getIplImage()
Returns IPL/OpenCV view of image, if possible.
bool isBayer8(int v)
Basic implementations of debayering functions.
An interface for reading from a network connection.
int width
image width in pixels
int getTypeId()
ImageStorage::getTypeId.
An interface to the operating system, including Port based communication.
Floating point RGB pixel type.
yarp::os::NetUint16 PixelMono16
16-bit monochrome pixel type.
Base class for storing images.
RandScalar * implementation(void *t)
virtual void appendExternalBlock(const char *data, size_t len)=0
Send a block of data to the network connection, without making a copy.
void iplAllocateImageFP(IplImage *image, int doFill, float fillValue)
virtual bool expectBlock(char *data, size_t len)=0
Read a block of data from the network connection.
@ VOCAB_PIXEL_ENCODING_BAYER_BGGR8
void iplSetBorderMode(IplImage *src, int mode, int border, int constVal)
unsigned char * getRawImage() const
Access to the internal image buffer.
IplImage * iplCreateImageHeader(int nChannels, int alphaChannel, int depth, char *colorModel, char *channelSeq, int dataOrder, int origin, int align, int width, int height, IplROI *roi, IplImage *maskROI, void *imageId, IplTileInfo *tileInfo)
@ VOCAB_PIXEL_ENCODING_BAYER_GRBG8
void setQuantum(size_t imgQuantum)
virtual int getPixelCode() const
Gets pixel type identifier.