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>
This commit is contained in:
Ben Benson 2024-06-06 11:15:09 +01:00 committed by Kieran Bingham
parent 8bea2d5a8a
commit b95032a842
10 changed files with 57 additions and 149 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -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
----------------------------------------------------------------------

View file

@ -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)

View file

@ -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)

View file

@ -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
"""

View file

@ -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)