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
26
28{
29 // initialize stuff
31}
32
34{
35 // delete subdevice, of any
37}
38
40{
41 // open OS dependant device
42 yCTrace(USBCAMERA) << "input params are " << config.toString();
43
44#if defined(_MSC_VER)
46#elif defined __unix
48#endif
49
51 prop.fromString(config.toString());
52 if (!prop.check("pixelType")) {
53 switch (pixelType) {
55 prop.put("pixelType", VOCAB_PIXEL_MONO);
56 break;
57
58 case VOCAB_PIXEL_RGB:
59 default:
60 prop.put("pixelType", VOCAB_PIXEL_RGB);
61 break;
62 }
63 }
64 if (!os_device->open(prop)) {
65 delete os_device;
66 return false;
67 }
68
74
75 if (frameGrabberImage != nullptr) {
78 }
79
80 if (frameGrabberImageRaw != nullptr) {
83 }
84 return true;
85}
86
88{
89 // close OS dependant device
91 delete os_device;
92 return true;
93}
94
96{
97 if (frameGrabberImage != nullptr) {
98 return frameGrabberImage->width();
99 }
100 if (frameGrabberImageRaw != nullptr) {
101 return frameGrabberImageRaw->width();
102 }
103
104 return 0;
105}
106
108{
109 if (frameGrabberImage != nullptr) {
110 return frameGrabberImage->height();
111 }
112 if (frameGrabberImageRaw != nullptr) {
114 }
115
116 return 0;
117}
118
120{
121 if (deviceTimed != nullptr) {
123 }
124
125 return yarp::os::Stamp();
126}
127
129{
130 if (deviceRgbVisualParam != nullptr) {
132 }
133 return 0;
134}
135
137{
138 if (deviceRgbVisualParam != nullptr) {
140 }
141 return 0;
142}
143
144
146{
147 if (deviceRgbVisualParam != nullptr) {
149 }
150 return ReturnValue::return_code::return_value_error_not_ready;
151}
152
154{
155 if (deviceRgbVisualParam != nullptr) {
157 }
158 return ReturnValue::return_code::return_value_error_not_ready;
159}
160
162{
163 if (width <= 0 || height <= 0) {
164 yCError(USBCAMERA) << "usbCamera: invalid width or height";
165 return ReturnValue::return_code::return_value_error_method_failed;
166 }
167 if (deviceRgbVisualParam != nullptr) {
168 _width = width;
169 _height = height;
171 }
172 return ReturnValue::return_code::return_value_error_not_ready;
173}
174
175yarp::dev::ReturnValue USBCameraDriver::getRgbFOV(double& horizontalFov, double& verticalFov)
176{
177 if (deviceRgbVisualParam != nullptr) {
178 return deviceRgbVisualParam->getRgbFOV(horizontalFov, verticalFov);
179 }
180 return ReturnValue::return_code::return_value_error_not_ready;
181}
182
183yarp::dev::ReturnValue USBCameraDriver::setRgbFOV(double horizontalFov, double verticalFov)
184{
185 if (deviceRgbVisualParam != nullptr) {
186 return deviceRgbVisualParam->setRgbFOV(horizontalFov, verticalFov);
187 }
188 return ReturnValue::return_code::return_value_error_not_ready;
189}
190
192{
193 if (deviceRgbVisualParam != nullptr) {
195 }
196 return ReturnValue::return_code::return_value_error_not_ready;
197}
198
200{
201 if (deviceRgbVisualParam != nullptr) {
203 }
204 return ReturnValue::return_code::return_value_error_not_ready;
205}
206
208{
209 if (deviceRgbVisualParam != nullptr) {
211 }
212 return ReturnValue::return_code::return_value_error_not_ready;
213}
214
215
223
228
233
238
240{
241 return USBCameraDriver::width();
242}
243
245{
247}
248
256
261
266
268{
269 return USBCameraDriver::width();
270}
271
273{
275}
276
277
278/* Implementation of IFrameGrabberControls2 interface
279 *
280 * Actual function will be implemented by OS specific devices
281 */
282
284{
285 if (deviceControls != nullptr) {
287 }
288 return ReturnValue::return_code::return_value_error_not_ready;
289}
290
292{
293 if (deviceControls != nullptr) {
295 }
296 return ReturnValue::return_code::return_value_error_not_ready;
297}
298
300{
301 if (deviceControls != nullptr) {
302 return deviceControls->setFeature(feature, value);
303 }
304 return ReturnValue::return_code::return_value_error_not_ready;
305}
306
308{
309 if (deviceControls != nullptr) {
310 return deviceControls->getFeature(feature, value);
311 }
312 return ReturnValue::return_code::return_value_error_not_ready;
313}
314
316{
317 if (deviceControls != nullptr) {
318 return deviceControls->getFeature(feature, value1, value2);
319 }
320 return ReturnValue::return_code::return_value_error_not_ready;
321}
322
324{
325 if (deviceControls != nullptr) {
326 return deviceControls->setFeature(feature, value1, value2);
327 }
328 return ReturnValue::return_code::return_value_error_not_ready;
329}
330
332{
333 if (deviceControls != nullptr) {
335 }
336 return ReturnValue::return_code::return_value_error_not_ready;
337}
338
340{
341 if (deviceControls != nullptr) {
342 return deviceControls->setActive(feature, onoff);
343 }
344 return ReturnValue::return_code::return_value_error_not_ready;
345}
346
348{
349 if (deviceControls != nullptr) {
351 }
352 return ReturnValue::return_code::return_value_error_not_ready;
353}
354
356{
357 if (deviceControls != nullptr) {
359 }
360 return ReturnValue::return_code::return_value_error_not_ready;
361}
362
364{
365 if (deviceControls != nullptr) {
367 }
368 return ReturnValue::return_code::return_value_error_not_ready;
369}
370
372{
373 if (deviceControls != nullptr) {
375 }
376 return ReturnValue::return_code::return_value_error_not_ready;
377}
378
380{
381 if (deviceControls != nullptr) {
383 }
384 return ReturnValue::return_code::return_value_error_not_ready;
385}
386
388{
389 if (deviceControls != nullptr) {
391 }
392 return ReturnValue::return_code::return_value_error_not_ready;
393}
394
396{
397 if (deviceControls != nullptr) {
399 }
400 return ReturnValue::return_code::return_value_error_not_ready;
401}
CameraDescriptor camera
FeatureMode mode
@ 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
yarp::dev::ReturnValue getImage(yarp::sig::ImageOf< yarp::sig::PixelMono > &image) override
Get an image from the frame grabber.
int width() const override
Return the width of each frame.
int height() const override
Return the height of each frame.
yarp::dev::ReturnValue 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
yarp::dev::ReturnValue getMode(yarp::dev::cameraFeature_id_t feature, yarp::dev::FeatureMode &mode) override
Get the current mode for the feature.
yarp::dev::ReturnValue setRgbFOV(double horizontalFov, double verticalFov) override
Set the field of view (FOV) of the rgb camera.
yarp::dev::ReturnValue getRgbSupportedConfigurations(std::vector< yarp::dev::CameraConfig > &configurations) override
Get the possible configurations of the camera.
yarp::dev::ReturnValue getRgbFOV(double &horizontalFov, double &verticalFov) override
Get the field of view (FOV) of the rgb camera.
yarp::dev::IFrameGrabberImage * frameGrabberImage
Definition USBcamera.h:40
int getRgbWidth() override
Return the width of each frame.
yarp::dev::ReturnValue setMode(yarp::dev::cameraFeature_id_t feature, yarp::dev::FeatureMode mode) override
Set the requested mode for the feature.
yarp::dev::ReturnValue hasManual(yarp::dev::cameraFeature_id_t feature, bool &hasManual) override
Check if the requested feature has the 'manual' mode.
USBCameraDriver()
Constructor.
Definition USBcamera.cpp:27
int getRgbHeight() override
Return the height of each frame.
~USBCameraDriver() override
Destructor.
Definition USBcamera.cpp:33
yarp::dev::ReturnValue hasAuto(yarp::dev::cameraFeature_id_t feature, bool &hasAuto) override
Check if the requested feature has the 'auto' mode.
yarp::dev::ReturnValue hasOnOff(yarp::dev::cameraFeature_id_t feature, bool &HasOnOff) override
Check if the camera has the ability to turn on/off the requested feature.
yarp::dev::ReturnValue setFeature(yarp::dev::cameraFeature_id_t feature, double value) override
Set the requested feature to a value (saturation, brightness ... )
bool close() override
Close the DeviceDriver.
Definition USBcamera.cpp:87
yarp::dev::ReturnValue getFeature(yarp::dev::cameraFeature_id_t feature, double &value) override
Get the current value for the requested feature.
yarp::dev::ReturnValue hasFeature(yarp::dev::cameraFeature_id_t feature, bool &hasFeature) override
Check if camera has the requested feature (saturation, brightness ... )
yarp::dev::ReturnValue getRgbMirroring(bool &mirror) override
Get the mirroring setting of the sensor.
yarp::dev::ReturnValue setActive(yarp::dev::cameraFeature_id_t feature, bool onoff) override
Set the requested feature on or off.
yarp::dev::ReturnValue getRgbIntrinsicParam(yarp::sig::IntrinsicParams &intrinsic) override
Get the intrinsic parameters of the rgb camera.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition USBcamera.cpp:39
yarp::dev::ReturnValue getActive(yarp::dev::cameraFeature_id_t feature, bool &isActive) override
Get the current status of the feature, on or off.
yarp::dev::IFrameGrabberImageRaw * frameGrabberImageRaw
Definition USBcamera.h:41
yarp::dev::ReturnValue getRgbResolution(int &width, int &height) override
Get the resolution of the rgb image from the camera.
yarp::dev::IPreciselyTimed * deviceTimed
Definition USBcamera.h:39
yarp::dev::ReturnValue setRgbMirroring(bool mirror) override
Set the mirroring setting of the sensor.
yarp::dev::ReturnValue hasOnePush(yarp::dev::cameraFeature_id_t feature, bool &hasOnePush) override
Check if the requested feature has the 'onePush' mode.
yarp::dev::DeviceDriver * os_device
Definition USBcamera.h:42
yarp::dev::ReturnValue setOnePush(yarp::dev::cameraFeature_id_t feature) override
Set the requested feature to a value (saturation, brightness ... )
yarp::dev::ReturnValue getCameraDescription(yarp::dev::CameraDescriptor &camera) override
Implementation of IFrameGrabberControls2 interface.
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
int width() const
Definition USBcamera.cpp:95
yarp::dev::ReturnValue setRgbResolution(int width, int height) override
Set the resolution of the rgb image from the camera.
yarp::dev::IRgbVisualParams * deviceRgbVisualParam
Definition USBcamera.h:44
int height() const
yarp::dev::IFrameGrabberControls * deviceControls
Definition USBcamera.h:43
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 yarp::dev::ReturnValue setFeature(cameraFeature_id_t feature, double value)=0
Set the requested feature to a value (saturation, brightness ... )
virtual yarp::dev::ReturnValue hasOnOff(cameraFeature_id_t feature, bool &HasOnOff)=0
Check if the camera has the ability to turn on/off the requested feature.
virtual yarp::dev::ReturnValue getMode(cameraFeature_id_t feature, FeatureMode &mode)=0
Get the current mode for the feature.
virtual yarp::dev::ReturnValue hasManual(cameraFeature_id_t feature, bool &hasManual)=0
Check if the requested feature has the 'manual' mode.
virtual yarp::dev::ReturnValue setOnePush(cameraFeature_id_t feature)=0
Set the requested feature to a value (saturation, brightness ... )
virtual yarp::dev::ReturnValue getCameraDescription(CameraDescriptor &camera)=0
Get a basic description of the camera hw.
virtual yarp::dev::ReturnValue hasOnePush(cameraFeature_id_t feature, bool &hasOnePush)=0
Check if the requested feature has the 'onePush' mode.
virtual yarp::dev::ReturnValue getActive(cameraFeature_id_t feature, bool &isActive)=0
Get the current status of the feature, on or off.
virtual yarp::dev::ReturnValue hasAuto(cameraFeature_id_t feature, bool &hasAuto)=0
Check if the requested feature has the 'auto' mode.
virtual yarp::dev::ReturnValue setActive(cameraFeature_id_t feature, bool onoff)=0
Set the requested feature on or off.
virtual yarp::dev::ReturnValue setMode(cameraFeature_id_t feature, FeatureMode mode)=0
Set the requested mode for the feature.
virtual yarp::dev::ReturnValue hasFeature(cameraFeature_id_t, bool &hasFeature)=0
Check if camera has the requested feature (saturation, brightness ... )
virtual yarp::dev::ReturnValue getFeature(cameraFeature_id_t feature, double &value)=0
Get the current value for the requested feature.
virtual int width() const =0
Return the width of each frame.
virtual int height() const =0
Return the height of each frame.
virtual yarp::dev::ReturnValue 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 yarp::dev::ReturnValue setRgbFOV(double horizontalFov, double verticalFov)=0
Set the field of view (FOV) of the rgb camera.
virtual yarp::dev::ReturnValue setRgbMirroring(bool mirror)=0
Set the mirroring setting of the sensor.
virtual yarp::dev::ReturnValue getRgbFOV(double &horizontalFov, double &verticalFov)=0
Get the field of view (FOV) of the rgb camera.
virtual yarp::dev::ReturnValue getRgbIntrinsicParam(yarp::sig::IntrinsicParams &intrinsic)=0
Get the intrinsic parameters of the rgb camera.
virtual int getRgbHeight()=0
Return the height of each frame.
virtual yarp::dev::ReturnValue getRgbMirroring(bool &mirror)=0
Get the mirroring setting of the sensor.
virtual yarp::dev::ReturnValue getRgbSupportedConfigurations(std::vector< yarp::dev::CameraConfigData > &configurations)=0
Get the possible configurations of the camera.
virtual yarp::dev::ReturnValue setRgbResolution(int width, int height)=0
Set the resolution of the rgb image from the camera.
virtual yarp::dev::ReturnValue getRgbResolution(int &width, int &height)=0
Get the resolution of the rgb image from the 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:32
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:980
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:18
Typed image class.
Definition Image.h:603
#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.
The IntrinsicParams struct to handle the intrinsic parameter of cameras(RGB and RGBD either).