A C++ YARP library that provides the iCub robot with stereo vision capabilities.
OpenCV
: git clone https://github.com/opencv/opencv.git
.git clone https://github.com/opencv/opencv_contrib.git
.OpenCV
by filling in OPENCV_EXTRA_MODULES_PATH
with the path to opencv_contrib/modules
and then toggling on all possible modules.OpenCV
.We also make use of LIBELAS for computing disparity maps, but there is no need to download it, since it is incorporated inside this code. For more information about how we incorporate the library, please see this README.
Online documentation is available here: https://robotology.github.io/stereo-vision.
The main classes introduced by this repository are the following ones:
StereoCamera
: handles everything related to the geometry of the stereo system.DisparityModule
: implements the main logic driving the computation of the disparity map, exposing the ports through which an user can obtain both the disparity and depth maps. This is the only object which interfaces itself with the (optional) graphical user interface.StereoMatcherNew
: carries out the computation and post-processing operations of the disparity map, by getting the rectified images directly from the StereoCamera
being used.The stereo parameters are saved within the configuration file SFM.ini
, and are loaded and saved at runtime. In case the parameters are not available in the configuration file (as in the case you run this new module on a PC for the first time), the usual default values are loaded.
The module expects 320x240 images by default. It can be used with 640x480 images by invoking it with the --use640
flag.
This repository comes with a GUI which helps the user during the fine-tuning of the parameters of this module.
The components (and the code related to) the GUI can be disabled by means of a toggle in the CMake configuration, named USE_DISPARITYMODULE_GUI
. Disabling it, takes away the single header file representing the GUI base code, together with all the other bits of source related to it. Thus, compiling the module without the GUI included actually removes everything about it from the final result.
The GUI makes it now easier to recalibrate the stereo system, to save the calibration, to load default stereo parameters and to save the current ones. Once it is not useful anymore, it can be quitted, closing it for the rest of the execution.
When compiled with GUI functionalities, the module can be launched with the graphical interface by invoking it with the flag --gui
.
It is possible to add a new stereo matching method by editing the content of just a few files. These are the steps to follow:
file StereoMatcher.h
:
void matchMethodX();
- add a new item to the [enumeration](./modules/DisparityModule/StereoMatcher.h#L27) used to represent the different matching algorithms available:
```cpp
enum SM_MATCHING_ALG {
SGBM_OPENCV = 0,
SGBM_CUDA,
LIBELAS,
METHODX
};
file StereoMatcher.cpp
:
void StereoMatcherNew::matchMethodX()
{
[...]
// code executing the matching
[...]
this->disparity16 = resulting_disparity;
}
file DisparityModule.cpp
:
if (rf.check("sgbm"))
this->stereo_matching = SM_MATCHING_ALG::SGBM_OPENCV;
[...]
else if(rf.check("methodX"))
this->stereo_matching = SM_MATCHING_ALG::METHODX;
file StereoMatcher.cpp
:
switch
within the StereoMatcherNew::compute()
function:case SM_MATCHING_ALG::METHODX:
this->matchMethodX();
break;
The following additional step is optional, and meant to be considered only if you plan to use this module with also the GUI functionalities:
(optional) file cvgui.cpp
:
this->updated |= cvuimine::radioButtons(frame, "Stereo Matching Alg.:", {"SGBM", "SGBM_CUDA", "LibElas", "MethodX"}, {20, 90, 190, 260}, 0);
NOTE: you might want to enlarge the GUI window, since now there are more options in the radio buttons group associated with the choice of the stereo matching algorithm, this can be done by changing line 60 of the file:
int gui_width = 450;
the value 450 is the one specified for the width, when initially designed. Increasing this value will make the window a little bigger, correctly fitting your needs.
switch
construct in GUI::convertIDTOEnum()
:switch(this->stereo_matching_id)
{
[...]
case 3:
this->params.stereo_matching = SM_MATCHING_ALG::METHODX;
break;
}
switch
construct in GUI::convertEnumToID()
:switch(this->params.stereo_matching)
{
[...]
case SM_MATCHING_ALG::METHODX:
this->stereo_matching_id = 3;
break;
}
A few things are not complete (however, they don't compromise the functionality of the module), and still require a quick correction each one:
The files contained in this repository are licensed under the GNU General Public License v2.0 later (see the file LICENSE for details), except the following files: