PYTHON 18
Sgm.py Guest on 7th October 2020 07:27:43 AM
  1. import os
  2. import subprocess
  3. import sys
  4.  
  5. sets_dir = "sets/"
  6. p1 = "17"
  7. p2 = "58"
  8. thresh = "35"
  9. input_dmin = "0"
  10. input_dmax = "60"
  11. resize = "300x300"
  12.  
  13. # Change these as needed to fit file structure
  14. # Work only for images that start with test*
  15. test_set_prefix = sets_dir + "/"
  16. sgm_loc = "sgm/stereo2"
  17. html_path = "~/public_html/mondrian/sets/"
  18. output_prefix = "output/"
  19. pfm2png_loc = "pfm2png/pfm2png"
  20. imginfo_loc = "pfm2png/imginfo"
  21.  
  22. remove_images = 1 # remove test images and .pfm's from root directory after running script
  23.  
  24. if len(sys.argv) > 1:
  25.         set_dir = sets_dir + sys.argv[1]
  26. else:
  27.         set_dir = sets_dir + raw_input("Test set name? ")
  28.  
  29. if len(sys.argv) > 2:
  30.         scale = float(sys.argv[2])
  31.         input_dmax = str(int(float(input_dmax) * scale))
  32.  
  33.  
  34. os.system("mkdir " + output_prefix)
  35.  
  36. print('set dir is %s' % set_dir)
  37. for setDirName, subdirList, setfileList in os.walk(set_dir):
  38.         print('Found set directory: %s' % setDirName)
  39.         #if setDirName == sets_dir:
  40. #               continue
  41.         html_path = "~/public_html/mondrian/" + setDirName + "/"
  42.         for dirName in subdirList:
  43.                 print('Found image pair directory: %s' % dirName)
  44.                 test_set_prefix = setDirName + "/"
  45.                 #for test_name in subdirList:
  46.                 test_name = dirName
  47.        
  48.         # generate disparity maps
  49.                 os.system(sgm_loc + " " + p1 + " " + p2 + " " + input_dmin + " " + input_dmax + " " + test_set_prefix + test_name + "/left.png " + test_set_prefix + test_name + "/right.png " + output_prefix + "left-disp-sgm.pfm " + output_prefix + "right-disp-sgm.pfm")
  50.                
  51.  
  52.                 # make web destination directory
  53.                 os.system("mkdir -p " + html_path + test_name)
  54.                
  55.                 # Get dmax from imginfo utility and use it to convert pfms to pngs
  56.                 min_max = subprocess.check_output(["./" + imginfo_loc, "-m", test_set_prefix + test_name + "/right-gt.pfm"]).split()
  57.                 dmin_r = min_max[0]
  58.                 dmax_r = min_max[1]
  59.                 min_max = subprocess.check_output(["./" + imginfo_loc, "-m", test_set_prefix + test_name + "/left-gt.pfm"]).split()
  60.                 dmin_l = min_max[0]
  61.                 dmax_l = min_max[1]
  62.                 dmax = str(int(round(max(float(dmax_r), float(dmax_l)) * 1.05))) # add 5% to avoid saturated colors
  63.                 dmin = str(int(round(min(float(dmin_r), float(dmin_l)) * 0.95))) # subtract 5% to avoid saturated colors
  64.  
  65.                 os.system("cp " + output_prefix + "/left-disp-sgm.pfm " + html_path + test_name+"/left-disp-sgm.pfm")
  66.                 os.system("cp " + output_prefix + "/right-disp-sgm.pfm " + html_path + test_name+"/right-disp-sgm.pfm")
  67.  
  68.  
  69.                 os.system(pfm2png_loc + " -m " + dmin + " -d " + dmax + " -r 40 " + output_prefix + "left-disp-sgm.pfm " + html_path + test_name+"/left-sgm.png")
  70.                 os.system(pfm2png_loc + " -m " + dmin + " -d " + dmax + " -r 40 " + output_prefix + "right-disp-sgm.pfm " + html_path + test_name+"/right-sgm.png")

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.