From patchwork Wed Jul 6 10:18:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 16562 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 A7890BD1F1 for ; Wed, 6 Jul 2022 10:18:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0AA5E63311; Wed, 6 Jul 2022 12:18:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657102725; bh=5FsbFz2rxnf0KR6y5J6BXxva5T3QeWoXql4B0h6nlF8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=j2CND4XFaCk9kSzgmS0NStYnWw8Sp64boGcysL0dcEHPVMQgTnqS9mZYfZHPz4oFg FDAZdTxvfJMAwe3yQ9P55YSTDlzGGYykBiTeB4yfK0Ij+iQOaTHA3LeZIn8lmWywEQ 9EdwxcDoGystBKfh9E+V1DsVgQJMexKOIIEybuLlZbLxmG69/Em95Qp8FX1pO+Ect5 u2Rx+7z5SY68Mi/zDKdAyx5wkbSdIyj05cD7lRX4ZonABqgy03fgZCOKMD3PulCW3o 6ewL3b9duGShCp1Hh5PL5wM2fbGO8n7ou95PIYt3jlmRn7BXCbxfZVuPH8cmUpeMK9 KNqOxNYnnEkBQ== Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DB11F6330C for ; Wed, 6 Jul 2022 12:18:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="O47he72w"; dkim-atps=neutral Received: by mail-wr1-x432.google.com with SMTP id q9so21355438wrd.8 for ; Wed, 06 Jul 2022 03:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Wc2GJ1T1krXJ6ZHwNTDoiOGNKOl2Qvj3QnBeLDfseAc=; b=O47he72wSIUO0sOKCobeqiEc1OgEu0KzOvCk3L4cp5fOyRwZyPcAlzxWk3PzeJODEN pCb58vXz2b5YiDCXuZLfCvgEIwpWtpnfCIqyD5zz3VE5VEBwzQESF37Sl6YSnic4mkAk 6Xx1RIaxNxZxUqp/oFPDKz+6zVRyNyxj4aaLZLdX8cmdvujBBpmUUh/86vWo7m1ZKFXM 1Umy+gEij2nYfwRIZB+Oaib9UMz2at7H0nW3HGySKpFOXgyrgohR0zB7vBnbb0NcHN18 am6vdcLxiEJl8CJazuPFkFbzMnJdMKo5nG306JpggcGqr1TduJGza1hDyuhQ/jrkped9 iw3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Wc2GJ1T1krXJ6ZHwNTDoiOGNKOl2Qvj3QnBeLDfseAc=; b=3CixIkqYvS/iLziyfKZ81N6SHSGt+A/fMf6PsZdW9FlI5k1CxqJhxPHzusIm7wx6M4 OlGdlKci/+1gKUGD8DlQFj7UJb3esfsKJ7kHmwOL4vXQvJa0MsGCZ7DZVFD5DxNLuzAI +4dLVJNgIlAeJMoMampgBJp+nYc0vllURzTn375ufY81i8nfHAjBGlW3ajCayIs/JhyM ePklQy8lp6S1hmIECCgus1Ym//v76vHbg+jmDhcR29tB+RmfjM28Jof5p84w2FhDreFS gKwRW+O1+aoVr9A74BhII2lAxjzTM0C41oQ5DyqFQVUqZvVrWcg9SFlJPb1IxC29hXZ1 Z5cA== X-Gm-Message-State: AJIora/tnih5NXK+A/Ey4hP5XOs9HK14x4y3XftbCv6Q6O28+wmXGAoV FpqDkKfFvtjW3+Ecu+T/p5v+mJa2zeRg9Q== X-Google-Smtp-Source: AGRyM1v7JmRFIjT7PcxhrUbbC7K1qkbQJIf14e7U8U9mDM8ko6esX4zTp6fhsM9XmEgllp0CIWmdZA== X-Received: by 2002:a05:6000:168a:b0:21b:b8a4:799 with SMTP id y10-20020a056000168a00b0021bb8a40799mr38269452wrd.56.1657102721405; Wed, 06 Jul 2022 03:18:41 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id i1-20020adffc01000000b0021b5861eaf7sm35950820wrr.3.2022.07.06.03.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 03:18:41 -0700 (PDT) To: libcamera-devel@lists.libcamera.org, william.vinnicombe@raspberrypi.com Date: Wed, 6 Jul 2022 11:18:34 +0100 Message-Id: <20220706101836.20153-2-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220706101836.20153-1-david.plowman@raspberrypi.com> References: <20220706101836.20153-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/3] utils: raspberrypi: ctt: load_image: Ignore JPEG files with no raw data 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: , X-Patchwork-Original-From: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: William Vinnicombe The load_image function would throw errors with JPEG or JPG files containing no raw data. Prevent throwing these errors by returning 0 if an error has occurred. Signed-off-by: William Vinnicombe Reviewed-by: David Plowman Reviewed-by: Laurent Pinchart --- utils/raspberrypi/ctt/ctt_image_load.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 66adb237..934db123 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -358,6 +358,11 @@ def load_image(Cam, im_str, mac_config=None, show=False, mac=True, show_meta=Fal Img = dng_load_image(Cam, im_str) else: Img = brcm_load_image(Cam, im_str) + """ + handle errors smoothly if loading image failed + """ + if Img == 0: + return 0 if show_meta: Img.print_meta() From patchwork Wed Jul 6 10:18:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 16563 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 80BA8BD1F1 for ; Wed, 6 Jul 2022 10:18:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7F26763313; Wed, 6 Jul 2022 12:18:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657102725; bh=uyKuipDDdz/XZhk1uvlh59NH/oIDbLiIp/gjCbAu/q8=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=H8CZpkXfWsVPVUtRvdOUNDPSMR/ILlGWjlOOAM3zYJXy9cn7yUxJSdpDxkAS5xYt4 omjnoxKb+vYammX7URLB9E8cO4Yy//WJa44huyukQcMURchVEidgk0W1gfp50zpUfi KcEAbpUSMdb6exyTcWStERK4mUSkYUQdOtN02w389aUS/lnJ2S3CP7TvqHwqdhwEzr Y55VrlWymz2niuJyxYOLx6iGwhk6mpgO7aniAu8thWvfrcvU28RNLMWkb3BPj485yR mKFsPF1v8WXIOmUOq6jNIfg4srLqWzs5mFVEhjmlRehaZhzhFq5SkkGqcNJsJr2nIV n6CiWuZVj485Q== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 836BD6330E for ; Wed, 6 Jul 2022 12:18:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="HpEQOljt"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id o4so21376613wrh.3 for ; Wed, 06 Jul 2022 03:18:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=TFoDYgGxHC/i4sL9ves7P72QTIn58Xk+z4xJBL6J09M=; b=HpEQOljtCgBhPkhwAAMgF8PL/bWj0mJ573Ccz/fSBlwGySb4YPyYm3DEWhhiiNauMz K4Ef58TTVvRyrp9oo8Gcz3bVgCWUKDvmFAO5w38aL2l+kgrFrxpN6B2p6ZIwnpW0Ta4+ FNh7kOR7A7s+zOXn618FQdffvCzvoc5ZwdDKxfqCMWSUxL6zFL9GE+hk6ad7Dd8U9Dcl sO9Lb5+HmpjJ4kdaM3EMXNSBXiXFhS8NlYGsR+tyoOert2BVdySY4XIUYrFLM9NRRiGo 7Fi+PazM7RJNnNmveKhH+EEWKyjURd0KYovu3ctg1+FeNecp5Fh9KqIDAssXlpbxIQio HUtg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TFoDYgGxHC/i4sL9ves7P72QTIn58Xk+z4xJBL6J09M=; b=ViblyE37UU3Om9E28PqZw9IfQhFujcLvUXM2Z7Q+cuaje9w+1tN11+xo/LEN5BaACU AQTTGe9O5P2ATIT6nMC3972mUsDcHdVp3ZEKx+WIg2Msam9ZCY9lnHbhhGK/6ddQBh0w ctGTFi6iVi0bCY+1G0l+kogApLUDLKL+M8cjHM1S6DWknuvyVybqFUAJ2wev9Oo3qgMK 8KcuU/lSSTkKvx+K6A796vLD5hdp/Tnrfjm/gsx3CwADcK75f6NAu9EpABG2PwtXm+HQ eWQGRM7G/tp/NCnzuZ00oYmuW447Vp9e5IuxMHvYbNKCUdPGVYtYimZ9QoJXI/Fats7q mitA== X-Gm-Message-State: AJIora9vedaM813ECi+XaI77gm2aDMDyT/WARM4+3XPjU4BjeQsUNEsk 3ziep02OlYcqm+ZaKdt3F3chT+ZFCii/sw== X-Google-Smtp-Source: AGRyM1s+0ZyrFZcY8AvxCpHkb9zMKH6dlrusrIbePVpZDz7hxoJ8WoNznieEslU3v8i3mfEqQ/6TBw== X-Received: by 2002:a05:6000:1a87:b0:21c:65c8:2d8 with SMTP id f7-20020a0560001a8700b0021c65c802d8mr37604684wry.370.1657102721991; Wed, 06 Jul 2022 03:18:41 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id i1-20020adffc01000000b0021b5861eaf7sm35950820wrr.3.2022.07.06.03.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 03:18:41 -0700 (PDT) To: libcamera-devel@lists.libcamera.org, william.vinnicombe@raspberrypi.com Date: Wed, 6 Jul 2022 11:18:35 +0100 Message-Id: <20220706101836.20153-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220706101836.20153-1-david.plowman@raspberrypi.com> References: <20220706101836.20153-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/3] utils: raspberrypi: ctt: Add alsc_only method 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: , X-Patchwork-Original-From: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: William Vinnicombe The ctt would not work if only passed alsc images. Added alsc_only.py to run alsc calibration only, and modified check_imgs to allow for no macbeth chart images. Example usage would be ./alsc_only.py -i tuning-images/ -o sensor.json with the same optional arguments as the original ctt. Signed-off-by: William Vinnicombe Reviewed-by: David Plowman Reviewed-by: Naushir Patuck --- utils/raspberrypi/ctt/alsc_only.py | 118 +++++++++++++++++++++++++++++ utils/raspberrypi/ctt/ctt.py | 8 +- 2 files changed, 124 insertions(+), 2 deletions(-) create mode 100755 utils/raspberrypi/ctt/alsc_only.py diff --git a/utils/raspberrypi/ctt/alsc_only.py b/utils/raspberrypi/ctt/alsc_only.py new file mode 100755 index 00000000..318adc8c --- /dev/null +++ b/utils/raspberrypi/ctt/alsc_only.py @@ -0,0 +1,118 @@ +#!/usr/bin/env python3 +# +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (C) 2022, Raspberry Pi (Trading) Limited +# +# alsc_only.py - alsc tuning tool + +from ctt import * + + +def run_alsc(json_output, directory, config, log_output): + """ + check input files are jsons + """ + if json_output[-5:] != '.json': + raise ArgError('\n\nError: Output must be a json file!') + if config is not None: + """ + check if config file is actually a json + """ + if config[-5:] != '.json': + raise ArgError('\n\nError: Config file must be a json file!') + """ + read configurations + """ + try: + with open(config, 'r') as config_json: + configs = json.load(config_json) + except FileNotFoundError: + configs = {} + config = False + except json.decoder.JSONDecodeError: + configs = {} + config = True + + else: + configs = {} + """ + load configurations from config file, if not given then set default + only load configurations needed for alsc, and directly define others + """ + plot = get_config(configs, "plot", [], 'list') + alsc_d = get_config(configs, "alsc", {}, 'dict') + do_alsc_colour = get_config(alsc_d, "do_alsc_colour", 1, 'bool') + luminance_strength = get_config(alsc_d, "luminance_strength", 0.5, 'num') + blacklevel = get_config(configs, "blacklevel", -1, 'num') + mac_config = (0, 0) + + if blacklevel < -1 or blacklevel >= 2**16: + print('\nInvalid blacklevel, defaulted to 64') + blacklevel = -1 + + if luminance_strength < 0 or luminance_strength > 1: + print('\nInvalid luminance_strength strength, defaulted to 0.5') + luminance_strength = 0.5 + + """ + sanitise directory path + """ + if directory[-1] != '/': + directory += '/' + """ + initialise tuning tool and load images + """ + try: + Cam = Camera(json_output) + Cam.log_user_input(json_output, directory, config, log_output) + disable = set(Cam.json.keys()).symmetric_difference({"rpi.alsc"}) + Cam.disable = disable + Cam.plot = plot + Cam.add_imgs(directory, mac_config, blacklevel) + except FileNotFoundError: + raise ArgError('\n\nError: Input image directory not found!') + + """ + preform calibrations as long as check_imgs returns True + Only performs the alsc calibration + """ + if Cam.check_imgs(macbeth=False): + Cam.json_remove(disable) + print('\nSTARTING CALIBRATIONS') + Cam.alsc_cal(luminance_strength, do_alsc_colour) + print('\nFINISHED CALIBRATIONS') + Cam.write_json() + Cam.write_log(log_output) + print('\nCalibrations written to: '+json_output) + if log_output is None: + log_output = 'ctt_log.txt' + print('Log file written to: '+log_output) + pass + else: + Cam.write_log(log_output) + + +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_alsc(json_output, directory, config, log_output) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 15064634..0ea4854d 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -664,7 +664,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 +672,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... """ From patchwork Wed Jul 6 10:18:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 16564 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 DC28FC3274 for ; Wed, 6 Jul 2022 10:18:47 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0349A6330C; Wed, 6 Jul 2022 12:18:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657102726; bh=RQ8wvOavvrjqraqVzxUjFxKxPzWH7QDhqyNY3EjH6MA=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=fj069aNg2nMYIIR5nTuhr9lfK97peL7m3r3Eg/U0AJU1I+KBxrM83E+yd5jCT1jcr RXJx9Qkke44UHpYPbH0WHwkejORw2SEocEAVOLmDs4n22YtBUf+o/iLiSVXAcZcRMn HoGhSTQE01xULI98IGYZ7r2zzREufuEQsEn92g9fumrD2xyBirjXNpHpXLrxtPODAW 2wsg6udvghfZHkE+77pk7byPLfCtgnUhaQxfFcgpY6Ds0lbDO7Ho3FVrv9Jef14qXj 3YZ1L/hySCtlUmV0TB/MtMDSRXSVhWC4vb3vvfX7kZAUmCrWuc9L4xw0NjaP+EXES2 BvuV1mjybD9cg== Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 368976330C for ; Wed, 6 Jul 2022 12:18:43 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="hCkXx4zu"; dkim-atps=neutral Received: by mail-wr1-x430.google.com with SMTP id s1so21355145wra.9 for ; Wed, 06 Jul 2022 03:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ssYnUC4vEKEUNpb7OK9FxfyCRxXfp/cJaoAdu/dquFw=; b=hCkXx4zub2f7GzjVONoU/A5Gtum6uHBQ1ANdmW41l7PBpyxTSqJNmEqlU77NWmASuf B/7C1lWAMCYXObDkBn066RuXlPaJUZSm3A8Zjbu72qTYVgZfiiogpdvIT8HafrH1oktP f3gYxy1POGCWU0lbY0RqOtHPLfQbenDPopuBbz5mpnDUNuI8C8uL+HrmKXUJpGr4E6AN P2nj+cQt79Gs/X7IXwWmNSCRKvI0wUN9G/Hu9v3JLkyFOLAW0hoQ4+XapvLi5sFW+XBU /dyIPp7UQXrrrTLWMezprF5eGsXrOW4+WeOTB7WhbZAeSYxroyW8I1cBEZAfJaMa0jU7 Wvxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ssYnUC4vEKEUNpb7OK9FxfyCRxXfp/cJaoAdu/dquFw=; b=lxCryYcLx0J9mwRFw6JacpMZBc6CTouFo+mHrqJ0n86zdNTAgHoyzNlW74jqEAFl18 ZPfthDtt+LXhuzDPPpPNP9sQ1cP4Ktpbhs5m9EltVwRrs2FAcADoGeiBmMrgbZow97IR KdNMz0rz38D2vQLtnmOTTd1b2usqN4TYnd/husPTDeqDNYMneIhHDm0g8RY289TmaFrE YvfTw+cD+YdMQN2vqvQBAhWT+IH4FOC1cyEC7NET/qF8/uMdDWToLInZAh+xExnzGXQ5 WSQP12zfnR8JnbEPqNHhfhP3SIqfO7W73qmcu05+mcdavEmz+WPkP62NyVj+3znVFC/H YRUQ== X-Gm-Message-State: AJIora9M5LvWUiCUFFJnWy80Wxp0sjonCs/mb3g00X9z/JqDUFCMjVz/ ORfhO4e/sZj2hkRfjKicrRBPLMRDKF1h1A== X-Google-Smtp-Source: AGRyM1tUGfhU8gYKD0BA+MMX1cb7dNTaznpyeEflgI32ClYM6gH+pZD2aP3Pi4+jIvAhBvLk9RhXMQ== X-Received: by 2002:adf:f345:0:b0:21d:6a26:6d8f with SMTP id e5-20020adff345000000b0021d6a266d8fmr15208313wrp.538.1657102722645; Wed, 06 Jul 2022 03:18:42 -0700 (PDT) Received: from pi4-davidp.pitowers.org ([2a00:1098:3142:14:e4a2:3070:eea4:e434]) by smtp.gmail.com with ESMTPSA id i1-20020adffc01000000b0021b5861eaf7sm35950820wrr.3.2022.07.06.03.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Jul 2022 03:18:42 -0700 (PDT) To: libcamera-devel@lists.libcamera.org, william.vinnicombe@raspberrypi.com Date: Wed, 6 Jul 2022 11:18:36 +0100 Message-Id: <20220706101836.20153-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220706101836.20153-1-david.plowman@raspberrypi.com> References: <20220706101836.20153-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/3] utils: raspberrypi: ctt: dng_load_image: Work with DNG files from Picamera2 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: , X-Patchwork-Original-From: David Plowman via libcamera-devel From: David Plowman Reply-To: David Plowman Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: William Vinnicombe The exif tags are different between raw files from libcamera-apps and from Picamera2, causing issues loading data. Add code to identify which tags are being used, and then load the metadata from the correct tags. Signed-off-by: William Vinnicombe Reviewed-by: David Plowman Reviewed-by: Naushir Patuck --- utils/raspberrypi/ctt/ctt_image_load.py | 26 ++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_image_load.py b/utils/raspberrypi/ctt/ctt_image_load.py index 934db123..29c17581 100644 --- a/utils/raspberrypi/ctt/ctt_image_load.py +++ b/utils/raspberrypi/ctt/ctt_image_load.py @@ -301,17 +301,29 @@ def dng_load_image(Cam, im_str): metadata.read() Img.ver = 100 # random value - Img.w = metadata['Exif.SubImage1.ImageWidth'].value + """ + libcamera-apps create a separate Exif.Subimage1 for the picture + picamera2 stores everything under Exif.Image + this code detects which one is being used, and therefore extracts the correct values + """ + try: + Img.w = metadata['Exif.SubImage1.ImageWidth'].value + subimage = "SubImage1" + photo = "Photo" + except KeyError: + Img.w = metadata['Exif.Image.ImageWidth'].value + subimage = "Image" + photo = "Image" Img.pad = 0 - Img.h = metadata['Exif.SubImage1.ImageLength'].value - white = metadata['Exif.SubImage1.WhiteLevel'].value + Img.h = metadata[f'Exif.{subimage}.ImageLength'].value + white = metadata[f'Exif.{subimage}.WhiteLevel'].value Img.sigbits = int(white).bit_length() Img.fmt = (Img.sigbits - 4) // 2 - Img.exposure = int(metadata['Exif.Photo.ExposureTime'].value*1000000) - Img.againQ8 = metadata['Exif.Photo.ISOSpeedRatings'].value*256/100 + Img.exposure = int(metadata[f'Exif.{photo}.ExposureTime'].value*1000000) + Img.againQ8 = metadata[f'Exif.{photo}.ISOSpeedRatings'].value*256/100 Img.againQ8_norm = Img.againQ8 / 256 Img.camName = metadata['Exif.Image.Model'].value - Img.blacklevel = int(metadata['Exif.SubImage1.BlackLevel'].value[0]) + Img.blacklevel = int(metadata[f'Exif.{subimage}.BlackLevel'].value[0]) Img.blacklevel_16 = Img.blacklevel << (16 - Img.sigbits) bayer_case = { '0 1 1 2': (0, (0, 1, 2, 3)), @@ -319,7 +331,7 @@ def dng_load_image(Cam, im_str): '2 1 1 0': (2, (3, 2, 1, 0)), '1 0 2 1': (3, (1, 0, 3, 2)) } - cfa_pattern = metadata['Exif.SubImage1.CFAPattern'].value + cfa_pattern = metadata[f'Exif.{subimage}.CFAPattern'].value Img.pattern = bayer_case[cfa_pattern][0] Img.order = bayer_case[cfa_pattern][1]