[{"id":34075,"web_url":"https://patchwork.libcamera.org/comment/34075/","msgid":"<CAEmqJPqXaM-iOzM+Dk8oqWJX=gasZb_bk=+fHtN9EUZawKMwKw@mail.gmail.com>","date":"2025-04-28T13:20:47","subject":"Re: [PATCH 2/2] utils: raspberrypi: ctt: Fix NaNs in chromatic\n\taberration tables","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\nOn Mon, 28 Apr 2025 at 11:36, David Plowman\n<david.plowman@raspberrypi.com> wrote:\n>\n> NaNs can appear if no black dots can be found and analysed in a\n> particular region of the calibration image. There needs to be at least\n> one such dot in every 8x8 cell covering the image.\n>\n> This is now detected, and an error message issued. No CAC tables are\n> generated, so CAC is disabled.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n> ---\n>  utils/raspberrypi/ctt/ctt.py     |  9 ++++++---\n>  utils/raspberrypi/ctt/ctt_cac.py | 32 +++++++++++++++++++++++++++-----\n>  2 files changed, 33 insertions(+), 8 deletions(-)\n>\n> diff --git a/utils/raspberrypi/ctt/ctt.py b/utils/raspberrypi/ctt/ctt.py\n> index 96f1b5e6..186afda5 100755\n> --- a/utils/raspberrypi/ctt/ctt.py\n> +++ b/utils/raspberrypi/ctt/ctt.py\n> @@ -198,9 +198,12 @@ class Camera:\n>          \"\"\"\n>          Write output to json\n>          \"\"\"\n> -        self.json['rpi.cac']['cac'] = cacs\n> -        self.log += '\\nCAC calibration written to json file'\n> -        print('Finished CAC calibration')\n> +        if cacs:\n> +            self.json['rpi.cac']['cac'] = cacs\n> +            self.log += '\\nCAC calibration written to json file'\n> +            print('Finished CAC calibration')\n> +        else:\n> +            self.log += \"\\nCAC calibration failed\"\n>\n>\n>      \"\"\"\n> diff --git a/utils/raspberrypi/ctt/ctt_cac.py b/utils/raspberrypi/ctt/ctt_cac.py\n> index 5a4c5101..a1183989 100644\n> --- a/utils/raspberrypi/ctt/ctt_cac.py\n> +++ b/utils/raspberrypi/ctt/ctt_cac.py\n> @@ -108,12 +108,29 @@ def shifts_to_yaml(red_shift, blue_shift, image_dimensions, output_grid_size=9):\n>          ybsgrid[xgridloc][ygridloc].append(blue_shift[3])\n>\n>      # Now calculate the average pixel shift for each square in the grid\n> +    grid_incomplete = False\n>      for x in range(output_grid_size - 1):\n>          for y in range(output_grid_size - 1):\n> -            xrgrid[x, y] = np.mean(xrsgrid[x][y])\n> -            yrgrid[x, y] = np.mean(yrsgrid[x][y])\n> -            xbgrid[x, y] = np.mean(xbsgrid[x][y])\n> -            ybgrid[x, y] = np.mean(ybsgrid[x][y])\n> +            if xrsgrid[x][y]:\n> +                xrgrid[x, y] = np.mean(xrsgrid[x][y])\n> +            else:\n> +                grid_incomplete = True\n> +            if yrsgrid[x][y]:\n> +                yrgrid[x, y] = np.mean(yrsgrid[x][y])\n> +            else:\n> +                grid_incomplete = True\n> +            if xbsgrid[x][y]:\n> +                xbgrid[x, y] = np.mean(xbsgrid[x][y])\n> +            else:\n> +                grid_incomplete = True\n> +            if ybsgrid[x][y]:\n> +                ybgrid[x, y] = np.mean(ybsgrid[x][y])\n> +            else:\n> +                grid_incomplete = True\n> +\n> +    if grid_incomplete:\n> +        raise RuntimeError(\"\\nERROR: CAC measurements do not span the image!\"\n> +                           \"\\nConsider using improved CAC images, or remove them entirely.\\n\")\n>\n>      # Next, we start to interpolate the central points of the grid that gets passed to the tuning file\n>      input_grids = np.array([xrgrid, yrgrid, xbgrid, ybgrid])\n> @@ -219,7 +236,12 @@ def cac(Cam):\n>      # tuning file\n>      print(\"\\nCreating output grid\")\n>      Cam.log += '\\nCreating output grid'\n> -    rx, ry, bx, by = shifts_to_yaml(red_shift, blue_shift, image_size)\n> +    try:\n> +        rx, ry, bx, by = shifts_to_yaml(red_shift, blue_shift, image_size)\n> +    except RuntimeError as e:\n> +        print(str(e))\n> +        Cam.log += \"\\nCAC correction failed! CAC will not be enabled.\"\n> +        return {}\n>\n>      print(\"CAC correction complete!\")\n>      Cam.log += '\\nCAC correction complete!'\n> --\n> 2.34.1\n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":["parsemail@patchwork.libcamera.org","kbingham@ideasonboard.com"],"Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0953BBE08B\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Apr 2025 15:10:33 +0000 (UTC)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net\n\t[86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 52715AF\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 29 Apr 2025 17:10:27 +0200 (CEST)","from perceval.ideasonboard.com\n\tby perceval.ideasonboard.com with LMTP id 6KHkIs2AD2jFkDMA4E0KoQ\n\t(envelope-from <libcamera-devel-bounces@lists.libcamera.org>)\n\tfor <kbingham@ideasonboard.com>; Mon, 28 Apr 2025 15:21:17 +0200","from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\tby perceval.ideasonboard.com (Postfix) with ESMTPS\n\tid 6A71D1E3;\tMon, 28 Apr 2025 15:21:17 +0200 (CEST)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 4C73268ADA;\n\tMon, 28 Apr 2025 15:21:21 +0200 (CEST)","from mail-ua1-x935.google.com (mail-ua1-x935.google.com\n\t[IPv6:2607:f8b0:4864:20::935])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F27EF68AD0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Apr 2025 15:21:18 +0200 (CEST)","by mail-ua1-x935.google.com with SMTP id\n\ta1e0cc1a2514c-86d587c61a1so274053241.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 28 Apr 2025 06:21:18 -0700 (PDT)"],"Authentication-Results":["perceval.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.a=rsa-sha256 header.s=google header.b=ozMdt+Ng; \n\tdkim-atps=neutral","lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"ozMdt+Ng\";\tdkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1745846478; x=1746451278;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=NbUoJ2/VV9Y8BqBEsDkqeR0rcrxZ4Na1W29251wxIOQ=;\n\tb=ozMdt+Ng6EqtAox3VfjooGXgxLxnt6N+OsIyGy/MrlNORhbG9SGzfHV+5I8kDGTX7W\n\trZay5P6C9B+s7X2WoKaNQh2oR/I+9YVwk0wlP5inJZ8N/8Udh7eDMmMxEQ4mhYxHntW+\n\trJfezmmsSroSBDzDoUdpNbRZ8dsE96Bn4RDk2WiFTq9r1EWhYrIWddrBA4ngPebwSKuo\n\tqIIR0J1kQoduTdNuS048LgDPw3ksnLEQ1/Erl5YKmR978Og8Y00GhuIIpVn3o8nc41Wi\n\thE/hPcRjStbAR7oCCcYzoYkGc25HZBpfyZu0oni0nCE4RwAk+byTaiV75lkMmoDiC7Gg\n\tye/A==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1745846478; x=1746451278;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=NbUoJ2/VV9Y8BqBEsDkqeR0rcrxZ4Na1W29251wxIOQ=;\n\tb=UvSXWRCAqucN8MZJ7+//32AzZUb5Y6M3Qpi1QskXP7O580TmgB/G4onXjEWanFNKXT\n\tAa60KLGJ3GAyRYgsgzehQ/ShG9hLQwncIZce5Pl03pK8dRlfGWfqNigp2IarzOfGhxox\n\ttID6G5PliIDTSef+nmF++KFDfQvCTyB9UHGSSPlJfUxzoL6cye4J8wx3rqptRDFmfml/\n\tkrUTyQS9fk9hmluUgsl27owZDUn8sqgFg66kDC+rL/GLcCisiTCwc1yenVJQm1RbKmLM\n\tNWWahCCWozhfoCJIADGcJ19ZUn/G6noCF6pEGT585dCd4TzwqO+HuiplG/YA3fQvAKoD\n\tWF9w==","X-Gm-Message-State":"AOJu0Yylx9fKwaX6BybnC717Ax+vL4o8P+w6pMZDMonZ9mFuiQa3XqMB\n\tPyGCmMl/9cvUC5aPYpIB3OIySC5SVRQJAdr6yp0Cy2heHoT73afO1Bx8E6HMbeS4ZtHX+anATgm\n\t1FnYF4oq+R+jry4A81s33TG4U7zNPDjsQyOBoOQ==","X-Gm-Gg":"ASbGncvjjfeVrBr0sjgXDPL6440lbud6tCkRIvqq/W/dpj3ogTVdSggTFbjm8NYrbqq\n\tysSQqxrOWbhMXeTCZiDdCaQLTCP+g8qYf3+f4gC2628fjnfd/Srl4dWK78RlIOOsHV7rdxZQDfP\n\tmH6mTO7XHXFvjxaNnFn8nt+C4C4hF8xHCgy8z/qd10y56OF1vqz2vcXQ==","X-Google-Smtp-Source":"=?utf-8?q?AGHT+IFDF80seGYN6+Yu68VvNGmCyaEAjJC7LfCHN?=\n\t=?utf-8?q?QZl+LeDSnXQ+ikVr7M08y6lBkjgao9dfzAJOk7h7ufHeCz3xR8=3D?=","X-Received":"by 2002:a05:6102:2081:b0:4c1:9610:fedb with SMTP id\n\tada2fe7eead31-4d545268b3amr2137531137.5.1745846477870;\n\tMon, 28 Apr 2025 06:21:17 -0700 (PDT)","MIME-Version":"1.0","References":"<20250428103604.151551-1-david.plowman@raspberrypi.com>\n\t<20250428103604.151551-3-david.plowman@raspberrypi.com>","In-Reply-To":"<20250428103604.151551-3-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Mon, 28 Apr 2025 14:20:47 +0100","X-Gm-Features":"ATxdqUGmcOrZdkJX6jKMK7KUHkJpOV6HXxidx2AYBX_hDqxgIvNItt2HQJ4YXFE","Message-ID":"<CAEmqJPqXaM-iOzM+Dk8oqWJX=gasZb_bk=+fHtN9EUZawKMwKw@mail.gmail.com>","Subject":"Re: [PATCH 2/2] utils: raspberrypi: ctt: Fix NaNs in chromatic\n\taberration tables","To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"text/plain; charset=\"UTF-8\"","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>","X-TUID":"wzVA7juNC055","Resent-From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Resent-To":"parsemail@patchwork.libcamera.org"}}]