From patchwork Fri Dec 1 11:07:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 19260 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 D0EE5BDE6B for ; Fri, 1 Dec 2023 11:07:58 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 42BF6629CC; Fri, 1 Dec 2023 12:07:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1701428878; bh=h18YOdTgL8zGUzitrhgroPcecQ8HKSWj+sLYPDhubmY=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=RoduZyg+MQyUtO5by4IHZ1M5ViWYMxwvTj5g+TMYuCScp0UGR2KCQxnZKY3eSNJOc dYYO2a9AVtLzfR2KLgUQqfsVA/SnAURUEA1ZMzdQRMVHoOyLFpQmBUIKLSO2YGogp5 FEv6870qj823LhMEZBZHSfbH0Mum0jVLSqFNElqt62H+j/11syzWVzCeSqm7BRRduW o9bQhUBDo9Qi/Lg9uf0KghOELgHORQ7BOfjtFv3sEyV45U1WmKFSdUWFXy+mGJqu7O qnBNj7mO+YzvIWy0WBvIogQgAna0hyX17j6VMgo2s5hrbgggkMSGgsRv6YgcKmCfO9 9T3ErB/oG0aaA== Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 244F561D9F for ; Fri, 1 Dec 2023 12:07:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="iO1dm/YS"; dkim-atps=neutral Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3332fc9b9b2so651358f8f.1 for ; Fri, 01 Dec 2023 03:07:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1701428876; x=1702033676; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=BNoEF4nTV/5aBKVPBjQ/4bKmwmQq4HhdvjaGIRsSC3Y=; b=iO1dm/YSSrr39O0+OSy/rWXSla6evrcaojyYkHNdhuZelGbUxgwB/eD8Mcbz1HoJO/ sZmPohZ7f84Z0GZ9J28o3Ur8KQPasIn1eOxePYoCRpDycS8gDOukvrwfTVH2cSTxt2pB dVymfzsZm/CRWRPe2HpzUGQRWsfuF6j5Bb9a8xgqHurGNuLS8QoP6/4rDFPGv0N1mfwX rbI8chWqE5czOluIEIK7v5M+DeeS6KVYn5tgDJtDsAXnwlSwc1AzB9KG/YszmKYRnDVN 0Fnvm8ECL9u4lM6oMGTO0w6ItmkLr0q50VxAGdJMgdl8TOONvMYG5gh1NYKGLSRFTuvF V5TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701428876; x=1702033676; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=BNoEF4nTV/5aBKVPBjQ/4bKmwmQq4HhdvjaGIRsSC3Y=; b=A6ZsEYt+JnMX9SCL1S+Pal1gw6n3LOiqVAyug7Q2mjFeT/ufCfWHmwv524kibJhhNv +LNIAisMeZL7gcQN2ahHV5Yc1LZ5u8Lfx3MMUJc0eJq4meQIgnuag2x3b7TjIXMASjjT dDydK8bryPH4HeUQky/j1+4OojJp/jmil4Uo5Yup3AXtdBVCX0+AiSG6ziwyj6Cwjgn6 6alyabewTyKfKT7D8boiNjuSm0dBYByB3H+wyRI0hFAMaZIvXq2Pn0/e/9P4zRSa9rtd lloXDLGVdXVjkFHow+7hztbNUDuXSZ69bxROqR9WNo9AsqVsWTOMGXXQpZLpzzCmS/4K 7/zg== X-Gm-Message-State: AOJu0Yy6PRsOXwj23gR/YkU2XX8BYI0yB1JkIqMPsf+zi9QQ5kp3hSYM DqkfVVhwS8JLLignuEI7d2/b5eFsbyEiaXm4LGI= X-Google-Smtp-Source: AGHT+IFZR1ciYTKMd728u2rNJXO7h2u8/majOCXunXHknWP5P22+9ZaAzhzN40r0voeLUQ0APGlvZw== X-Received: by 2002:adf:fc92:0:b0:333:2fd2:7661 with SMTP id g18-20020adffc92000000b003332fd27661mr400351wrr.82.1701428876157; Fri, 01 Dec 2023 03:07:56 -0800 (PST) Received: from davidp-xps-13.. ([194.233.231.115]) by smtp.gmail.com with ESMTPSA id m7-20020adffa07000000b003330b139fa5sm3913022wrr.30.2023.12.01.03.07.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Dec 2023 03:07:55 -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 Subject: [libcamera-devel] [PATCH] utils: raspberrypi: ctt: Improve the Macbeth Chart search reliability 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" Previously the code would brighten up images in case the Macbeth Chart is slightly dark, and also zoom in on sections of it to look for charts occupying less of the field of view. But it would not do both together. This change makes the search for smaller charts also repeat that search for the brightened up images that it made earlier, thereby increasing the chances of success for non-optimal tuning images. There are also a couple of very small drive-by typo fixes. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck Reviewed-by: Kieran Bingham Tested-by: Kieran Bingham --- utils/raspberrypi/ctt/ctt_macbeth_locator.py | 69 ++++++++++++-------- 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt_macbeth_locator.py b/utils/raspberrypi/ctt/ctt_macbeth_locator.py index 3e95df89..178aeed0 100644 --- a/utils/raspberrypi/ctt/ctt_macbeth_locator.py +++ b/utils/raspberrypi/ctt/ctt_macbeth_locator.py @@ -57,6 +57,10 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): """ cor, mac, coords, msg = get_macbeth_chart(img, ref_data) + # Keep a list that will include this and any brightened up versions of + # the image for reuse. + all_images = [img] + """ following bits of code tries to fix common problems with simple techniques. @@ -71,6 +75,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): if cor < 0.75: a = 2 img_br = cv2.convertScaleAbs(img, alpha=a, beta=0) + all_images.append(img_br) cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data) if cor_b > cor: cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b @@ -81,6 +86,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): if cor < 0.75: a = 4 img_br = cv2.convertScaleAbs(img, alpha=a, beta=0) + all_images.append(img_br) cor_b, mac_b, coords_b, msg_b = get_macbeth_chart(img_br, ref_data) if cor_b > cor: cor, mac, coords, msg = cor_b, mac_b, coords_b, msg_b @@ -128,23 +134,26 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): h_inc = int(h/6) """ for each subselection, look for a macbeth chart + loop over this and any brightened up images that we made to increase the + likelihood of success """ - for i in range(3): - for j in range(3): - w_s, h_s = i*w_inc, j*h_inc - img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel] - cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) - """ - if the correlation is better than the best then record the - scale and current subselection at which macbeth chart was - found. Also record the coordinates, macbeth chart and message. - """ - if cor_ij > cor: - cor = cor_ij - mac, coords, msg = mac_ij, coords_ij, msg_ij - ii, jj = i, j - w_best, h_best = w_inc, h_inc - d_best = 1 + for img_br in all_images: + for i in range(3): + for j in range(3): + w_s, h_s = i*w_inc, j*h_inc + img_sel = img_br[w_s:w_s+w_sel, h_s:h_s+h_sel] + cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) + """ + if the correlation is better than the best then record the + scale and current subselection at which macbeth chart was + found. Also record the coordinates, macbeth chart and message. + """ + if cor_ij > cor: + cor = cor_ij + mac, coords, msg = mac_ij, coords_ij, msg_ij + ii, jj = i, j + w_best, h_best = w_inc, h_inc + d_best = 1 """ scale 2 @@ -157,17 +166,19 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): h_sel = int(h/2) w_inc = int(w/8) h_inc = int(h/8) - for i in range(5): - for j in range(5): - w_s, h_s = i*w_inc, j*h_inc - img_sel = img[w_s:w_s+w_sel, h_s:h_s+h_sel] - cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) - if cor_ij > cor: - cor = cor_ij - mac, coords, msg = mac_ij, coords_ij, msg_ij - ii, jj = i, j - w_best, h_best = w_inc, h_inc - d_best = 2 + # Again, loop over any brightened up images as well + for img_br in all_images: + for i in range(5): + for j in range(5): + w_s, h_s = i*w_inc, j*h_inc + img_sel = img_br[w_s:w_s+w_sel, h_s:h_s+h_sel] + cor_ij, mac_ij, coords_ij, msg_ij = get_macbeth_chart(img_sel, ref_data) + if cor_ij > cor: + cor = cor_ij + mac, coords, msg = mac_ij, coords_ij, msg_ij + ii, jj = i, j + w_best, h_best = w_inc, h_inc + d_best = 2 """ The following code checks for macbeth charts at even smaller scales. This @@ -238,7 +249,7 @@ def find_macbeth(Cam, img, mac_config=(0, 0)): print error or success message """ print(msg) - Cam.log += '\n' + msg + Cam.log += '\n' + str(msg) if msg == success_msg: coords_fit = coords Cam.log += '\nMacbeth chart vertices:\n' @@ -606,7 +617,7 @@ def get_macbeth_chart(img, ref_data): '\nNot enough squares found' '\nPossible problems:\n' '- Macbeth chart is occluded\n' - '- Macbeth chart is too dark of bright\n' + '- Macbeth chart is too dark or bright\n' ) ref_cents = np.array(ref_cents)