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.
#include "FileFrameGrabber.h"
#include <cstdio>
int main(
int argc,
char* argv[])
{
DriverCreator* file_grabber_factory = new DriverCreatorOf<FileFrameGrabber>("file_grabber",
"grabber",
"FileFrameGrabber");
Drivers::factory().add(file_grabber_factory);
Property config;
if (argc == 1) {
config.fromString("(device file_grabber) (pattern \"image/%03d.ppm\")");
} else {
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;
}