Patch Detail
Show a patch.
GET /api/patches/24757/?format=api
{ "id": 24757, "url": "https://patchwork.libcamera.org/api/patches/24757/?format=api", "web_url": "https://patchwork.libcamera.org/patch/24757/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20251023144841.403689-31-stefan.klug@ideasonboard.com>", "date": "2025-10-23T14:48:31", "name": "[v2,30/35] libcamera: dw100_vertexmap: Implement parametric dewarping", "commit_ref": null, "pull_url": null, "state": "superseded", "archived": false, "hash": "98c6989620d16bada917d755f34f5b3709512f61", "submitter": { "id": 184, "url": "https://patchwork.libcamera.org/api/people/184/?format=api", "name": "Stefan Klug", "email": "stefan.klug@ideasonboard.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/24757/mbox/", "series": [ { "id": 5520, "url": "https://patchwork.libcamera.org/api/series/5520/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5520", "date": "2025-10-23T14:48:01", "name": "Full dewarper support on imx8mp", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5520/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/24757/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/24757/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 031DFC3344\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Oct 2025 14:50:18 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 80B9D60854;\n\tThu, 23 Oct 2025 16:50:18 +0200 (CEST)", "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CC1FE607ED\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 16:50:16 +0200 (CEST)", "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:7328:357b:4ce1:72b6])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id CB6821127; \n\tThu, 23 Oct 2025 16:48:31 +0200 (CEST)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"d84fuRgi\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1761230911;\n\tbh=UpEvhD8cXzD3/aA5BBffZLonOzc8X/lKUqsIeTlFF1c=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=d84fuRgiFEbQ2YLovBKaoAUFtUazVMkpGoihP0eySAHDVqeFvTmp1ZrAzadC54VGi\n\tKa1r7Q8A73d82Fm59sVSTt0uVzfIgrmOmJjvkGEOyR1U2RB74MxGyj4tRE5xvlt7ii\n\tVnra/SqtEMohIX7N5W4a+XwaDDwZ6YOtRTS6jMn8=", "From": "Stefan Klug <stefan.klug@ideasonboard.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>", "Subject": "[PATCH v2 30/35] libcamera: dw100_vertexmap: Implement parametric\n\tdewarping", "Date": "Thu, 23 Oct 2025 16:48:31 +0200", "Message-ID": "<20251023144841.403689-31-stefan.klug@ideasonboard.com>", "X-Mailer": "git-send-email 2.48.1", "In-Reply-To": "<20251023144841.403689-1-stefan.klug@ideasonboard.com>", "References": "<20251023144841.403689-1-stefan.klug@ideasonboard.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "Implement functions to allow lens dewarping based on the common lens\ndewarp model used e.g. by OpenCV.\n\nSee https://docs.opencv.org/4.12.0/d9/d0c/group__calib3d.html for an\nin depth explanation of the parameters.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v2:\n- Adapt to vertex map implementation based on affine transforms\n- Improved documentation\n- dropped loadDewarpParams function as it was never used\n---\n .../converter/converter_dw100_vertexmap.h | 16 +++\n .../converter/converter_dw100_vertexmap.cpp | 98 +++++++++++++++++--\n 2 files changed, 108 insertions(+), 6 deletions(-)", "diff": "diff --git a/include/libcamera/internal/converter/converter_dw100_vertexmap.h b/include/libcamera/internal/converter/converter_dw100_vertexmap.h\nindex e72cb72bb9f1..b05ed8338a23 100644\n--- a/include/libcamera/internal/converter/converter_dw100_vertexmap.h\n+++ b/include/libcamera/internal/converter/converter_dw100_vertexmap.h\n@@ -10,6 +10,9 @@\n #include <libcamera/geometry.h>\n #include <libcamera/transform.h>\n \n+#include \"libcamera/internal/matrix.h\"\n+#include \"libcamera/internal/vector.h\"\n+\n namespace libcamera {\n \n class Dw100VertexMap\n@@ -55,9 +58,17 @@ public:\n \tvoid setMode(const ScaleMode mode) { mode_ = mode; }\n \tScaleMode mode() const { return mode_; }\n \n+\tint setDewarpParams(const Matrix<double, 3, 3> &cm, const Span<const double> &coeffs);\n+\tbool dewarpParamsValid() { return dewarpParamsValid_; }\n+\n+\tvoid setLensDewarpEnable(bool enable) { lensDewarpEnable_ = enable; }\n+\tbool lensDewarpEnable() { return lensDewarpEnable_; }\n+\n \tstd::vector<uint32_t> getVertexMap();\n \n private:\n+\tVector<double, 2> dewarpPoint(const Vector<double, 2> &p);\n+\n \tRectangle scalerCrop_;\n \tRectangle sensorCrop_;\n \tTransform transform_ = Transform::Identity;\n@@ -71,6 +82,11 @@ private:\n \tdouble effectiveScaleY_;\n \tPoint effectiveOffset_;\n \tRectangle effectiveScalerCrop_;\n+\n+\tMatrix<double, 3, 3> dewarpM_ = Matrix<double, 3, 3>::identity();\n+\tstd::array<double, 12> dewarpCoeffs_;\n+\tbool lensDewarpEnable_ = true;\n+\tbool dewarpParamsValid_ = false;\n };\n \n } /* namespace libcamera */\ndiff --git a/src/libcamera/converter/converter_dw100_vertexmap.cpp b/src/libcamera/converter/converter_dw100_vertexmap.cpp\nindex 0e930479b6f7..f2be9a697ff3 100644\n--- a/src/libcamera/converter/converter_dw100_vertexmap.cpp\n+++ b/src/libcamera/converter/converter_dw100_vertexmap.cpp\n@@ -184,8 +184,6 @@ int dw100VerticesForLength(const int length)\n * | | | | | Transpose) | | Rotate) |\n * +-------------+ +-------------+ +------------+ +-----------------+\n *\n- * \\todo Lens dewarp is not yet implemented. An identity map is used instead.\n- *\n * All parameters are clamped to valid values before creating the vertex map.\n *\n * The constrains process works as follows:\n@@ -546,10 +544,8 @@ std::vector<uint32_t> Dw100VertexMap::getVertexMap()\n \n \t\t\tp = transformPoint(outputToSensor, p);\n \n-\t\t\t/*\n-\t\t\t * \\todo: Transformations in sensor space to be added\n-\t\t\t * here.\n-\t\t\t */\n+\t\t\tif (dewarpParamsValid_ && lensDewarpEnable_)\n+\t\t\t\tp = dewarpPoint(p);\n \n \t\t\tp = transformPoint(sensorToInput, p);\n \n@@ -563,4 +559,94 @@ std::vector<uint32_t> Dw100VertexMap::getVertexMap()\n \treturn res;\n }\n \n+/**\n+ * \\brief Set the dewarp parameters\n+ * \\param cm The camera matrix\n+ * \\param coeffs The dewarp coefficients\n+ *\n+ * Sets the dewarp parameters according to the commonly used dewarp model. See\n+ * https://docs.opencv.org/4.12.0/d9/d0c/group__calib3d.html for further details\n+ * on the model. The parameter \\a coeffs must either hold 4,5,8 or 12 values.\n+ * They represent the parameters k1,k2,p1,p2[,k3[,k4,k5,k6[,s1,s2,s3,s4]]] in\n+ * the model.\n+ *\n+ * \\return A negative number on error, 0 otherwise\n+ */\n+int Dw100VertexMap::setDewarpParams(const Matrix<double, 3, 3> &cm,\n+\t\t\t\t const Span<const double> &coeffs)\n+{\n+\tdewarpM_ = cm;\n+\tdewarpCoeffs_.fill(0.0);\n+\n+\tif (coeffs.size() != 4 && coeffs.size() != 5 &&\n+\t coeffs.size() != 8 && coeffs.size() != 12) {\n+\t\tLOG(Converter, Error)\n+\t\t\t<< \"Dewarp 'coefficients' must have 4, 5, 8 or 12 values\";\n+\t\tdewarpParamsValid_ = false;\n+\t\treturn -EINVAL;\n+\t}\n+\tstd::copy(coeffs.begin(), coeffs.end(), dewarpCoeffs_.begin());\n+\n+\tdewarpParamsValid_ = true;\n+\treturn 0;\n+}\n+\n+/**\n+ * \\fn Dw100VertexMap::dewarpParamsValid()\n+ * \\brief Returns if the dewarp parameters are valid\n+ *\n+ * \\return True if the dewarp parameters are valid, fals otherwise\n+ */\n+\n+/**\n+ * \\fn Dw100VertexMap::setLensDewarpEnable()\n+ * \\brief Enables or disabled lens dewarping\n+ * \\param[in] enable Enable or disable lens dewarping\n+ */\n+\n+/**\n+ * \\fn Dw100VertexMap::lensDewarpEnable()\n+ * \\brief Returns if lens dewarping is enabled\n+ */\n+\n+/**\n+ * \\brief Apply dewarp calculation to a point\n+ * \\param p The point to dewarp\n+ *\n+ * Applies the dewarp transformation to point \\a p according to the commonly\n+ * used dewarp model. See\n+ * https://docs.opencv.org/4.12.0/d9/d0c/group__calib3d.html for further details\n+ * on the model.\n+ *\n+ * \\return The dewarped point\n+ */\n+Vector2d Dw100VertexMap::dewarpPoint(const Vector2d &p)\n+{\n+\tdouble x, y;\n+\tdouble k1 = dewarpCoeffs_[0];\n+\tdouble k2 = dewarpCoeffs_[1];\n+\tdouble p1 = dewarpCoeffs_[2];\n+\tdouble p2 = dewarpCoeffs_[3];\n+\tdouble k3 = dewarpCoeffs_[4];\n+\tdouble k4 = dewarpCoeffs_[5];\n+\tdouble k5 = dewarpCoeffs_[6];\n+\tdouble k6 = dewarpCoeffs_[7];\n+\tdouble s1 = dewarpCoeffs_[8];\n+\tdouble s2 = dewarpCoeffs_[9];\n+\tdouble s3 = dewarpCoeffs_[10];\n+\tdouble s4 = dewarpCoeffs_[11];\n+\n+\ty = (p.y() - dewarpM_[1][2]) / dewarpM_[1][1];\n+\tx = (p.x() - dewarpM_[0][2] - y * dewarpM_[0][1]) / dewarpM_[0][0];\n+\n+\tdouble r2 = x * x + y * y;\n+\tdouble d = (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2) /\n+\t\t (1 + k4 * r2 + k5 * r2 * r2 + k6 * r2 * r2 * r2);\n+\tx = x * d + 2 * p1 * x * y + p2 * (r2 + 2 * x * x) + s1 * r2 + s2 * r2 * r2;\n+\ty = y * d + 2 * p2 * x * y + p1 * (r2 + 2 * y * y) + s3 * r2 + s4 * r2 * r2;\n+\n+\treturn { { x * dewarpM_[0][0] + y * dewarpM_[0][1] + dewarpM_[0][2],\n+\t\t y * dewarpM_[1][1] + dewarpM_[1][2] } };\n+}\n+\n } /* namespace libcamera */\n", "prefixes": [ "v2", "30/35" ] }