YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
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
15#include <yarp/dev/IWrapper.h>
17
18#include <limits>
19
20template <typename ImageType>
22 public yarp::dev::IFrameGrabberOf<ImageType>
23{
24protected:
28
29public:
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
62 public FrameGrabberCropperOf<yarp::sig::ImageOf<yarp::sig::PixelRgb>>,
63 public FrameGrabberCropperOf<yarp::sig::ImageOf<yarp::sig::PixelMono>>,
68{
69 yarp::dev::IFrameGrabberControls* iFrameGrabberControls{nullptr};
70 yarp::dev::IFrameGrabberControlsDC1394* iFrameGrabberControlsDC1394{nullptr};
71 yarp::dev::IRgbVisualParams* iRgbVisualParams{nullptr};
72 yarp::dev::IPreciselyTimed* iPreciselyTimed{nullptr};
73
74 bool forwardRgbVisualParams{false};
75
76public:
82 ~FrameGrabberCropper() override;
83
84 // yarp::dev::DeviceDriver
85 bool close() override;
86 bool open(yarp::os::Searchable& config) override;
87
88 // yarp::dev::IWrapper
89 bool attach(yarp::dev::PolyDriver* poly) override;
90 bool detach() override;
91
92 // yarp::dev::IMultipleWrapper
93 bool attachAll(const yarp::dev::PolyDriverList& device2attach) override;
94 bool detachAll() override;
95
96
97 // yarp::dev::IFrameGrabberControls
99 {
100 if (!iFrameGrabberControls) {
101 return false;
102 }
103 return iFrameGrabberControls->getCameraDescription(camera);
104 }
105
106 bool hasFeature(int feature, bool* hasFeature) override
107 {
108 if (!iFrameGrabberControls) {
109 return false;
110 }
111 return iFrameGrabberControls->hasFeature(feature, hasFeature);
112 }
113
114 bool setFeature(int feature, double value) override
115 { if (!iFrameGrabberControls) {
116 return false;
117 }
118 return iFrameGrabberControls->setFeature(feature, value);
119 }
120
121 bool getFeature(int feature, double* value) override
122 {
123 if (!iFrameGrabberControls) {
124 return false;
125 }
126 return iFrameGrabberControls->getFeature(feature, value);
127 }
128
129 bool setFeature(int feature, double value1, double value2) override
130 {
131 if (!iFrameGrabberControls) {
132 return false;
133 }
134 return iFrameGrabberControls->setFeature(feature, value1, value2);
135 }
136
137 bool getFeature(int feature, double* value1, double* value2) override
138 {
139 if (!iFrameGrabberControls) {
140 return false;
141 }
142 return iFrameGrabberControls->getFeature(feature, value1, value2);
143 }
144
145 bool hasOnOff(int feature, bool* HasOnOff) override
146 {
147 if (!iFrameGrabberControls) {
148 return false;
149 }
150 return iFrameGrabberControls->hasOnOff(feature, HasOnOff);
151 }
152
153 bool setActive(int feature, bool onoff) override
154 {
155 if (!iFrameGrabberControls) {
156 return false;
157 }
158 return iFrameGrabberControls->setActive(feature, onoff);
159 }
160
161 bool getActive(int feature, bool* isActive) override
162 {
163 if (!iFrameGrabberControls) {
164 return false;
165 }
166 return iFrameGrabberControls->getActive(feature, isActive);
167 }
168
169 bool hasAuto(int feature, bool* hasAuto) override
170 {
171 if (!iFrameGrabberControls) {
172 return false;
173 }
174 return iFrameGrabberControls->hasAuto(feature, hasAuto);
175 }
176
177 bool hasManual(int feature, bool* hasManual) override
178 {
179 if (!iFrameGrabberControls) {
180 return false;
181 }
182 return iFrameGrabberControls->hasManual(feature, hasManual);
183 }
184
185 bool hasOnePush(int feature, bool* hasOnePush) override
186 {
187 if (!iFrameGrabberControls) {
188 return false;
189 }
190 return iFrameGrabberControls->hasOnePush(feature, hasOnePush);
191 }
192
193 bool setMode(int feature, FeatureMode mode) override
194 {
195 if (!iFrameGrabberControls) {
196 return false;
197 }
198 return iFrameGrabberControls->setMode(feature, mode);
199 }
200
201 bool getMode(int feature, FeatureMode* mode) override
202 {
203 if (!iFrameGrabberControls) {
204 return false;
205 }
206 return iFrameGrabberControls->getMode(feature, mode);
207 }
208
209 bool setOnePush(int feature) override
210 {
211 if (!iFrameGrabberControls) {
212 return false;
213 }
214 return iFrameGrabberControls->setOnePush(feature);
215 }
216
217
218 // yarp::dev::IFrameGrabberControlsDC1394
219 unsigned int getVideoModeMaskDC1394() override
220 {
221 if (!iFrameGrabberControlsDC1394) {
222 return 0;
223 }
224 return iFrameGrabberControlsDC1394->getVideoModeMaskDC1394();
225 }
226
227 unsigned int getVideoModeDC1394() override
228 {
229 if (!iFrameGrabberControlsDC1394) {
230 return 0;
231 }
232 return iFrameGrabberControlsDC1394->getVideoModeMaskDC1394();
233 }
234
235 bool setVideoModeDC1394(int video_mode) override
236 {
237 if (!iFrameGrabberControlsDC1394) {
238 return false;
239 }
240 return iFrameGrabberControlsDC1394->setVideoModeDC1394(video_mode);
241 }
242
243 unsigned int getFPSMaskDC1394() override
244 {
245 if (!iFrameGrabberControlsDC1394) {
246 return 0;
247 }
248 return iFrameGrabberControlsDC1394->getFPSMaskDC1394();
249 }
250
251 unsigned int getFPSDC1394() override
252
253 {
254 if (!iFrameGrabberControlsDC1394) {
255 return 0;
256 }
257 return iFrameGrabberControlsDC1394->getFPSDC1394();
258 }
259
260 bool setFPSDC1394(int fps) override
261
262 {
263 if (!iFrameGrabberControlsDC1394) {
264 return false;
265 }
266 return iFrameGrabberControlsDC1394->setFPSDC1394(fps);
267 }
268
269 unsigned int getISOSpeedDC1394() override
270 {
271 if (!iFrameGrabberControlsDC1394) {
272 return 0;
273 }
274 return iFrameGrabberControlsDC1394->getISOSpeedDC1394();
275 }
276
277 bool setISOSpeedDC1394(int speed) override
278
279 {
280 if (!iFrameGrabberControlsDC1394) {
281 return false;
282 }
283 return iFrameGrabberControlsDC1394->setISOSpeedDC1394(speed);
284 }
285
286 unsigned int getColorCodingMaskDC1394(unsigned int video_mode) override
287 {
288 if (!iFrameGrabberControlsDC1394) {
289 return 0;
290 }
291 return iFrameGrabberControlsDC1394->getColorCodingMaskDC1394(video_mode);
292 }
293
294 unsigned int getColorCodingDC1394() override
295 {
296 if (!iFrameGrabberControlsDC1394) {
297 return 0;
298 }
299 return iFrameGrabberControlsDC1394->getColorCodingDC1394();
300 }
301
302 bool setColorCodingDC1394(int coding) override
303 {
304 if (!iFrameGrabberControlsDC1394) {
305 return false;
306 }
307 return iFrameGrabberControlsDC1394->setColorCodingDC1394(coding);
308 }
309
310 bool getFormat7MaxWindowDC1394(unsigned int& xdim,
311 unsigned int& ydim,
312 unsigned int& xstep,
313 unsigned int& ystep,
314 unsigned int& xoffstep,
315 unsigned int& yoffstep) override
316 {
317 if (!iFrameGrabberControlsDC1394) {
318 return false;
319 }
320 return iFrameGrabberControlsDC1394->getFormat7MaxWindowDC1394(xdim, ydim, xstep, ystep, xoffstep, yoffstep);
321 }
322
323 bool getFormat7WindowDC1394(unsigned int& xdim, unsigned int& ydim, int& x0, int& y0) override
324 {
325 if (!iFrameGrabberControlsDC1394) {
326 return false;
327 }
328 return iFrameGrabberControlsDC1394->getFormat7WindowDC1394(xdim, ydim, x0, y0);
329 }
330
331 bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0) override
332 {
333 if (!iFrameGrabberControlsDC1394) {
334 return false;
335 }
336 return iFrameGrabberControlsDC1394->setFormat7WindowDC1394(xdim, ydim, x0, y0);
337 }
338
339 bool setOperationModeDC1394(bool b1394b) override
340 {
341 if (!iFrameGrabberControlsDC1394) {
342 return false;
343 }
344 return iFrameGrabberControlsDC1394->setOperationModeDC1394(b1394b);
345 }
346
348 {
349 if (!iFrameGrabberControlsDC1394) {
350 return false;
351 }
352 return iFrameGrabberControlsDC1394->getOperationModeDC1394();
353 }
354
355 bool setTransmissionDC1394(bool bTxON) override
356 {
357 if (!iFrameGrabberControlsDC1394) {
358 return false;
359 }
360 return iFrameGrabberControlsDC1394->setTransmissionDC1394(bTxON);
361 }
362
363 bool getTransmissionDC1394() override
364 {
365 if (!iFrameGrabberControlsDC1394) {
366 return false;
367 }
368 return iFrameGrabberControlsDC1394->getTransmissionDC1394();
369 }
370
371 bool setBroadcastDC1394(bool onoff) override
372 {
373 if (!iFrameGrabberControlsDC1394) {
374 return false;
375 }
376 return iFrameGrabberControlsDC1394->setBroadcastDC1394(onoff);
377 }
378
379 bool setDefaultsDC1394() override
380 {
381 if (!iFrameGrabberControlsDC1394) {
382 return false;
383 }
384 return iFrameGrabberControlsDC1394->setDefaultsDC1394();
385 }
386
387 bool setResetDC1394() override
388 {
389 if (!iFrameGrabberControlsDC1394) {
390 return false;
391 }
392 return iFrameGrabberControlsDC1394->setResetDC1394();
393 }
394
395 bool setPowerDC1394(bool onoff) override
396 {
397 if (!iFrameGrabberControlsDC1394) {
398 return false;
399 }
400 return iFrameGrabberControlsDC1394->setPowerDC1394(onoff);
401 }
402
403 bool setCaptureDC1394(bool bON) override
404 {
405 if (!iFrameGrabberControlsDC1394) {
406 return false;
407 }
408 return iFrameGrabberControlsDC1394->setCaptureDC1394(bON);
409 }
410
411 unsigned int getBytesPerPacketDC1394() override
412 {
413 if (!iFrameGrabberControlsDC1394) {
414 return 0;
415 }
416 return iFrameGrabberControlsDC1394->getBytesPerPacketDC1394();
417 }
418
419 bool setBytesPerPacketDC1394(unsigned int bpp) override
420 {
421 if (!iFrameGrabberControlsDC1394) {
422 return false;
423 }
424 return iFrameGrabberControlsDC1394->setBytesPerPacketDC1394(bpp);
425 }
426
427
428 // yarp::dev::IRgbVisualParams
433
438
439 bool setRgbResolution(int width, int height) override
440 {
441 if (!iRgbVisualParams || !forwardRgbVisualParams) {
442 return false;
443 }
444 return iRgbVisualParams->setRgbResolution(width, height);
445 }
446
447 bool getRgbFOV(double& horizontalFov, double& verticalFov) override
448 {
449 if (!iRgbVisualParams || !forwardRgbVisualParams) {
450 horizontalFov = std::numeric_limits<double>::quiet_NaN();
451 verticalFov = std::numeric_limits<double>::quiet_NaN();
452 return false;
453 }
454 return iRgbVisualParams->getRgbFOV(horizontalFov, verticalFov);
455 }
456
457 bool setRgbFOV(double horizontalFov, double verticalFov) override
458 {
459 if (!iRgbVisualParams || !forwardRgbVisualParams) {
460 return false;
461 }
462 return iRgbVisualParams->setRgbFOV(horizontalFov, verticalFov);
463 }
464
465 bool getRgbIntrinsicParam(yarp::os::Property& intrinsic) override
466 {
467 if (!iRgbVisualParams || !forwardRgbVisualParams) {
468 intrinsic.clear();
469 return false;
470 }
471 return iRgbVisualParams->getRgbIntrinsicParam(intrinsic);
472 }
473
474 bool getRgbMirroring(bool& mirror) override
475 {
476 if (!iRgbVisualParams || !forwardRgbVisualParams) {
477 mirror = false;
478 return false;
479 }
480 return iRgbVisualParams->getRgbMirroring(mirror);
481
482 }
483
484 bool setRgbMirroring(bool mirror) override
485 {
486 if (!iRgbVisualParams || !forwardRgbVisualParams) {
487 return false;
488 }
489 return iRgbVisualParams->setRgbMirroring(mirror);
490 }
491
492
493 // yarp::dev::IPreciselyTimed
495 {
496 if (!iPreciselyTimed) {
497 return yarp::os::Stamp();
498 }
499 return iPreciselyTimed->getLastInputStamp();
500 }
501};
502
503#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.
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
FrameGrabberCropper & operator=(FrameGrabberCropper &&)=delete
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).
FrameGrabberCropper & operator=(const FrameGrabberCropper &)=delete
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.
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.
Control interface for frame grabber devices that conform to the 1394-based Digital Camera Specificati...
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.
Read a YARP-format image (of a specific type) from a device.
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.
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a time stamp and/or sequence number.
Definition Stamp.h:21
size_t size() const
Definition Vector.h:322