|
|
|
|
@ -10935,47 +10935,31 @@ void MeshTexture::GenerateTexture(bool bGlobalSeamLeveling, bool bLocalSeamLevel
@@ -10935,47 +10935,31 @@ void MeshTexture::GenerateTexture(bool bGlobalSeamLeveling, bool bLocalSeamLevel
|
|
|
|
|
ASSERT(imageData.image.isInside(Point2f(aabb.ptMin))); |
|
|
|
|
ASSERT(imageData.image.isInside(Point2f(aabb.ptMax))); |
|
|
|
|
|
|
|
|
|
if (bOriginFaceview) |
|
|
|
|
{ |
|
|
|
|
// ===== 替换 GenerateTexture 中第一个循环里设置 rect 的代码 =====
|
|
|
|
|
if (bOriginFaceview) { |
|
|
|
|
texturePatch.rect.x = FLOOR2INT(aabb.ptMin[0]) - border; |
|
|
|
|
texturePatch.rect.y = FLOOR2INT(aabb.ptMin[1]) - border; |
|
|
|
|
texturePatch.rect.width = CEIL2INT(aabb.ptMax[0] - aabb.ptMin[0]) + border * 2; |
|
|
|
|
texturePatch.rect.height = CEIL2INT(aabb.ptMax[1] - aabb.ptMin[1]) + border * 2; |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
} else { |
|
|
|
|
texturePatch.rect.x = std::max(0, FLOOR2INT(aabb.ptMin[0]) - border); |
|
|
|
|
texturePatch.rect.y = std::max(0, FLOOR2INT(aabb.ptMin[1]) - border); |
|
|
|
|
// 限制尺寸不超过图像实际范围
|
|
|
|
|
const cv::Mat& img = images[texturePatch.label].image; |
|
|
|
|
texturePatch.rect.width = std::min( |
|
|
|
|
CEIL2INT(aabb.ptMax[0]-aabb.ptMin[0])+border*2, |
|
|
|
|
img.cols - texturePatch.rect.x |
|
|
|
|
); |
|
|
|
|
texturePatch.rect.height = std::min( |
|
|
|
|
CEIL2INT(aabb.ptMax[1]-aabb.ptMin[1])+border*2, |
|
|
|
|
img.rows - texturePatch.rect.y |
|
|
|
|
); |
|
|
|
|
texturePatch.rect.width = CEIL2INT(aabb.ptMax[0] - aabb.ptMin[0]) + border * 2; |
|
|
|
|
texturePatch.rect.height = CEIL2INT(aabb.ptMax[1] - aabb.ptMin[1]) + border * 2; |
|
|
|
|
// 裁剪到图像范围内
|
|
|
|
|
texturePatch.rect.width = std::min(texturePatch.rect.width, img.cols - texturePatch.rect.x); |
|
|
|
|
texturePatch.rect.height = std::min(texturePatch.rect.height, img.rows - texturePatch.rect.y); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// 设置 texturePatch.rect 后添加边界检查
|
|
|
|
|
texturePatch.rect.width = std::max(1, texturePatch.rect.width); // 宽度至少为1
|
|
|
|
|
texturePatch.rect.height = std::max(1, texturePatch.rect.height); // 高度至少为1
|
|
|
|
|
|
|
|
|
|
// 检查ROI是否超出图像实际范围
|
|
|
|
|
if (texturePatch.rect.x < 0) { |
|
|
|
|
texturePatch.rect.width += texturePatch.rect.x; // 修正负起点
|
|
|
|
|
texturePatch.rect.x = 0; |
|
|
|
|
} |
|
|
|
|
if (texturePatch.rect.y < 0) { |
|
|
|
|
texturePatch.rect.height += texturePatch.rect.y; |
|
|
|
|
texturePatch.rect.y = 0; |
|
|
|
|
} |
|
|
|
|
// 确保ROI不超出图像右/下边界
|
|
|
|
|
texturePatch.rect.width = std::min(texturePatch.rect.width, imageData.image.cols - texturePatch.rect.x); |
|
|
|
|
texturePatch.rect.height = std::min(texturePatch.rect.height, imageData.image.rows - texturePatch.rect.y); |
|
|
|
|
//*/
|
|
|
|
|
// ★ 关键修复:确保 rect 至少 1x1,防止后续空 Mat 写越界
|
|
|
|
|
if (texturePatch.rect.width <= 0 || texturePatch.rect.height <= 0) { |
|
|
|
|
// 退化成一个 1x1 的 patch,避免后续崩溃
|
|
|
|
|
texturePatch.rect.width = 1; |
|
|
|
|
texturePatch.rect.height = 1; |
|
|
|
|
texturePatch.rect.x = std::min(texturePatch.rect.x, images[texturePatch.label].image.cols - 1); |
|
|
|
|
texturePatch.rect.y = std::min(texturePatch.rect.y, images[texturePatch.label].image.rows - 1); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
ASSERT(imageData.image.isInside(texturePatch.rect.tl())); |
|
|
|
|
ASSERT(imageData.image.isInside(texturePatch.rect.br())); |
|
|
|
|
|