45 yCError(SERVERGRABBER) <<
"ServerGrabberResponder: invalid server pointer";
52 if(server->
respond(command,reply,left,
false))
58 return DeviceResponder::respond(command, reply);
123 if(isSubdeviceOwned && poly2)
129 isSubdeviceOwned=
false;
139 yCIWarning(SERVERGRABBER,
id()) <<
"The 'grabberDual' device is deprecated in favour of 'frameGrabber_nws_yarp' (and eventually 'frameGrabberCropper').";
140 yCIWarning(SERVERGRABBER,
id()) <<
"The old device is no longer supported, and it will be deprecated in YARP 3.7 and removed in YARP 4.";
141 yCIWarning(SERVERGRABBER,
id()) <<
"Please update your scripts.";
144 yCIError(SERVERGRABBER,
id(),
"Did you just try to open the same ServerGrabber twice?");
150 yCIError(SERVERGRABBER,
id()) <<
"Device ServerGrabber failed to open, check previous log for error messages.";
156 yCIError(SERVERGRABBER,
id()) <<
"Error initializing YARP ports";
160 if(isSubdeviceOwned){
161 if(! openAndAttachSubDevice(config))
163 yCIError(SERVERGRABBER,
id(),
"Error while opening subdevice");
169 yCIInfo(SERVERGRABBER,
id()) <<
"Running, waiting for attach...";
170 if (!openDeferredAttach(config)) {
210 if (config.
check(
"period",
"refresh period(in ms) of the broadcasted values through yarp ports")
216 if((config.
check(
"subdevice")) && (config.
check(
"left_config") || config.
check(
"right_config")))
218 yCIError(SERVERGRABBER,
id()) <<
"Found both 'subdevice' and 'left_config/right_config' parameters...";
221 if (!config.
check(
"subdevice",
"name of the subdevice to use as a data source")
222 && config.
check(
"left_config",
"name of the ini file containing the configuration of one of two subdevices to use as a data source")
223 && config.
check(
"right_config",
"name of the ini file containing the configuration of one of two subdevices to use as a data source")) {
226 if (config.
check(
"twoCameras",
"if true ServerGrabber will open and handle two devices, if false only one")) {
229 if (config.
check(
"split",
"set 'true' to split the streaming on two different ports")) {
232 if(config.
check(
"capabilities",
"two capabilities supported, COLOR and RAW respectively for rgb and raw streaming"))
234 if (config.
find(
"capabilities").
asString() ==
"COLOR") {
236 }
else if (config.
find(
"capabilities").
asString() ==
"RAW") {
240 yCIWarning(SERVERGRABBER,
id()) <<
"'capabilities' parameter not found or misspelled, the option available are COLOR(default) and RAW, using default";
242 param.
canDrop = !config.
check(
"no_drop",
"if present, use strict policy for sending data");
243 param.
addStamp = config.
check(
"stamp",
"if present, add timestamps to data");
246 config.
check(
"single_threaded",
247 "if present, operate in single threaded mode");
249 std::string rootName;
250 rootName = config.
check(
"name",
Value(
"/grabber"),
251 "name of port to send data on").asString();
267 rpcPort_Name = rootName +
"/left/rpc";
268 rpcPort2_Name = rootName +
"/right/rpc";
271 pImg_Name = rootName +
"/left";
272 pImg2_Name = rootName +
"/right";
274 pImg_Name = rootName;
279 if(config.
check(
"left_config") && config.
check(
"right_config"))
281 isSubdeviceOwned=
true;
285 isSubdeviceOwned=
false;
296 pImg_Name = rootName +
"/left";
297 pImg2_Name = rootName +
"/right";
301 pImg_Name = rootName;
303 rpcPort_Name = rootName +
"/rpc";
304 if(config.
check(
"subdevice"))
306 isSubdeviceOwned=
true;
310 isSubdeviceOwned=
false;
323 if(!rpcPort.
open(rpcPort_Name))
325 yCIError(SERVERGRABBER,
id()) <<
"Unable to open rpc Port" << rpcPort_Name.c_str();
332 if(!pImg.
open(pImg_Name))
334 yCIError(SERVERGRABBER,
id()) <<
"Unable to open image streaming Port" << pImg_Name.c_str();
341 if(!rpcPort2.
open(rpcPort2_Name))
343 yCIError(SERVERGRABBER,
id()) <<
"Unable to open rpc Port" << rpcPort2_Name.c_str();
353 if(!pImg2.
open(pImg2_Name))
355 yCIError(SERVERGRABBER,
id()) <<
"Unable to open image streaming Port" << pImg2_Name.c_str();
385 int nPoints = list->
size() /2;
390 for(
int i=0; i<nPoints; i++)
393 vertices[i].second = list->
get(i*2 +1).
asInt32();
423 imageInterface = fgImage;
426 std::for_each(vertices.
begin(), vertices.
end(), [=](
auto &pt) { pt.first += imageInterface->width() / 2; });
436 imageInterface = fgImage2;
442 if(vertices[0].first >= fgImage->
width())
444 imageInterface = fgImage2;
445 std::for_each(vertices.
begin(), vertices.
end(), [=](
auto &pt) { pt.first -= fgImage->width(); });
451 if(imageInterface !=
nullptr)
464 response.
addString(
"GetImageCrop failed: RECT mode requires 2 vertices.");
465 yCIError(SERVERGRABBER,
id()) <<
"GetImageCrop failed: RECT mode requires 2 vertices, got " << nPoints;
473 response.
addString(
"GetImageCrop failed: utils::cropRect error.");
474 yCIError(SERVERGRABBER,
id(),
"GetImageCrop failed: utils::cropRect error: (%d, %d) (%d, %d)",
484 response.
addString(
"List type not yet implemented");
508 yCIError(SERVERGRABBER,
id()) <<
"FrameGrabberImage interface received an unknown command " << cmd.
toString();
523 ret&=ifgCtrl2_Responder.
respond(cmd, response2);
524 if(!
ret || (response!=response2))
529 yCIWarning(SERVERGRABBER,
id()) <<
"Response different among cameras or failed";
540 ret=ifgCtrl2_Responder.
respond(cmd, response);
545 return ifgCtrl_Responder.
respond(cmd, response);
571 if(response!=response2)
576 yCIWarning(SERVERGRABBER,
id()) <<
"Response different among cameras or failed";
585 return rgbParser.
respond(cmd, response);
598 ret=ifgCtrl_DC1394_Responder.
respond(cmd, response);
599 ret&=ifgCtrl2_DC1394_Responder.
respond(cmd, response2);
600 if(!
ret || (response!=response2))
603 response.
addString(
"command not recognized");
605 yCIWarning(SERVERGRABBER,
id()) <<
"Responses different among cameras or failed";
613 ret=ifgCtrl_DC1394_Responder.
respond(cmd, response);
617 ret=ifgCtrl2_DC1394_Responder.
respond(cmd, response);
622 return ifgCtrl_DC1394_Responder.
respond(cmd, response);
626 yCIError(SERVERGRABBER,
id()) <<
"Command not recognized" << cmd.
toString();
636 bool rightDone=
false;
637 if (device2attach.
size() != 2)
639 yCIError(SERVERGRABBER,
id(),
"Expected two devices to be attached");
642 for(
int i=0;i<device2attach.
size();i++)
645 if (!Idevice2attach->
isValid())
647 yCIError(SERVERGRABBER,
id()) <<
"Device " << device2attach[i]->key <<
" to attach to is not valid ... cannot proceed";
650 if(device2attach[i]->key ==
"LEFT" && !leftDone)
652 leftDone |= Idevice2attach->
view(rgbVis_p);
653 leftDone |= Idevice2attach->
view(fgImage);
654 leftDone |= Idevice2attach->
view(fgImageRaw);
655 leftDone |= Idevice2attach->
view(fgCtrl);
656 leftDone |= Idevice2attach->
view(fgCtrl_DC1394);
658 else if(device2attach[i]->key ==
"RIGHT" && !rightDone)
660 rightDone |= Idevice2attach->
view(rgbVis_p2);
661 rightDone |= Idevice2attach->
view(fgImage2);
662 rightDone |= Idevice2attach->
view(fgImageRaw2);
663 rightDone |= Idevice2attach->
view(fgCtrl2);
664 rightDone |= Idevice2attach->
view(fgCtrl2_DC1394);
668 yCIError(SERVERGRABBER,
id()) <<
"Failed to attach. The two targets must be LEFT RIGHT and devices must implement"
669 " either IFrameGrabberImage or IFrameGrabberImageRaw";
678 if((fgImage==
nullptr) || (fgImage2==
nullptr))
680 yCIError(SERVERGRABBER,
id()) <<
"Capability \"COLOR\" required not supported";
687 if((fgImageRaw==
nullptr) || (fgImageRaw2==
nullptr))
689 yCIError(SERVERGRABBER,
id()) <<
"Capability \"RAW\" required not supported";
694 if((rgbVis_p ==
nullptr) || (rgbVis_p2 ==
nullptr))
696 yCIWarning(SERVERGRABBER,
id()) <<
"Targets has not IVisualParamInterface, some features cannot be available";
699 if(rgbVis_p !=
nullptr && rgbVis_p2 !=
nullptr)
703 yCIError(SERVERGRABBER,
id()) <<
"Error configuring interfaces for parsers";
707 if(fgCtrl !=
nullptr && fgCtrl2 !=
nullptr)
709 if(!(ifgCtrl_Responder.
configure(fgCtrl)) || !(ifgCtrl2_Responder.
configure(fgCtrl2)))
711 yCIError(SERVERGRABBER,
id()) <<
"Error configuring interfaces for parsers";
715 if(fgCtrl_DC1394 !=
nullptr && fgCtrl2_DC1394 !=
nullptr)
717 if(!(ifgCtrl_DC1394_Responder.
configure(fgCtrl_DC1394)) || !(ifgCtrl2_DC1394_Responder.
configure(fgCtrl2_DC1394)))
719 yCIError(SERVERGRABBER,
id()) <<
"Error configuring interfaces for parsers";
725 if (device2attach.
size() != 1)
727 yCIError(SERVERGRABBER,
id(),
"Expected one device to be attached");
731 Idevice2attach->
view(rgbVis_p);
732 Idevice2attach->
view(fgImage);
733 Idevice2attach->
view(fgImageRaw);
734 Idevice2attach->
view(fgCtrl);
735 Idevice2attach->
view(fgCtrl_DC1394);
741 yCIError(SERVERGRABBER,
id()) <<
"Capability \"COLOR\" required not supported";
748 if(fgImageRaw==
nullptr)
750 yCIError(SERVERGRABBER,
id()) <<
"Capability \"RAW\" required not supported";
756 if (!Idevice2attach->
isValid())
758 yCIError(SERVERGRABBER,
id()) <<
"Device " << device2attach[0]->key <<
" to attach to is not valid ... cannot proceed";
762 if(rgbVis_p ==
nullptr)
764 yCIWarning(SERVERGRABBER,
id()) <<
"Targets has not IVisualParamInterface, some features cannot be available";
768 if(rgbVis_p !=
nullptr)
772 yCIError(SERVERGRABBER,
id()) <<
"Error configuring interfaces for parsers";
776 if(fgCtrl !=
nullptr)
778 if(!(ifgCtrl_Responder.
configure(fgCtrl)))
780 yCIError(SERVERGRABBER,
id()) <<
"Error configuring interfaces for parsers";
785 if(fgCtrl_DC1394 !=
nullptr)
787 if(!(ifgCtrl_DC1394_Responder.
configure(fgCtrl_DC1394)))
789 yCIError(SERVERGRABBER,
id()) <<
"Error configuring interfaces for parsers";
795 PeriodicThread::setPeriod(period);
796 ret = PeriodicThread::start();
803 if (isSubdeviceOwned) {
820 fgImageRaw =
nullptr;
821 fgImageRaw2 =
nullptr;
824 fgCtrl_DC1394 =
nullptr;
825 fgCtrl2_DC1394 =
nullptr;
841 yCIError(SERVERGRABBER,
id()) <<
"Server grabber configured for two cameras, but only one provided";
853 yCIError(SERVERGRABBER,
id()) <<
"Invalid device to be attached";
863 bool ServerGrabber::openDeferredAttach(
Searchable &prop){
865 isSubdeviceOwned =
false;
869 bool ServerGrabber::openAndAttachSubDevice(
Searchable &prop){
875 std::string file, file2;
876 if(!prop.
check(
"left_config") || !prop.
check(
"right_config"))
878 yCIError(SERVERGRABBER,
id()) <<
"Missing 'left_config' or 'right_config' filename... ";
882 if(prop.
check(
"context"))
893 yCIError(SERVERGRABBER,
id()) <<
"Unable to find files specified in 'left_config' and/or 'right_config'";
910 yCIError(SERVERGRABBER,
id()) <<
"Error in the configuration file, the two images have to have the same dimensions";
921 yCIError(SERVERGRABBER,
id(),
"Opening devices... FAILED");
945 p.setMonitor(prop.getMonitor(),
"subdevice");
954 yCIError(SERVERGRABBER,
id(),
"opening subdevice... FAILED");
964 isSubdeviceOwned =
true;
1039 if(fgImage!=
nullptr && fgImage2 !=
nullptr)
1046 yCIError(SERVERGRABBER,
id()) <<
"Image not captured.. check hardware configuration";
1051 if(fgImageRaw!=
nullptr && fgImageRaw2 !=
nullptr)
1058 yCIError(SERVERGRABBER,
id()) <<
"Image not captured.. check hardware configuration";
1078 if(fgImage!=
nullptr && fgImage2 !=
nullptr)
1088 yCIError(SERVERGRABBER,
id()) <<
"Failed to concatenate images";
1092 yCIError(SERVERGRABBER,
id()) <<
"Image not captured.. check hardware configuration";
1097 if(fgImageRaw!=
nullptr && fgImageRaw2 !=
nullptr)
1106 yCIError(SERVERGRABBER,
id()) <<
"Failed to concatenate images";
1110 yCIError(SERVERGRABBER,
id()) <<
"Image not captured.. check hardware configuration";
1130 if(fgImage!=
nullptr)
1138 yCIError(SERVERGRABBER,
id()) <<
"Failed to split the image";
1145 yCIError(SERVERGRABBER,
id()) <<
"Image not captured.. check hardware configuration";
1150 if(fgImageRaw!=
nullptr)
1158 yCIError(SERVERGRABBER,
id()) <<
"Failed to split the image";
1166 yCIError(SERVERGRABBER,
id()) <<
"Image not captured.. check hardware configuration";
1186 if(fgImage!=
nullptr)
1191 yCIError(SERVERGRABBER,
id()) <<
"Image not captured.. check hardware configuration";
1196 if(fgImageRaw!=
nullptr)
1201 yCIError(SERVERGRABBER,
id()) <<
"Image not captured.. check hardware configuration";
1237 if(img_Raw!=
nullptr)
1242 if(img2_Raw!=
nullptr)
constexpr yarp::conf::vocab32_t VOCAB_RGB_VISUAL_PARAMS
constexpr yarp::conf::vocab32_t VOCAB_FRAMEGRABBER_CONTROL_DC1394
constexpr yarp::conf::vocab32_t VOCAB_FRAMEGRABBER_IMAGE
constexpr yarp::conf::vocab32_t VOCAB_FRAMEGRABBER_CONTROL
constexpr yarp::conf::vocab32_t VOCAB_CROP
constexpr yarp::conf::vocab32_t VOCAB_INTRINSIC_PARAM
constexpr yarp::conf::vocab32_t VOCAB_IS
constexpr yarp::conf::vocab32_t VOCAB_GET
constexpr yarp::conf::vocab32_t VOCAB_FAILED
constexpr yarp::conf::vocab32_t VOCAB_SET
constexpr double DEFAULT_THREAD_PERIOD
contains the definition of a Vector type
ServerGrabberResponder(bool _left=false)
bool configure(ServerGrabber *_server)
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply) override
Respond to a message.
grabberDual deprecated: A Network grabber for camera devices.
void threadRelease() override
Release method.
~ServerGrabber() override
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
bool detach() override
Detach the object (you must have first called attach).
bool open(yarp::os::Searchable &config) override
Configure with a set of options.
bool close() override
Close the DeviceDriver.
void setupFlexImage(const yarp::sig::Image &img, yarp::sig::FlexImage &flex_i)
void shallowCopyImages(const yarp::sig::FlexImage &src, yarp::sig::FlexImage &dest)
void run() override
Loop function.
bool detachAll() override
Detach the object (you must have first called attach).
bool initialize_YARP(yarp::os::Searchable ¶ms)
bool attachAll(const yarp::dev::PolyDriverList &device2attach) override
Attach to a list of objects.
bool respond(const yarp::os::Bottle &command, yarp::os::Bottle &reply, bool left, bool both)
bool fromConfig(yarp::os::Searchable &config)
bool threadInit() override
Initialization method.
bool view(T *&x)
Get an interface to the device driver.
virtual int width() const =0
Return the width of each frame.
virtual int height() const =0
Return the height of each frame.
virtual bool getImageCrop(cropType_id_t cropType, yarp::sig::VectorOf< std::pair< int, int >> vertices, ImageType &image)
Get a crop of the image from the frame grabber.
virtual bool getImage(ImageType &image)=0
Get an image from the frame grabber.
void push(PolyDriver *p, const char *k)
A container for a device driver.
bool close() override
Close the DeviceDriver.
bool isValid() const
Check if device is valid.
bool open(const std::string &txt)
Construct and configure a device by its common name.
A simple collection of objects that can be described and transmitted in a portable way.
void add(const Value &value)
Add a Value to the bottle, at the end of the list.
void addVocab32(yarp::conf::vocab32_t x)
Places a vocabulary item in the bottle, at the end of the list.
void append(const Bottle &alt)
Append the content of the given bottle to the current 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.
void promiseType(const Type &typ) override
Commit the port to a particular type of data.
void close() override
Stop port activity.
bool setEnvelope(PortWriter &envelope) override
Set an envelope (e.g., a timestamp) to the next message which will be sent.
void setReader(PortReader &reader) override
Set an external reader for port data.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void setStrict(bool strict=true) override
Call this to strictly keep all messages, or allow old ones to be quietly dropped.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
An abstraction for a periodic thread.
bool isRunning() const
Returns true when the thread is started, false otherwise.
void stop()
Call this to stop the thread, this call blocks until the thread is terminated (and releaseThread() ca...
void setReader(PortReader &reader) override
Set an external reader for port data.
void interrupt() override
Interrupt any current reads or writes attached to the port.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
A class for storing options and configuration information.
Value & find(const std::string &key) const override
Gets a value corresponding to a given keyword.
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
bool fromConfigFile(const std::string &fname, bool wipe=true)
Interprets a file as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
Helper class for finding config files and other external resources.
bool setDefaultContext(const std::string &contextName)
Sets the context for the current ResourceFinder object.
std::string findFileByName(const std::string &name)
Find the full path to a file.
A base class for nested structures that can be searched.
virtual bool isNull() const
Checks if the object is invalid.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
An abstraction for a time stamp and/or sequence number.
A single value (typically within a Bottle).
virtual yarp::conf::vocab32_t asVocab32() const
Get vocabulary identifier as an integer.
virtual bool asBool() const
Get boolean value.
virtual std::int32_t asInt32() const
Get 32-bit integer value.
virtual Bottle * asList() const
Get list value.
std::string toString() const override
Return a standard text representation of the content of the object.
virtual bool isInt32() const
Checks if value is a 32-bit integer.
virtual std::string asString() const
Get string value.
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
bool configure(yarp::dev::IFrameGrabberControlsDC1394 *interface)
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
bool configure(yarp::dev::IFrameGrabberControls *interface)
bool configure(yarp::dev::IRgbVisualParams *interface)
bool respond(const yarp::os::Bottle &cmd, yarp::os::Bottle &response) override
Respond to a message.
Image class with user control of representation details.
void setQuantum(size_t imgQuantum)
void setPixelCode(int imgPixelCode)
Base class for storing images.
bool topIsLowIndex() const
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.
unsigned char * getRawImage() const
Access to the internal image buffer.
size_t getRawImageSize() const
Access to the internal buffer size information (this is how much memory has been allocated for the im...
void resize(size_t imgWidth, size_t imgHeight)
Reallocate an image to be of a desired size, throwing away its current contents.
void setTopIsLowIndex(bool flag)
control whether image has origin at top left (default) or bottom left.
size_t getQuantum() const
The size of a row is constrained to be a multiple of the "quantum".
size_t height() const
Gets height of image in pixels.
virtual int getPixelCode() const
Gets pixel type identifier.
void resize(size_t size) override
Resize the vector.
iterator begin() noexcept
Returns an iterator to the beginning of the VectorOf.
iterator end() noexcept
Returns an iterator to the end of the VectorOf.
#define yCError(component,...)
#define yCIError(component, id,...)
#define YARP_LOG_COMPONENT(name,...)
#define yCIInfo(component, id,...)
#define yCIWarning(component, id,...)
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
An interface to the operating system, including Port based communication.
bool vertSplit(const yarp::sig::Image &inImg, yarp::sig::Image &outImgL, yarp::sig::Image &outImgR)
Split vertically an image in two images of the same size.
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.
bool horzConcat(const yarp::sig::Image &inImgL, const yarp::sig::Image &inImgR, yarp::sig::Image &outImg)
Concatenate horizontally two images of the same size in one with double width.