The Stereo Disparity application receives left and right stereo pair images and returns the disparity between them, which is a function of image depth. The result is saved into disparity.png.
This is using the CUDA backend and the provided sample images. You can try with other stereo pair images, respecting the constraints imposed by the algorithm.
For convenience, here's the code that is also installed in the samples directory.
#include <opencv2/core/version.hpp>
#if CV_MAJOR_VERSION >= 3
# include <opencv2/imgcodecs.hpp>
#else
# include <opencv2/highgui/highgui.hpp>
#endif
#include <opencv2/imgproc/imgproc.hpp>
#include <cstring>
#include <iostream>
#define CHECK_STATUS(STMT) \
do \
{ \
VPIStatus status = (STMT); \
if (status != VPI_SUCCESS) \
{ \
throw std::runtime_error(vpiStatusGetName(status)); \
} \
} while (0);
int main(int argc, char *argv[])
{
int retval = 0;
try
{
if (argc != 4)
{
throw std::runtime_error(std::string("Usage: ") + argv[0] + " <cpu|pva|cuda> <left image> <right image>");
}
std::string strDevType = argv[1];
std::string strLeftFileName = argv[2];
std::string strRightFileName = argv[3];
cv::Mat cvImageLeft = cv::imread(strLeftFileName, cv::IMREAD_GRAYSCALE);
if (cvImageLeft.empty())
{
throw std::runtime_error("Can't open '" + strLeftFileName + "'");
}
cv::Mat cvImageRight = cv::imread(strRightFileName, cv::IMREAD_GRAYSCALE);
if (cvImageRight.empty())
{
throw std::runtime_error("Can't open '" + strRightFileName + "'");
}
cvImageLeft.convertTo(cvImageLeft, CV_16UC1);
cvImageRight.convertTo(cvImageRight, CV_16UC1);
if (strDevType == "cpu")
{
}
else if (strDevType == "cuda")
{
}
else if (strDevType == "pva")
{
}
else
{
throw std::runtime_error("Backend '" + strDevType +
"' not recognized, it must be either cpu, cuda or pva.");
}
{
memset(&imgData, 0, sizeof(imgData));
}
{
double min, max;
minMaxLoc(cvOut, &min, &max);
cvOut.convertTo(cvOut, CV_8UC1, 255.0 / (max - min), -min);
imwrite("disparity_" + strDevType + ".png", cvOut);
}
}
catch (std::exception &e)
{
std::cerr << e.what() << std::endl;
retval = 1;
}
if (stream != NULL)
{
}
return retval;
}