From patchwork Fri Jun 20 12:42:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Naushir Patuck X-Patchwork-Id: 23612 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 A6543BDE6B for ; Fri, 20 Jun 2025 12:45:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4BF7261538; Fri, 20 Jun 2025 14:45:09 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="gbIhFK7c"; dkim-atps=neutral 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 5C20968DEC for ; Fri, 20 Jun 2025 14:45:00 +0200 (CEST) Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-3a577f164c8so288296f8f.2 for ; Fri, 20 Jun 2025 05:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1750423500; x=1751028300; 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=ZtR9/ErdKUSfx6biHWA2K9BllLNkDfqCLyVdT4Rw+b8=; b=gbIhFK7c78OFkcQTyE+YuhwTuKf7RcnYDjCQvdXttZER24g7NKyX8O6aL9svo/fju0 lgslcCrtVmlaGa8mpjRV9EfspQv5yUIPvJWS35pN3qMbn6mls2NDVEAmoeco9SIpicex JfQ1p5pX2BCs03AOgc2wmEMXMzBEjXRmgiA8OSQ+cMGHoYkERaV/ODA7zSbg2MEddLJT QrS9bDVT8zbCex9S7BECfJkWqdkO6IF9nqCsADO9J9weG33JcVriEhUoANYFx9dn1RzC OOvTFKd0uq9lgK6Y5o6LLXxnmTM8uYvJyIP8L4ZpB+CMZb0nFCBWwRNp7B4Sormi2CC3 n0Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1750423500; x=1751028300; 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=ZtR9/ErdKUSfx6biHWA2K9BllLNkDfqCLyVdT4Rw+b8=; b=DNX6fTRipl5zEqdD+1vWWr9pqEmP+DwxapEXQkN84C0v88y3/S5Ra2gO/jNPzYCRaM xdhw6vt43hU8Wy5NH3yrs8gBCw/3Qtwv4ZT4jLdW6dUbfV5Hd4l6ULacRmSQVWT+eao9 2vXrXGBMFCthYdU37fmchb/Y3WgrDPdsBJrZlw/oBReREjiKZy++ph0dHDJ5FUcDgRsd gXc1jMuVpaTgamJAi0eL2wT09QtYv0qNh4QUGtDP6bd667QoPE1TVbHrac53Izd3SMvV eIv0F9T9685h7eO+6YkcqLKEX1wttlim2sOEXY2TgcLKA31zvO2dPqMgS/jVgEbDuGup mnZA== X-Gm-Message-State: AOJu0Yzgt9i2JtnlqjKY2/gh3kvljnj4RIT7wEJZdAeHHL7jpcimagmA t9nZVgh7TwB4nA2WmGSRYEETEYa53cgVXUpr0/aMcIv/wFiNmro/B8uQ775KC1hg+vRxQzQ9tQ3 +fgOn X-Gm-Gg: ASbGncukm6OKLzyh5+e4T9g2w6mn26A4/ej2gCd4gK4ZZEGpr0aM4DlMu/Voe0ZKA5q iTVmicQSJzmK6urlxcONaYFMpBGVcP7jLqGBMQ4oSFS/Sqp04IIIWJcsWp7e8jatiMT3YDYgXVs 3yeUZ8EaWqZz9jl2/n/x8P/mv1Vl5rsh9R99qHuj3juTaljvvMBj8uj5kXQudzqpKDcA76p3OMg RubNjTQlJ4Q1V/pp5tIMto53Hj12OHUsnF5KTz/XmfcklHpxf1EbeXASmr82v9KSXBEa8YLYhyq RDL0xB4wMKLBXMlCErKkpghnm0t0kFi33pwYWA6mE+aB30JDLLyV6WK8HxtfSfWyNQ5uJh4xcXL 64a2zug== X-Google-Smtp-Source: AGHT+IEm+Fmnq9dEsZe60wPFdFCigAjle+kLrRC7WkeF+oRlF01b0ILE6Ukt/Ej640THCx6Y50GRdQ== X-Received: by 2002:a05:600c:6989:b0:43d:fa58:81d2 with SMTP id 5b1f17b1804b1-453659b60b2mr10262525e9.9.1750423499612; Fri, 20 Jun 2025 05:44:59 -0700 (PDT) Received: from NAUSH-P-DELL.pitowers.org ([93.93.133.154]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-45361461375sm41561525e9.14.2025.06.20.05.44.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Jun 2025 05:44:59 -0700 (PDT) From: Naushir Patuck To: libcamera-devel@lists.libcamera.org Cc: Nick Hollinghurst , Naushir Patuck Subject: [PATCH v1 4/8] ipa: rpi: controller: Autofocus CAF/PDAF stability tweak Date: Fri, 20 Jun 2025 13:42:25 +0100 Message-ID: <20250620124452.557855-5-naush@raspberrypi.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250620124452.557855-1-naush@raspberrypi.com> References: <20250620124452.557855-1-naush@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" From: Nick Hollinghurst When in Continuous AF mode using PDAF, only move the lens when phase has had the same sign for at least 4 frames. This reduces lens wobble in e.g. noisy conditions. Signed-off-by: Nick Hollinghurst Signed-off-by: Naushir Patuck Reviewed-by: Naushir Patuck --- src/ipa/rpi/controller/rpi/af.cpp | 12 +++++++++++- src/ipa/rpi/controller/rpi/af.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/ipa/rpi/controller/rpi/af.cpp b/src/ipa/rpi/controller/rpi/af.cpp index 5304f54ca967..3b2d6167df61 100644 --- a/src/ipa/rpi/controller/rpi/af.cpp +++ b/src/ipa/rpi/controller/rpi/af.cpp @@ -181,9 +181,11 @@ Af::Af(Controller *controller) ftarget_(-1.0), fsmooth_(-1.0), prevContrast_(0.0), + prevPhase_(0.0), skipCount_(0), stepCount_(0), dropCount_(0), + sameSignCount_(0), scanMaxContrast_(0.0), scanMinContrast_(1.0e9), scanData_(), @@ -513,6 +515,13 @@ void Af::doAF(double contrast, double phase, double conf) return; } + /* Count frames for which PDAF phase has had same sign */ + if (phase * prevPhase_ <= 0.0) + sameSignCount_ = 0; + else + sameSignCount_++; + prevPhase_ = phase; + if (scanState_ == ScanState::Pdaf) { /* * Use PDAF closed-loop control whenever available, in both CAF @@ -522,7 +531,8 @@ void Af::doAF(double contrast, double phase, double conf) * scan only after a number of frames with low PDAF confidence. */ if (conf > (dropCount_ ? 1.0 : 0.25) * cfg_.confEpsilon) { - doPDAF(phase, conf); + if (mode_ == AfModeAuto || sameSignCount_ >= 3) + doPDAF(phase, conf); if (stepCount_ > 0) stepCount_--; else if (mode_ != AfModeContinuous) diff --git a/src/ipa/rpi/controller/rpi/af.h b/src/ipa/rpi/controller/rpi/af.h index d8ece1ab119c..b06a3a16fab5 100644 --- a/src/ipa/rpi/controller/rpi/af.h +++ b/src/ipa/rpi/controller/rpi/af.h @@ -158,7 +158,9 @@ private: bool initted_; double ftarget_, fsmooth_; double prevContrast_; + double prevPhase_; unsigned skipCount_, stepCount_, dropCount_; + unsigned sameSignCount_; unsigned scanMaxIndex_; double scanMaxContrast_, scanMinContrast_; std::vector scanData_;