From patchwork Mon Jul 11 10:26:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dufresne via libcamera-devel X-Patchwork-Id: 16582 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 EC71FBD1F1 for ; Mon, 11 Jul 2022 10:31:31 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B49F360401; Mon, 11 Jul 2022 12:31:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657535490; bh=leIqYoa7gmb22d7dQVKCR5dxstWMme/vYijcJBtGy70=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=RI96ERjwO0fbEHMzj8CSPECVWLH3x2CqRbQjTwksn31ixm/KPdVGPKTEU0diCntYu 78U6RlHfE+XX6YZLAjXPa1VP6ZgIrjcGgYppGKYRzDR3VmgpsdzCBkylTZiZcKXnjn IsyZK76gUQnW2AHpQL0s9MdBoY0XjqQZOamfVn2FE2Fv6XEPwPzD/lCrQOJRq3r97Z mb913dorIgPeQ1H6kJ8kBRIlrioS10rexnpjB+vdwRNpkEquZHNhtOUsTfl1zuczxO k2B1bwiWf2FxeQRNfE1nRgGlwsIG5ep9G/gOZW0fhc+Jk1sV3GWaNwtltUBJSY+Ycb 4C/QC0jjYYltQ== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4549360401 for ; Mon, 11 Jul 2022 12:26:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="AkNIdUR6"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id 9-20020a1c0209000000b003a2dfdebe47so1940839wmc.3 for ; Mon, 11 Jul 2022 03:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hgBecB6GsSuUNGJ7Z6PxPun09afqeP2+nSpFxwdEzZs=; b=AkNIdUR6FiympdjhvCvz9ghq3IfyX3quohLRyU+Cl1/ql9rws/akVBpVginlKjQ6Ec lC4KKIsS5N2VD6ItsR7d+IYpzxgJ8NaK6DPinTN1edJNLHoFVe+rehjev9rxkaysbmwg wxSalR5lyswhb46Ly9Ebe47YxG33trCc9ndda4kaei6ghYrEyY9DHUGTE24hd3hoZbaU nEr37rvEn35XnUHXr6kI497V6xThc36nmjogdAoIAFAB+nqEZT0BK1pEuEoSryY+jxn3 edGMG2Zi+wTOeDlGYEb8HCaZSmIghKvliVd4RBIY0bDdzemVh49000fqvUMAvKUqiFoT kZOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hgBecB6GsSuUNGJ7Z6PxPun09afqeP2+nSpFxwdEzZs=; b=jQt4qKgdMHe2MZRr2QKq+Ih/y8XmXCFS5o4pXWGRlurgW4G/CdSO9F2hA9sIO3oE3d Qo5C7yrua2ZhtE2Mqhor4Aj2I5CDeBj3iZUhZy6/CCFwm0pRo+R+FZ9tuIo83uCLJ+Ba kCNHQQr6gixpBz3+WU9Q3g3GQEt1l2G6G2MZX/aBxukME44b7+v3If7qIaWooqmFJFDO nGnmUc8H0O29XK1EmuDFEqKKCxxVFNIFZv7FqmtygaH/0oMhe17t0UAWBqM2BfdO6sXq /7HplMyUadJXXxh6SYCqsHxCCuCRwY7yQM/7ZshhtleJPkMO0OCooEgf39Oj5gjCttne U/ow== X-Gm-Message-State: AJIora9JGUtU16PHbJ+MUkIxK80/SxctWrmz7zt44T5TaShrTfQIKJau 66GZ7YuberryHjRgNwSqqTt0EJkG8b4prg== X-Google-Smtp-Source: AGRyM1so0hFdvUgoMiL0gROo6vlRInLq6RaP19BCOM406+BrYrwjDj39M4p+sRW3z4753njOrVND8g== X-Received: by 2002:a05:600c:154c:b0:3a1:884e:72ac with SMTP id f12-20020a05600c154c00b003a1884e72acmr15777210wmg.23.1657535200613; Mon, 11 Jul 2022 03:26:40 -0700 (PDT) Received: from wv-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p12-20020a7bcc8c000000b0039749b01ea7sm8138000wma.32.2022.07.11.03.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 03:26:40 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 11 Jul 2022 11:26:27 +0100 Message-Id: <20220711102628.14269-2-william.vinnicombe@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711102628.14269-1-william.vinnicombe@raspberrypi.com> References: <20220711102628.14269-1-william.vinnicombe@raspberrypi.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 11 Jul 2022 12:31:27 +0200 Subject: [libcamera-devel] [PATCH v2 1/2] 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: "william.vinnicombe--- via libcamera-devel" From: Nicolas Dufresne via libcamera-devel Reply-To: william.vinnicombe@raspberrypi.com Cc: William Vinnicombe Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" From: William Vinnicombe The ctt would not work if only passed alsc images. Add alsc_only.py to run alsc calibration only, and modify 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 Reviewed-by: Laurent Pinchart --- utils/raspberrypi/ctt/alsc_only.py | 34 ++++++++++++++++++++++++++++++ utils/raspberrypi/ctt/ctt.py | 17 ++++++++++----- 2 files changed, 46 insertions(+), 5 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..7cd0ac01 --- /dev/null +++ b/utils/raspberrypi/ctt/alsc_only.py @@ -0,0 +1,34 @@ +#!/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 * + + +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, alsc_only=True) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 15064634..2bd97514 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... """ @@ -704,7 +708,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 +770,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 +785,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) From patchwork Mon Jul 11 10:26:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Dufresne via libcamera-devel X-Patchwork-Id: 16583 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 AE270BD1F1 for ; Mon, 11 Jul 2022 10:31:32 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 181FD63318; Mon, 11 Jul 2022 12:31:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1657535491; bh=ocygqkGskawhmMCslSR4PzBIKQE9Oq6OvUlzCoNQc7Q=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=Wd/FT69kvYsqLkHzazULLYBdNLae+se3vvHxkzvim0ac0PLip62msuGQ7hou6LVxg dHhCpsdFuZXRSdE6USj6pPzzv4wclv6Xu/Z+pp9lKPjuTMx79+ilG+KTvPLhnsv835 KKLWLRhU/VBqFm7VIyCg7beaPjkLHPRoKRYdlUQ22zgdNw8S9sLqaqLxRsqYspEJQA /NXjNG9I0r7I/Fidkw5tk2mfmwIDYyfqTYhLmbCPTTLI3ilEH/7wH1KGe5JdnRWo56 hhdEg9L/O6a0rfFJt33nsGNkJBUYItDROKQmY0CNkJTm1eR4l1q5sdFB5zwde/l0nO V3xW09WjTR8rg== Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D951560401 for ; Mon, 11 Jul 2022 12:26:41 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Z7MrJatA"; dkim-atps=neutral Received: by mail-wm1-x333.google.com with SMTP id 9-20020a1c0209000000b003a2dfdebe47so1940853wmc.3 for ; Mon, 11 Jul 2022 03:26:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IkpjAqUiQOxnAPFYlVvU5FcwtfCnYVkOCEuXbvSUyCA=; b=Z7MrJatA+wOohz/yqpne0xKGHsHGdG5hR/HnFlQ8jsOWpdeNTVD3N0UyRS4T7br5jL 2UmTVPYJ3SO4DbdxT/Bz3t9flKPJgqAm1zTbt6C7roZV58s2C28pBvkkLD0T6JZYPoLs CyKRf6pxuKeGjPVvCw5wc30sCE4OVRCHkfndwFWqe9zSHcGsaePdA6gy0Q+4VkjKUWYS UU7hd2/b1xG8qstvpKguC24dhIwGeG+XhgG4GGlvfSAP+HSQGOmXlMzgz8XYHKoIB0Aw Ndnb5WnMHmDPKXzHs4hB+VZzRU5vo0CySUwGVAd1i9ZpCIQoE140LwWBtSpiaRa+QlB1 d1Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IkpjAqUiQOxnAPFYlVvU5FcwtfCnYVkOCEuXbvSUyCA=; b=6f2UEP3kvaM66HYMpMAF/DGEd6C4LzYF1cLRzYwlq1lwno9stglAhNpc+JxoMokiZ5 +Hr0ZdCKbI6c0W3KgMq4Yy3zAYxXS3QzczlDOohEJx09LN8lVjq4bCae3vjRr0GlfAc/ snUYOyxJDUIdvdbneEG9FDsB0iZdRhTS6Kl/Uej1/EdVev6h4p5mKfSWFCMxdhrZOE6O rWOzZBjCq6tMfMegmCrwDljwwlczFGFsvpW/VTvB5x+PhAkgveFihtAxyENEGCIszLu0 mhyQ8VaLW/J9x9N/kMniSFwgYzZLW8CltMtEYQE7bcReGpX//E5JJTPgpv9SrOX5mcvL 4CXw== X-Gm-Message-State: AJIora/yrUGljmXlb9elMWLDlXVeVa7daCfZ9BjdR1qzNafvXmQqamc/ 7BjzAUXTTOVMVcM8Cs4V8kIrkgUIV4E+tA== X-Google-Smtp-Source: AGRyM1tzMbQ9KBoWwHccEo/5Iwrk1mn9f3D+pwdNF340PE9m+6fTSXS9yWTaKOzmZ+wnH2SbiWxSYQ== X-Received: by 2002:a05:600c:4f54:b0:3a0:4a5b:2692 with SMTP id m20-20020a05600c4f5400b003a04a5b2692mr15443582wmq.109.1657535201455; Mon, 11 Jul 2022 03:26:41 -0700 (PDT) Received: from wv-laptop.localdomain ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id p12-20020a7bcc8c000000b0039749b01ea7sm8138000wma.32.2022.07.11.03.26.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 03:26:41 -0700 (PDT) To: libcamera-devel@lists.libcamera.org Date: Mon, 11 Jul 2022 11:26:28 +0100 Message-Id: <20220711102628.14269-3-william.vinnicombe@raspberrypi.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220711102628.14269-1-william.vinnicombe@raspberrypi.com> References: <20220711102628.14269-1-william.vinnicombe@raspberrypi.com> MIME-Version: 1.0 X-Mailman-Approved-At: Mon, 11 Jul 2022 12:31:27 +0200 Subject: [libcamera-devel] [PATCH v2 2/2] 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: "william.vinnicombe--- via libcamera-devel" From: Nicolas Dufresne via libcamera-devel Reply-To: william.vinnicombe@raspberrypi.com Cc: William Vinnicombe 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]