[libcamera-devel,v2,3/6] src: ipa: raspberrypi: agc: Add GetConvergenceFrames method to AWB base class
diff mbox series

Message ID 20201207180121.6374-4-david.plowman@raspberrypi.com
State Superseded
Headers show
Series
  • Raspberry Pi AGC: initial frame drop count
Related show

Commit Message

David Plowman Dec. 7, 2020, 6:01 p.m. UTC
We add a GetConvergenceFrames method to the AwbAlgorithm class which
can be called when the AWB is started from scratch. It suggests how
many frames should be dropped before displaying any (while the AWB
converges).

The Raspberry Pi specific implementation makes this customisable from
the tuning file.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
---
 src/ipa/raspberrypi/controller/awb_algorithm.hpp |  1 +
 src/ipa/raspberrypi/controller/rpi/awb.cpp       | 13 +++++++++++++
 src/ipa/raspberrypi/controller/rpi/awb.hpp       |  2 ++
 3 files changed, 16 insertions(+)

Comments

Naushir Patuck Dec. 8, 2020, 10:08 a.m. UTC | #1
Hi David,

Thank you for your patch.

On Mon, 7 Dec 2020 at 18:02, David Plowman <david.plowman@raspberrypi.com>
wrote:

> We add a GetConvergenceFrames method to the AwbAlgorithm class which
> can be called when the AWB is started from scratch. It suggests how
> many frames should be dropped before displaying any (while the AWB
> converges).
>
> The Raspberry Pi specific implementation makes this customisable from
> the tuning file.
>
> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
> ---
>  src/ipa/raspberrypi/controller/awb_algorithm.hpp |  1 +
>  src/ipa/raspberrypi/controller/rpi/awb.cpp       | 13 +++++++++++++
>  src/ipa/raspberrypi/controller/rpi/awb.hpp       |  2 ++
>  3 files changed, 16 insertions(+)
>
> diff --git a/src/ipa/raspberrypi/controller/awb_algorithm.hpp
> b/src/ipa/raspberrypi/controller/awb_algorithm.hpp
> index 5be0c9f4..84ae313b 100644
> --- a/src/ipa/raspberrypi/controller/awb_algorithm.hpp
> +++ b/src/ipa/raspberrypi/controller/awb_algorithm.hpp
> @@ -15,6 +15,7 @@ class AwbAlgorithm : public Algorithm
>  public:
>         AwbAlgorithm(Controller *controller) : Algorithm(controller) {}
>         // An AWB algorithm must provide the following:
> +       virtual unsigned int GetConvergenceFrames(unsigned int
> mistrust_frames) const = 0;
>         virtual void SetMode(std::string const &mode_name) = 0;
>         virtual void SetManualGains(double manual_r, double manual_b) = 0;
>  };
> diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp
> b/src/ipa/raspberrypi/controller/rpi/awb.cpp
> index 020825e3..6b359ac5 100644
> --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp
> +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp
> @@ -59,6 +59,7 @@ void AwbConfig::Read(boost::property_tree::ptree const
> &params)
>         bayes = params.get<int>("bayes", 1);
>         frame_period = params.get<uint16_t>("frame_period", 10);
>         startup_frames = params.get<uint16_t>("startup_frames", 10);
> +       convergence_frames = params.get<unsigned
> int>("convergence_frames", 3);
>         speed = params.get<double>("speed", 0.05);
>         if (params.get_child_optional("ct_curve"))
>                 read_ct_curve(ct_r, ct_b, params.get_child("ct_curve"));
> @@ -165,6 +166,18 @@ void Awb::Initialise()
>         prev_sync_results_ = sync_results_;
>  }
>
> +unsigned int Awb::GetConvergenceFrames(unsigned int mistrust_frames) const
> +{
> +       // If colour gains have been explicitly set, there is no
> convergence
> +       // to happen, so no need to drop any frames - return zero.
> +       // Otherwise, any frames for which we have been told not to trust
> the
> +       // statistics must be added to our own count.
> +       if (manual_r_ && manual_b_)
> +               return 0;
> +       else
> +               return config_.convergence_frames + mistrust_frames;
> +}
> +
>

Similar to the comment on the AGC patch, could you not leave
mistrust_frames out and do the addition of mistrust frames in the IPA?
Either way,

Reviewed-by: Naushir Patuck <naush@raspberrypi.com>


>  void Awb::SetMode(std::string const &mode_name)
>  {
>         std::unique_lock<std::mutex> lock(settings_mutex_);
> diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp
> b/src/ipa/raspberrypi/controller/rpi/awb.hpp
> index 545d85a8..d86b9598 100644
> --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp
> @@ -37,6 +37,7 @@ struct AwbConfig {
>         uint16_t frame_period;
>         // number of initial frames for which speed taken as 1.0 (maximum)
>         uint16_t startup_frames;
> +       unsigned int convergence_frames; // approx number of frames to
> converge
>         double speed; // IIR filter speed applied to algorithm results
>         bool fast; // "fast" mode uses a 16x16 rather than 32x32 grid
>         Pwl ct_r; // function maps CT to r (= R/G)
> @@ -82,6 +83,7 @@ public:
>         char const *Name() const override;
>         void Initialise() override;
>         void Read(boost::property_tree::ptree const &params) override;
> +       unsigned int GetConvergenceFrames(unsigned int mistrust_frames)
> const override;
>         void SetMode(std::string const &name) override;
>         void SetManualGains(double manual_r, double manual_b) override;
>         void SwitchMode(CameraMode const &camera_mode, Metadata *metadata)
> override;
> --
> 2.20.1
>
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel
>
Laurent Pinchart Dec. 8, 2020, 11:38 a.m. UTC | #2
Hi David,

Thank you for the patch.

On Mon, Dec 07, 2020 at 06:01:18PM +0000, David Plowman wrote:
> We add a GetConvergenceFrames method to the AwbAlgorithm class which
> can be called when the AWB is started from scratch. It suggests how
> many frames should be dropped before displaying any (while the AWB
> converges).
> 
> The Raspberry Pi specific implementation makes this customisable from
> the tuning file.
> 
> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> ---
>  src/ipa/raspberrypi/controller/awb_algorithm.hpp |  1 +
>  src/ipa/raspberrypi/controller/rpi/awb.cpp       | 13 +++++++++++++
>  src/ipa/raspberrypi/controller/rpi/awb.hpp       |  2 ++
>  3 files changed, 16 insertions(+)
> 
> diff --git a/src/ipa/raspberrypi/controller/awb_algorithm.hpp b/src/ipa/raspberrypi/controller/awb_algorithm.hpp
> index 5be0c9f4..84ae313b 100644
> --- a/src/ipa/raspberrypi/controller/awb_algorithm.hpp
> +++ b/src/ipa/raspberrypi/controller/awb_algorithm.hpp
> @@ -15,6 +15,7 @@ class AwbAlgorithm : public Algorithm
>  public:
>  	AwbAlgorithm(Controller *controller) : Algorithm(controller) {}
>  	// An AWB algorithm must provide the following:
> +	virtual unsigned int GetConvergenceFrames(unsigned int mistrust_frames) const = 0;
>  	virtual void SetMode(std::string const &mode_name) = 0;
>  	virtual void SetManualGains(double manual_r, double manual_b) = 0;
>  };
> diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp
> index 020825e3..6b359ac5 100644
> --- a/src/ipa/raspberrypi/controller/rpi/awb.cpp
> +++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp
> @@ -59,6 +59,7 @@ void AwbConfig::Read(boost::property_tree::ptree const &params)
>  	bayes = params.get<int>("bayes", 1);
>  	frame_period = params.get<uint16_t>("frame_period", 10);
>  	startup_frames = params.get<uint16_t>("startup_frames", 10);
> +	convergence_frames = params.get<unsigned int>("convergence_frames", 3);
>  	speed = params.get<double>("speed", 0.05);
>  	if (params.get_child_optional("ct_curve"))
>  		read_ct_curve(ct_r, ct_b, params.get_child("ct_curve"));
> @@ -165,6 +166,18 @@ void Awb::Initialise()
>  	prev_sync_results_ = sync_results_;
>  }
>  
> +unsigned int Awb::GetConvergenceFrames(unsigned int mistrust_frames) const
> +{
> +	// If colour gains have been explicitly set, there is no convergence
> +	// to happen, so no need to drop any frames - return zero.
> +	// Otherwise, any frames for which we have been told not to trust the
> +	// statistics must be added to our own count.
> +	if (manual_r_ && manual_b_)
> +		return 0;
> +	else
> +		return config_.convergence_frames + mistrust_frames;
> +}
> +
>  void Awb::SetMode(std::string const &mode_name)
>  {
>  	std::unique_lock<std::mutex> lock(settings_mutex_);
> diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp
> index 545d85a8..d86b9598 100644
> --- a/src/ipa/raspberrypi/controller/rpi/awb.hpp
> +++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp
> @@ -37,6 +37,7 @@ struct AwbConfig {
>  	uint16_t frame_period;
>  	// number of initial frames for which speed taken as 1.0 (maximum)
>  	uint16_t startup_frames;
> +	unsigned int convergence_frames; // approx number of frames to converge
>  	double speed; // IIR filter speed applied to algorithm results
>  	bool fast; // "fast" mode uses a 16x16 rather than 32x32 grid
>  	Pwl ct_r; // function maps CT to r (= R/G)
> @@ -82,6 +83,7 @@ public:
>  	char const *Name() const override;
>  	void Initialise() override;
>  	void Read(boost::property_tree::ptree const &params) override;
> +	unsigned int GetConvergenceFrames(unsigned int mistrust_frames) const override;
>  	void SetMode(std::string const &name) override;
>  	void SetManualGains(double manual_r, double manual_b) override;
>  	void SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override;

Patch
diff mbox series

diff --git a/src/ipa/raspberrypi/controller/awb_algorithm.hpp b/src/ipa/raspberrypi/controller/awb_algorithm.hpp
index 5be0c9f4..84ae313b 100644
--- a/src/ipa/raspberrypi/controller/awb_algorithm.hpp
+++ b/src/ipa/raspberrypi/controller/awb_algorithm.hpp
@@ -15,6 +15,7 @@  class AwbAlgorithm : public Algorithm
 public:
 	AwbAlgorithm(Controller *controller) : Algorithm(controller) {}
 	// An AWB algorithm must provide the following:
+	virtual unsigned int GetConvergenceFrames(unsigned int mistrust_frames) const = 0;
 	virtual void SetMode(std::string const &mode_name) = 0;
 	virtual void SetManualGains(double manual_r, double manual_b) = 0;
 };
diff --git a/src/ipa/raspberrypi/controller/rpi/awb.cpp b/src/ipa/raspberrypi/controller/rpi/awb.cpp
index 020825e3..6b359ac5 100644
--- a/src/ipa/raspberrypi/controller/rpi/awb.cpp
+++ b/src/ipa/raspberrypi/controller/rpi/awb.cpp
@@ -59,6 +59,7 @@  void AwbConfig::Read(boost::property_tree::ptree const &params)
 	bayes = params.get<int>("bayes", 1);
 	frame_period = params.get<uint16_t>("frame_period", 10);
 	startup_frames = params.get<uint16_t>("startup_frames", 10);
+	convergence_frames = params.get<unsigned int>("convergence_frames", 3);
 	speed = params.get<double>("speed", 0.05);
 	if (params.get_child_optional("ct_curve"))
 		read_ct_curve(ct_r, ct_b, params.get_child("ct_curve"));
@@ -165,6 +166,18 @@  void Awb::Initialise()
 	prev_sync_results_ = sync_results_;
 }
 
+unsigned int Awb::GetConvergenceFrames(unsigned int mistrust_frames) const
+{
+	// If colour gains have been explicitly set, there is no convergence
+	// to happen, so no need to drop any frames - return zero.
+	// Otherwise, any frames for which we have been told not to trust the
+	// statistics must be added to our own count.
+	if (manual_r_ && manual_b_)
+		return 0;
+	else
+		return config_.convergence_frames + mistrust_frames;
+}
+
 void Awb::SetMode(std::string const &mode_name)
 {
 	std::unique_lock<std::mutex> lock(settings_mutex_);
diff --git a/src/ipa/raspberrypi/controller/rpi/awb.hpp b/src/ipa/raspberrypi/controller/rpi/awb.hpp
index 545d85a8..d86b9598 100644
--- a/src/ipa/raspberrypi/controller/rpi/awb.hpp
+++ b/src/ipa/raspberrypi/controller/rpi/awb.hpp
@@ -37,6 +37,7 @@  struct AwbConfig {
 	uint16_t frame_period;
 	// number of initial frames for which speed taken as 1.0 (maximum)
 	uint16_t startup_frames;
+	unsigned int convergence_frames; // approx number of frames to converge
 	double speed; // IIR filter speed applied to algorithm results
 	bool fast; // "fast" mode uses a 16x16 rather than 32x32 grid
 	Pwl ct_r; // function maps CT to r (= R/G)
@@ -82,6 +83,7 @@  public:
 	char const *Name() const override;
 	void Initialise() override;
 	void Read(boost::property_tree::ptree const &params) override;
+	unsigned int GetConvergenceFrames(unsigned int mistrust_frames) const override;
 	void SetMode(std::string const &name) override;
 	void SetManualGains(double manual_r, double manual_b) override;
 	void SwitchMode(CameraMode const &camera_mode, Metadata *metadata) override;