Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layered Image #3155

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
67 changes: 67 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,68 @@ 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.r = colorkey;
ColorkeyRGB.g = colorkey;
ColorkeyRGB.b = 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.
* @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 backgroud 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 backgroud 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
Loading