Skip to content

Commit

Permalink
Calibration: use serial numbers instead of camera ordinals
Browse files Browse the repository at this point in the history
Summary:
The unpacker expects ISP config files with the format `<serial_number>.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
  • Loading branch information
aparrapo authored and facebook-github-bot committed May 1, 2017
1 parent 8352a29 commit bc1b9e2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions surround360_render/CALIBRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/<serial_number>.tiff. Go to /surround360_render and run the following command:
<pre>
python scripts/color_calibrate_all.py \
--data_dir ~/Desktop/color_calibration \
Expand All @@ -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/<serial_number>/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:
<pre>
python scripts/vignetting_calibrate.py \
--data_dir ~/Desktop/vignetting_calibration \
Expand Down
4 changes: 2 additions & 2 deletions surround360_render/scripts/color_calibrate_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "\"")
Expand Down
20 changes: 13 additions & 7 deletions surround360_render/scripts/vignetting_calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__))
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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"]
Expand All @@ -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,
Expand All @@ -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"

Expand Down

0 comments on commit bc1b9e2

Please sign in to comment.