Goal
In this tutorial you will learn how to
- Configure a QuasiDenseStero object
- Compute dense Stereo correspondences.
#include <fstream>
{
leftImg = imread("./imgLeft.png", IMREAD_COLOR);
rightImg = imread("./imgRight.png", IMREAD_COLOR);
stereo->process(leftImg, rightImg);
disp = stereo->getDisparity();
vector<stereo::MatchQuasiDense> matches;
stereo->getDenseMatches(matches);
std::ofstream dense("./dense.txt", std::ios::out);
for (
uint i=0; i< matches.size(); i++)
{
dense << matches[i].p0 << matches[i].p1 << endl;
}
dense.close();
return 0;
}
n-dimensional dense array class
Definition mat.hpp:829
MatSize size
Definition mat.hpp:2177
Template class for specifying the size of an image or rectangle.
Definition types.hpp:335
std::shared_ptr< _Tp > Ptr
Definition cvstd_wrapper.hpp:23
uint32_t uint
Definition interface.h:42
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3
Explanation:
The program loads a stereo image pair.
After importing the images.
leftImg =
imread(
"./imgLeft.png", IMREAD_COLOR);
rightImg =
imread(
"./imgRight.png", IMREAD_COLOR);
We need to know the frame size of a single image, in order to create an instance of a QuasiDesnseStereo
object.
Because we didn't specify the second argument in the constructor, the QuasiDesnseStereo
object will load default parameters.
We can then pass the imported stereo images in the process method like this
stereo->process(leftImg, rightImg);
The process method contains most of the functionality of the class and does two main things.
- Computes a sparse stereo based in "Good Features to Track" and "pyramidal Lucas-Kanade" flow algorithm
- Based on those sparse stereo points, densifies the stereo correspondences using Quasi Dense Stereo method.
After the execution of process()
we can display the disparity Image of the stereo.
disp =
stereo->getDisparity();
At this point we can also extract all the corresponding points using getDenseMatches()
method and export them in a file.
vector<stereo::MatchQuasiDense> matches;
stereo->getDenseMatches(matches);
std::ofstream dense("./dense.txt", std::ios::out);
for (
uint i=0; i< matches.size(); i++)
{
dense << matches[i].p0 << matches[i].p1 << endl;
}
dense.close();