{"id":20775,"url":"https://patchwork.libcamera.org/api/1.1/patches/20775/?format=json","web_url":"https://patchwork.libcamera.org/patch/20775/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20240805120522.1613342-6-stefan.klug@ideasonboard.com>","date":"2024-08-05T12:05:06","name":"[v1,5/6] libtuning: Add initial AWB module","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"b66032472baaa938ee898eecee4de98f299e78b5","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/20775/mbox/","series":[{"id":4486,"url":"https://patchwork.libcamera.org/api/1.1/series/4486/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4486","date":"2024-08-05T12:05:01","name":"rkisp1: Add manual colour temperature control","version":1,"mbox":"https://patchwork.libcamera.org/series/4486/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/20775/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/20775/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 3FD09C323E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  5 Aug 2024 12:06:08 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id CCB51633B2;\n\tMon,  5 Aug 2024 14:06:07 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id AD1D963385\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  5 Aug 2024 14:06:02 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:30ff:e7b4:349c:44ce])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 5F568581;\n\tMon,  5 Aug 2024 14:05:11 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"rpKo5ZMh\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1722859511;\n\tbh=drQpmeEVWshewFVgjah1K/r7bqB8fNREwlf4SYeJN8g=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=rpKo5ZMhuDj4HbgZp0MV2kCvDMLrZu1MXHq2OYE8ceIcTEOhsbbBQ0uxCPZ39wcMg\n\tbfzjF7GCa+jipo4gR2789zIFXbi5h1um9snDbZBsL+5Nu0e+sOd58kK83JXgv+lsOq\n\tjOUirQHhIfctrJeC/s28y46KcVIK605U7aXNAFmg=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"David Plowman <david.plowman@raspberrypi.com>,\n\tStefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH v1 5/6] libtuning: Add initial AWB module","Date":"Mon,  5 Aug 2024 14:05:06 +0200","Message-ID":"<20240805120522.1613342-6-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20240805120522.1613342-1-stefan.klug@ideasonboard.com>","References":"<20240805120522.1613342-1-stefan.klug@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"This AWB modules uses the awb function from Raspberry Pi to calculate\nthe needed white balance gains per colour temperature. It stores these\ngains in the tuning file. Currently they are only used for the manual\ncolour temperature control. It is likely that they will be used with\nmore complex awb algorithms.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n---\n .../tuning/libtuning/modules/awb/__init__.py  |  6 +++\n utils/tuning/libtuning/modules/awb/awb.py     | 42 +++++++++++++++++++\n utils/tuning/libtuning/modules/awb/rkisp1.py  | 27 ++++++++++++\n 3 files changed, 75 insertions(+)\n create mode 100644 utils/tuning/libtuning/modules/awb/__init__.py\n create mode 100644 utils/tuning/libtuning/modules/awb/awb.py\n create mode 100644 utils/tuning/libtuning/modules/awb/rkisp1.py","diff":"diff --git a/utils/tuning/libtuning/modules/awb/__init__.py b/utils/tuning/libtuning/modules/awb/__init__.py\nnew file mode 100644\nindex 000000000000..2d67f10cfc4f\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/awb/__init__.py\n@@ -0,0 +1,6 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2024, Ideas On Board\n+\n+from libtuning.modules.awb.awb import AWB\n+from libtuning.modules.awb.rkisp1 import AWBRkISP1\ndiff --git a/utils/tuning/libtuning/modules/awb/awb.py b/utils/tuning/libtuning/modules/awb/awb.py\nnew file mode 100644\nindex 000000000000..5680a44fd3e3\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/awb/awb.py\n@@ -0,0 +1,42 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2024, Ideas On Board\n+\n+import logging\n+\n+from ..module import Module\n+\n+from libtuning.ctt_awb import awb\n+import numpy as np\n+\n+logger = logging.getLogger(__name__)\n+\n+\n+class AWB(Module):\n+    type = 'awb'\n+    hr_name = 'AWB (Base)'\n+    out_name = 'GenericAWB'\n+\n+    def __init__(self, *,\n+                 debug: list):\n+        super().__init__()\n+\n+        self.debug = debug\n+\n+    def do_calculation(self, images):\n+        logger.info('Starting AWB calculation')\n+\n+        imgs = [img for img in images if img.macbeth is not None]\n+\n+        gains, _, _ = awb(imgs, None, None, False)\n+        gains = np.array(gains)\n+        gains = gains.reshape(-1, 3)\n+\n+        res = []\n+        for v in gains:\n+            res.append({\n+                'ct': int(v[0]),\n+                'gains': [float(1.0 / v[1]), float(1.0 / v[2])]\n+            })\n+\n+        return res\ndiff --git a/utils/tuning/libtuning/modules/awb/rkisp1.py b/utils/tuning/libtuning/modules/awb/rkisp1.py\nnew file mode 100644\nindex 000000000000..e3ddeb50c9a1\n--- /dev/null\n+++ b/utils/tuning/libtuning/modules/awb/rkisp1.py\n@@ -0,0 +1,27 @@\n+# SPDX-License-Identifier: GPL-2.0-or-later\n+#\n+# Copyright (C) 2024, Ideas On Board\n+#\n+# AWB module for tuning rkisp1\n+\n+from .awb import AWB\n+\n+import libtuning as lt\n+\n+\n+class AWBRkISP1(AWB):\n+    hr_name = 'AWB (RkISP1)'\n+    out_name = 'Awb'\n+\n+    def __init__(self, **kwargs):\n+        super().__init__(**kwargs)\n+\n+    def validate_config(self, config: dict) -> bool:\n+        return True\n+\n+    def process(self, config: dict, images: list, outputs: dict) -> dict:\n+        output = {}\n+\n+        output['gains'] = self.do_calculation(images)\n+\n+        return output\n","prefixes":["v1","5/6"]}