38template <
typename ImageType>
41 std::lock_guard<std::mutex> lock(m_mutex);
47 }
else if (reader.
check()) {
50 m_lastHeight =
image.height();
51 m_lastWidth =
image.width();
60 const std::string& remote,
61 const std::string& carrier)
63 std::lock_guard<std::mutex> lock(m_mutex);
66 yCError(FRAMEGRABBER_NWC_YARP) <<
"Failed to open " << local <<
"port.";
69 if (!remote.empty()) {
70 yCInfo(FRAMEGRABBER_NWC_YARP) <<
"Connecting" << port.
getName() <<
"to" << remote;
72 yCError(FRAMEGRABBER_NWC_YARP) <<
"Failed to connect" << local <<
"to" << remote;
76 yCInfo(FRAMEGRABBER_NWC_YARP) <<
"No remote specified. Waiting for connection";
86 std::lock_guard<std::mutex> lock(m_mutex);
88 m_lastStamp = {0, 0.0};
108 yarp::proto::framegrabber::FrameGrabberOf_Forwarder<
ImageType, IfVocab, ImgVocab>(rpcPort)
117 std::lock_guard<std::mutex> lock(m_mutex);
118 if (!m_streamReceiver) {
122 return m_streamReceiver->lastHeight();
130 std::lock_guard<std::mutex> lock(m_mutex);
131 if (!m_streamReceiver) {
135 return m_streamReceiver->lastWidth();
143 std::lock_guard<std::mutex> lock(m_mutex);
144 if (!m_streamReceiver) {
148 return m_streamReceiver->lastImage(
image);
158 std::lock_guard<std::mutex> lock(m_mutex);
159 if(!m_streamReceiver) {
164 if (vertices.
size() != 2) {
165 yCError(FRAMEGRABBER_NWC_YARP,
"GetImageCrop failed: RECT mode requires 2 vertices");
169 bool b = m_streamReceiver->lastImage(full);
172 yCError(FRAMEGRABBER_NWC_YARP,
"GetImageCrop failed: No image received");
177 yCError(FRAMEGRABBER_NWC_YARP,
"GetImageCrop failed: utils::cropRect error: (%d, %d) (%d, %d)",
186 yCError(FRAMEGRABBER_NWC_YARP,
"List type not yet implemented");
199 std::lock_guard<std::mutex> lock(m_mutex);
200 m_streamReceiver = streamReceiver;
212 yarp::proto::framegrabber::FrameGrabberControls_Forwarder(rpcPort),
213 yarp::proto::framegrabber::FrameGrabberControlsDC1394_Forwarder(rpcPort),
214 yarp::proto::framegrabber::RgbVisualParams_Forwarder(rpcPort)
233 std::string rpc_local =
m_local +
"/rpc_client";
234 std::string rpc_remote =
m_remote +
"/rpc";
235 if (!rpcPort.
open(rpc_local)) {
236 yCError(FRAMEGRABBER_NWC_YARP) <<
"Failed to open " << rpc_local <<
"port.";
240 yCInfo(FRAMEGRABBER_NWC_YARP) <<
"Connecting" << rpcPort.
getName() <<
"to" << rpc_remote;
242 yCError(FRAMEGRABBER_NWC_YARP) <<
"Failed to connect" << rpcPort.
getName() <<
"to" << rpc_remote;
246 yCInfo(FRAMEGRABBER_NWC_YARP) <<
"No remote specified. Waiting for connection";
257 streamReceiver.
close();
constexpr yarp::conf::vocab32_t VOCAB_FRAMEGRABBER_IMAGERAW
yarp::sig::ImageOf< yarp::sig::PixelRgb > ImageType
int width() const override
Return the width of each frame.
bool getImageCrop(cropType_id_t cropType, yarp::sig::VectorOf< std::pair< int, int > > vertices, ImageType &image) override
Get a crop of the image from the frame grabber.
FrameGrabberOf_ForwarderWithStream(yarp::os::Port &rpcPort)
int height() const override
Return the height of each frame.
void setStreamReceiver(StreamReceiver *m_streamReceiver)
bool getImage(ImageType &image) override
Get an image from the frame grabber.
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool close() override
Close the DeviceDriver.
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
bool lastImage(ImageType &image)
yarp::os::Stamp lastStamp() const
bool open(const std::string &local, const std::string &remote, const std::string &carrier)
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
T * read(bool shouldWait=true) override
Read an available object from the port.
virtual bool getEnvelope(PortReader &envelope)
bool check()
Check if data is available.
void attach(Port &port)
Attach this buffer to a particular port.
T * lastRead() override
Get the last data returned by read()
A mini-server for network communication.
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.
bool isOpen() const
Check if the port has been opened.
A base class for nested structures that can be searched.
An abstraction for a time stamp and/or sequence number.
int height() const override
Return the height of each frame.
int width() const override
Return the width of each frame.
bool getImage(ImageType &image) override
Get an image from the frame grabber.
bool getImageCrop(cropType_id_t cropType, yarp::sig::VectorOf< std::pair< int, int > > vertices, ImageType &image) override
Get a crop of the image from the frame grabber.
size_t width() const
Gets width of image in pixels.
size_t height() const
Gets height of image in pixels.
#define yCInfo(component,...)
#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.
The main, catch-all namespace for YARP.