From patchwork Thu Jun 6 10:15:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 20217 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 27E7AC3292 for ; Thu, 6 Jun 2024 10:15:40 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id BF5686545C; Thu, 6 Jun 2024 12:15:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ZyZ9UXk0"; dkim-atps=neutral Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id CE2F465459 for ; Thu, 6 Jun 2024 12:15:31 +0200 (CEST) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-a6265d3ba8fso66156166b.0 for ; Thu, 06 Jun 2024 03:15:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1717668931; x=1718273731; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=YT/0a30myRtwZY+6s62GqXPjSHD/laXp1qrzJp9sYzs=; b=ZyZ9UXk0CvgJthTZrxOVFyIL1toJZHeI+UDibpqasCZo7j84H2ygeXXkH8wbPbz+mu Bahlyw5xtQL5Xpqaizr9K6CBS7WNfr5aXjuHpse5bRo4yDDNClmIeElamV62aVbc/hU8 dIhqoTdprc9/b75vr6cIdS3CkDwY8ARZ2B0/NLtWZ04xaug9f3aeVI5q3XGL59vL5DAC OQaHvjI4ek6yEtKuVZkcIkfEiZLSoxlH755su6EYCKcRcTYSJsYaL1XLCuGejYU/8I15 +Vs98Geyb1Zfw5V+jUFnPLxDM+T3cF1bAoxtoHIh9Kf+3t8ZgpWRmlBL8TzEJDxvXIvh ozgw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717668931; x=1718273731; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=YT/0a30myRtwZY+6s62GqXPjSHD/laXp1qrzJp9sYzs=; b=U748zleFPxT79XgFX1h5zT6eowWuSBAb0/Cfp88YkH5borLkrHssWuvTUbYcVHsJX0 RcxRYUeta6W8JNwD8EiGP972H74fqSeNZdq06sqVGS4/2dUzODxY869qz23jGF6KhGv/ Ugcm+VeSaVPWdDEbffcizSlKJf3BATpTZrPV+bHKgcdk9sNKcxnGs85UQFUJvFHMwFTQ mw5FUhUDip/Vnc8+bMPiOCgqbhA46pWCBpotZ6qsmjflgN/7mANygxMPAT1CWqcnb8uH itx04r6rKetmKj38CfRCTjJYdvCssfF8QD7QdNCRb81kAmllS0tUQrGxXwwOQAdbJSHf s1yg== X-Gm-Message-State: AOJu0YzJTdNecL0O1kZ7pHpXSC7ExImZy4T58O6uy1JeDRcs9retcg4p fkmh6WVm6P1R+mbJ2yYhHjJBYT7mCfqJ6lc/0ZSeZaZjvmTnfgMZrFaXOr5aVApKUSUHP3Joebb C X-Google-Smtp-Source: AGHT+IHpUCV3ePiCOo2EvKbksE+ajGp1iwGGgSWhFi0MaxpdgBDa9axKXMnXon6HtR1nAVyJDZ/8Fw== X-Received: by 2002:a17:906:8302:b0:a66:7b79:3572 with SMTP id a640c23a62f3a-a699f362134mr312554266b.15.1717668930907; Thu, 06 Jun 2024 03:15:30 -0700 (PDT) Received: from pi5-davidp.pitowers.org ([2001:4d4e:300:1f:c732:5d0a:406b:ae46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a6c805c59a2sm75809866b.50.2024.06.06.03.15.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 03:15:30 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: Ben Benson , Ben Benson , Naushir Patuck Subject: [PATCH 3/6] utils: raspberrypi: ctt: Changed CTT handling of VC4 and PiSP Date: Thu, 6 Jun 2024 11:15:09 +0100 Message-Id: <20240606101512.375178-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240606101512.375178-1-david.plowman@raspberrypi.com> References: <20240606101512.375178-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: Ben Benson 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 Reviewed-by: Naushir Patuck --- .../ctt/{alsc_pisp.py => alsc_only.py} | 13 +++++-- utils/raspberrypi/ctt/alsc_vc4.py | 37 ------------------ utils/raspberrypi/ctt/cac_only.py | 9 ++--- utils/raspberrypi/ctt/{ctt_run.py => ctt.py} | 38 ++++++++++++++++--- utils/raspberrypi/ctt/ctt_image_load.py | 1 - utils/raspberrypi/ctt/ctt_log.txt | 31 --------------- utils/raspberrypi/ctt/ctt_pisp.py | 33 +--------------- .../raspberrypi/ctt/ctt_pretty_print_json.py | 8 +++- utils/raspberrypi/ctt/ctt_tools.py | 3 +- utils/raspberrypi/ctt/ctt_vc4.py | 33 +--------------- 10 files changed, 57 insertions(+), 149 deletions(-) rename utils/raspberrypi/ctt/{alsc_pisp.py => alsc_only.py} (69%) delete mode 100755 utils/raspberrypi/ctt/alsc_vc4.py rename utils/raspberrypi/ctt/{ctt_run.py => ctt.py} (96%) delete mode 100644 utils/raspberrypi/ctt/ctt_log.txt diff --git a/utils/raspberrypi/ctt/alsc_pisp.py b/utils/raspberrypi/ctt/alsc_only.py similarity index 69% rename from utils/raspberrypi/ctt/alsc_pisp.py rename to 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 similarity index 96% rename from utils/raspberrypi/ctt/ctt_run.py rename to 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)