6
6
* @brief This example connects to a remote grabber (generally, RGB) device.
7
7
*/
8
8
9
- #include < cstdio >
9
+ #include < yarp/conf/version.h >
10
10
11
+ #include < yarp/os/LogStream.h>
11
12
#include < yarp/os/Network.h>
12
13
#include < yarp/os/Property.h>
13
14
14
15
#include < yarp/dev/PolyDriver.h>
15
- #include < yarp/dev/FrameGrabberInterfaces.h>
16
+
17
+ #if YARP_VERSION_MINOR >= 5
18
+ # include < yarp/dev/IFrameGrabberImage.h>
19
+ # include < yarp/dev/IFrameGrabberControls.h>
20
+ #else
21
+ # include < yarp/dev/FrameGrabberInterfaces.h>
22
+ #endif
16
23
17
24
int main (int argc, char *argv[])
18
25
{
19
26
yarp::os::Network yarp;
20
27
21
28
if (!yarp::os::Network::checkNetwork ())
22
29
{
23
- std::printf ( " Please start a yarp name server first\n " ) ;
30
+ yError () << " Please start a yarp name server first" ;
24
31
return 1 ;
25
32
}
26
33
27
- yarp::os::Property options;
28
-
29
- options. put ( " device " , " remote_grabber " );
30
- options. put ( " local " , " /exampleRemoteGrabber " );
31
- options. put ( " remote " , " /grabber " ) ;
34
+ yarp::os::Property options {
35
+ { " device " , yarp::os::Value ( " remote_grabber " )},
36
+ { " local " , yarp::os::Value ( " /exampleRemoteGrabber " )},
37
+ { " remote " , yarp::os::Value ( " /grabber " )},
38
+ } ;
32
39
33
40
yarp::dev::PolyDriver dd (options);
34
41
35
42
if (!dd.isValid ())
36
43
{
37
- std::printf ( " Device not available. \n " ) ;
44
+ yError () << " Device not available" ;
38
45
return 1 ;
39
46
}
40
47
@@ -43,44 +50,45 @@ int main(int argc, char *argv[])
43
50
44
51
if (!dd.view (iFrameGrabberImage))
45
52
{
46
- std::printf ( " [error] Problems acquiring image interface\n " ) ;
53
+ yError () << " Problems acquiring image interface" ;
47
54
return 1 ;
48
55
}
56
+
49
57
if (!dd.view (iFrameGrabberControls))
50
58
{
51
- std::printf ( " [error] Problems acquiring controls interface\n " ) ;
59
+ yError () << " Problems acquiring controls interface" ;
52
60
return 1 ;
53
61
}
54
62
55
- std::printf (" [success] acquired interfaces\n " );
56
-
57
63
bool has;
58
- if (iFrameGrabberControls->hasFeature (YARP_FEATURE_ZOOM, &has))
64
+
65
+ if (iFrameGrabberControls->hasFeature (YARP_FEATURE_ZOOM, &has))
59
66
{
60
- if (has)
67
+ if (has)
61
68
{
62
69
double val;
63
70
iFrameGrabberControls->getFeature (YARP_FEATURE_ZOOM, &val);
64
- printf ( " Zoom feature: %f \n " , val) ;
71
+ yInfo () << " Zoom feature:" << val;
65
72
}
66
73
else
67
- printf ( " Zoom feature: not supported\n " ) ;
74
+ yInfo () << " Zoom feature: not supported" ;
68
75
}
69
76
else
70
- printf ( " Fail: iFrameGrabberControls->hasFeature\n " ) ;
77
+ yWarning () << " iFrameGrabberControls->hasFeature() failed " ;
71
78
72
79
// The following delay should avoid bad status
73
80
yarp::os::Time::delay (1 );
74
81
75
82
yarp::sig::ImageOf<yarp::sig::PixelRgb> image;
76
- if (!iFrameGrabberImage->getImage (image))
83
+
84
+ if (!iFrameGrabberImage->getImage (image))
77
85
{
78
- std::printf ( " [error] Problems getting image\n " ) ;
86
+ yError () << " Problems getting image" ;
79
87
return 1 ;
80
88
}
81
89
82
- std::printf ( " Width: %d \n " , iFrameGrabberImage->width () );
83
- std::printf ( " Height: %d \n " , iFrameGrabberImage->height () );
90
+ yInfo () << " Width:" << iFrameGrabberImage->width ();
91
+ yInfo () << " Height:" << iFrameGrabberImage->height ();
84
92
85
93
dd.close ();
86
94
0 commit comments