YARP
Yet Another Robot Platform
dev/file_grabber/file_grabber.cpp

This example shows how we would make a new device for a camera.We make a device that reads images from file. The only step missing here is to integrate the device into the YARP library.

Here's the header file, dev/file_grabber/FileFrameGrabber.h

And here's how we can use it. In fact, we just grab the first image from the device.

/*
* Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
* Copyright (C) 2006-2010 RobotCub Consortium
* All rights reserved.
*
* This software may be modified and distributed under the terms of the
* BSD-3-Clause license. See the accompanying LICENSE file for details.
*/
#include <yarp/sig/Image.h>
#include "FileFrameGrabber.h"
#include <cstdio>
int main(int argc, char* argv[])
{
Network yarp;
// give YARP a factory for creating instances of FileFrameGrabber
DriverCreator* file_grabber_factory = new DriverCreatorOf<FileFrameGrabber>("file_grabber",
"grabber",
"FileFrameGrabber");
Drivers::factory().add(file_grabber_factory); // hand factory over to YARP
// use YARP to create and configure an instance of FileFrameGrabber
Property config;
if (argc == 1) {
// no arguments, use a default
config.fromString("(device file_grabber) (pattern \"image/%03d.ppm\")");
} else {
// expect something like '--device file_grabber --pattern "image/%03d.ppm"'
// or '--device dragonfly'
// or '--device fakeFrameGrabber --period 0.5 --mode [ball]'
config.fromCommand(argc, argv);
}
PolyDriver dd(config);
if (!dd.isValid()) {
printf("Failed to create and configure a device\n");
return 1;
}
IFrameGrabberImage* grabberInterface;
if (!dd.view(grabberInterface)) {
printf("Failed to view device through IFrameGrabberImage interface\n");
return 1;
}
ImageOf<PixelRgb> img;
grabberInterface->getImage(img);
printf("Got a %zux%zu image\n", img.width(), img.height());
dd.close();
return 0;
}
Network.h
Drivers.h
yarp::dev::DriverCreatorOf
A factory for creating driver objects of a particular type.
Definition: Drivers.h:85
main
int main(int argc, char *argv[])
Definition: yarpros.cpp:261
yarp::sig::ImageOf
Typed image class.
Definition: Image.h:647
Property.h
yarp::dev::IFrameGrabberImage
Read a YARP-format image from a device.
Definition: FrameGrabberInterfaces.h:241
PolyDriver.h
yarp::dev::PolyDriver
A container for a device driver.
Definition: PolyDriver.h:27
yarp::dev::DriverCreator
A base class for factories that create driver objects.
Definition: Drivers.h:31
FrameGrabberInterfaces.h
define common interfaces to discover remote camera capabilities
Image.h
yarp::sig::PixelRgb
Packed RGB pixel type.
Definition: Image.h:453
yarp::os::Network
Utilities for manipulating the YARP network, including initialization and shutdown.
Definition: Network.h:786
yarp
The main, catch-all namespace for YARP.
Definition: environment.h:18
yarp::dev::Drivers
Global factory for devices.
Definition: Drivers.h:175
yarp::os::Property
A class for storing options and configuration information.
Definition: Property.h:37