Skip to content

Commit

Permalink
Merge pull request #3155 from robotology/layered_image
Browse files Browse the repository at this point in the history
Layered Image
  • Loading branch information
randaz81 authored Jan 14, 2025
2 parents 6b4bb23 + 0493a00 commit 61be8f3
Show file tree
Hide file tree
Showing 11 changed files with 991 additions and 35 deletions.
40 changes: 36 additions & 4 deletions doc/release/master.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
master {#master}
-----------
YARP <yarp-3.11> (UNRELEASED) {#yarp_3_11}
============================

* Branch changes
The angular acceleration and linear velocity values measured by a particular sensor can now be extracted and used via the sensor remapper.
[TOC]

YARP <yarp-3.11> Release Notes
=============================


A (partial) list of bug fixed and issues resolved in this release can be found
[here](https://github.com/robotology/yarp/issues?q=label%3A%22Fixed+in%3A+YARP+yarp-3.10%22).

Fixes
-----

New Features
------------

### devices

#### multiplenalogsensorremapper

* The angular acceleration and linear velocity values measured by a sensor can now be extracted and used via the sensor remapper.
* Also involves `multipleanalogsensorclient` and `multipleanalogsensorserver` as a breaking change.

### GUIs

#### `yarpopencvdisplay`

* `yarpopencvdisplay` is now able to display a `yarp::sig::LayeredImage`

### Libraries

#### `libYARP_sig`

* added new datatype `yarp::sig::LayeredImage`
* added `yarp::sig::utils::sum()` to transform `yarp::sig::LayeredImage` to `yarp::sig::Image`
2 changes: 2 additions & 0 deletions src/libYARP_sig/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(YARP_sig_HDRS
yarp/sig/ImageNetworkHeader.h
yarp/sig/ImageUtils.h
yarp/sig/IntrinsicParams.h
yarp/sig/LayeredImage.h
yarp/sig/LaserMeasurementData.h
yarp/sig/Matrix.h
yarp/sig/PointCloud.h
Expand All @@ -40,6 +41,7 @@ set(YARP_sig_SRCS
yarp/sig/ImageUtils.cpp
yarp/sig/IntrinsicParams.cpp
yarp/sig/LaserMeasurementData.cpp
yarp/sig/LayeredImage.cpp
yarp/sig/Matrix.cpp
yarp/sig/PointCloudBase.cpp
yarp/sig/PointCloudUtils.cpp
Expand Down
8 changes: 6 additions & 2 deletions src/libYARP_sig/src/yarp/sig/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,13 @@ bool Image::operator==(const Image& alt) const
//test byte per byte
unsigned char* raw1 = getRawImage();
unsigned char* raw2 = alt.getRawImage();
for (size_t i = 0; i < raw1size; i++, raw1++, raw2++)
if (raw1 == nullptr) { return false;}
if (raw2 == nullptr) { return false;}
for (size_t i = 0; i < raw1size; i++)
{
if (*raw1 != *raw2) { return false; }
if (raw1[i] != raw2[i]) {
return false;
}
}
return true;
}
Expand Down
8 changes: 8 additions & 0 deletions src/libYARP_sig/src/yarp/sig/ImageNetworkHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ class ImageNetworkHeader
height = image.height();
paramBlobLen = image.getRawImageSize();
}

void setToImage(FlexImage& image)
{
image.setPixelCode(id);
//setPixelSize() is already set by setPixelCode
image.setQuantum(quantum);
image.resize(width, height);
}
};
YARP_END_PACK

Expand Down
65 changes: 65 additions & 0 deletions src/libYARP_sig/src/yarp/sig/ImageUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <yarp/sig/ImageUtils.h>
#include <cstring>
#include <algorithm> // std::math
#include <yarp/os/Log.h>
#include <yarp/os/LogStream.h>

using namespace yarp::sig;

Expand Down Expand Up @@ -141,3 +143,66 @@ bool utils::cropRect(const yarp::sig::Image& inImg,

return true;
}

bool utils::sum(Image& OutImg, const Image& InImg, bool enable_colorkey, int colorkey, bool enable_alpha, float alpha, size_t offset_x, size_t offset_y)
{
if (OutImg.getPixelCode() != InImg.getPixelCode())
{
yError() << "utils::sum() Input and Output images must have the same pixelcode";
return false;
}

if (InImg.getPixelCode() != VOCAB_PIXEL_RGB)
{
yError() << "utils::sum() Unimplemented pixelcode";
return false;
}

yarp::sig::PixelRgb ColorkeyRGB;
ColorkeyRGB = *reinterpret_cast<yarp::sig::PixelRgb*>(&colorkey);

size_t yis = InImg.height();
size_t xis = InImg.width();
size_t yos = OutImg.height();
size_t xos = OutImg.width();

for (size_t y = 0; y < yis; ++y)
{
for (size_t x = 0; x < xis; ++x)
{
size_t xo = x + offset_x;
size_t yo = y + offset_y;
if (xo > xos) {
xo = xos;
}
if (yo > yos) {
yo = yos;
}

unsigned char* layer_pointer = InImg.getPixelAddress(x, y);
unsigned char* outimg_pointer = OutImg.getPixelAddress(xo, yo);

yarp::sig::PixelRgb* layer_pointer_rgb = reinterpret_cast<yarp::sig::PixelRgb*>(layer_pointer);
yarp::sig::PixelRgb* outimg_pointer_rgb = reinterpret_cast<yarp::sig::PixelRgb*>(outimg_pointer);

if (enable_colorkey && layer_pointer_rgb->r == ColorkeyRGB.r && layer_pointer_rgb->g == ColorkeyRGB.g && layer_pointer_rgb->b == ColorkeyRGB.b)
{
continue;
}
else if (enable_alpha)
{
outimg_pointer_rgb->r = layer_pointer_rgb->r * alpha + outimg_pointer_rgb->r * (1 - alpha);
outimg_pointer_rgb->g = layer_pointer_rgb->g * alpha + outimg_pointer_rgb->g * (1 - alpha);
outimg_pointer_rgb->b = layer_pointer_rgb->b * alpha + outimg_pointer_rgb->b * (1 - alpha);
}
else
{
outimg_pointer_rgb->r = layer_pointer_rgb->r;
outimg_pointer_rgb->g = layer_pointer_rgb->g;
outimg_pointer_rgb->b = layer_pointer_rgb->b;
}
}
}

return true;
}
22 changes: 22 additions & 0 deletions src/libYARP_sig/src/yarp/sig/ImageUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ bool YARP_sig_API cropRect(const yarp::sig::Image& inImg,
const std::pair<unsigned int, unsigned int>& vertex1,
const std::pair<unsigned int, unsigned int>& vertex2,
yarp::sig::Image& outImg);

/**
* @brief applies an image on the top over another image. Currently it is implemented only for RGB Images
* @param[in/out] OutImg the output image. It must be a valid image on the top of which data will be summed. It may contain a background or it can be zero.
* @param[in] InImg the layer to be applied
* @param[in] colorkey colorkey for the InImg image. If a pixel is == colorkey, then it will be made transparent and the background will be visible.
* @param[in] alpha to be applied to InImg.
* @param[in] off_x horizontal offset applied to InImg. Excess will be cropped.
* @param[in] off_y vertical offset applied to InImg. Excess will be cropped.
* @note The two images must have the same pixelCode.
* @return true on success, false if image cannot be summed because of incompatible format.
*/
bool YARP_sig_API sum(yarp::sig::Image& OutImg,
const yarp::sig::Image& InImg,
bool colorkey_enable,
int colorkey,
bool alpha_enable,
float alpha,
size_t off_x,
size_t off_y);

} // namespace yarp::sig::utils


#endif // YARP_SIG_IMAGEUTILS_H
Loading

0 comments on commit 61be8f3

Please sign in to comment.