| Message ID | 20260617144858.754729-3-stefan.klug@ideasonboard.com |
|---|---|
| State | New |
| Headers | show |
| Series |
|
| Related | show |
Quoting Stefan Klug (2026-06-17 15:48:35) > For some use cases (like removing a skew introduced by the camera > geometry) it is necessary to define the output camera matrix. Add that > functionality by adding an optional tuning parameter "cmNew" to the > Dewarp configuration. If that parameter is not provided, cm is used > instead. > Somewhere we should reference the OpenCV dewarp processes, but I think that will also come from the tuning guides and tools anyway, so I don't think we need to hold this up specifically. Now I understand this a bit better: Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> > > --- > > Changes in v0.2: > - Swapped cm and cmNew in the output calculation > --- > .../converter/converter_dw100_vertexmap.h | 2 ++ > src/libcamera/converter/converter_dw100.cpp | 15 ++++++++++++++- > .../converter/converter_dw100_vertexmap.cpp | 8 ++++++-- > 3 files changed, 22 insertions(+), 3 deletions(-) > > diff --git a/include/libcamera/internal/converter/converter_dw100_vertexmap.h b/include/libcamera/internal/converter/converter_dw100_vertexmap.h > index 6b6f3bae9f50..185cdb7a5cd6 100644 > --- a/include/libcamera/internal/converter/converter_dw100_vertexmap.h > +++ b/include/libcamera/internal/converter/converter_dw100_vertexmap.h > @@ -33,6 +33,7 @@ public: > > struct DewarpParams { > DewarpParams() : cm(Matrix<double, 3, 3>::identity()), > + cmNew(Matrix<double, 3, 3>::identity()), > coefficients({}) > { > } > @@ -40,6 +41,7 @@ public: > int setCoefficients(Span<const double> coeffs); > > Matrix<double, 3, 3> cm; > + Matrix<double, 3, 3> cmNew; > > struct { > double k1; > diff --git a/src/libcamera/converter/converter_dw100.cpp b/src/libcamera/converter/converter_dw100.cpp > index d05823fa4d4c..77f778c7f103 100644 > --- a/src/libcamera/converter/converter_dw100.cpp > +++ b/src/libcamera/converter/converter_dw100.cpp > @@ -104,9 +104,10 @@ int ConverterDW100Module::init(const ValueNode ¶ms) > > auto &cm = params["cm"]; > auto &coefficients = params["coefficients"]; > + auto &cmNew = params["cmNew"]; > > /* If nothing is provided, the dewarper is still functional */ > - if (!cm && !coefficients) > + if (!cm && !coefficients && !cmNew) > return 0; > > if (!cm) { > @@ -140,6 +141,18 @@ int ConverterDW100Module::init(const ValueNode ¶ms) > return -EINVAL; > } > > + if (cmNew) { > + matrix = cmNew.get<Matrix<double, 3, 3>>(); > + if (!matrix) { > + LOG(Converter, Error) << "Failed to load 'cmNew' value"; > + return -EINVAL; > + } > + > + dp.cmNew = *matrix; > + } else { > + dp.cmNew = dp.cm; > + } > + > dewarpParams_ = dp; > > return 0; > diff --git a/src/libcamera/converter/converter_dw100_vertexmap.cpp b/src/libcamera/converter/converter_dw100_vertexmap.cpp > index 6986f137cbc8..48f74885297f 100644 > --- a/src/libcamera/converter/converter_dw100_vertexmap.cpp > +++ b/src/libcamera/converter/converter_dw100_vertexmap.cpp > @@ -234,6 +234,9 @@ int dw100VerticesForLength(const int length) > * \var Dw100VertexMap::DewarpParams::cm > * \brief The camera matrix > * > + * \var Dw100VertexMap::DewarpParams::cmNew > + * \brief The new camera matrix after dewarping > + * > * \var Dw100VertexMap::DewarpParams::coefficients > * \brief Structure containing the lens dewarp coefficients > > @@ -664,10 +667,11 @@ Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p) > double x, y; > double xout, yout; > auto &cm = dewarpParams_->cm; > + auto &cmNew = dewarpParams_->cmNew; > auto &c = dewarpParams_->coefficients; > > - y = (p.y() - cm[1][2]) / cm[1][1]; > - x = (p.x() - cm[0][2] - y * cm[0][1]) / cm[0][0]; > + y = (p.y() - cmNew[1][2]) / cmNew[1][1]; > + x = (p.x() - cmNew[0][2] - y * cmNew[0][1]) / cmNew[0][0]; > > double r2 = x * x + y * y; > double r4 = r2 * r2; > -- > 2.53.0 >
Quoting Stefan Klug (2026-06-17 23:48:35) > For some use cases (like removing a skew introduced by the camera > geometry) it is necessary to define the output camera matrix. Add that > functionality by adding an optional tuning parameter "cmNew" to the > Dewarp configuration. If that parameter is not provided, cm is used > instead. > > Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> > > --- > > Changes in v0.2: > - Swapped cm and cmNew in the output calculation > --- > .../converter/converter_dw100_vertexmap.h | 2 ++ > src/libcamera/converter/converter_dw100.cpp | 15 ++++++++++++++- > .../converter/converter_dw100_vertexmap.cpp | 8 ++++++-- > 3 files changed, 22 insertions(+), 3 deletions(-) > > diff --git a/include/libcamera/internal/converter/converter_dw100_vertexmap.h b/include/libcamera/internal/converter/converter_dw100_vertexmap.h > index 6b6f3bae9f50..185cdb7a5cd6 100644 > --- a/include/libcamera/internal/converter/converter_dw100_vertexmap.h > +++ b/include/libcamera/internal/converter/converter_dw100_vertexmap.h > @@ -33,6 +33,7 @@ public: > > struct DewarpParams { > DewarpParams() : cm(Matrix<double, 3, 3>::identity()), > + cmNew(Matrix<double, 3, 3>::identity()), > coefficients({}) > { > } > @@ -40,6 +41,7 @@ public: > int setCoefficients(Span<const double> coeffs); > > Matrix<double, 3, 3> cm; > + Matrix<double, 3, 3> cmNew; > > struct { > double k1; > diff --git a/src/libcamera/converter/converter_dw100.cpp b/src/libcamera/converter/converter_dw100.cpp > index d05823fa4d4c..77f778c7f103 100644 > --- a/src/libcamera/converter/converter_dw100.cpp > +++ b/src/libcamera/converter/converter_dw100.cpp > @@ -104,9 +104,10 @@ int ConverterDW100Module::init(const ValueNode ¶ms) > > auto &cm = params["cm"]; > auto &coefficients = params["coefficients"]; > + auto &cmNew = params["cmNew"]; > > /* If nothing is provided, the dewarper is still functional */ > - if (!cm && !coefficients) > + if (!cm && !coefficients && !cmNew) > return 0; > > if (!cm) { > @@ -140,6 +141,18 @@ int ConverterDW100Module::init(const ValueNode ¶ms) > return -EINVAL; > } > > + if (cmNew) { > + matrix = cmNew.get<Matrix<double, 3, 3>>(); > + if (!matrix) { > + LOG(Converter, Error) << "Failed to load 'cmNew' value"; > + return -EINVAL; > + } > + > + dp.cmNew = *matrix; > + } else { > + dp.cmNew = dp.cm; > + } > + > dewarpParams_ = dp; > > return 0; > diff --git a/src/libcamera/converter/converter_dw100_vertexmap.cpp b/src/libcamera/converter/converter_dw100_vertexmap.cpp > index 6986f137cbc8..48f74885297f 100644 > --- a/src/libcamera/converter/converter_dw100_vertexmap.cpp > +++ b/src/libcamera/converter/converter_dw100_vertexmap.cpp > @@ -234,6 +234,9 @@ int dw100VerticesForLength(const int length) > * \var Dw100VertexMap::DewarpParams::cm > * \brief The camera matrix > * > + * \var Dw100VertexMap::DewarpParams::cmNew > + * \brief The new camera matrix after dewarping > + * > * \var Dw100VertexMap::DewarpParams::coefficients > * \brief Structure containing the lens dewarp coefficients > > @@ -664,10 +667,11 @@ Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p) > double x, y; > double xout, yout; > auto &cm = dewarpParams_->cm; > + auto &cmNew = dewarpParams_->cmNew; > auto &c = dewarpParams_->coefficients; > > - y = (p.y() - cm[1][2]) / cm[1][1]; > - x = (p.x() - cm[0][2] - y * cm[0][1]) / cm[0][0]; > + y = (p.y() - cmNew[1][2]) / cmNew[1][1]; > + x = (p.x() - cmNew[0][2] - y * cmNew[0][1]) / cmNew[0][0]; > > double r2 = x * x + y * y; > double r4 = r2 * r2; > -- > 2.53.0 >
diff --git a/include/libcamera/internal/converter/converter_dw100_vertexmap.h b/include/libcamera/internal/converter/converter_dw100_vertexmap.h index 6b6f3bae9f50..185cdb7a5cd6 100644 --- a/include/libcamera/internal/converter/converter_dw100_vertexmap.h +++ b/include/libcamera/internal/converter/converter_dw100_vertexmap.h @@ -33,6 +33,7 @@ public: struct DewarpParams { DewarpParams() : cm(Matrix<double, 3, 3>::identity()), + cmNew(Matrix<double, 3, 3>::identity()), coefficients({}) { } @@ -40,6 +41,7 @@ public: int setCoefficients(Span<const double> coeffs); Matrix<double, 3, 3> cm; + Matrix<double, 3, 3> cmNew; struct { double k1; diff --git a/src/libcamera/converter/converter_dw100.cpp b/src/libcamera/converter/converter_dw100.cpp index d05823fa4d4c..77f778c7f103 100644 --- a/src/libcamera/converter/converter_dw100.cpp +++ b/src/libcamera/converter/converter_dw100.cpp @@ -104,9 +104,10 @@ int ConverterDW100Module::init(const ValueNode ¶ms) auto &cm = params["cm"]; auto &coefficients = params["coefficients"]; + auto &cmNew = params["cmNew"]; /* If nothing is provided, the dewarper is still functional */ - if (!cm && !coefficients) + if (!cm && !coefficients && !cmNew) return 0; if (!cm) { @@ -140,6 +141,18 @@ int ConverterDW100Module::init(const ValueNode ¶ms) return -EINVAL; } + if (cmNew) { + matrix = cmNew.get<Matrix<double, 3, 3>>(); + if (!matrix) { + LOG(Converter, Error) << "Failed to load 'cmNew' value"; + return -EINVAL; + } + + dp.cmNew = *matrix; + } else { + dp.cmNew = dp.cm; + } + dewarpParams_ = dp; return 0; diff --git a/src/libcamera/converter/converter_dw100_vertexmap.cpp b/src/libcamera/converter/converter_dw100_vertexmap.cpp index 6986f137cbc8..48f74885297f 100644 --- a/src/libcamera/converter/converter_dw100_vertexmap.cpp +++ b/src/libcamera/converter/converter_dw100_vertexmap.cpp @@ -234,6 +234,9 @@ int dw100VerticesForLength(const int length) * \var Dw100VertexMap::DewarpParams::cm * \brief The camera matrix * + * \var Dw100VertexMap::DewarpParams::cmNew + * \brief The new camera matrix after dewarping + * * \var Dw100VertexMap::DewarpParams::coefficients * \brief Structure containing the lens dewarp coefficients @@ -664,10 +667,11 @@ Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p) double x, y; double xout, yout; auto &cm = dewarpParams_->cm; + auto &cmNew = dewarpParams_->cmNew; auto &c = dewarpParams_->coefficients; - y = (p.y() - cm[1][2]) / cm[1][1]; - x = (p.x() - cm[0][2] - y * cm[0][1]) / cm[0][0]; + y = (p.y() - cmNew[1][2]) / cmNew[1][1]; + x = (p.x() - cmNew[0][2] - y * cmNew[0][1]) / cmNew[0][0]; double r2 = x * x + y * y; double r4 = r2 * r2;
For some use cases (like removing a skew introduced by the camera geometry) it is necessary to define the output camera matrix. Add that functionality by adding an optional tuning parameter "cmNew" to the Dewarp configuration. If that parameter is not provided, cm is used instead. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> --- Changes in v0.2: - Swapped cm and cmNew in the output calculation --- .../converter/converter_dw100_vertexmap.h | 2 ++ src/libcamera/converter/converter_dw100.cpp | 15 ++++++++++++++- .../converter/converter_dw100_vertexmap.cpp | 8 ++++++-- 3 files changed, 22 insertions(+), 3 deletions(-)