In this tutorial you will learn how to grab images with ViSP, either from cameras or from a video stream.
Grabbing images from a real camera is only possible if you have installed the corresponding 3rd party. The complete list of 3rd parties supported by ViSP and dedicated to framegrabbing is given here. From this page you will also found useful information to install these 3rd parties.
All the material (source code and videos) described in this tutorial is part of ViSP source code and could be downloaded using the following command:
After ViSP 3.0.0, we introduce vpFlyCaptureGrabber class, a wrapper over PointGrey FlyCapture SDK that allows to grab images from any PointGrey camera. This grabber was tested under Ubuntu and Windows with the following cameras:
Flea3 USB 3.0 cameras (FL3-U3-32S2M-CS, FL3-U3-13E4C-C)
Flea2 firewire camera (FL2-03S2C)
Dragonfly2 firewire camera (DR2-COL)
It should also work with GigE PGR cameras.
The following example also available in tutorial-grabber-flycapture.cpp shows how to use vpFlyCaptureGrabber to capture grey level images from a PointGrey camera under Ubuntu or Windows. The following example suppose that a window renderer (libX11 on Ubuntu or GDI on Windows) and FlyCapture SDK 3rd party are available throw VISP.
std::cout << "Catch an exception: " << e.getStringMessage() << std::endl;
}
#else
(void) argc;
(void) argv;
#ifndef VISP_HAVE_FLYCAPTURE
std::cout << "Install Flycapture SDK, configure and build ViSP again to use this example" << std::endl;
#endif
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
std::cout << "This turorial should be built with c++11 support" << std::endl;
#endif
#endif
}
Here after we explain the source code.
First an instance of the frame grabber is created.
vpFlyCaptureGrabber g; // Create a grabber based on FlyCapture SDK third party lib
Once the grabber is created, we turn auto shutter and auto gain on and set the camera image size, color coding, and framerate. These settings are enclosed in a try/catch to be able to continue if one of these settings are not supported by the camera.
Depending on the command line options we are recording a sequence of images, or single shot images. We are also waiting for a non blocking mouse event to quit the while loop.
The next example also available in tutorial-grabber-1394.cpp shows how to use a framegrabber to acquire color images from a firewire or USB3 camera under Unix. The following example suppose that libX11 and libdc1394-2 3rd party are available.
std::cout << "Catch an exception: " << e << std::endl;
}
#else
(void) argc;
(void) argv;
#ifndef VISP_HAVE_DC1394
std::cout << "Install libdc1394, configure and build ViSP again to use this example" << std::endl;
#endif
#if (VISP_CXX_STANDARD < VISP_CXX_STANDARD_11)
std::cout << "This turorial should be built with c++11 support" << std::endl;
#endif
#endif
}
Here after we explain the new lines that are introduced.
First an instance of the frame grabber is created. During the creating a bus reset is send. If you don't want to reset the firewire bus, just turn reset to false.
vp1394TwoGrabber g(reset); // Create a grabber based on libdc1394-2.x third party lib
Once the grabber is created, we set the camera image size, color coding, and framerate.
catch(...) { // If settings are not available just catch execption to
// continue with default settings
std::cout << "Warning: cannot modify camera settings" << std::endl;
}
}
Note that here you can specify some other settings such as the firewire transmission speed. For a more complete list of settings see vp1394TwoGrabber class.
As in the previous example, depending on the command line options we are recording a sequence of images, or single shot images. We are also waiting for a non blocking mouse event to quit the while loop.
If you want to grab images from an usb camera under Unix, you may use vpV4l2Grabber class that is a wrapper over Video For Linux SDK. To this end libv4l should be installed. An example is provided in tutorial-grabber-v4l2.cpp.
It is also possible to grab images using librealsense, the SDK provided for Intel Realsense RDB-D cameras. You may find an example in tutorial-grabber-realsense.cpp.
There is getRealSense2Info.cpp in example/device/framegrabber folder that could be used to get the device serial number.
$ ./getRealSense2Info
RealSense characteristics:
Intel RealSense T265 11622110409 0.2.0.951
Device info:
Name : Intel RealSense T265
Serial Number : 11622110409
Firmware Version : 0.2.0.951
Physical Port : 2-3-2
Product Id : 0B37
Usb Type Descriptor : 3.1
Product Line : T200
Frame grabbing using Occipital Structure SDK
If you have a Structure Core RGB-D camera, it is also possible to grab images using libStructure the cross-platform library that comes with Occipital Structure SDK. You may find an example in tutorial-grabber-structure-core.cpp. It allows to save visible and depth images.
It is also possible to grab images using CMU1394 SDK if you want to use a firewire camera under Windows. You may find an example in tutorial-grabber-CMU1394.cpp.
Frame grabbing using Parrot Bebop 2 drone
It is also possible to grab images using a Parrot Bebop 2 drone. You may find an example in tutorial-grabber-bebop2.cpp.
Warning
Image grabbing with Bebop 2 drone only works if ViSP was built with Parrot ARSDK3 and OpenCV support.
With ViSP it also possible to get images from an input video stream. Supported formats are *.avi, *.mp4, *.mov, *.ogv, *.flv and many others... To this end we exploit OpenCV 3rd party.
The example below available in tutorial-video-reader.cpp shows how to consider an mpeg video stream.
Warning
We recall that this example only works if ViSP was built with OpenCV support.
Set the name of the video stream. Here videoname corresponds to a video file name location. For example we provide the file video.mpg located in the same folder than the executable.
The vpVideoReader class can also handle a sequence of images. For example, to read the following images:
where you specify that each image number is coded with 4 digits. Here, we will use libpng or OpenCV to read PNG images. Supported image formats are PPM, PGM, PNG and JPEG.
Then as for any other grabber, you have to initialize the frame grabber using: