diff options
Diffstat (limited to 'utils/raspberrypi/ctt/ctt.py')
-rwxr-xr-x | utils/raspberrypi/ctt/ctt.py | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 15064634..89159e63 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: BSD-2-Clause # -# Copyright (C) 2019, Raspberry Pi (Trading) Limited +# Copyright (C) 2019, Raspberry Pi Ltd # # ctt.py - camera tuning tool @@ -15,7 +15,7 @@ from ctt_alsc import * from ctt_lux import * from ctt_noise import * from ctt_geq import * -from ctt_pretty_print_json import * +from ctt_pretty_print_json import pretty_print import random import json import re @@ -350,7 +350,7 @@ class Camera: alsc_out = alsc_all(self, do_alsc_colour, plot) cal_cr_list, cal_cb_list, luminance_lut, av_corn = alsc_out """ - write ouput to json and finish if not do_alsc_colour + write output to json and finish if not do_alsc_colour """ if not do_alsc_colour: self.json['rpi.alsc']['luminance_lut'] = luminance_lut @@ -511,13 +511,17 @@ class Camera: """ def write_json(self): """ - Write json dictionary to file + Write json dictionary to file using our version 2 format """ - jstring = json.dumps(self.json, sort_keys=False) - """ - make it pretty :) - """ - pretty_print_json(jstring, self.jf) + + out_json = { + "version": 2.0, + 'target': 'bcm2835', + "algorithms": [{name: data} for name, data in self.json.items()], + } + + with open(self.jf, 'w') as f: + f.write(pretty_print(out_json)) """ add a new section to the log file @@ -664,7 +668,7 @@ class Camera: - incorrect filename/extension - images from different cameras """ - def check_imgs(self): + def check_imgs(self, macbeth=True): self.log += '\n\nImages found:' self.log += '\nMacbeth : {}'.format(len(self.imgs)) self.log += '\nALSC : {} '.format(len(self.imgs_alsc)) @@ -672,10 +676,14 @@ class Camera: """ check usable images found """ - if len(self.imgs) == 0: + if len(self.imgs) == 0 and macbeth: print('\nERROR: No usable macbeth chart images found') self.log += '\nERROR: No usable macbeth chart images found' return 0 + elif len(self.imgs) == 0 and len(self.imgs_alsc) == 0: + print('\nERROR: No usable images found') + self.log += '\nERROR: No usable images found' + return 0 """ Double check that every image has come from the same camera... """ @@ -704,7 +712,7 @@ class Camera: return 0 -def run_ctt(json_output, directory, config, log_output): +def run_ctt(json_output, directory, config, log_output, alsc_only=False): """ check input files are jsons """ @@ -766,6 +774,8 @@ def run_ctt(json_output, directory, config, log_output): try: Cam = Camera(json_output) Cam.log_user_input(json_output, directory, config, log_output) + if alsc_only: + disable = set(Cam.json.keys()).symmetric_difference({"rpi.alsc"}) Cam.disable = disable Cam.plot = plot Cam.add_imgs(directory, mac_config, blacklevel) @@ -779,8 +789,9 @@ def run_ctt(json_output, directory, config, log_output): ccm also technically does an awb but it measures this from the macbeth chart in the image rather than using calibration data """ - if Cam.check_imgs(): - Cam.json['rpi.black_level']['black_level'] = Cam.blacklevel_16 + if Cam.check_imgs(macbeth=not alsc_only): + if not alsc_only: + Cam.json['rpi.black_level']['black_level'] = Cam.blacklevel_16 Cam.json_remove(disable) print('\nSTARTING CALIBRATIONS') Cam.alsc_cal(luminance_strength, do_alsc_colour) |