From patchwork Mon Apr 28 10:36:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 23294 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 C982CC331E for ; Mon, 28 Apr 2025 10:36:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6EFE868AD9; Mon, 28 Apr 2025 12:36:12 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="q5QEHmAy"; dkim-atps=neutral Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4B51D68AD0 for ; Mon, 28 Apr 2025 12:36:09 +0200 (CEST) Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-43cfa7e7f54so30651475e9.1 for ; Mon, 28 Apr 2025 03:36:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1745836568; x=1746441368; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5joiZvz1p7nQlQ68R/6+IBWH9tU58Kcenv9xI4HsEGU=; b=q5QEHmAyL2GIIT7usy4b/TeSQ3YnuAXnP0P+BgJ/YSz2Fn4tEztBUtmT7SwVDkKPrU oxoJEqnpeafTgURDWw5d474+Y7kybASVQjDhesZBuz6HaTi3PbpagS7V0bEf6XOexMe4 6e1YNGt+CePRie7g3AYw9YDgUZfSHTDYsRRmkWb8NxttQrs0kg28kEcckcUS9Cv/TNYS EdGMGWoqvzkFaJdUcYrsdkOvcf6Qw+OFgFURuKnBV+pN4Y2ksyw40kFtWaYj6ijvg6io AYKiYnn+VB2p7myOppdVyBGEB8aL4KGSyD5GRhDV7Tuj+qh1pvBmVD9x3yDtBiEjGq2Q 9mJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745836568; x=1746441368; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5joiZvz1p7nQlQ68R/6+IBWH9tU58Kcenv9xI4HsEGU=; b=l30Fg8Pqfj/OdY034Xu524RKgwcswPGeFSWPLsNePaRF9uLMSMl1rJz7Y+7NGs9bgv 8hZTLadW2RtLM6xVMiQ3zbqjpYADiNwOO2sLj3oK5nGKFxlr2Xpbhv5RpX00YGS69M9k FH33+fMLB4+3xLuPbddPa/PWDAwYAh61f36jzd+c83haO2G5KbnX6Zye8lR3yG0pHS1s yDb2dVxOrwEL94p3FNYH/BrEaNY9fPEu4aEJuxggTB4c4XHJpU45x+KBZozUShJrqtbL eJytErdIzQKk7m+f3DiXD6Ll8C3OMM+4BwxCb6D4YlwyiqymwyWpLKJx4/dxZ8OLr2ZD h5Cw== X-Gm-Message-State: AOJu0YwMluEz44GiG9R6jc4oY1aMja/kgEOlP9OB5mH3AiGXSYE16VgU /CcLJSiL5R8HUJj9FkLPVaPHHATXGu+TeJiWmBdAHubcpXotKxTqXgjhiHHnmHeISDQPV+gbpXF S X-Gm-Gg: ASbGnctrHEnqe3wWY5lYCwBFv2l5qEQ0zvFltJ9jChS8uZsl5S/E3rofvw+yxx19UqP LVMxKzwqCz86hwUyqRY3G8C2LBPkiyDe45xT7U1ehUWRhB+s5Xl23U9bD0krkjN8QsQXTvBriLo +5qGNeoFuI8rVVlL/8wJ6hUDbISFNeRET+Q+Gg5wur7keQDaq74FQ40hstxGqBPa5NLnX37/7mT QWmK1Xvd/GO31n3EcX5ECEDTOOmG1SmFx7HifPErhq5jq3QQuGOwtmjPqq9JN6IUs2uje0TCoYt 7kLSqcfQ6TWX4zVLKNtu6nmDNMZq0OAdMLR8ng5PRpDqay2FlEwoUco7po+cDl2q3QckoNpklj8 = X-Google-Smtp-Source: AGHT+IEJM97PuEIzwjCkmFxV69yMZCbt4WyGxzjTDorpWFG64qxiJFATuVIVmCqRQWsDg5MIIpWljw== X-Received: by 2002:a05:600c:1d81:b0:439:4c1e:d810 with SMTP id 5b1f17b1804b1-440a65eeacdmr88407495e9.9.1745836568513; Mon, 28 Apr 2025 03:36:08 -0700 (PDT) Received: from davidp-xps-13.pitowers.org ([2a00:1098:3142:1f:6594:d5bc:c5ae:99b5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4408d04802fsm116243185e9.1.2025.04.28.03.36.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Apr 2025 03:36:08 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH 2/2] utils: raspberrypi: ctt: Fix NaNs in chromatic aberration tables Date: Mon, 28 Apr 2025 11:36:04 +0100 Message-Id: <20250428103604.151551-3-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250428103604.151551-1-david.plowman@raspberrypi.com> References: <20250428103604.151551-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" NaNs can appear if no black dots can be found and analysed in a particular region of the calibration image. There needs to be at least one such dot in every 8x8 cell covering the image. This is now detected, and an error message issued. No CAC tables are generated, so CAC is disabled. Signed-off-by: David Plowman Reviewed-by: Naushir Patuck --- utils/raspberrypi/ctt/ctt.py | 9 ++++++--- utils/raspberrypi/ctt/ctt_cac.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py index 96f1b5e6..186afda5 100755 --- a/utils/raspberrypi/ctt/ctt.py +++ b/utils/raspberrypi/ctt/ctt.py @@ -198,9 +198,12 @@ class Camera: """ Write output to json """ - self.json['rpi.cac']['cac'] = cacs - self.log += '\nCAC calibration written to json file' - print('Finished CAC calibration') + if cacs: + self.json['rpi.cac']['cac'] = cacs + self.log += '\nCAC calibration written to json file' + print('Finished CAC calibration') + else: + self.log += "\nCAC calibration failed" """ diff --git a/utils/raspberrypi/ctt/ctt_cac.py b/utils/raspberrypi/ctt/ctt_cac.py index 5a4c5101..a1183989 100644 --- a/utils/raspberrypi/ctt/ctt_cac.py +++ b/utils/raspberrypi/ctt/ctt_cac.py @@ -108,12 +108,29 @@ def shifts_to_yaml(red_shift, blue_shift, image_dimensions, output_grid_size=9): ybsgrid[xgridloc][ygridloc].append(blue_shift[3]) # Now calculate the average pixel shift for each square in the grid + grid_incomplete = False for x in range(output_grid_size - 1): for y in range(output_grid_size - 1): - xrgrid[x, y] = np.mean(xrsgrid[x][y]) - yrgrid[x, y] = np.mean(yrsgrid[x][y]) - xbgrid[x, y] = np.mean(xbsgrid[x][y]) - ybgrid[x, y] = np.mean(ybsgrid[x][y]) + if xrsgrid[x][y]: + xrgrid[x, y] = np.mean(xrsgrid[x][y]) + else: + grid_incomplete = True + if yrsgrid[x][y]: + yrgrid[x, y] = np.mean(yrsgrid[x][y]) + else: + grid_incomplete = True + if xbsgrid[x][y]: + xbgrid[x, y] = np.mean(xbsgrid[x][y]) + else: + grid_incomplete = True + if ybsgrid[x][y]: + ybgrid[x, y] = np.mean(ybsgrid[x][y]) + else: + grid_incomplete = True + + if grid_incomplete: + raise RuntimeError("\nERROR: CAC measurements do not span the image!" + "\nConsider using improved CAC images, or remove them entirely.\n") # Next, we start to interpolate the central points of the grid that gets passed to the tuning file input_grids = np.array([xrgrid, yrgrid, xbgrid, ybgrid]) @@ -219,7 +236,12 @@ def cac(Cam): # tuning file print("\nCreating output grid") Cam.log += '\nCreating output grid' - rx, ry, bx, by = shifts_to_yaml(red_shift, blue_shift, image_size) + try: + rx, ry, bx, by = shifts_to_yaml(red_shift, blue_shift, image_size) + except RuntimeError as e: + print(str(e)) + Cam.log += "\nCAC correction failed! CAC will not be enabled." + return {} print("CAC correction complete!") Cam.log += '\nCAC correction complete!'