pipeline: rkisp1: Load dewarp parameters from tuning file
Load the dewarp parameters from the tuning file. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
@@ -31,6 +31,8 @@ public:
|
||||
|
||||
static std::unique_ptr<ConverterDW100Module> createModule(DeviceEnumerator *enumerator);
|
||||
|
||||
int init(const YamlObject ¶ms);
|
||||
|
||||
int configure(const StreamConfiguration &inputCfg,
|
||||
const std::vector<std::reference_wrapper<StreamConfiguration>>
|
||||
&outputCfg);
|
||||
@@ -67,12 +69,18 @@ private:
|
||||
int applyControls(const Stream *stream, const V4L2Request *request);
|
||||
void reinitRequest(V4L2Request *request);
|
||||
|
||||
struct DewarpParms {
|
||||
Matrix<double, 3, 3> cm;
|
||||
std::vector<double> coeffs;
|
||||
};
|
||||
|
||||
struct VertexMapInfo {
|
||||
Dw100VertexMap map;
|
||||
bool update;
|
||||
};
|
||||
|
||||
std::map<const Stream *, VertexMapInfo> vertexMaps_;
|
||||
std::optional<DewarpParms> dewarpParams_;
|
||||
unsigned int inputBufferCount_;
|
||||
V4L2M2MConverter converter_;
|
||||
Rectangle sensorCrop_;
|
||||
|
||||
@@ -70,6 +70,74 @@ ConverterDW100Module::createModule(DeviceEnumerator *enumerator)
|
||||
return {};
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Initialize the module with configuration data
|
||||
* \param[in] params The config parameters
|
||||
*
|
||||
* This function shall be called from the pipeline handler to initialize the
|
||||
* module with the provided parameters.
|
||||
*
|
||||
* A typical tuning file entry for the dewarper looks like this:
|
||||
* \code{.unparsed}
|
||||
* modules:
|
||||
* - Dewarp:
|
||||
* cm: [
|
||||
* 1.0, 0.0, 0.0,
|
||||
* 0.0, 1.0, 0.0,
|
||||
* 0.0, 0.0, 1.0,
|
||||
* ]
|
||||
* coefficients: [
|
||||
* 0,0,0,0,0,
|
||||
* ]
|
||||
* \endcode
|
||||
*
|
||||
* The \a cm and \a coefficients parameters are documented in
|
||||
* Dw100VertexMap::setDewarpParams()
|
||||
*
|
||||
* \sa Dw100VertexMap::setDewarpParams()
|
||||
* \return 0 if successful, an error code otherwise
|
||||
*/
|
||||
int ConverterDW100Module::init(const YamlObject ¶ms)
|
||||
{
|
||||
DewarpParms dp;
|
||||
|
||||
auto &cm = params["cm"];
|
||||
auto &coefficients = params["coefficients"];
|
||||
|
||||
/* If nothing is provided, the dewarper is still functional */
|
||||
if (!cm && !coefficients)
|
||||
return 0;
|
||||
|
||||
if (!cm) {
|
||||
LOG(Converter, Error) << "Dewarp parameters are missing 'cm' value";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
auto matrix = cm.get<Matrix<double, 3, 3>>();
|
||||
if (!matrix) {
|
||||
LOG(Converter, Error) << "Failed to load 'cm' value";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dp.cm = *matrix;
|
||||
|
||||
if (!coefficients) {
|
||||
LOG(Converter, Error) << "Dewarp parameters are missing 'coefficients' value";
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
const auto coeffs = coefficients.getList<double>();
|
||||
if (!coeffs) {
|
||||
LOG(Converter, Error) << "Dewarp parameters 'coefficients' value is not a list";
|
||||
return -EINVAL;
|
||||
}
|
||||
dp.coeffs = std::move(*coeffs);
|
||||
|
||||
dewarpParams_ = dp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \copydoc libcamera::V4L2M2MConverter::configure
|
||||
*/
|
||||
@@ -93,6 +161,9 @@ int ConverterDW100Module::configure(const StreamConfiguration &inputCfg,
|
||||
vertexMap.setInputSize(inputCfg.size);
|
||||
vertexMap.setOutputSize(outputCfg.size);
|
||||
vertexMap.setSensorCrop(sensorCrop_);
|
||||
|
||||
if (dewarpParams_)
|
||||
vertexMap.setDewarpParams(dewarpParams_->cm, dewarpParams_->coeffs);
|
||||
info.update = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -453,10 +453,18 @@ int RkISP1CameraData::loadTuningFile(const std::string &path)
|
||||
|
||||
const auto &modules = (*data)["modules"].asList();
|
||||
for (const auto &module : modules) {
|
||||
if (module.contains("Dewarp")) {
|
||||
canUseDewarper_ = true;
|
||||
break;
|
||||
}
|
||||
const auto ¶ms = module["Dewarp"];
|
||||
if (!params)
|
||||
continue;
|
||||
|
||||
ret = pipe()->dewarper_->init(params);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
LOG(RkISP1, Info) << "Dw100 dewarper initialized";
|
||||
|
||||
canUseDewarper_ = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user