libcamera: converter: converter_dw100_vertexmap: Fix dewarp parameter p2 handling

The lens dewarp implementation done in commit 1784e08be3 ("libcamera:
dw100_vertexmap: Implement parametric dewarping") handles the dewarp
parameter p2 incorrectly because it uses the already dewarped x value as
input for the calculation of the y value. Fix that by using separate
variables for the output value. Do so for x and y to keep the code
symmetric even if it is only strictly required for y.

Fixes: 1784e08be3 ("libcamera: dw100_vertexmap: Implement parametric dewarping")
Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Stefan Klug
2026-02-09 12:28:14 +01:00
parent b181327131
commit 1dcf9957a4

View File

@@ -628,6 +628,7 @@ int Dw100VertexMap::setDewarpParams(const Matrix<double, 3, 3> &cm,
Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p)
{
double x, y;
double xout, yout;
double k1 = dewarpCoeffs_[0];
double k2 = dewarpCoeffs_[1];
double p1 = dewarpCoeffs_[2];
@@ -647,11 +648,11 @@ Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p)
double r2 = x * x + y * y;
double d = (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2) /
(1 + k4 * r2 + k5 * r2 * r2 + k6 * r2 * r2 * r2);
x = x * d + 2 * p1 * x * y + p2 * (r2 + 2 * x * x) + s1 * r2 + s2 * r2 * r2;
y = y * d + 2 * p2 * x * y + p1 * (r2 + 2 * y * y) + s3 * r2 + s4 * r2 * r2;
xout = x * d + 2 * p1 * x * y + p2 * (r2 + 2 * x * x) + s1 * r2 + s2 * r2 * r2;
yout = y * d + 2 * p2 * x * y + p1 * (r2 + 2 * y * y) + s3 * r2 + s4 * r2 * r2;
return { { x * dewarpM_[0][0] + y * dewarpM_[0][1] + dewarpM_[0][2],
y * dewarpM_[1][1] + dewarpM_[1][2] } };
return { { xout * dewarpM_[0][0] + yout * dewarpM_[0][1] + dewarpM_[0][2],
yout * dewarpM_[1][1] + dewarpM_[1][2] } };
}
} /* namespace libcamera */