From e1258c2d3e11fa7e00c114cdab9d6e8393b977a5 Mon Sep 17 00:00:00 2001 From: hesuicong Date: Wed, 1 Apr 2026 10:31:19 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A2=9C=E8=89=B2=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/MVS/SceneTexture.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/libs/MVS/SceneTexture.cpp b/libs/MVS/SceneTexture.cpp index f25a642..06e566e 100644 --- a/libs/MVS/SceneTexture.cpp +++ b/libs/MVS/SceneTexture.cpp @@ -9746,28 +9746,36 @@ bool PointInTriangle(const Point2f& p, const Point2f& a, const Point2f& b, const } // 辅助函数:从图像中双线性插值采样颜色 +// SampleImageBilinear 函数可能存在错误 Pixel8U SampleImageBilinear(const Image8U3& image, const Point2f& point) { - int x = (int)point.x; - int y = (int)point.y; + float x = point.x, y = point.y; + int x0 = (int)x, y0 = (int)y; + int x1 = x0 + 1, y1 = y0 + 1; - // 确保在图像范围内 - if (x < 0 || x >= image.cols-1 || y < 0 || y >= image.rows-1) { - return Pixel8U(0, 0, 0); - } + // 边界检查 + x1 = MIN(x1, image.cols-1); + y1 = MIN(y1, image.rows-1); - float dx = point.x - x; - float dy = point.y - y; + float dx = x - x0; + float dy = y - y0; - const Pixel8U& p00 = image(y, x); - const Pixel8U& p01 = image(y, x+1); - const Pixel8U& p10 = image(y+1, x); - const Pixel8U& p11 = image(y+1, x+1); + // 正确获取像素(注意OpenCV是BGR顺序) + const Pixel8U& p00 = image(y0, x0); + const Pixel8U& p01 = image(y0, x1); + const Pixel8U& p10 = image(y1, x0); + const Pixel8U& p11 = image(y1, x1); + // 双线性插值计算 Pixel8U result; for (int c = 0; c < 3; ++c) { - float top = p00[c] * (1-dx) + p01[c] * dx; - float bottom = p10[c] * (1-dx) + p11[c] * dx; - result[c] = (uint8_t)(top * (1-dy) + bottom * dy); + float v00 = p00[c]; + float v01 = p01[c]; + float v10 = p10[c]; + float v11 = p11[c]; + + float top = v00 + (v01 - v00) * dx; + float bottom = v10 + (v11 - v10) * dx; + result[c] = (uint8_t)(top + (bottom - top) * dy); } return result;