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.
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.
Source code explained
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImage.h>
#include <visp3/gui/vpDisplayGDI.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpImageStorageWorker.h>
#include <visp3/sensor/vpFlyCaptureGrabber.h>
void usage(constchar *argv[], int error)
{
std::cout << "SYNOPSIS" << std::endl
<< " " << argv[0] << " [--change-settings]"
<< " [--seqname <sequence name>]"
<< " [--record <mode>]"
<< " [--no-display]"
<< " [--help] [-h]" << std::endl
<< std::endl;
std::cout << "DESCRIPTION" << std::endl
<< " --change-settings" << std::endl
<< " Force camera settings to auto shutter, auto gain and 640x480 MONO8 image" << std::endl
<< " acquisition at 60 fps." << std::endl
<< std::endl
<< " --seqname <sequence name>" << std::endl
<< " Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
<< " Default: empty." << std::endl
<< std::endl
<< " --record <mode>" << std::endl
<< " Allowed values for mode are:" << std::endl
<< " 0: record all the captures images (continuous mode)," << std::endl
<< " 1: record only images selected by a user click (single shot mode)." << std::endl
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.
Source code explained
The source code is the following:
#include <visp3/core/vpConfig.h>
#include <visp3/core/vpImage.h>
#include <visp3/gui/vpDisplayOpenCV.h>
#include <visp3/gui/vpDisplayX.h>
#include <visp3/io/vpImageStorageWorker.h>
#include <visp3/sensor/vp1394TwoGrabber.h>
void usage(constchar *argv[], int error)
{
std::cout << "SYNOPSIS" << std::endl
<< " " << argv[0] << " [--change-settings]"
<< " [--seqname <sequence name>]"
<< " [--record <mode>]"
<< " [--no-display]"
<< " [--help] [-h]" << std::endl
<< std::endl;
std::cout << "DESCRIPTION" << std::endl
<< " --change-settings" << std::endl
<< " Force camera settings to acquire 640x480 images in M0NO8 at 60 fps." << std::endl
<< std::endl
<< " --seqname <sequence name>" << std::endl
<< " Name of the sequence of image to create (ie: /tmp/image%04d.jpg)." << std::endl
<< " Default: empty." << std::endl
<< std::endl
<< " --record <mode>" << std::endl
<< " Allowed values for mode are:" << std::endl
<< " 0: record all the captures images (continuous mode)," << std::endl
<< " 1: record only images selected by a user click (single shot mode)." << std::endl
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:
% ls *.png
image0000.png
image0001.png
image0002.png
image0003.png
image0004.png
...
you may use the following:
g.setFileName("./image%04d.png");
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:
To read an other video, let say my-video.mpg, you may use:
./tutorial-grabber-realsense --name my-video.mpg
Next tutorial
You are now ready to see how to continue with:
a simple image processing that shows how to track blobs explained in Tutorial: Blob tracking.
There is also the Tutorial: How to manipulate a video or a sequence of images that could be useful when you need to visualize, rename or change the format of a captured video or sequence of successive images, typically for deep learning purpose.