dense_disparity.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include <opencv2/core.hpp>
  2. #include <opencv2/highgui.hpp>
  3. #include <fstream>
  4. #include <opencv2/stereo.hpp>
  5. using namespace cv;
  6. using namespace std;
  7. int main()
  8. {
  9. //! [load]
  10. cv::Mat rightImg, leftImg;
  11. leftImg = imread("./imgLeft.png", IMREAD_COLOR);
  12. rightImg = imread("./imgRight.png", IMREAD_COLOR);
  13. //! [load]
  14. //! [create]
  15. cv::Size frameSize = leftImg.size();
  16. Ptr<stereo::QuasiDenseStereo> stereo = stereo::QuasiDenseStereo::create(frameSize);
  17. //! [create]
  18. //! [process]
  19. stereo->process(leftImg, rightImg);
  20. //! [process]
  21. //! [disp]
  22. cv::Mat disp;
  23. disp = stereo->getDisparity();
  24. cv::namedWindow("disparity map");
  25. cv::imshow("disparity map", disp);
  26. //! [disp]
  27. cv::namedWindow("right channel");
  28. cv::namedWindow("left channel");
  29. cv::imshow("left channel", leftImg);
  30. cv::imshow("right channel", rightImg);
  31. //! [export]
  32. vector<stereo::MatchQuasiDense> matches;
  33. stereo->getDenseMatches(matches);
  34. std::ofstream dense("./dense.txt", std::ios::out);
  35. for (uint i=0; i< matches.size(); i++)
  36. {
  37. dense << matches[i].p0 << matches[i].p1 << endl;
  38. }
  39. dense.close();
  40. //! [export]
  41. cv::waitKey(0);
  42. return 0;
  43. }