YARP
Yet Another Robot Platform
frameGrabberCropper.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef YARP_FRAMEGRABBERCROPPER_FRAMEGRABBERCROPPER_H
7 #define YARP_FRAMEGRABBERCROPPER_FRAMEGRABBERCROPPER_H
8 
9 #include <yarp/dev/PolyDriver.h>
15 #include <yarp/dev/IWrapper.h>
17 
18 #include <limits>
19 
20 template <typename ImageType>
22  public yarp::dev::IFrameGrabberOf<ImageType>
23 {
24 protected:
28 
29 public:
30  ~FrameGrabberCropperOf() override = default;
31 
32  bool getImage(ImageType& image) override
33  {
34  if (iFrameGrabberOf != nullptr) {
35  return iFrameGrabberOf->getImageCrop(cropType, vertices, image);
36  }
37  return false;
38  }
39 
40  int height() const override
41  {
42  if (vertices.size() == 2) {
43  return vertices[1].second - vertices[0].second + 1;
44  }
45  return 0;
46  }
47 
48  int width() const override
49  {
50  if (vertices.size() == 2) {
51  return vertices[1].first - vertices[0].first + 1;
52  }
53  return 0;
54  }
55 };
56 
57 
60  public yarp::dev::IWrapper,
62  public FrameGrabberCropperOf<yarp::sig::ImageOf<yarp::sig::PixelRgb>>,
63  public FrameGrabberCropperOf<yarp::sig::ImageOf<yarp::sig::PixelMono>>,
68 {
69  yarp::dev::PolyDriver* subdevice{nullptr};
70  bool subdeviceOwned{false};
71 
72  yarp::dev::IFrameGrabberControls* iFrameGrabberControls{nullptr};
73  yarp::dev::IFrameGrabberControlsDC1394* iFrameGrabberControlsDC1394{nullptr};
74  yarp::dev::IRgbVisualParams* iRgbVisualParams{nullptr};
75  yarp::dev::IPreciselyTimed* iPreciselyTimed{nullptr};
76 
77  bool forwardRgbVisualParams{false};
78 
79 public:
80  FrameGrabberCropper() = default;
85  ~FrameGrabberCropper() override;
86 
87  // yarp::dev::DeviceDriver
88  bool close() override;
89  bool open(yarp::os::Searchable& config) override;
90 
91  // yarp::dev::IWrapper
92  bool attach(yarp::dev::PolyDriver* poly) override;
93  bool detach() override;
94 
95  // yarp::dev::IMultipleWrapper
96  bool attachAll(const yarp::dev::PolyDriverList& device2attach) override;
97  bool detachAll() override;
98 
99 
100  // yarp::dev::IFrameGrabberControls
101  bool getCameraDescription(CameraDescriptor* camera) override
102  {
103  if (!iFrameGrabberControls) {
104  return false;
105  }
106  return iFrameGrabberControls->getCameraDescription(camera);
107  }
108 
109  bool hasFeature(int feature, bool* hasFeature) override
110  {
111  if (!iFrameGrabberControls) {
112  return false;
113  }
114  return iFrameGrabberControls->hasFeature(feature, hasFeature);
115  }
116 
117  bool setFeature(int feature, double value) override
118  { if (!iFrameGrabberControls) {
119  return false;
120  }
121  return iFrameGrabberControls->setFeature(feature, value);
122  }
123 
124  bool getFeature(int feature, double* value) override
125  {
126  if (!iFrameGrabberControls) {
127  return false;
128  }
129  return iFrameGrabberControls->getFeature(feature, value);
130  }
131 
132  bool setFeature(int feature, double value1, double value2) override
133  {
134  if (!iFrameGrabberControls) {
135  return false;
136  }
137  return iFrameGrabberControls->setFeature(feature, value1, value2);
138  }
139 
140  bool getFeature(int feature, double* value1, double* value2) override
141  {
142  if (!iFrameGrabberControls) {
143  return false;
144  }
145  return iFrameGrabberControls->getFeature(feature, value1, value2);
146  }
147 
148  bool hasOnOff(int feature, bool* HasOnOff) override
149  {
150  if (!iFrameGrabberControls) {
151  return false;
152  }
153  return iFrameGrabberControls->hasOnOff(feature, HasOnOff);
154  }
155 
156  bool setActive(int feature, bool onoff) override
157  {
158  if (!iFrameGrabberControls) {
159  return false;
160  }
161  return iFrameGrabberControls->setActive(feature, onoff);
162  }
163 
164  bool getActive(int feature, bool* isActive) override
165  {
166  if (!iFrameGrabberControls) {
167  return false;
168  }
169  return iFrameGrabberControls->getActive(feature, isActive);
170  }
171 
172  bool hasAuto(int feature, bool* hasAuto) override
173  {
174  if (!iFrameGrabberControls) {
175  return false;
176  }
177  return iFrameGrabberControls->hasAuto(feature, hasAuto);
178  }
179 
180  bool hasManual(int feature, bool* hasManual) override
181  {
182  if (!iFrameGrabberControls) {
183  return false;
184  }
185  return iFrameGrabberControls->hasManual(feature, hasManual);
186  }
187 
188  bool hasOnePush(int feature, bool* hasOnePush) override
189  {
190  if (!iFrameGrabberControls) {
191  return false;
192  }
193  return iFrameGrabberControls->hasOnePush(feature, hasOnePush);
194  }
195 
196  bool setMode(int feature, FeatureMode mode) override
197  {
198  if (!iFrameGrabberControls) {
199  return false;
200  }
201  return iFrameGrabberControls->setMode(feature, mode);
202  }
203 
204  bool getMode(int feature, FeatureMode* mode) override
205  {
206  if (!iFrameGrabberControls) {
207  return false;
208  }
209  return iFrameGrabberControls->getMode(feature, mode);
210  }
211 
212  bool setOnePush(int feature) override
213  {
214  if (!iFrameGrabberControls) {
215  return false;
216  }
217  return iFrameGrabberControls->setOnePush(feature);
218  }
219 
220 
221  // yarp::dev::IFrameGrabberControlsDC1394
222  unsigned int getVideoModeMaskDC1394() override
223  {
224  if (!iFrameGrabberControlsDC1394) {
225  return 0;
226  }
227  return iFrameGrabberControlsDC1394->getVideoModeMaskDC1394();
228  }
229 
230  unsigned int getVideoModeDC1394() override
231  {
232  if (!iFrameGrabberControlsDC1394) {
233  return 0;
234  }
235  return iFrameGrabberControlsDC1394->getVideoModeMaskDC1394();
236  }
237 
238  bool setVideoModeDC1394(int video_mode) override
239  {
240  if (!iFrameGrabberControlsDC1394) {
241  return false;
242  }
243  return iFrameGrabberControlsDC1394->setVideoModeDC1394(video_mode);
244  }
245 
246  unsigned int getFPSMaskDC1394() override
247  {
248  if (!iFrameGrabberControlsDC1394) {
249  return 0;
250  }
251  return iFrameGrabberControlsDC1394->getFPSMaskDC1394();
252  }
253 
254  unsigned int getFPSDC1394() override
255 
256  {
257  if (!iFrameGrabberControlsDC1394) {
258  return 0;
259  }
260  return iFrameGrabberControlsDC1394->getFPSDC1394();
261  }
262 
263  bool setFPSDC1394(int fps) override
264 
265  {
266  if (!iFrameGrabberControlsDC1394) {
267  return false;
268  }
269  return iFrameGrabberControlsDC1394->setFPSDC1394(fps);
270  }
271 
272  unsigned int getISOSpeedDC1394() override
273  {
274  if (!iFrameGrabberControlsDC1394) {
275  return 0;
276  }
277  return iFrameGrabberControlsDC1394->getISOSpeedDC1394();
278  }
279 
280  bool setISOSpeedDC1394(int speed) override
281 
282  {
283  if (!iFrameGrabberControlsDC1394) {
284  return false;
285  }
286  return iFrameGrabberControlsDC1394->setISOSpeedDC1394(speed);
287  }
288 
289  unsigned int getColorCodingMaskDC1394(unsigned int video_mode) override
290  {
291  if (!iFrameGrabberControlsDC1394) {
292  return 0;
293  }
294  return iFrameGrabberControlsDC1394->getColorCodingMaskDC1394(video_mode);
295  }
296 
297  unsigned int getColorCodingDC1394() override
298  {
299  if (!iFrameGrabberControlsDC1394) {
300  return 0;
301  }
302  return iFrameGrabberControlsDC1394->getColorCodingDC1394();
303  }
304 
305  bool setColorCodingDC1394(int coding) override
306  {
307  if (!iFrameGrabberControlsDC1394) {
308  return false;
309  }
310  return iFrameGrabberControlsDC1394->setColorCodingDC1394(coding);
311  }
312 
313  bool getFormat7MaxWindowDC1394(unsigned int& xdim,
314  unsigned int& ydim,
315  unsigned int& xstep,
316  unsigned int& ystep,
317  unsigned int& xoffstep,
318  unsigned int& yoffstep) override
319  {
320  if (!iFrameGrabberControlsDC1394) {
321  return false;
322  }
323  return iFrameGrabberControlsDC1394->getFormat7MaxWindowDC1394(xdim, ydim, xstep, ystep, xoffstep, yoffstep);
324  }
325 
326  bool getFormat7WindowDC1394(unsigned int& xdim, unsigned int& ydim, int& x0, int& y0) override
327  {
328  if (!iFrameGrabberControlsDC1394) {
329  return false;
330  }
331  return iFrameGrabberControlsDC1394->getFormat7WindowDC1394(xdim, ydim, x0, y0);
332  }
333 
334  bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0) override
335  {
336  if (!iFrameGrabberControlsDC1394) {
337  return false;
338  }
339  return iFrameGrabberControlsDC1394->setFormat7WindowDC1394(xdim, ydim, x0, y0);
340  }
341 
342  bool setOperationModeDC1394(bool b1394b) override
343  {
344  if (!iFrameGrabberControlsDC1394) {
345  return false;
346  }
347  return iFrameGrabberControlsDC1394->setOperationModeDC1394(b1394b);
348  }
349 
350  bool getOperationModeDC1394() override
351  {
352  if (!iFrameGrabberControlsDC1394) {
353  return false;
354  }
355  return iFrameGrabberControlsDC1394->getOperationModeDC1394();
356  }
357 
358  bool setTransmissionDC1394(bool bTxON) override
359  {
360  if (!iFrameGrabberControlsDC1394) {
361  return false;
362  }
363  return iFrameGrabberControlsDC1394->setTransmissionDC1394(bTxON);
364  }
365 
366  bool getTransmissionDC1394() override
367  {
368  if (!iFrameGrabberControlsDC1394) {
369  return false;
370  }
371  return iFrameGrabberControlsDC1394->getTransmissionDC1394();
372  }
373 
374  bool setBroadcastDC1394(bool onoff) override
375  {
376  if (!iFrameGrabberControlsDC1394) {
377  return false;
378  }
379  return iFrameGrabberControlsDC1394->setBroadcastDC1394(onoff);
380  }
381 
382  bool setDefaultsDC1394() override
383  {
384  if (!iFrameGrabberControlsDC1394) {
385  return false;
386  }
387  return iFrameGrabberControlsDC1394->setDefaultsDC1394();
388  }
389 
390  bool setResetDC1394() override
391  {
392  if (!iFrameGrabberControlsDC1394) {
393  return false;
394  }
395  return iFrameGrabberControlsDC1394->setResetDC1394();
396  }
397 
398  bool setPowerDC1394(bool onoff) override
399  {
400  if (!iFrameGrabberControlsDC1394) {
401  return false;
402  }
403  return iFrameGrabberControlsDC1394->setPowerDC1394(onoff);
404  }
405 
406  bool setCaptureDC1394(bool bON) override
407  {
408  if (!iFrameGrabberControlsDC1394) {
409  return false;
410  }
411  return iFrameGrabberControlsDC1394->setCaptureDC1394(bON);
412  }
413 
414  unsigned int getBytesPerPacketDC1394() override
415  {
416  if (!iFrameGrabberControlsDC1394) {
417  return 0;
418  }
419  return iFrameGrabberControlsDC1394->getBytesPerPacketDC1394();
420  }
421 
422  bool setBytesPerPacketDC1394(unsigned int bpp) override
423  {
424  if (!iFrameGrabberControlsDC1394) {
425  return false;
426  }
427  return iFrameGrabberControlsDC1394->setBytesPerPacketDC1394(bpp);
428  }
429 
430 
431  // yarp::dev::IRgbVisualParams
432  int getRgbHeight() override
433  {
435  }
436 
437  int getRgbWidth() override
438  {
440  }
441 
442  bool setRgbResolution(int width, int height) override
443  {
444  if (!iRgbVisualParams || !forwardRgbVisualParams) {
445  return false;
446  }
447  return iRgbVisualParams->setRgbResolution(width, height);
448  }
449 
450  bool getRgbFOV(double& horizontalFov, double& verticalFov) override
451  {
452  if (!iRgbVisualParams || !forwardRgbVisualParams) {
453  horizontalFov = std::numeric_limits<double>::quiet_NaN();
454  verticalFov = std::numeric_limits<double>::quiet_NaN();
455  return false;
456  }
457  return iRgbVisualParams->getRgbFOV(horizontalFov, verticalFov);
458  }
459 
460  bool setRgbFOV(double horizontalFov, double verticalFov) override
461  {
462  if (!iRgbVisualParams || !forwardRgbVisualParams) {
463  return false;
464  }
465  return iRgbVisualParams->setRgbFOV(horizontalFov, verticalFov);
466  }
467 
468  bool getRgbIntrinsicParam(yarp::os::Property& intrinsic) override
469  {
470  if (!iRgbVisualParams || !forwardRgbVisualParams) {
471  intrinsic.clear();
472  return false;
473  }
474  return iRgbVisualParams->getRgbIntrinsicParam(intrinsic);
475  }
476 
477  bool getRgbMirroring(bool& mirror) override
478  {
479  if (!iRgbVisualParams || !forwardRgbVisualParams) {
480  mirror = false;
481  return false;
482  }
483  return iRgbVisualParams->getRgbMirroring(mirror);
484 
485  }
486 
487  bool setRgbMirroring(bool mirror) override
488  {
489  if (!iRgbVisualParams || !forwardRgbVisualParams) {
490  return false;
491  }
492  return iRgbVisualParams->setRgbMirroring(mirror);
493  }
494 
495 
496  // yarp::dev::IPreciselyTimed
498  {
499  if (!iPreciselyTimed) {
500  return yarp::os::Stamp();
501  }
502  return iPreciselyTimed->getLastInputStamp();
503  }
504 };
505 
506 #endif // YARP_FRAMEGRABBERCROPPER_FRAMEGRABBERCROPPER_H
cropType_id_t
@ YARP_CROP_RECT
~FrameGrabberCropperOf() override=default
yarp::sig::VectorOf< std::pair< int, int > > vertices
static constexpr cropType_id_t cropType
yarp::dev::IFrameGrabberOf< ImageType > * iFrameGrabberOf
int width() const override
Return the width of each frame.
int height() const override
Return the height of each frame.
bool getImage(ImageType &image) override
Get an image from the frame grabber.
unsigned int getColorCodingMaskDC1394(unsigned int video_mode) override
bool close() override
Close the DeviceDriver.
bool hasManual(int feature, bool *hasManual) override
Check if the requested feature has the 'manual' mode.
bool setBroadcastDC1394(bool onoff) override
bool setTransmissionDC1394(bool bTxON) override
FrameGrabberCropper(const FrameGrabberCropper &)=delete
bool setDefaultsDC1394() override
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
bool hasFeature(int feature, bool *hasFeature) override
Check if camera has the requested feature (saturation, brightness ...
bool setCaptureDC1394(bool bON) override
unsigned int getVideoModeDC1394() override
unsigned int getFPSMaskDC1394() override
bool setColorCodingDC1394(int coding) override
bool setActive(int feature, bool onoff) override
Set the requested feature on or off.
FrameGrabberCropper & operator=(FrameGrabberCropper &&)=delete
bool hasOnOff(int feature, bool *HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
unsigned int getFPSDC1394() override
bool attachAll(const yarp::dev::PolyDriverList &device2attach) override
Attach to a list of objects.
bool getCameraDescription(CameraDescriptor *camera) override
Get a basic description of the camera hw.
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
bool setBytesPerPacketDC1394(unsigned int bpp) override
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
int getRgbWidth() override
Return the width of each frame.
bool getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0) override
bool detach() override
Detach the object (you must have first called attach).
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool setFPSDC1394(int fps) override
bool getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep) override
unsigned int getBytesPerPacketDC1394() override
FrameGrabberCropper(FrameGrabberCropper &&)=delete
bool getTransmissionDC1394() override
bool setVideoModeDC1394(int video_mode) override
bool getFeature(int feature, double *value) override
Get the current value for the requested feature.
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
unsigned int getColorCodingDC1394() override
bool setOperationModeDC1394(bool b1394b) override
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
bool getFeature(int feature, double *value1, double *value2) override
Get the current value for the requested feature.
unsigned int getISOSpeedDC1394() override
bool setResetDC1394() override
bool hasOnePush(int feature, bool *hasOnePush) override
Check if the requested feature has the 'onePush' mode.
bool detachAll() override
Detach the object (you must have first called attach).
bool hasAuto(int feature, bool *hasAuto) override
Check if the requested feature has the 'auto' mode.
bool getActive(int feature, bool *isActive) override
Get the current status of the feature, on or off.
bool setFeature(int feature, double value1, double value2) override
Set the requested feature to a value using 2 params (like white balance)
bool getOperationModeDC1394() override
bool setFeature(int feature, double value) override
Set the requested feature to a value (saturation, brightness ...
unsigned int getVideoModeMaskDC1394() override
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setISOSpeedDC1394(int speed) override
bool setMode(int feature, FeatureMode mode) override
Set the requested mode for the feature.
FrameGrabberCropper & operator=(const FrameGrabberCropper &)=delete
int getRgbHeight() override
Return the height of each frame.
bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0) override
bool setPowerDC1394(bool onoff) override
FrameGrabberCropper()=default
bool getMode(int feature, FeatureMode *mode) override
Get the current mode for the feature.
bool attach(yarp::dev::PolyDriver *poly) override
Attach to another object.
bool setOnePush(int feature) override
Set the requested feature to a value (saturation, brightness ...
Interface implemented by all device drivers.
Definition: DeviceDriver.h:30
virtual unsigned int getISOSpeedDC1394()=0
virtual bool setISOSpeedDC1394(int speed)=0
virtual unsigned int getBytesPerPacketDC1394()=0
virtual bool setPowerDC1394(bool onoff)=0
virtual unsigned int getFPSMaskDC1394()=0
virtual bool getFormat7WindowDC1394(unsigned int &xdim, unsigned int &ydim, int &x0, int &y0)=0
virtual unsigned int getFPSDC1394()=0
virtual bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0)=0
virtual bool setBroadcastDC1394(bool onoff)=0
virtual bool setBytesPerPacketDC1394(unsigned int bpp)=0
virtual bool setColorCodingDC1394(int coding)=0
virtual bool getFormat7MaxWindowDC1394(unsigned int &xdim, unsigned int &ydim, unsigned int &xstep, unsigned int &ystep, unsigned int &xoffstep, unsigned int &yoffstep)=0
virtual bool setFPSDC1394(int fps)=0
virtual bool setVideoModeDC1394(int video_mode)=0
virtual unsigned int getColorCodingMaskDC1394(unsigned int video_mode)=0
virtual unsigned int getVideoModeMaskDC1394()=0
virtual unsigned int getColorCodingDC1394()=0
virtual bool setCaptureDC1394(bool bON)=0
virtual bool setOperationModeDC1394(bool b1394b)=0
virtual bool setTransmissionDC1394(bool bTxON)=0
Control interface for frame grabber devices.
virtual bool setFeature(int feature, double value)=0
Set the requested feature to a value (saturation, brightness ...
virtual bool setOnePush(int feature)=0
Set the requested feature to a value (saturation, brightness ...
virtual bool getFeature(int feature, double *value)=0
Get the current value for the requested feature.
virtual bool hasManual(int feature, bool *hasManual)=0
Check if the requested feature has the 'manual' mode.
virtual bool setMode(int feature, FeatureMode mode)=0
Set the requested mode for the feature.
virtual bool hasOnOff(int feature, bool *HasOnOff)=0
Check if the camera has the ability to turn on/off the requested feature.
virtual bool hasAuto(int feature, bool *hasAuto)=0
Check if the requested feature has the 'auto' mode.
virtual bool getMode(int feature, FeatureMode *mode)=0
Get the current mode for the feature.
virtual bool getCameraDescription(CameraDescriptor *camera)=0
Get a basic description of the camera hw.
virtual bool getActive(int feature, bool *isActive)=0
Get the current status of the feature, on or off.
virtual bool setActive(int feature, bool onoff)=0
Set the requested feature on or off.
virtual bool hasFeature(int feature, bool *hasFeature)=0
Check if camera has the requested feature (saturation, brightness ...
virtual bool hasOnePush(int feature, bool *hasOnePush)=0
Check if the requested feature has the 'onePush' mode.
Interface for an object that can wrap/attach to to another.
virtual yarp::os::Stamp getLastInputStamp()=0
Return the time stamp relative to the last acquisition.
An interface for retrieving intrinsic parameter from a rgb camera.
virtual bool setRgbMirroring(bool mirror)=0
Set the mirroring setting of the sensor.
virtual bool getRgbIntrinsicParam(yarp::os::Property &intrinsic)=0
Get the intrinsic parameters of the rgb camera.
virtual bool setRgbResolution(int width, int height)=0
Set the resolution of the rgb image from the camera.
virtual bool getRgbMirroring(bool &mirror)=0
Get the mirroring setting of the sensor.
virtual bool getRgbFOV(double &horizontalFov, double &verticalFov)=0
Get the field of view (FOV) of the rgb camera.
virtual bool setRgbFOV(double horizontalFov, double verticalFov)=0
Set the field of view (FOV) of the rgb camera.
Interface for an object that can wrap/or "attach" to another.
Definition: IWrapper.h:25
A container for a device driver.
Definition: PolyDriver.h:23
A class for storing options and configuration information.
Definition: Property.h:33
void clear()
Remove all associations.
Definition: Property.cpp:1057
A base class for nested structures that can be searched.
Definition: Searchable.h:63
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:21
Provides:
Definition: Vector.h:117
size_t size() const
Definition: Vector.h:321