ipa: rkisp1: Add support for bayes AWB algorithm from libipa
Now that libipa contains a bayes AWB algorithm, add it as supported algorithm to the rkisp1 ipa. The decision between the grey world algorithm and the bayesian is done based on the "algorithm" property of the "Awb" algorithm in the tuning file. If the lux value in the frameContext is set by the Lux algorithm it is taken into account. If the lux value is 0 the prior likelihood estimation gets ignored in the AWB calculations. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>
This commit is contained in:
parent
f45eb6bd9d
commit
7a4012ec79
1 changed files with 36 additions and 12 deletions
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
#include <libcamera/ipa/core_ipa_interface.h>
|
#include <libcamera/ipa/core_ipa_interface.h>
|
||||||
|
|
||||||
|
#include "libipa/awb_bayes.h"
|
||||||
#include "libipa/awb_grey.h"
|
#include "libipa/awb_grey.h"
|
||||||
#include "libipa/colours.h"
|
#include "libipa/colours.h"
|
||||||
|
|
||||||
|
@ -47,13 +48,21 @@ public:
|
||||||
RkISP1AwbStats(const RGB<double> &rgbMeans)
|
RkISP1AwbStats(const RGB<double> &rgbMeans)
|
||||||
: rgbMeans_(rgbMeans)
|
: rgbMeans_(rgbMeans)
|
||||||
{
|
{
|
||||||
|
rg_ = rgbMeans_.r() / rgbMeans_.g();
|
||||||
|
bg_ = rgbMeans_.b() / rgbMeans_.g();
|
||||||
}
|
}
|
||||||
|
|
||||||
double computeColourError([[maybe_unused]] const RGB<double> &gains) const override
|
double computeColourError(const RGB<double> &gains) const override
|
||||||
{
|
{
|
||||||
LOG(RkISP1Awb, Error)
|
/*
|
||||||
<< "RkISP1AwbStats::computeColourError is not implemented";
|
* Compute the sum of the squared colour error (non-greyness) as it
|
||||||
return 0.0;
|
* appears in the log likelihood equation.
|
||||||
|
*/
|
||||||
|
double deltaR = gains.r() * rg_ - 1.0;
|
||||||
|
double deltaB = gains.b() * bg_ - 1.0;
|
||||||
|
double delta2 = deltaR * deltaR + deltaB * deltaB;
|
||||||
|
|
||||||
|
return delta2;
|
||||||
}
|
}
|
||||||
|
|
||||||
RGB<double> getRGBMeans() const override
|
RGB<double> getRGBMeans() const override
|
||||||
|
@ -63,6 +72,8 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
RGB<double> rgbMeans_;
|
RGB<double> rgbMeans_;
|
||||||
|
double rg_;
|
||||||
|
double bg_;
|
||||||
};
|
};
|
||||||
|
|
||||||
Awb::Awb()
|
Awb::Awb()
|
||||||
|
@ -80,13 +91,30 @@ int Awb::init(IPAContext &context, const YamlObject &tuningData)
|
||||||
kMaxColourTemperature,
|
kMaxColourTemperature,
|
||||||
kDefaultColourTemperature);
|
kDefaultColourTemperature);
|
||||||
|
|
||||||
awbAlgo_ = std::make_unique<AwbGrey>();
|
if (!tuningData.contains("algorithm"))
|
||||||
|
LOG(RkISP1Awb, Info) << "No awb algorithm specified."
|
||||||
|
<< " Default to grey world";
|
||||||
|
|
||||||
|
auto mode = tuningData["algorithm"].get<std::string>("grey");
|
||||||
|
if (mode == "grey") {
|
||||||
|
awbAlgo_ = std::make_unique<AwbGrey>();
|
||||||
|
} else if (mode == "bayes") {
|
||||||
|
awbAlgo_ = std::make_unique<AwbBayes>();
|
||||||
|
} else {
|
||||||
|
LOG(RkISP1Awb, Error) << "Unknown awb algorithm: " << mode;
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
LOG(RkISP1Awb, Debug) << "Using awb algorithm: " << mode;
|
||||||
|
|
||||||
int ret = awbAlgo_->init(tuningData);
|
int ret = awbAlgo_->init(tuningData);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
LOG(RkISP1Awb, Error) << "Failed to init awb algorithm";
|
LOG(RkISP1Awb, Error) << "Failed to init awb algorithm";
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const auto &src = awbAlgo_->controls();
|
||||||
|
cmap.insert(src.begin(), src.end());
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,6 +161,8 @@ void Awb::queueRequest(IPAContext &context,
|
||||||
<< (*awbEnable ? "Enabling" : "Disabling") << " AWB";
|
<< (*awbEnable ? "Enabling" : "Disabling") << " AWB";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
awbAlgo_->handleControls(controls);
|
||||||
|
|
||||||
frameContext.awb.autoEnabled = awb.autoEnabled;
|
frameContext.awb.autoEnabled = awb.autoEnabled;
|
||||||
|
|
||||||
if (awb.autoEnabled)
|
if (awb.autoEnabled)
|
||||||
|
@ -273,14 +303,8 @@ void Awb::process(IPAContext &context,
|
||||||
rgbMeans.b() < kMeanMinThreshold)
|
rgbMeans.b() < kMeanMinThreshold)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/*
|
|
||||||
* \Todo: Hardcode lux to a fixed value, until an estimation is
|
|
||||||
* implemented.
|
|
||||||
*/
|
|
||||||
int lux = 1000;
|
|
||||||
|
|
||||||
RkISP1AwbStats awbStats{ rgbMeans };
|
RkISP1AwbStats awbStats{ rgbMeans };
|
||||||
AwbResult awbResult = awbAlgo_->calculateAwb(awbStats, lux);
|
AwbResult awbResult = awbAlgo_->calculateAwb(awbStats, frameContext.lux.lux);
|
||||||
|
|
||||||
activeState.awb.temperatureK = awbResult.colourTemperature;
|
activeState.awb.temperatureK = awbResult.colourTemperature;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue