movie3d.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include <opencv2/opencv.hpp>
  2. #include <opencv2/calib3d/calib3d.hpp>
  3. #include <opencv2/highgui/highgui.hpp>
  4. #include <opencv2/imgproc/imgproc.hpp>
  5. #include <stdio.h>
  6. #include <iostream>
  7. int main()
  8. {
  9. // Check for left and right camera IDs
  10. std::string CamL_id{"data/stereoL.mp4"}, CamR_id{"data/stereoR.mp4"}; // These values can change depending on the system
  11. cv::VideoCapture camL(CamL_id), camR(CamR_id);
  12. cv::Mat Left_Stereo_Map1, Left_Stereo_Map2;
  13. cv::Mat Right_Stereo_Map1, Right_Stereo_Map2;
  14. cv::FileStorage cv_file = cv::FileStorage("data/params_cpp.xml", cv::FileStorage::READ);
  15. cv_file["Left_Stereo_Map_x"] >> Left_Stereo_Map1;
  16. cv_file["Left_Stereo_Map_y"] >> Left_Stereo_Map2;
  17. cv_file["Right_Stereo_Map_x"] >> Right_Stereo_Map1;
  18. cv_file["Right_Stereo_Map_y"] >> Right_Stereo_Map2;
  19. cv_file.release();
  20. // Check if left camera is attched
  21. if (!camL.isOpened())
  22. {
  23. std::cout << "Could not open camera with index : " << CamL_id << std::endl;
  24. return -1;
  25. }
  26. // Check if right camera is attached
  27. if (!camL.isOpened())
  28. {
  29. std::cout << "Could not open camera with index : " << CamL_id << std::endl;
  30. return -1;
  31. }
  32. cv::Mat frameL, frameR;
  33. for (size_t i{0}; i<100000; i++)
  34. {
  35. camL >> frameL;
  36. camR >> frameR;
  37. cv::Mat Left_nice, Right_nice;
  38. cv::remap(frameL,
  39. Left_nice,
  40. Left_Stereo_Map1,
  41. Left_Stereo_Map2,
  42. cv::INTER_LANCZOS4,
  43. cv::BORDER_CONSTANT,
  44. 0);
  45. cv::remap(frameR,
  46. Right_nice,
  47. Right_Stereo_Map1,
  48. Right_Stereo_Map2,
  49. cv::INTER_LANCZOS4,
  50. cv::BORDER_CONSTANT,
  51. 0);
  52. cv::Mat Left_nice_split[3], Right_nice_split[3];
  53. std::vector<cv::Mat> Anaglyph_channels;
  54. cv::split(Left_nice, Left_nice_split);
  55. cv::split(Right_nice, Right_nice_split);
  56. Anaglyph_channels.push_back(Left_nice_split[0]);
  57. Anaglyph_channels.push_back(Left_nice_split[1]);
  58. Anaglyph_channels.push_back(Right_nice_split[2]);
  59. cv::Mat Anaglyph_img;
  60. cv::merge(Anaglyph_channels, Anaglyph_img);
  61. cv::imshow("Anaglyph image", Anaglyph_img);
  62. cv::waitKey(1);
  63. }
  64. return 0;
  65. }