sample_quasi_dense.py 790 B

123456789101112131415161718192021
  1. import numpy as np
  2. import cv2 as cv
  3. left_img = cv.imread(cv.samples.findFile("aloeL.jpg"), cv.IMREAD_COLOR)
  4. right_img = cv.imread(cv.samples.findFile("aloeR.jpg"), cv.IMREAD_COLOR)
  5. frame_size = leftImg.shape[0:2];
  6. stereo = cv.stereo.QuasiDenseStereo_create(frame_size[::-1])
  7. stereo.process(left_img, right_img)
  8. disp = stereo.getDisparity()
  9. cv.imshow("disparity", disp)
  10. cv.waitKey()
  11. dense_matches = stereo.getDenseMatches()
  12. try:
  13. with open("dense.txt", "wt") as f:
  14. # if you want all matches use for idx in len(dense_matches): It can be a big file
  15. for idx in range(0, min(10, len(dense_matches))):
  16. nb = f.write(str(dense_matches[idx].p0) + "\t" + str(dense_matches[idx].p1) + "\t" + str(dense_matches[idx].corr) + "\n")
  17. except:
  18. print("Cannot open file")