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>
20
21template <typename ImageType>
23 public yarp::dev::IFrameGrabberOf<ImageType>
24{
25protected:
29
30public:
31 ~FrameGrabberCropperOf() override = default;
32
33 bool getImage(ImageType& image) override
34 {
35 if (iFrameGrabberOf != nullptr) {
36 return iFrameGrabberOf->getImageCrop(cropType, vertices, image);
37 }
38 return false;
39 }
40
41 int height() const override
42 {
43 if (vertices.size() == 2) {
44 return vertices[1].second - vertices[0].second + 1;
45 }
46 return 0;
47 }
48
49 int width() const override
50 {
51 if (vertices.size() == 2) {
52 return vertices[1].first - vertices[0].first + 1;
53 }
54 return 0;
55 }
56};
57
70 public FrameGrabberCropperOf<yarp::sig::ImageOf<yarp::sig::PixelRgb>>,
71 public FrameGrabberCropperOf<yarp::sig::ImageOf<yarp::sig::PixelMono>>,
77{
78 yarp::dev::IFrameGrabberControls* iFrameGrabberControls{nullptr};
79 yarp::dev::IFrameGrabberControlsDC1394* iFrameGrabberControlsDC1394{nullptr};
80 yarp::dev::IRgbVisualParams* iRgbVisualParams{nullptr};
81 yarp::dev::IPreciselyTimed* iPreciselyTimed{nullptr};
82
83public:
89 ~FrameGrabberCropper() override;
90
91 // yarp::dev::DeviceDriver
92 bool close() override;
93 bool open(yarp::os::Searchable& config) override;
94
95 // yarp::dev::IWrapper
96 bool attach(yarp::dev::PolyDriver* poly) override;
97 bool detach() override;
98
99 // yarp::dev::IMultipleWrapper
100 bool attachAll(const yarp::dev::PolyDriverList& device2attach) override;
101 bool detachAll() override;
102
103
104 // yarp::dev::IFrameGrabberControls
106 {
107 if (!iFrameGrabberControls) {
108 return false;
109 }
110 return iFrameGrabberControls->getCameraDescription(camera);
111 }
112
113 bool hasFeature(int feature, bool* hasFeature) override
114 {
115 if (!iFrameGrabberControls) {
116 return false;
117 }
118 return iFrameGrabberControls->hasFeature(feature, hasFeature);
119 }
120
121 bool setFeature(int feature, double value) override
122 { if (!iFrameGrabberControls) {
123 return false;
124 }
125 return iFrameGrabberControls->setFeature(feature, value);
126 }
127
128 bool getFeature(int feature, double* value) override
129 {
130 if (!iFrameGrabberControls) {
131 return false;
132 }
133 return iFrameGrabberControls->getFeature(feature, value);
134 }
135
136 bool setFeature(int feature, double value1, double value2) override
137 {
138 if (!iFrameGrabberControls) {
139 return false;
140 }
141 return iFrameGrabberControls->setFeature(feature, value1, value2);
142 }
143
144 bool getFeature(int feature, double* value1, double* value2) override
145 {
146 if (!iFrameGrabberControls) {
147 return false;
148 }
149 return iFrameGrabberControls->getFeature(feature, value1, value2);
150 }
151
152 bool hasOnOff(int feature, bool* HasOnOff) override
153 {
154 if (!iFrameGrabberControls) {
155 return false;
156 }
157 return iFrameGrabberControls->hasOnOff(feature, HasOnOff);
158 }
159
160 bool setActive(int feature, bool onoff) override
161 {
162 if (!iFrameGrabberControls) {
163 return false;
164 }
165 return iFrameGrabberControls->setActive(feature, onoff);
166 }
167
168 bool getActive(int feature, bool* isActive) override
169 {
170 if (!iFrameGrabberControls) {
171 return false;
172 }
173 return iFrameGrabberControls->getActive(feature, isActive);
174 }
175
176 bool hasAuto(int feature, bool* hasAuto) override
177 {
178 if (!iFrameGrabberControls) {
179 return false;
180 }
181 return iFrameGrabberControls->hasAuto(feature, hasAuto);
182 }
183
184 bool hasManual(int feature, bool* hasManual) override
185 {
186 if (!iFrameGrabberControls) {
187 return false;
188 }
189 return iFrameGrabberControls->hasManual(feature, hasManual);
190 }
191
192 bool hasOnePush(int feature, bool* hasOnePush) override
193 {
194 if (!iFrameGrabberControls) {
195 return false;
196 }
197 return iFrameGrabberControls->hasOnePush(feature, hasOnePush);
198 }
199
200 bool setMode(int feature, FeatureMode mode) override
201 {
202 if (!iFrameGrabberControls) {
203 return false;
204 }
205 return iFrameGrabberControls->setMode(feature, mode);
206 }
207
208 bool getMode(int feature, FeatureMode* mode) override
209 {
210 if (!iFrameGrabberControls) {
211 return false;
212 }
213 return iFrameGrabberControls->getMode(feature, mode);
214 }
215
216 bool setOnePush(int feature) override
217 {
218 if (!iFrameGrabberControls) {
219 return false;
220 }
221 return iFrameGrabberControls->setOnePush(feature);
222 }
223
224
225 // yarp::dev::IFrameGrabberControlsDC1394
226 unsigned int getVideoModeMaskDC1394() override
227 {
228 if (!iFrameGrabberControlsDC1394) {
229 return 0;
230 }
231 return iFrameGrabberControlsDC1394->getVideoModeMaskDC1394();
232 }
233
234 unsigned int getVideoModeDC1394() override
235 {
236 if (!iFrameGrabberControlsDC1394) {
237 return 0;
238 }
239 return iFrameGrabberControlsDC1394->getVideoModeMaskDC1394();
240 }
241
242 bool setVideoModeDC1394(int video_mode) override
243 {
244 if (!iFrameGrabberControlsDC1394) {
245 return false;
246 }
247 return iFrameGrabberControlsDC1394->setVideoModeDC1394(video_mode);
248 }
249
250 unsigned int getFPSMaskDC1394() override
251 {
252 if (!iFrameGrabberControlsDC1394) {
253 return 0;
254 }
255 return iFrameGrabberControlsDC1394->getFPSMaskDC1394();
256 }
257
258 unsigned int getFPSDC1394() override
259
260 {
261 if (!iFrameGrabberControlsDC1394) {
262 return 0;
263 }
264 return iFrameGrabberControlsDC1394->getFPSDC1394();
265 }
266
267 bool setFPSDC1394(int fps) override
268
269 {
270 if (!iFrameGrabberControlsDC1394) {
271 return false;
272 }
273 return iFrameGrabberControlsDC1394->setFPSDC1394(fps);
274 }
275
276 unsigned int getISOSpeedDC1394() override
277 {
278 if (!iFrameGrabberControlsDC1394) {
279 return 0;
280 }
281 return iFrameGrabberControlsDC1394->getISOSpeedDC1394();
282 }
283
284 bool setISOSpeedDC1394(int speed) override
285
286 {
287 if (!iFrameGrabberControlsDC1394) {
288 return false;
289 }
290 return iFrameGrabberControlsDC1394->setISOSpeedDC1394(speed);
291 }
292
293 unsigned int getColorCodingMaskDC1394(unsigned int video_mode) override
294 {
295 if (!iFrameGrabberControlsDC1394) {
296 return 0;
297 }
298 return iFrameGrabberControlsDC1394->getColorCodingMaskDC1394(video_mode);
299 }
300
301 unsigned int getColorCodingDC1394() override
302 {
303 if (!iFrameGrabberControlsDC1394) {
304 return 0;
305 }
306 return iFrameGrabberControlsDC1394->getColorCodingDC1394();
307 }
308
309 bool setColorCodingDC1394(int coding) override
310 {
311 if (!iFrameGrabberControlsDC1394) {
312 return false;
313 }
314 return iFrameGrabberControlsDC1394->setColorCodingDC1394(coding);
315 }
316
317 bool getFormat7MaxWindowDC1394(unsigned int& xdim,
318 unsigned int& ydim,
319 unsigned int& xstep,
320 unsigned int& ystep,
321 unsigned int& xoffstep,
322 unsigned int& yoffstep) override
323 {
324 if (!iFrameGrabberControlsDC1394) {
325 return false;
326 }
327 return iFrameGrabberControlsDC1394->getFormat7MaxWindowDC1394(xdim, ydim, xstep, ystep, xoffstep, yoffstep);
328 }
329
330 bool getFormat7WindowDC1394(unsigned int& xdim, unsigned int& ydim, int& x0, int& y0) override
331 {
332 if (!iFrameGrabberControlsDC1394) {
333 return false;
334 }
335 return iFrameGrabberControlsDC1394->getFormat7WindowDC1394(xdim, ydim, x0, y0);
336 }
337
338 bool setFormat7WindowDC1394(unsigned int xdim, unsigned int ydim, int x0, int y0) override
339 {
340 if (!iFrameGrabberControlsDC1394) {
341 return false;
342 }
343 return iFrameGrabberControlsDC1394->setFormat7WindowDC1394(xdim, ydim, x0, y0);
344 }
345
346 bool setOperationModeDC1394(bool b1394b) override
347 {
348 if (!iFrameGrabberControlsDC1394) {
349 return false;
350 }
351 return iFrameGrabberControlsDC1394->setOperationModeDC1394(b1394b);
352 }
353
355 {
356 if (!iFrameGrabberControlsDC1394) {
357 return false;
358 }
359 return iFrameGrabberControlsDC1394->getOperationModeDC1394();
360 }
361
362 bool setTransmissionDC1394(bool bTxON) override
363 {
364 if (!iFrameGrabberControlsDC1394) {
365 return false;
366 }
367 return iFrameGrabberControlsDC1394->setTransmissionDC1394(bTxON);
368 }
369
370 bool getTransmissionDC1394() override
371 {
372 if (!iFrameGrabberControlsDC1394) {
373 return false;
374 }
375 return iFrameGrabberControlsDC1394->getTransmissionDC1394();
376 }
377
378 bool setBroadcastDC1394(bool onoff) override
379 {
380 if (!iFrameGrabberControlsDC1394) {
381 return false;
382 }
383 return iFrameGrabberControlsDC1394->setBroadcastDC1394(onoff);
384 }
385
386 bool setDefaultsDC1394() override
387 {
388 if (!iFrameGrabberControlsDC1394) {
389 return false;
390 }
391 return iFrameGrabberControlsDC1394->setDefaultsDC1394();
392 }
393
394 bool setResetDC1394() override
395 {
396 if (!iFrameGrabberControlsDC1394) {
397 return false;
398 }
399 return iFrameGrabberControlsDC1394->setResetDC1394();
400 }
401
402 bool setPowerDC1394(bool onoff) override
403 {
404 if (!iFrameGrabberControlsDC1394) {
405 return false;
406 }
407 return iFrameGrabberControlsDC1394->setPowerDC1394(onoff);
408 }
409
410 bool setCaptureDC1394(bool bON) override
411 {
412 if (!iFrameGrabberControlsDC1394) {
413 return false;
414 }
415 return iFrameGrabberControlsDC1394->setCaptureDC1394(bON);
416 }
417
418 unsigned int getBytesPerPacketDC1394() override
419 {
420 if (!iFrameGrabberControlsDC1394) {
421 return 0;
422 }
423 return iFrameGrabberControlsDC1394->getBytesPerPacketDC1394();
424 }
425
426 bool setBytesPerPacketDC1394(unsigned int bpp) override
427 {
428 if (!iFrameGrabberControlsDC1394) {
429 return false;
430 }
431 return iFrameGrabberControlsDC1394->setBytesPerPacketDC1394(bpp);
432 }
433
434
435 // yarp::dev::IRgbVisualParams
440
445
446 bool setRgbResolution(int width, int height) override
447 {
448 if (!iRgbVisualParams || !m_forwardRgbVisualParams) {
449 return false;
450 }
451 return iRgbVisualParams->setRgbResolution(width, height);
452 }
453
454 bool getRgbFOV(double& horizontalFov, double& verticalFov) override
455 {
456 if (!iRgbVisualParams || !m_forwardRgbVisualParams) {
457 horizontalFov = std::numeric_limits<double>::quiet_NaN();
458 verticalFov = std::numeric_limits<double>::quiet_NaN();
459 return false;
460 }
461 return iRgbVisualParams->getRgbFOV(horizontalFov, verticalFov);
462 }
463
464 bool setRgbFOV(double horizontalFov, double verticalFov) override
465 {
466 if (!iRgbVisualParams || !m_forwardRgbVisualParams) {
467 return false;
468 }
469 return iRgbVisualParams->setRgbFOV(horizontalFov, verticalFov);
470 }
471
472 bool getRgbIntrinsicParam(yarp::os::Property& intrinsic) override
473 {
474 if (!iRgbVisualParams || !m_forwardRgbVisualParams) {
475 intrinsic.clear();
476 return false;
477 }
478 return iRgbVisualParams->getRgbIntrinsicParam(intrinsic);
479 }
480
481 bool getRgbMirroring(bool& mirror) override
482 {
483 if (!iRgbVisualParams || !m_forwardRgbVisualParams) {
484 mirror = false;
485 return false;
486 }
487 return iRgbVisualParams->getRgbMirroring(mirror);
488
489 }
490
491 bool setRgbMirroring(bool mirror) override
492 {
493 if (!iRgbVisualParams || !m_forwardRgbVisualParams) {
494 return false;
495 }
496 return iRgbVisualParams->setRgbMirroring(mirror);
497 }
498
499
500 // yarp::dev::IPreciselyTimed
502 {
503 if (!iPreciselyTimed) {
504 return yarp::os::Stamp();
505 }
506 return iPreciselyTimed->getLastInputStamp();
507 }
508};
509
510#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.
This class is the parameters parser for class FrameGrabberCropper.
FrameGrabberCropper: An image frame grabber device which can also crop the frame.
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:341