summaryrefslogtreecommitdiff
path: root/utils/raspberrypi/ctt
diff options
context:
space:
mode:
authorBen Benson <ben.benson@raspberrypi.com>2024-06-06 11:15:09 +0100
committerKieran Bingham <kieran.bingham@ideasonboard.com>2024-06-13 11:02:26 +0100
commitb95032a84259d5a6281bfb5b126711a47da02285 (patch)
tree842bc8d095b1dbf8aada59624ffaa69dea8b1ae5 /utils/raspberrypi/ctt
parent8bea2d5a8adf1901f49e6449a731e3fd02272b3d (diff)
utils: raspberrypi: ctt: Changed CTT handling of VC4 and PiSP
Changed how users select which platform to tune for. Now users specify a command line argument, '-t', to specify which target platform. Signed-off-by: Ben Benson <ben.benson@raspberrypi.com> Signed-off-by: David Plowman <david.plowman@raspberrypi.com> Reviewed-by: Naushir Patuck <naush@raspberrypi.com> Tested-by: Naushir Patuck <naush@raspberrypi.com> Acked-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'utils/raspberrypi/ctt')
-rwxr-xr-xutils/raspberrypi/ctt/alsc_only.py (renamed from utils/raspberrypi/ctt/alsc_pisp.py)13
-rwxr-xr-xutils/raspberrypi/ctt/alsc_vc4.py37
-rw-r--r--utils/raspberrypi/ctt/cac_only.py9
-rwxr-xr-xutils/raspberrypi/ctt/ctt.py (renamed from utils/raspberrypi/ctt/ctt_run.py)38
-rw-r--r--utils/raspberrypi/ctt/ctt_image_load.py1
-rw-r--r--utils/raspberrypi/ctt/ctt_log.txt31
-rwxr-xr-xutils/raspberrypi/ctt/ctt_pisp.py33
-rwxr-xr-xutils/raspberrypi/ctt/ctt_pretty_print_json.py8
-rw-r--r--utils/raspberrypi/ctt/ctt_tools.py3
-rwxr-xr-xutils/raspberrypi/ctt/ctt_vc4.py33
10 files changed, 57 insertions, 149 deletions
diff --git a/utils/raspberrypi/ctt/alsc_pisp.py b/utils/raspberrypi/ctt/alsc_only.py
index d0034ae1..a521c4ad 100755
--- a/utils/raspberrypi/ctt/alsc_pisp.py
+++ b/utils/raspberrypi/ctt/alsc_only.py
@@ -4,12 +4,11 @@
#
# Copyright (C) 2022, Raspberry Pi Ltd
#
-# alsc_only.py - alsc tuning tool
+# alsc tuning tool
import sys
-from ctt_pisp import json_template, grid_size, target
-from ctt_run import run_ctt
+from ctt import *
from ctt_tools import parse_input
if __name__ == '__main__':
@@ -25,6 +24,7 @@ if __name__ == '__main__':
'-o' : Name of output json file.
Optional Arguments:
+ '-t' : Target platform - 'pisp' or 'vc4'. Default 'vc4'
'-c' : Config file for the CTT. If not passed, default parameters used.
'-l' : Name of output log file. If not passed, 'ctt_log.txt' used.
""")
@@ -33,5 +33,10 @@ if __name__ == '__main__':
"""
parse input arguments
"""
- json_output, directory, config, log_output = parse_input()
+ json_output, directory, config, log_output, target = parse_input()
+ if target == 'pisp':
+ from ctt_pisp import json_template, grid_size
+ elif target == 'vc4':
+ from ctt_vc4 import json_template, grid_size
+
run_ctt(json_output, directory, config, log_output, json_template, grid_size, target, alsc_only=True)
diff --git a/utils/raspberrypi/ctt/alsc_vc4.py b/utils/raspberrypi/ctt/alsc_vc4.py
deleted file mode 100755
index caf6a174..00000000
--- a/utils/raspberrypi/ctt/alsc_vc4.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python3
-#
-# SPDX-License-Identifier: BSD-2-Clause
-#
-# Copyright (C) 2022, Raspberry Pi (Trading) Limited
-#
-# alsc tuning tool
-
-import sys
-
-from ctt_vc4 import json_template, grid_size, target
-from ctt_run import run_ctt
-from ctt_tools import parse_input
-
-if __name__ == '__main__':
- """
- initialise calibration
- """
- if len(sys.argv) == 1:
- print("""
- VC4 Lens Shading Camera Tuning Tool version 1.0
-
- Required Arguments:
- '-i' : Calibration image directory.
- '-o' : Name of output json file.
-
- Optional Arguments:
- '-c' : Config file for the CTT. If not passed, default parameters used.
- '-l' : Name of output log file. If not passed, 'ctt_log.txt' used.
- """)
- quit(0)
- else:
- """
- parse input arguments
- """
- json_output, directory, config, log_output = parse_input()
- run_ctt(json_output, directory, config, log_output, json_template, grid_size, target, alsc_only=True)
diff --git a/utils/raspberrypi/ctt/cac_only.py b/utils/raspberrypi/ctt/cac_only.py
index 2bb11ccc..1c0a8193 100644
--- a/utils/raspberrypi/ctt/cac_only.py
+++ b/utils/raspberrypi/ctt/cac_only.py
@@ -2,7 +2,7 @@
#
# SPDX-License-Identifier: BSD-2-Clause
#
-# Copyright (C) 2023, Raspberry Pi (Trading) Limited
+# Copyright (C) 2023, Raspberry Pi (Trading) Ltd.
#
# cac_only.py - cac tuning tool
@@ -102,11 +102,11 @@ def cac(filelist, output_filepath, plot_results=False):
sample = sample.replace("ry_vals", pprint_array(rx * -1))
sample = sample.replace("bx_vals", pprint_array(by * -1))
sample = sample.replace("by_vals", pprint_array(bx * -1))
- print("Successfully converted to YAML")
+ print("Successfully converted to JSON")
f = open(str(output_filepath), "w+")
f.write(sample)
f.close()
- print("Successfully written to yaml file")
+ print("Successfully written to json file")
'''
If you wish to see a plot of the colour channel shifts, add the -p or --plots option
Can be a quick way of validating if the data/dots you've got are good, or if you need to
@@ -139,5 +139,4 @@ if __name__ == "__main__":
plot_results = True
arg_output = argv[output_location + 1]
- logfile = open("log.txt", "a+")
- cac(filelist, arg_output, plot_results, logfile)
+ cac(filelist, arg_output, plot_results)
diff --git a/utils/raspberrypi/ctt/ctt_run.py b/utils/raspberrypi/ctt/ctt.py
index 074136a1..522933bd 100755
--- a/utils/raspberrypi/ctt/ctt_run.py
+++ b/utils/raspberrypi/ctt/ctt.py
@@ -185,22 +185,22 @@ class Camera:
except ArithmeticError:
print('ERROR: Matrix is singular!\nTake new pictures and try again...')
self.log += '\nERROR: Singular matrix encountered during fit!'
- self.log += '\nCCM aborted!'
+ self.log += '\nCAC aborted!'
return 1
else:
"""
case where config options suggest greyscale camera. No point in doing CAC
"""
cal_cr_list, cal_cb_list = None, None
- self.log += '\nWARNING: No ALSC tables found.\nCCM calibration '
+ self.log += '\nWARNING: No ALSC tables found.\nCAC calibration '
self.log += 'performed without ALSC correction...'
"""
Write output to json
"""
self.json['rpi.cac']['cac'] = cacs
- self.log += '\nCCM calibration written to json file'
- print('Finished CCM calibration')
+ self.log += '\nCAC calibration written to json file'
+ print('Finished CAC calibration')
"""
@@ -710,7 +710,6 @@ def run_ctt(json_output, directory, config, log_output, json_template, grid_size
mac_small = get_config(macbeth_d, "small", 0, 'bool')
mac_show = get_config(macbeth_d, "show", 0, 'bool')
mac_config = (mac_small, mac_show)
- cac_d = get_config(configs, "cac", {}, 'dict')
if blacklevel < -1 or blacklevel >= 2**16:
print('\nInvalid blacklevel, defaulted to 64')
@@ -770,3 +769,32 @@ def run_ctt(json_output, directory, config, log_output, json_template, grid_size
pass
else:
Cam.write_log(log_output)
+
+if __name__ == '__main__':
+ """
+ initialise calibration
+ """
+ if len(sys.argv) == 1:
+ print("""
+ PiSP Tuning Tool version 1.0
+ Required Arguments:
+ '-i' : Calibration image directory.
+ '-o' : Name of output json file.
+
+ Optional Arguments:
+ '-t' : Target platform - 'pisp' or 'vc4'. Default 'vc4'
+ '-c' : Config file for the CTT. If not passed, default parameters used.
+ '-l' : Name of output log file. If not passed, 'ctt_log.txt' used.
+ """)
+ quit(0)
+ else:
+ """
+ parse input arguments
+ """
+ json_output, directory, config, log_output, target = parse_input()
+ if target == 'pisp':
+ from ctt_pisp import json_template, grid_size
+ elif target == 'vc4':
+ from ctt_vc4 import json_template, grid_size
+
+ run_ctt(json_output, directory, config, log_output, json_template, grid_size, target)
diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py
index ea5fa360..531de328 100644
--- a/utils/raspberrypi/ctt/ctt_image_load.py
+++ b/utils/raspberrypi/ctt/ctt_image_load.py
@@ -351,7 +351,6 @@ def dng_load_image(Cam, im_str):
c3 = np.left_shift(raw_data[1::2, 1::2].astype(np.int64), shift)
Img.channels = [c0, c1, c2, c3]
Img.rgb = raw_im.postprocess()
- Img.sizes = raw_im.sizes
except Exception:
print("\nERROR: failed to load DNG file", im_str)
diff --git a/utils/raspberrypi/ctt/ctt_log.txt b/utils/raspberrypi/ctt/ctt_log.txt
deleted file mode 100644
index 682e24e4..00000000
--- a/utils/raspberrypi/ctt/ctt_log.txt
+++ /dev/null
@@ -1,31 +0,0 @@
-Log created : Fri Aug 25 17:02:58 2023
-
-----------------------------------------------------------------------
-User Arguments
-----------------------------------------------------------------------
-
-Json file output: output.json
-Calibration images directory: ../ctt/
-No configuration file input... using default options
-No log file path input... using default: ctt_log.txt
-
-----------------------------------------------------------------------
-Image Loading
-----------------------------------------------------------------------
-
-Directory: ../ctt/
-Files found: 1
-
-Image: alsc_3000k_0.dng
-Identified as an ALSC image
-Colour temperature: 3000 K
-
-Images found:
-Macbeth : 0
-ALSC : 1
-CAC: 0
-
-Camera metadata
-ERROR: No usable macbeth chart images found
-
-----------------------------------------------------------------------
diff --git a/utils/raspberrypi/ctt/ctt_pisp.py b/utils/raspberrypi/ctt/ctt_pisp.py
index 862587a6..4c432f17 100755
--- a/utils/raspberrypi/ctt/ctt_pisp.py
+++ b/utils/raspberrypi/ctt/ctt_pisp.py
@@ -4,13 +4,8 @@
#
# Copyright (C) 2019, Raspberry Pi Ltd
#
-# ctt_pisp.py - camera tuning tool for PiSP platforms
+# ctt_pisp.py - camera tuning tool data for PiSP platforms
-import os
-import sys
-
-from ctt_run import run_ctt
-from ctt_tools import parse_input
json_template = {
"rpi.black_level": {
@@ -207,29 +202,3 @@ json_template = {
}
grid_size = (32, 32)
-
-target = 'pisp'
-
-if __name__ == '__main__':
- """
- initialise calibration
- """
- if len(sys.argv) == 1:
- print("""
- PiSP Camera Tuning Tool version 1.0
-
- Required Arguments:
- '-i' : Calibration image directory.
- '-o' : Name of output json file.
-
- Optional Arguments:
- '-c' : Config file for the CTT. If not passed, default parameters used.
- '-l' : Name of output log file. If not passed, 'ctt_log.txt' used.
- """)
- quit(0)
- else:
- """
- parse input arguments
- """
- json_output, directory, config, log_output = parse_input()
- run_ctt(json_output, directory, config, log_output, json_template, grid_size, target)
diff --git a/utils/raspberrypi/ctt/ctt_pretty_print_json.py b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
index d3bd7d97..350cec65 100755
--- a/utils/raspberrypi/ctt/ctt_pretty_print_json.py
+++ b/utils/raspberrypi/ctt/ctt_pretty_print_json.py
@@ -108,6 +108,7 @@ def pretty_print(in_json: dict, custom_elems={}) -> str:
if __name__ == "__main__":
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter, description=
'Prettify a version 2.0 camera tuning config JSON file.')
+ parser.add_argument('-t', '--target', type=str, help='Target platform', choices=['pisp', 'vc4'], default='vc4')
parser.add_argument('input', type=str, help='Input tuning file.')
parser.add_argument('output', type=str, nargs='?',
help='Output converted tuning file. If not provided, the input file will be updated in-place.',
@@ -117,7 +118,12 @@ if __name__ == "__main__":
with open(args.input, 'r') as f:
in_json = json.load(f)
- out_json = pretty_print(in_json)
+ if args.target == 'pisp':
+ from ctt_pisp import grid_size
+ elif args.target == 'vc4':
+ from ctt_vc4 import grid_size
+
+ out_json = pretty_print(in_json, custom_elems={'table': grid_size[0], 'luminance_lut': grid_size[0]})
with open(args.output if args.output is not None else args.input, 'w') as f:
f.write(out_json)
diff --git a/utils/raspberrypi/ctt/ctt_tools.py b/utils/raspberrypi/ctt/ctt_tools.py
index 27c52193..50b01ecf 100644
--- a/utils/raspberrypi/ctt/ctt_tools.py
+++ b/utils/raspberrypi/ctt/ctt_tools.py
@@ -65,11 +65,12 @@ def parse_input():
directory = get_config(args_dict, '-i', None, 'string')
config = get_config(args_dict, '-c', None, 'string')
log_path = get_config(args_dict, '-l', None, 'string')
+ target = get_config(args_dict, '-t', "vc4", 'string')
if directory is None:
raise ArgError('\n\nERROR! No input directory given.')
if json_output is None:
raise ArgError('\n\nERROR! No output json given.')
- return json_output, directory, config, log_path
+ return json_output, directory, config, log_path, target
"""
diff --git a/utils/raspberrypi/ctt/ctt_vc4.py b/utils/raspberrypi/ctt/ctt_vc4.py
index 86acfd47..7154e110 100755
--- a/utils/raspberrypi/ctt/ctt_vc4.py
+++ b/utils/raspberrypi/ctt/ctt_vc4.py
@@ -4,13 +4,8 @@
#
# Copyright (C) 2019, Raspberry Pi Ltd
#
-# ctt_vc4.py - camera tuning tool for VC4 platforms
+# ctt_vc4.py - camera tuning tool data for VC4 platforms
-import os
-import sys
-
-from ctt_run import run_ctt
-from ctt_tools import parse_input
json_template = {
"rpi.black_level": {
@@ -129,29 +124,3 @@ json_template = {
}
grid_size = (16, 12)
-
-target = 'bcm2835'
-
-if __name__ == '__main__':
- """
- initialise calibration
- """
- if len(sys.argv) == 1:
- print("""
- VC4 Camera Tuning Tool version 1.0
-
- Required Arguments:
- '-i' : Calibration image directory.
- '-o' : Name of output json file.
-
- Optional Arguments:
- '-c' : Config file for the CTT. If not passed, default parameters used.
- '-l' : Name of output log file. If not passed, 'ctt_log.txt' used.
- """)
- quit(0)
- else:
- """
- parse input arguments
- """
- json_output, directory, config, log_output = parse_input()
- run_ctt(json_output, directory, config, log_output, json_template, grid_size, target)