YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
USBcamera.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7#include "USBcamera.h"
9
10#if defined(_MSC_VER)
11# include <WIN_camera.h>
12#elif defined __unix
13# include <V4L_camera.h>
14#endif
15
16#include <yarp/os/LogStream.h>
17#include <yarp/os/Semaphore.h>
18#include <yarp/os/Stamp.h>
19
21
22using namespace yarp::os;
23using namespace yarp::dev;
24
25
27
29{
30 // initialize stuff
32}
33
35{
36 // delete subdevice, of any
38}
39
41{
42 // open OS dependant device
43 yCTrace(USBCAMERA) << "input params are " << config.toString();
44
45#if defined(_MSC_VER)
47#elif defined __unix
49#endif
50
52 prop.fromString(config.toString());
53 if (!prop.check("pixelType")) {
54 switch (pixelType) {
56 prop.put("pixelType", VOCAB_PIXEL_MONO);
57 break;
58
59 case VOCAB_PIXEL_RGB:
60 default:
61 prop.put("pixelType", VOCAB_PIXEL_RGB);
62 break;
63 }
64 }
65 if (!os_device->open(prop)) {
66 delete os_device;
67 return false;
68 }
69
75
76 if (frameGrabberImage != nullptr) {
79 }
80
81 if (frameGrabberImageRaw != nullptr) {
84 }
85 return true;
86}
87
89{
90 // close OS dependant device
92 delete os_device;
93 return true;
94}
95
97{
98 if (frameGrabberImage != nullptr) {
99 return frameGrabberImage->width();
100 }
101 if (frameGrabberImageRaw != nullptr) {
102 return frameGrabberImageRaw->width();
103 }
104
105 return 0;
106}
107
109{
110 if (frameGrabberImage != nullptr) {
111 return frameGrabberImage->height();
112 }
113 if (frameGrabberImageRaw != nullptr) {
115 }
116
117 return 0;
118}
119
121{
122 if (deviceTimed != nullptr) {
124 }
125
126 return yarp::os::Stamp();
127}
128
130{
131 if (deviceRgbVisualParam != nullptr) {
133 }
134 return 0;
135}
136
138{
139 if (deviceRgbVisualParam != nullptr) {
141 }
142 return 0;
143}
144
145
147{
148 if (deviceRgbVisualParam != nullptr) {
150 }
151 return false;
152}
153
154bool USBCameraDriver::getRgbResolution(int& width, int& height)
155{
156 if (deviceRgbVisualParam != nullptr) {
158 }
159 return false;
160}
161
162bool USBCameraDriver::setRgbResolution(int width, int height)
163{
164 if (width <= 0 || height <= 0) {
165 yCError(USBCAMERA) << "usbCamera: invalid width or height";
166 return false;
167 }
168 if (deviceRgbVisualParam != nullptr) {
169 _width = width;
170 _height = height;
172 }
173 return false;
174}
175
176bool USBCameraDriver::getRgbFOV(double& horizontalFov, double& verticalFov)
177{
178 if (deviceRgbVisualParam != nullptr) {
179 return deviceRgbVisualParam->getRgbFOV(horizontalFov, verticalFov);
180 }
181 return false;
182}
183
184bool USBCameraDriver::setRgbFOV(double horizontalFov, double verticalFov)
185{
186 if (deviceRgbVisualParam != nullptr) {
187 return deviceRgbVisualParam->setRgbFOV(horizontalFov, verticalFov);
188 }
189 return false;
190}
191
193{
194 if (deviceRgbVisualParam != nullptr) {
196 }
197 return false;
198}
199
201{
202 if (deviceRgbVisualParam != nullptr) {
204 }
205 return false;
206}
207
209{
210 if (deviceRgbVisualParam != nullptr) {
212 }
213 return false;
214}
215
216
224
229
234
239
241{
242 return USBCameraDriver::width();
243}
244
246{
248}
249
257
262
267
269{
270 return USBCameraDriver::width();
271}
272
274{
276}
277
278
279/* Implementation of IFrameGrabberControls2 interface
280 *
281 * Actual function will be implemented by OS specific devices
282 */
283
285{
286 if (deviceControls != nullptr) {
288 }
289 return false;
290}
291
293{
294 if (deviceControls != nullptr) {
296 }
297 return false;
298}
299
301{
302 if (deviceControls != nullptr) {
303 return deviceControls->setFeature(feature, value);
304 }
305 return false;
306}
307
308bool USBCameraDriver::getFeature(int feature, double* value)
309{
310 if (deviceControls != nullptr) {
311 return deviceControls->getFeature(feature, value);
312 }
313 return false;
314}
315
317{
318 if (deviceControls != nullptr) {
320 }
321 return false;
322}
323
325{
326 if (deviceControls != nullptr) {
328 }
329 return false;
330}
331
333{
334 if (deviceControls != nullptr) {
336 }
337 return false;
338}
339
341{
342 if (deviceControls != nullptr) {
344 }
345 return false;
346}
347
348bool USBCameraDriver::getActive(int feature, bool* isActive)
349{
350 if (deviceControls != nullptr) {
351 return deviceControls->getActive(feature, isActive);
352 }
353 return false;
354}
355
357{
358 if (deviceControls != nullptr) {
360 }
361 return false;
362}
363
365{
366 if (deviceControls != nullptr) {
368 }
369 return false;
370}
371
373{
374 if (deviceControls != nullptr) {
376 }
377 return false;
378}
379
381{
382 if (deviceControls != nullptr) {
383 return deviceControls->setMode(feature, mode);
384 }
385 return false;
386}
387
389{
390 if (deviceControls != nullptr) {
391 return deviceControls->getMode(feature, mode);
392 }
393 return false;
394}
395
397{
398 if (deviceControls != nullptr) {
400 }
401 return false;
402}
@ VOCAB_PIXEL_MONO
Definition Image.h:42
@ VOCAB_PIXEL_RGB
Definition Image.h:44
const yarp::os::LogComponent & USBCAMERA()
int height() const override
Return the height of each frame.
~USBCameraDriverRaw() override
int width() const override
Return the width of each frame.
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelMono > &image) override
Get an image from the frame grabber.
int height() const override
Return the height of each frame.
bool getImage(yarp::sig::ImageOf< yarp::sig::PixelRgb > &image) override
Get an image from the frame grabber.
~USBCameraDriverRgb() override
int width() const override
Return the width of each frame.
usbCamera: YARP device driver implementation for acquiring images from USB cameras.
Definition USBcamera.h:34
bool setFeature(int feature, double value) override
Set the requested feature to a value (saturation, brightness ... )
bool getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
yarp::dev::IFrameGrabberImage * frameGrabberImage
Definition USBcamera.h:40
int getRgbWidth() override
Return the width of each frame.
bool hasOnePush(int feature, bool *hasOnePush) override
Check if the requested feature has the 'onePush' mode.
USBCameraDriver()
Constructor.
Definition USBcamera.cpp:28
bool getFeature(int feature, double *value) override
Get the current value for the requested feature.
int getRgbHeight() override
Return the height of each frame.
bool hasOnOff(int feature, bool *HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
bool setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
~USBCameraDriver() override
Destructor.
Definition USBcamera.cpp:34
bool close() override
Close the DeviceDriver.
Definition USBcamera.cpp:88
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 open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition USBcamera.cpp:40
bool getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
bool setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
bool getMode(int feature, FeatureMode *mode) override
Get the current mode for the feature.
bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
bool hasFeature(int feature, bool *hasFeature) override
Check if camera has the requested feature (saturation, brightness ... )
yarp::dev::IFrameGrabberImageRaw * frameGrabberImageRaw
Definition USBcamera.h:41
bool setMode(int feature, FeatureMode mode) override
Set the requested mode for the feature.
yarp::dev::IPreciselyTimed * deviceTimed
Definition USBcamera.h:39
bool getRgbIntrinsicParam(yarp::os::Property &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool setOnePush(int feature) override
Set the requested feature to a value (saturation, brightness ... )
bool getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
bool hasManual(int feature, bool *hasManual) override
Check if the requested feature has the 'manual' mode.
yarp::dev::DeviceDriver * os_device
Definition USBcamera.h:42
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
int width() const
Definition USBcamera.cpp:96
yarp::dev::IRgbVisualParams * deviceRgbVisualParam
Definition USBcamera.h:44
bool setActive(int feature, bool onoff) override
Set the requested feature on or off.
int height() const
bool getCameraDescription(CameraDescriptor *camera) override
Implementation of IFrameGrabberControls2 interface.
yarp::dev::IFrameGrabberControls * deviceControls
Definition USBcamera.h:43
bool setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
Interface implemented by all device drivers.
virtual bool close()
Close the DeviceDriver.
virtual bool open(yarp::os::Searchable &config)
Open the DeviceDriver.
bool view(T *&x)
Get an interface to the device driver.
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.
virtual int width() const =0
Return the width of each frame.
virtual int height() const =0
Return the height of each frame.
virtual bool getImage(ImageType &image)=0
Get an image from the frame grabber.
virtual yarp::os::Stamp getLastInputStamp()=0
Return the time stamp relative to the last acquisition.
virtual bool getRgbSupportedConfigurations(yarp::sig::VectorOf< yarp::dev::CameraConfig > &configurations)
Get the possible configurations of the 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 getRgbResolution(int &width, int &height)
Get the resolution of the rgb image from the 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 int getRgbHeight()=0
Return the height of each frame.
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.
virtual int getRgbWidth()=0
Return the width of each frame.
A mini-server for performing network communication in the background.
A class for storing options and configuration information.
Definition Property.h:33
void fromString(const std::string &txt, bool wipe=true)
Interprets a string as a list of properties.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.
Definition Property.cpp:987
bool check(const std::string &key) const override
Check if there exists a property of the given name.
A base class for nested structures that can be searched.
Definition Searchable.h:31
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.
Definition Stamp.h:21
Typed image class.
Definition Image.h:605
#define yCError(component,...)
#define yCTrace(component,...)
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.