6#ifndef YARP_FRAMEGRABBER_PROTOCOL_FRAMEGRABBEROF_RESPONDER_INL_H
7#define YARP_FRAMEGRABBER_PROTOCOL_FRAMEGRABBEROF_RESPONDER_INL_H
16YARP_LOG_COMPONENT(FRAMEGRABBEROF_RESPONDER,
"yarp.proto.framegrabber.FrameGrabberOf_Responder")
28 yCError(FRAMEGRABBEROF_RESPONDER) <<
"Invalid IFrameGrabberOf interface received";
32 iFrameGrabberOf = interface;
41 if (!iFrameGrabberOf) {
44 if (std::is_same<ImageType, yarp::sig::ImageOf<yarp::sig::PixelRgb>>::value) {
45 reply.
addString(
"Selected camera device has no IFrameGrabberImage interface");
46 yCError(FRAMEGRABBEROF_RESPONDER) <<
"Selected camera device has no IFrameGrabberImage interface";
47 }
else if (std::is_same<ImageType, yarp::sig::ImageOf<yarp::sig::PixelMono>>::value) {
48 reply.
addString(
"Selected camera device has no IFrameGrabberImageRaw interface");
49 yCError(FRAMEGRABBEROF_RESPONDER) <<
"Selected camera device has no IFrameGrabberImageRaw interface";
51 reply.
addString(
"Selected camera device has no IFrameGrabberOf<ImageType> interface");
52 yCError(FRAMEGRABBEROF_RESPONDER) <<
"Selected camera device has no IFrameGrabberOf<ImageType> interface";
59 yCError(FRAMEGRABBEROF_RESPONDER) <<
"Received a command not belonging to this interface.";
71 reply.
addInt32(iFrameGrabberOf->height());
78 reply.
addInt32(iFrameGrabberOf->width());
83 iFrameGrabberOf->getImage(
image);
85 if (
image.width() == 0 ||
image.height() == 0 ||
image.getRawImage() ==
nullptr) {
87 reply.
addString(
"Could not retrieve image from device.");
88 yCError(FRAMEGRABBEROF_RESPONDER) <<
"Could not retrieve image from device.";
103 if (cmd.
size() != 5) {
105 reply.
addString(
"GetImageCrop failed: Invalid command received.");
106 yCError(FRAMEGRABBEROF_RESPONDER) <<
"GetImageCrop failed: Invalid command received, got " << cmd.
toString();
113 reply.
addString(
"GetImageCrop failed: Empty vertices list received.");
114 yCError(FRAMEGRABBEROF_RESPONDER) <<
"GetImageCrop failed: Empty vertices list received.";
118 size_t nPoints = list->
size() / 2;
123 for (
size_t i = 0; i < nPoints; i++) {
124 vertices[i].first = list->
get(i * 2).
asInt32();
125 vertices[i].second = list->
get(i * 2 + 1).
asInt32();
137 reply.
addString(
"GetImageCrop failed: RECT mode requires 2 vertices.");
138 yCError(FRAMEGRABBEROF_RESPONDER) <<
"GetImageCrop failed: RECT mode requires 2 vertices, got " << nPoints;
142 iFrameGrabberOf->getImage(full);
146 reply.
addString(
"GetImageCrop failed: utils::cropRect error.");
147 yCError(FRAMEGRABBEROF_RESPONDER,
"GetImageCrop failed: utils::cropRect error: (%d, %d) (%d, %d)",
156 reply.
addString(
"List type not yet implemented");
157 yCError(FRAMEGRABBEROF_RESPONDER) <<
"List type not yet implemented";
162 yCError(FRAMEGRABBEROF_RESPONDER) <<
"Crop type unknown";
180 reply.
addString(
"Received an unknown command");
181 yCError(FRAMEGRABBEROF_RESPONDER) <<
"Received an unknown command " << cmd.
toString();
constexpr yarp::conf::vocab32_t VOCAB_CROP
constexpr yarp::conf::vocab32_t VOCAB_IS
constexpr yarp::conf::vocab32_t VOCAB_WIDTH
constexpr yarp::conf::vocab32_t VOCAB_GET
constexpr yarp::conf::vocab32_t VOCAB_FAILED
constexpr yarp::conf::vocab32_t VOCAB_SET
constexpr yarp::conf::vocab32_t VOCAB_HEIGHT
yarp::sig::ImageOf< yarp::sig::PixelRgb > ImageType
Read a YARP-format image (of a specific type) from a device.
A simple collection of objects that can be described and transmitted in a portable way.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
Bottle & addList()
Places an empty nested list in the bottle, at the end of the list.
size_type size() const
Gets the number of elements in the bottle.
Value & get(size_type index) const
Reads a Value v from a certain part of the list.
void clear()
Empties the bottle of any objects it contains.
void addInt32(std::int32_t x)
Places a 32-bit integer in the bottle, at the end of the list.
void addString(const char *str)
Places a string in the bottle, at the end of the list.
std::string toString() const override
Gives a human-readable textual representation of the bottle.
static bool copyPortable(const PortWriter &writer, PortReader &reader)
Copy one portable to another, via writing and reading.
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual Bottle * asList() const
Get list value.
bool configure(yarp::dev::IFrameGrabberOf< ImageType > *interface)
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
void resize(size_t size) override
Resize the vector.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
bool 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)
Crop a rectangle area out of an image given two opposite vertices.