From 5f06661d9b1761f35b468c1e6e41684ed5f45b6d Mon Sep 17 00:00:00 2001 From: hesuicong Date: Tue, 13 Oct 2026 14:17:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=BB=E6=8E=89=E7=A9=BA=E7=99=BD=E9=97=B4?= =?UTF-8?q?=E9=9A=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/MVS/SceneTexture.cpp | 41 ++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/libs/MVS/SceneTexture.cpp b/libs/MVS/SceneTexture.cpp index c406106..2452ef8 100644 --- a/libs/MVS/SceneTexture.cpp +++ b/libs/MVS/SceneTexture.cpp @@ -15724,9 +15724,6 @@ void MeshTexture::ApplyGlobalSeamLevelingOnRCPatches( { if (rcPatches.empty()) return; - Image8U3 localAtlas(textureSize, textureSize); - localAtlas.memset(0); // 全部填 0 = 黑色 - DEBUG_EXTRA("ApplyGlobalSeamLevelingOnRCPatches: bridging %zu rcPatches...", rcPatches.size()); DEBUG_EXTRA("faceTexcoords ptr=%p, scene ptr=%p", &faceTexcoords, &scene.mesh.faceTexcoords); // ========== 1. 构建 texturePatches ========== @@ -16009,23 +16006,19 @@ void MeshTexture::ApplyGlobalSeamLevelingOnRCPatches( cv::Mat remapped; cv::remap(correctedPatch, remapped, mapX, mapY, cv::INTER_LINEAR, cv::BORDER_CONSTANT, cv::Scalar(0,0,0)); - for (int y = 0; y < patchH; ++y) - { - for (int x = 0; x < patchW; ++x) { - cv::Vec3b color = remapped.at(y, x); - if (color[0] == 0 && color[1] == 0 && color[2] == 0) continue; + for (int y = 0; y < patchH; ++y) { + for (int x = 0; x < patchW; ++x) { + cv::Vec3b color = remapped.at(y, x); + if (color[0] == 0 && color[1] == 0 && color[2] == 0) continue; - int atlasX = x + minX, atlasY = y + minY; - if (atlasX < 0 || atlasX >= textureSize || atlasY < 0 || atlasY >= textureSize) continue; - // atlas(atlasY, atlasX) = Pixel8U{color[2], color[1], color[0]}; - if (atlasY >= 0 && atlasY < atlas.rows && atlasX >= 0 && atlasX < atlas.cols) { - // 用 cv::Mat 的 at 方法,它内部有边界检查(Debug 模式下) - cv::Vec3b& pixel = localAtlas.at(atlasY, atlasX); - pixel[0] = color[0]; - pixel[1] = color[1]; - pixel[2] = color[2]; - } - } + int atlasX = x + minX, atlasY = y + minY; + if (atlasX < 0 || atlasX >= textureSize || atlasY < 0 || atlasY >= textureSize) continue; + + cv::Vec3b& pixel = atlas.at(atlasY, atlasX); + pixel[0] = color[0]; + pixel[1] = color[1]; + pixel[2] = color[2]; + } } // // 调试用:导出调整后的 atlas @@ -16035,7 +16028,6 @@ void MeshTexture::ApplyGlobalSeamLevelingOnRCPatches( // cv::imwrite(dbgName, atlas); // DEBUG_EXTRA("Exported %s", dbgName); } - atlas = localAtlas; } DEBUG_EXTRA("Re-rasterization done."); @@ -16372,10 +16364,11 @@ bool MeshTexture::RasterizeVirtualFaces( float currentScore = virtualFaceViewWeights[i].empty() ? -1.0f : virtualFaceViewWeights[i][0]; - int minX = std::max(0, (int)floor(geom.uvBounds.ptMin.x() * textureSize)); - int maxX = std::min(textureSize - 1, (int)ceil(geom.uvBounds.ptMax.x() * textureSize)); - int minY = std::max(0, (int)floor(geom.uvBounds.ptMin.y() * textureSize)); - int maxY = std::min(textureSize - 1, (int)ceil(geom.uvBounds.ptMax.y() * textureSize)); + int pad = 4; + int minX = std::max(0, (int)floor(geom.uvBounds.ptMin.x() * textureSize - pad)); + int maxX = std::min(textureSize - 1, (int)ceil(geom.uvBounds.ptMax.x() * textureSize + pad)); + int minY = std::max(0, (int)floor(geom.uvBounds.ptMin.y() * textureSize - pad)); + int maxY = std::min(textureSize - 1, (int)ceil(geom.uvBounds.ptMax.y() * textureSize + pad)); if (minX > maxX || minY > maxY) continue; int patchW = maxX - minX + 1, patchH = maxY - minY + 1;