From bc1b9e2ee53a1903e8df0213b0e4d180ba4bb057 Mon Sep 17 00:00:00 2001 From: Albert Parra Pozo Date: Mon, 1 May 2017 10:02:18 -0700 Subject: [PATCH] Calibration: use serial numbers instead of camera ordinals Summary: The unpacker expects ISP config files with the format `.json`, but color and vignetting calibration use `ispX.json`. This diff modifies these calibration scripts so that we can use the expected format, and not having to rename the files later on. Reviewed By: tox-fb Differential Revision: D4978283 fbshipit-source-id: 90a246650782c17f080339be5e33bf64b936193c --- surround360_render/CALIBRATION.md | 4 ++-- .../scripts/color_calibrate_all.py | 4 ++-- .../scripts/vignetting_calibrate.py | 20 ++++++++++++------- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/surround360_render/CALIBRATION.md b/surround360_render/CALIBRATION.md index f90748b6..011c0d2e 100644 --- a/surround360_render/CALIBRATION.md +++ b/surround360_render/CALIBRATION.md @@ -20,7 +20,7 @@ The steps below describe the color calibration process for a set of cameras from * Under the known illuminant, place the MacBeth chart and the SpyderCUBE in front of a camera and take a picture using our camera control software. An example image can found in /surround360_render/res/example_data/color_calibration_input.png. Repeat for each camera. -* Save the images inside a directory called "charts". For this example, we are assuming they are under ~/Desktop/color_calibration/charts/cam[0-16].tiff. Go to /surround360_render and run the following command: +* Save the images inside a directory called "charts". For this example, we are assuming they are under ~/Desktop/color_calibration/charts/.tiff. Go to /surround360_render and run the following command:
 python scripts/color_calibrate_all.py \
 --data_dir ~/Desktop/color_calibration \
@@ -43,7 +43,7 @@ The steps below describe the calibration process for a set of cameras.
 
 * Under a uniform and constant illuminant, place the grayscale chart in front of a camera and take as many pictures as desired (recommended more than 20) using our camera control software so as to cover the entire image region with samples of the chart in all positions. An example image can found in /surround360_render/res/example_data/vignetting_calibration_sample.tiff. Repeat for each camera.
 
-* Save the set of images for each camera inside a directory called "charts". For this example, we acquired 100 images per camera, for 17 cameras, and we placed them under ~/Desktop/vignetting_calibration/cam[0-16]/charts/[0-99].tiff. Note the file structure, where each camera has its own directory. We also assume that color calibration has been run on these cameras, and we already have a directory ~/Desktop/vignetting_calibration/isp with each camera's ISP json config file. Go to /surround360_render and run the following command:
+* Save the set of RAW images for each camera inside a directory called "charts". For this example, we acquired 100 images per camera, for 17 cameras, and we placed them under ~/Desktop/vignetting_calibration//charts/[000000-000099].tiff. Note the file structure, where each camera has its own directory. We also assume that color calibration has been run on these cameras, and we already have a directory ~/Desktop/vignetting_calibration/isp with each camera's ISP json config file. Go to /surround360_render and run the following command:
 
 python scripts/vignetting_calibrate.py \
 --data_dir ~/Desktop/vignetting_calibration \
diff --git a/surround360_render/scripts/color_calibrate_all.py b/surround360_render/scripts/color_calibrate_all.py
index 8a73df24..856a42f1 100755
--- a/surround360_render/scripts/color_calibrate_all.py
+++ b/surround360_render/scripts/color_calibrate_all.py
@@ -229,9 +229,9 @@ def median(list):
 
   thread_list = []
   for i in range(len(out_dirs)):
-    camera_number = re.findall("cam(\d+)", camera_names[i])[0]
+    serial_number = re.findall("(\d+)", camera_names[i])[0]
     isp_src = out_dirs[i] + "/isp_out.json"
-    isp_dst = isp_dir + "/isp" + camera_number + ".json"
+    isp_dst = isp_dir + "/" + serial_number + ".json"
 
     print "Copying " + isp_src + " to " + isp_dst + "..."
     os.system("cp \"" + isp_src + "\" \"" + isp_dst + "\"")
diff --git a/surround360_render/scripts/vignetting_calibrate.py b/surround360_render/scripts/vignetting_calibrate.py
index 9ee98bab..968c03a7 100755
--- a/surround360_render/scripts/vignetting_calibrate.py
+++ b/surround360_render/scripts/vignetting_calibrate.py
@@ -11,6 +11,9 @@
 import subprocess
 import sys
 import time
+
+from os import listdir
+from os.path import isdir, isfile, join
 from timeit import default_timer as timer
 
 script_dir = os.path.dirname(os.path.realpath(__file__))
@@ -44,13 +47,17 @@
 {FLAGS_EXTRA}
 """
 
+def list_dirs_numbers(src_dir):
+  return filter(
+    lambda f: f.isdigit(),
+    [f for f in listdir(src_dir) if isdir(join(src_dir, f))])
+
 def list_tiff(src_dir): return [os.path.join(src_dir, fn) for fn in next(os.walk(src_dir))[2] if fn.endswith('.tiff')]
 
 def parse_args():
   parse_type = argparse.ArgumentParser
   parser = parse_type(description=TITLE, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
   parser.add_argument('--data_dir',             help='directory containing calibration images and ISP config files', required=True)
-  parser.add_argument('--num_cams',             help='number of cameras', required=False, default=17)
   parser.add_argument('--image_width',          help='image width', required=False, default=2048)
   parser.add_argument('--image_height',         help='image height', required=False, default=2048)
   parser.add_argument('--load_data',            help='skip acquisition step and load data containing locations and RGB medians ', action='store_true')
@@ -91,7 +98,6 @@ def file_exists(file_path, file_runtimes):
 if __name__ == "__main__":
   args = parse_args()
   data_dir          = args["data_dir"]
-  num_cams          = args["num_cams"]
   image_width       = args["image_width"]
   image_height      = args["image_height"]
   load_data         = args["load_data"]
@@ -111,16 +117,16 @@ def file_exists(file_path, file_runtimes):
   if save_debug_images:
     flags_extra += " --save_debug_images"
 
-  for i in range(int(num_cams)):
-    input_dir = data_dir + "/cam" + str(i)
+  for serial_number in list_dirs_numbers(data_dir):
+    input_dir = data_dir + "/" + serial_number
     dir_acquisition = input_dir + "/acquisition"
-    isp_json = data_dir + "/isp/isp" + str(i) + ".json"
+    isp_json = data_dir + "/isp/" + serial_number + ".json"
 
     if not file_exists(isp_json, file_runtimes):
       sys.exit()
 
     if not load_data:
-      print "[cam" + str(i) + "] Generating data for vignetting correction..."
+      print "[" + serial_number + "] Generating data for vignetting correction..."
 
       acquisition_params = {
         "SURROUND360_RENDER_DIR": surround360_render_dir,
@@ -133,7 +139,7 @@ def file_exists(file_path, file_runtimes):
       acquisition_command = ACQUISITION_COMMAND_TEMPLATE.replace("\n", " ").format(**acquisition_params)
       run_step("acquisition", acquisition_command, file_runtimes)
 
-    print "[cam" + str(i) + "] Computing vignetting..."
+    print "[" + serial_number + "] Computing vignetting..."
 
     data_json_file = dir_acquisition + "/data.json"