{"id":19260,"url":"https://patchwork.libcamera.org/api/1.1/patches/19260/?format=json","web_url":"https://patchwork.libcamera.org/patch/19260/","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":"<20231201110753.4288-1-david.plowman@raspberrypi.com>","date":"2023-12-01T11:07:53","name":"[libcamera-devel] utils: raspberrypi: ctt: Improve the Macbeth Chart search reliability","commit_ref":"66479605baca4a22e2b7a17c2a8cf9f9be9a7724","pull_url":null,"state":"accepted","archived":false,"hash":"dfb8ee1816f16f25bd136d881d4fa3bae554cd71","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/1.1/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/19260/mbox/","series":[{"id":4094,"url":"https://patchwork.libcamera.org/api/1.1/series/4094/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4094","date":"2023-12-01T11:07:53","name":"[libcamera-devel] utils: raspberrypi: ctt: Improve the Macbeth Chart search reliability","version":1,"mbox":"https://patchwork.libcamera.org/series/4094/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/19260/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/19260/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 D0EE5BDE6B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  1 Dec 2023 11:07:58 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42BF6629CC;\n\tFri,  1 Dec 2023 12:07:58 +0100 (CET)","from mail-wr1-x431.google.com (mail-wr1-x431.google.com\n\t[IPv6:2a00:1450:4864:20::431])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 244F561D9F\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 Dec 2023 12:07:57 +0100 (CET)","by mail-wr1-x431.google.com with SMTP id\n\tffacd0b85a97d-3332fc9b9b2so651358f8f.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 01 Dec 2023 03:07:57 -0800 (PST)","from davidp-xps-13.. ([194.233.231.115])\n\tby smtp.gmail.com with ESMTPSA id\n\tm7-20020adffa07000000b003330b139fa5sm3913022wrr.30.2023.12.01.03.07.55\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 01 Dec 2023 03:07:55 -0800 (PST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1701428878;\n\tbh=h18YOdTgL8zGUzitrhgroPcecQ8HKSWj+sLYPDhubmY=;\n\th=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post:\n\tList-Help:List-Subscribe:From:Reply-To:From;\n\tb=RoduZyg+MQyUtO5by4IHZ1M5ViWYMxwvTj5g+TMYuCScp0UGR2KCQxnZKY3eSNJOc\n\tdYYO2a9AVtLzfR2KLgUQqfsVA/SnAURUEA1ZMzdQRMVHoOyLFpQmBUIKLSO2YGogp5\n\tFEv6870qj823LhMEZBZHSfbH0Mum0jVLSqFNElqt62H+j/11syzWVzCeSqm7BRRduW\n\to9bQhUBDo9Qi/Lg9uf0KghOELgHORQ7BOfjtFv3sEyV45U1WmKFSdUWFXy+mGJqu7O\n\tqnBNj7mO+YzvIWy0WBvIogQgAna0hyX17j6VMgo2s5hrbgggkMSGgsRv6YgcKmCfO9\n\t9T3ErB/oG0aaA==","v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1701428876; x=1702033676;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=BNoEF4nTV/5aBKVPBjQ/4bKmwmQq4HhdvjaGIRsSC3Y=;\n\tb=iO1dm/YSSrr39O0+OSy/rWXSla6evrcaojyYkHNdhuZelGbUxgwB/eD8Mcbz1HoJO/\n\tsZmPohZ7f84Z0GZ9J28o3Ur8KQPasIn1eOxePYoCRpDycS8gDOukvrwfTVH2cSTxt2pB\n\tdVymfzsZm/CRWRPe2HpzUGQRWsfuF6j5Bb9a8xgqHurGNuLS8QoP6/4rDFPGv0N1mfwX\n\trbI8chWqE5czOluIEIK7v5M+DeeS6KVYn5tgDJtDsAXnwlSwc1AzB9KG/YszmKYRnDVN\n\t0Fnvm8ECL9u4lM6oMGTO0w6ItmkLr0q50VxAGdJMgdl8TOONvMYG5gh1NYKGLSRFTuvF\n\tV5TQ=="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"iO1dm/YS\"; dkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1701428876; x=1702033676;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=BNoEF4nTV/5aBKVPBjQ/4bKmwmQq4HhdvjaGIRsSC3Y=;\n\tb=A6ZsEYt+JnMX9SCL1S+Pal1gw6n3LOiqVAyug7Q2mjFeT/ufCfWHmwv524kibJhhNv\n\t+LNIAisMeZL7gcQN2ahHV5Yc1LZ5u8Lfx3MMUJc0eJq4meQIgnuag2x3b7TjIXMASjjT\n\tdDydK8bryPH4HeUQky/j1+4OojJp/jmil4Uo5Yup3AXtdBVCX0+AiSG6ziwyj6Cwjgn6\n\t6alyabewTyKfKT7D8boiNjuSm0dBYByB3H+wyRI0hFAMaZIvXq2Pn0/e/9P4zRSa9rtd\n\tlloXDLGVdXVjkFHow+7hztbNUDuXSZ69bxROqR9WNo9AsqVsWTOMGXXQpZLpzzCmS/4K\n\t7/zg==","X-Gm-Message-State":"AOJu0Yy6PRsOXwj23gR/YkU2XX8BYI0yB1JkIqMPsf+zi9QQ5kp3hSYM\n\tDqkfVVhwS8JLLignuEI7d2/b5eFsbyEiaXm4LGI=","X-Google-Smtp-Source":"AGHT+IFZR1ciYTKMd728u2rNJXO7h2u8/majOCXunXHknWP5P22+9ZaAzhzN40r0voeLUQ0APGlvZw==","X-Received":"by 2002:adf:fc92:0:b0:333:2fd2:7661 with SMTP id\n\tg18-20020adffc92000000b003332fd27661mr400351wrr.82.1701428876157; \n\tFri, 01 Dec 2023 03:07:56 -0800 (PST)","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  1 Dec 2023 11:07:53 +0000","Message-Id":"<20231201110753.4288-1-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.34.1","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [PATCH] utils: raspberrypi: ctt: Improve the\n\tMacbeth Chart search reliability","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>","From":"David Plowman via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"David Plowman <david.plowman@raspberrypi.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Previously the code would brighten up images in case the Macbeth Chart\nis slightly dark, and also zoom in on sections of it to look for\ncharts occupying less of the field of view. But it would not do both\ntogether.\n\nThis change makes the search for smaller charts also repeat that\nsearch for the brightened up images that it made earlier, thereby\nincreasing the chances of success for non-optimal tuning images.\n\nThere are also a couple of very small drive-by typo fixes.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\n---\n utils/raspberrypi/ctt/ctt_macbeth_locator.py | 69 ++++++++++++--------\n 1 file changed, 40 insertions(+), 29 deletions(-)","diff":"diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py\nindex 3e95df89..178aeed0 100644\n--- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py\n+++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py\n@@ -57,6 +57,10 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):\n     \"\"\"\n     cor, mac, coords, msg = get_macbeth_chart(img, ref_data)\n \n+    # Keep a list that will include this and any brightened up versions of\n+    # the image for reuse.\n+    all_images = [img]\n+\n     \"\"\"\n     following bits of code tries to fix common problems with simple\n     techniques.\n@@ -71,6 +75,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):\n     if cor < 0.75:\n         a = 2\n         img_br = cv2.convertScaleAbs(img, alpha=a, beta=0)\n+        all_images.append(img_br)\n         cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data)\n         if cor_b > cor:\n             cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b\n@@ -81,6 +86,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):\n     if cor < 0.75:\n         a = 4\n         img_br = cv2.convertScaleAbs(img, alpha=a, beta=0)\n+        all_images.append(img_br)\n         cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data)\n         if cor_b > cor:\n             cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b\n@@ -128,23 +134,26 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):\n         h_inc = int(h/6)\n         \"\"\"\n         for each subselection, look for a macbeth chart\n+        loop over this and any brightened up images that we made to increase the\n+        likelihood of success\n         \"\"\"\n-        for i in range(3):\n-            for j in range(3):\n-                w_s, h_s = i*w_inc, j*h_inc\n-                img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel]\n-                cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data)\n-                \"\"\"\n-                if the correlation is better than the best then record the\n-                scale and current subselection at which macbeth chart was\n-                found. Also record the coordinates, macbeth chart and message.\n-                \"\"\"\n-                if cor_ij > cor:\n-                    cor = cor_ij\n-                    mac, coords, msg = mac_ij, coords_ij, msg_ij\n-                    ii, jj = i, j\n-                    w_best, h_best = w_inc, h_inc\n-                    d_best = 1\n+        for img_br in all_images:\n+            for i in range(3):\n+                for j in range(3):\n+                    w_s, h_s = i*w_inc, j*h_inc\n+                    img_sel = img_br[w_s:w_s+w_sel, h_s:h_s+h_sel]\n+                    cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data)\n+                    \"\"\"\n+                    if the correlation is better than the best then record the\n+                    scale and current subselection at which macbeth chart was\n+                    found. Also record the coordinates, macbeth chart and message.\n+                    \"\"\"\n+                    if cor_ij > cor:\n+                        cor = cor_ij\n+                        mac, coords, msg = mac_ij, coords_ij, msg_ij\n+                        ii, jj = i, j\n+                        w_best, h_best = w_inc, h_inc\n+                        d_best = 1\n \n     \"\"\"\n     scale 2\n@@ -157,17 +166,19 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):\n         h_sel = int(h/2)\n         w_inc = int(w/8)\n         h_inc = int(h/8)\n-        for i in range(5):\n-            for j in range(5):\n-                w_s, h_s = i*w_inc, j*h_inc\n-                img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel]\n-                cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data)\n-                if cor_ij > cor:\n-                    cor = cor_ij\n-                    mac, coords, msg = mac_ij, coords_ij, msg_ij\n-                    ii, jj = i, j\n-                    w_best, h_best = w_inc, h_inc\n-                    d_best = 2\n+        # Again, loop over any brightened up images as well\n+        for img_br in all_images:\n+            for i in range(5):\n+                for j in range(5):\n+                    w_s, h_s = i*w_inc, j*h_inc\n+                    img_sel = img_br[w_s:w_s+w_sel, h_s:h_s+h_sel]\n+                    cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data)\n+                    if cor_ij > cor:\n+                        cor = cor_ij\n+                        mac, coords, msg = mac_ij, coords_ij, msg_ij\n+                        ii, jj = i, j\n+                        w_best, h_best = w_inc, h_inc\n+                        d_best = 2\n \n     \"\"\"\n     The following code checks for macbeth charts at even smaller scales. This\n@@ -238,7 +249,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)):\n     print error or success message\n     \"\"\"\n     print(msg)\n-    Cam.log += '\\n' + msg\n+    Cam.log += '\\n' + str(msg)\n     if msg == success_msg:\n         coords_fit = coords\n         Cam.log += '\\nMacbeth chart vertices:\\n'\n@@ -606,7 +617,7 @@ def get_macbeth_chart(img, ref_data):\n                     '\\nNot enough squares found'\n                     '\\nPossible problems:\\n'\n                     '- Macbeth chart is occluded\\n'\n-                    '- Macbeth chart is too dark of bright\\n'\n+                    '- Macbeth chart is too dark or bright\\n'\n                 )\n \n             ref_cents = np.array(ref_cents)\n","prefixes":["libcamera-devel"]}