From patchwork Fri Jan 22 10:22:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 10954 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 EB233BD808 for ; Fri, 22 Jan 2021 10:22:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id A386C68244; Fri, 22 Jan 2021 11:22:28 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="JsI6qv6W"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id C46A968232 for ; Fri, 22 Jan 2021 11:22:26 +0100 (CET) Received: by mail-wr1-x42a.google.com with SMTP id a12so4546978wrv.8 for ; Fri, 22 Jan 2021 02:22:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zb3NETcE7o4MJ7BSr2BjfXSGp5ODCyGLNCbIC2n8h1M=; b=JsI6qv6W/nsQiCM6z8FLjsmaz8urpnVjPVV+AjT7FvmjRqr9hq66oj74jhtPrDiPyN hhHf84e+Tpt95oyt+j/4mZfe5BVtLDrMPR7Q6nbIG/KGlU7/3Q0Z341GekAo5mPD7S6P Zmof0w42w/KHiY6slCdADlyDMrM5HYW3o2+zvP0rj/Xd92ia8Ia9upF0PhN7CCJW1Bpq GF9ZC99luYty8K2DaWPjqeT4xPEc2GXxZjDTZO2ygZTJFh5D2yMcmMqbbWvD7Itjjgk2 XgRxG28xwFe4kfQ9sPsBFwZMTVKG0+Y9p/WIfX/gddOFp5NJsc1aXa1Dw3/TFjLmoH5F vd6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zb3NETcE7o4MJ7BSr2BjfXSGp5ODCyGLNCbIC2n8h1M=; b=Hu62QzdCeU5wyBUoUvwCU/lSNPzvutk8JCq0Hd9PWh8SDkXblhET1u/iSVs5hLaGuN OYqnq0ITh7sWgFOl8iHxhnyQMUYlbym0hy3hyl4rQwfPKQQqR9Bm+es25eoNY30NNuW7 b9RPCt+PrjpGcC5RcthOvq1nX57x5m7mDnD1yA5ac5/jcpRpzMeZU2nteLv8HCkFA8HF 6mCNfTng97U6lrEPsXnIoWNFXWfdX5BdgnltsMcuQPmbtHhTMw8MSBfLrsWeAcwUORDD oYIfN8rKgqhZzO+3qwkJ8m1GBz9FufrKhG6husfjXG4GxOOAMKsIDKWyXkxJpk7XpigS VMmQ== X-Gm-Message-State: AOAM532IcjvVCR4SJ/oDW7/eEX53mK2XUKM8vV8WXZ5gaS7AARNTGd0Z VWddxTf7oamklwp+TvX5I7tuQfcqtVmS0b5g X-Google-Smtp-Source: ABdhPJwycL+cV+BjhJpbVzZWuLQw/w2lpfRpPKhioOtJO1rK75cnCCztSDOTs+wQHx9CeJ9D11ZSGQ== X-Received: by 2002:adf:edc8:: with SMTP id v8mr3713385wro.374.1611310946012; Fri, 22 Jan 2021 02:22:26 -0800 (PST) Received: from pi4-davidp.lan (plowpeople3.plus.com. [80.229.223.72]) by smtp.gmail.com with ESMTPSA id p15sm11469221wrt.15.2021.01.22.02.22.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jan 2021 02:22:25 -0800 (PST) From: David Plowman To: libcamera-devel@lists.libcamera.org Date: Fri, 22 Jan 2021 10:22:09 +0000 Message-Id: <20210122102211.12768-4-david.plowman@raspberrypi.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210122102211.12768-1-david.plowman@raspberrypi.com> References: <20210122102211.12768-1-david.plowman@raspberrypi.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/5] ipa: raspberrypi: awb: Replace Raspberry Pi debug with libcamera debug 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" Signed-off-by: David Plowman --- src/ipa/raspberrypi/controller/rpi/awb.cpp | 92 +++++++++++----------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp index f66c2b29..34f3644b 100644 --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp @@ -5,12 +5,16 @@ * awb.cpp - AWB control algorithm */ -#include "../logging.hpp" +#include "libcamera/internal/log.h" + #include "../lux_status.h" #include "awb.hpp" using namespace RPiController; +using namespace libcamera; + +LOG_DEFINE_CATEGORY(RPiAwb) #define NAME "rpi.awb" @@ -58,7 +62,7 @@ static void read_ct_curve(Pwl &ct_r, Pwl &ct_b, void AwbConfig::Read(boost::property_tree::ptree const ¶ms) { - RPI_LOG("AwbConfig"); + LOG(RPiAwb, Debug) << "AwbConfig"; bayes = params.get("bayes", 1); frame_period = params.get("frame_period", 10); startup_frames = params.get("startup_frames", 10); @@ -104,8 +108,7 @@ void AwbConfig::Read(boost::property_tree::ptree const ¶ms) if (bayes) { if (ct_r.Empty() || ct_b.Empty() || priors.empty() || default_mode == nullptr) { - RPI_WARN( - "Bayesian AWB mis-configured - switch to Grey method"); + LOG(RPiAwb, Warning) << "Bayesian AWB mis-configured - switch to Grey method"; bayes = false; } } @@ -220,7 +223,7 @@ void Awb::SwitchMode([[maybe_unused]] CameraMode const &camera_mode, void Awb::fetchAsyncResults() { - RPI_LOG("Fetch AWB results"); + LOG(RPiAwb, Debug) << "Fetch AWB results"; async_finished_ = false; async_started_ = false; sync_results_ = async_results_; @@ -229,7 +232,7 @@ void Awb::fetchAsyncResults() void Awb::restartAsync(StatisticsPtr &stats, std::string const &mode_name, double lux) { - RPI_LOG("Starting AWB thread"); + LOG(RPiAwb, Debug) << "Starting AWB thread"; // this makes a new reference which belongs to the asynchronous thread statistics_ = stats; // store the mode as it could technically change @@ -254,11 +257,11 @@ void Awb::Prepare(Metadata *image_metadata) double speed = frame_count_ < (int)config_.startup_frames ? 1.0 : config_.speed; - RPI_LOG("Awb: frame_count " << frame_count_ << " speed " << speed); + LOG(RPiAwb, Debug) << "Awb: frame_count " << frame_count_ << " speed " << speed; { std::unique_lock lock(mutex_); if (async_started_ && async_finished_) { - RPI_LOG("AWB thread finished"); + LOG(RPiAwb, Debug) << "AWB thread finished"; fetchAsyncResults(); } } @@ -275,9 +278,9 @@ void Awb::Prepare(Metadata *image_metadata) prev_sync_results_.gain_b = speed * sync_results_.gain_b + (1.0 - speed) * prev_sync_results_.gain_b; image_metadata->Set("awb.status", prev_sync_results_); - RPI_LOG("Using AWB gains r " << prev_sync_results_.gain_r << " g " - << prev_sync_results_.gain_g << " b " - << prev_sync_results_.gain_b); + LOG(RPiAwb, Debug) << "Using AWB gains r " << prev_sync_results_.gain_r << " g " + << prev_sync_results_.gain_g << " b " + << prev_sync_results_.gain_b; } void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata) @@ -287,7 +290,7 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata) frame_phase_++; if (frame_count2_ < (int)config_.startup_frames) frame_count2_++; - RPI_LOG("Awb: frame_phase " << frame_phase_); + LOG(RPiAwb, Debug) << "Awb: frame_phase " << frame_phase_; if (frame_phase_ >= (int)config_.frame_period || frame_count2_ < (int)config_.startup_frames) { // Update any settings and any image metadata that we need. @@ -299,12 +302,12 @@ void Awb::Process(StatisticsPtr &stats, Metadata *image_metadata) struct LuxStatus lux_status = {}; lux_status.lux = 400; // in case no metadata if (image_metadata->Get("lux.status", lux_status) != 0) - RPI_LOG("No lux metadata found"); - RPI_LOG("Awb lux value is " << lux_status.lux); + LOG(RPiAwb, Debug) << "No lux metadata found"; + LOG(RPiAwb, Debug) << "Awb lux value is " << lux_status.lux; std::unique_lock lock(mutex_); if (async_started_ == false) { - RPI_LOG("AWB thread starting"); + LOG(RPiAwb, Debug) << "AWB thread starting"; restartAsync(stats, mode_name, lux_status.lux); } } @@ -375,7 +378,7 @@ double Awb::computeDelta2Sum(double gain_r, double gain_b) double delta_r = gain_r * z.R - 1 - config_.whitepoint_r; double delta_b = gain_b * z.B - 1 - config_.whitepoint_b; double delta2 = delta_r * delta_r + delta_b * delta_b; - //RPI_LOG("delta_r " << delta_r << " delta_b " << delta_b << " delta2 " << delta2); + //LOG(RPiAwb, Debug) << "delta_r " << delta_r << " delta_b " << delta_b << " delta2 " << delta2; delta2 = std::min(delta2, config_.delta_limit); delta2_sum += delta2; } @@ -438,10 +441,10 @@ double Awb::coarseSearch(Pwl const &prior) double prior_log_likelihood = prior.Eval(prior.Domain().Clip(t)); double final_log_likelihood = delta2_sum - prior_log_likelihood; - RPI_LOG("t: " << t << " gain_r " << gain_r << " gain_b " - << gain_b << " delta2_sum " << delta2_sum - << " prior " << prior_log_likelihood << " final " - << final_log_likelihood); + LOG(RPiAwb, Debug) << "t: " << t << " gain_r " << gain_r << " gain_b " + << gain_b << " delta2_sum " << delta2_sum + << " prior " << prior_log_likelihood << " final " + << final_log_likelihood; points_.push_back(Pwl::Point(t, final_log_likelihood)); if (points_.back().y < points_[best_point].y) best_point = points_.size() - 1; @@ -452,7 +455,7 @@ double Awb::coarseSearch(Pwl const &prior) mode_->ct_hi); } t = points_[best_point].x; - RPI_LOG("Coarse search found CT " << t); + LOG(RPiAwb, Debug) << "Coarse search found CT " << t; // We have the best point of the search, but refine it with a quadratic // interpolation around its neighbours. if (points_.size() > 2) { @@ -461,8 +464,8 @@ double Awb::coarseSearch(Pwl const &prior) t = interpolate_quadatric(points_[best_point - 1], points_[best_point], points_[best_point + 1]); - RPI_LOG("After quadratic refinement, coarse search has CT " - << t); + LOG(RPiAwb, Debug) << "After quadratic refinement, coarse search has CT " + << t; } return t; } @@ -514,8 +517,8 @@ void Awb::fineSearch(double &t, double &r, double &b, Pwl const &prior) double gain_r = 1 / r_test, gain_b = 1 / b_test; double delta2_sum = computeDelta2Sum(gain_r, gain_b); points[j].y = delta2_sum - prior_log_likelihood; - RPI_LOG("At t " << t_test << " r " << r_test << " b " - << b_test << ": " << points[j].y); + LOG(RPiAwb, Debug) << "At t " << t_test << " r " << r_test << " b " + << b_test << ": " << points[j].y; if (points[j].y < points[best_point].y) best_point = j; } @@ -532,17 +535,16 @@ void Awb::fineSearch(double &t, double &r, double &b, Pwl const &prior) double gain_r = 1 / r_test, gain_b = 1 / b_test; double delta2_sum = computeDelta2Sum(gain_r, gain_b); double final_log_likelihood = delta2_sum - prior_log_likelihood; - RPI_LOG("Finally " - << t_test << " r " << r_test << " b " << b_test << ": " - << final_log_likelihood - << (final_log_likelihood < best_log_likelihood ? " BEST" - : "")); + LOG(RPiAwb, Debug) << "Finally " + << t_test << " r " << r_test << " b " << b_test << ": " + << final_log_likelihood + << (final_log_likelihood < best_log_likelihood ? " BEST" : ""); if (best_t == 0 || final_log_likelihood < best_log_likelihood) best_log_likelihood = final_log_likelihood, best_t = t_test, best_r = r_test, best_b = b_test; } t = best_t, r = best_r, b = best_b; - RPI_LOG("Fine search found t " << t << " r " << r << " b " << b); + LOG(RPiAwb, Debug) << "Fine search found t " << t << " r " << r << " b " << b; } void Awb::awbBayes() @@ -556,13 +558,13 @@ void Awb::awbBayes() Pwl prior = interpolatePrior(); prior *= zones_.size() / (double)(AWB_STATS_SIZE_X * AWB_STATS_SIZE_Y); prior.Map([](double x, double y) { - RPI_LOG("(" << x << "," << y << ")"); + LOG(RPiAwb, Debug) << "(" << x << "," << y << ")"; }); double t = coarseSearch(prior); double r = config_.ct_r.Eval(t); double b = config_.ct_b.Eval(t); - RPI_LOG("After coarse search: r " << r << " b " << b << " (gains r " - << 1 / r << " b " << 1 / b << ")"); + LOG(RPiAwb, Debug) << "After coarse search: r " << r << " b " << b << " (gains r " + << 1 / r << " b " << 1 / b << ")"; // Not entirely sure how to handle the fine search yet. Mostly the // estimated CT is already good enough, but the fine search allows us to // wander transverely off the CT curve. Under some illuminants, where @@ -570,8 +572,8 @@ void Awb::awbBayes() // though I probably need more real datasets before deciding exactly how // this should be controlled and tuned. fineSearch(t, r, b, prior); - RPI_LOG("After fine search: r " << r << " b " << b << " (gains r " - << 1 / r << " b " << 1 / b << ")"); + LOG(RPiAwb, Debug) << "After fine search: r " << r << " b " << b << " (gains r " + << 1 / r << " b " << 1 / b << ")"; // Write results out for the main thread to pick up. Remember to adjust // the gains from the ones that the "canonical sensor" would require to // the ones needed by *this* sensor. @@ -583,7 +585,7 @@ void Awb::awbBayes() void Awb::awbGrey() { - RPI_LOG("Grey world AWB"); + LOG(RPiAwb, Debug) << "Grey world AWB"; // Make a separate list of the derivatives for each of red and blue, so // that we can sort them to exclude the extreme gains. We could // consider some variations, such as normalising all the zones first, or @@ -620,21 +622,21 @@ void Awb::doAwb() async_results_.gain_r = manual_r_; async_results_.gain_g = 1.0; async_results_.gain_b = manual_b_; - RPI_LOG("Using manual white balance: gain_r " - << async_results_.gain_r << " gain_b " - << async_results_.gain_b); + LOG(RPiAwb, Debug) << "Using manual white balance: gain_r " + << async_results_.gain_r << " gain_b " + << async_results_.gain_b; } else { prepareStats(); - RPI_LOG("Valid zones: " << zones_.size()); + LOG(RPiAwb, Debug) << "Valid zones: " << zones_.size(); if (zones_.size() > config_.min_regions) { if (config_.bayes) awbBayes(); else awbGrey(); - RPI_LOG("CT found is " - << async_results_.temperature_K - << " with gains r " << async_results_.gain_r - << " and b " << async_results_.gain_b); + LOG(RPiAwb, Debug) << "CT found is " + << async_results_.temperature_K + << " with gains r " << async_results_.gain_r + << " and b " << async_results_.gain_b; } } }