进一步整理finalPatch逻辑
This commit is contained in:
1 parent
209fe6a260
commit
875f0c5be5
1 file changed
+69
-69
+69
-69
@@ -16695,83 +16695,83 @@ bool MeshTexture::RasterizeVirtualFaces(
|
|||||||
|
|
||||||
cv::Mat highFreq = highFreqAccum;
|
cv::Mat highFreq = highFreqAccum;
|
||||||
|
|
||||||
// ========== 每个顶点独立判断可见性(增强版)==========
|
// ========== 每个顶点独立判断可见性(增强版)==========
|
||||||
bool vertexVisible[3] = {false, false, false};
|
bool vertexVisible[3] = {false, false, false};
|
||||||
cv::Vec3f vertexBestColor[3] = {cv::Vec3f(0,0,0), cv::Vec3f(0,0,0), cv::Vec3f(0,0,0)};
|
cv::Vec3f vertexBestColor[3] = {cv::Vec3f(0,0,0), cv::Vec3f(0,0,0), cv::Vec3f(0,0,0)};
|
||||||
|
|
||||||
// 检查主视图
|
// 检查主视图
|
||||||
for (int j = 0; j < 3; ++j) {
|
for (int j = 0; j < 3; ++j) {
|
||||||
int vx = (int)(uv[j].x * textureSize) - minX;
|
int vx = (int)(uv[j].x * textureSize) - minX;
|
||||||
int vy = (int)(uv[j].y * textureSize) - minY;
|
int vy = (int)(uv[j].y * textureSize) - minY;
|
||||||
if (vx >= 0 && vx < patchW && vy >= 0 && vy < patchH) {
|
if (vx >= 0 && vx < patchW && vy >= 0 && vy < patchH) {
|
||||||
cv::Vec3f color = mainFloat.at<cv::Vec3f>(vy, vx);
|
cv::Vec3f color = mainFloat.at<cv::Vec3f>(vy, vx);
|
||||||
if (color[0] > 0.0f || color[1] > 0.0f || color[2] > 0.0f) {
|
if (color[0] > 0.0f || color[1] > 0.0f || color[2] > 0.0f) {
|
||||||
vertexVisible[j] = true;
|
vertexVisible[j] = true;
|
||||||
vertexBestColor[j] = color;
|
vertexBestColor[j] = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果主视图不可见,检查辅助视图
|
// 如果主视图不可见,检查辅助视图
|
||||||
if (hasLowFreqViews && (!vertexVisible[0] || !vertexVisible[1] || !vertexVisible[2])) {
|
if (hasLowFreqViews && (!vertexVisible[0] || !vertexVisible[1] || !vertexVisible[2])) {
|
||||||
for (const auto& lfv : lowFreqViews) {
|
for (const auto& lfv : lowFreqViews) {
|
||||||
if (lfv.viewId >= (IIndex)images.size() || images[lfv.viewId].image.empty()) continue;
|
if (lfv.viewId >= (IIndex)images.size() || images[lfv.viewId].image.empty()) continue;
|
||||||
|
|
||||||
// 对该辅助视图重新采样该顶点位置
|
// 对该辅助视图重新采样该顶点位置
|
||||||
const Camera& auxCam = images[lfv.viewId].camera;
|
const Camera& auxCam = images[lfv.viewId].camera;
|
||||||
bool auxCamValid = (auxCam.K(0,0) > 0 && auxCam.K(1,1) > 0);
|
bool auxCamValid = (auxCam.K(0,0) > 0 && auxCam.K(1,1) > 0);
|
||||||
|
|
||||||
for (int j = 0; j < 3; ++j) {
|
for (int j = 0; j < 3; ++j) {
|
||||||
if (vertexVisible[j]) continue; // 已经可见就跳过
|
if (vertexVisible[j]) continue; // 已经可见就跳过
|
||||||
|
|
||||||
// 用3D投影得到该顶点在辅助视图中的像素位置
|
// 用3D投影得到该顶点在辅助视图中的像素位置
|
||||||
Point2f imgPt;
|
Point2f imgPt;
|
||||||
if (auxCamValid) {
|
if (auxCamValid) {
|
||||||
imgPt = auxCam.ProjectPointP(v[j]);
|
imgPt = auxCam.ProjectPointP(v[j]);
|
||||||
} else {
|
} else {
|
||||||
// 用 homography fallback
|
// 用 homography fallback
|
||||||
const auto& geomRef = m_virtualFaceGeometries[i];
|
const auto& geomRef = m_virtualFaceGeometries[i];
|
||||||
auto it = geomRef.viewHomographies.find(lfv.viewId);
|
auto it = geomRef.viewHomographies.find(lfv.viewId);
|
||||||
if (it == geomRef.viewHomographies.end()) continue;
|
if (it == geomRef.viewHomographies.end()) continue;
|
||||||
|
|
||||||
const float* H = it->second.ptr<float>();
|
const float* H = it->second.ptr<float>();
|
||||||
float u = uv[j].x;
|
float u = uv[j].x;
|
||||||
float v_coord = uv[j].y;
|
float v_coord = uv[j].y;
|
||||||
float w = H[6]*u + H[7]*v_coord + H[8];
|
float w = H[6]*u + H[7]*v_coord + H[8];
|
||||||
if (std::abs(w) < 1e-12f) continue;
|
if (std::abs(w) < 1e-12f) continue;
|
||||||
|
|
||||||
float projX = (H[0]*u + H[1]*v_coord + H[2]) / w;
|
float projX = (H[0]*u + H[1]*v_coord + H[2]) / w;
|
||||||
float projY = (H[3]*u + H[4]*v_coord + H[5]) / w;
|
float projY = (H[3]*u + H[4]*v_coord + H[5]) / w;
|
||||||
imgPt = Point2f(projX, projY);
|
imgPt = Point2f(projX, projY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (imgPt.x >= 0 && imgPt.x < images[lfv.viewId].image.cols &&
|
if (imgPt.x >= 0 && imgPt.x < images[lfv.viewId].image.cols &&
|
||||||
imgPt.y >= 0 && imgPt.y < images[lfv.viewId].image.rows) {
|
imgPt.y >= 0 && imgPt.y < images[lfv.viewId].image.rows) {
|
||||||
// 采样该像素颜色
|
// 采样该像素颜色
|
||||||
cv::Vec3f auxColor = imagesFloat[lfv.viewId].at<cv::Vec3f>((int)imgPt.y, (int)imgPt.x);
|
cv::Vec3f auxColor = imagesFloat[lfv.viewId].at<cv::Vec3f>((int)imgPt.y, (int)imgPt.x);
|
||||||
if (auxColor[0] > 0.0f || auxColor[1] > 0.0f || auxColor[2] > 0.0f) {
|
if (auxColor[0] > 0.0f || auxColor[1] > 0.0f || auxColor[2] > 0.0f) {
|
||||||
vertexVisible[j] = true;
|
vertexVisible[j] = true;
|
||||||
vertexBestColor[j] = auxColor;
|
vertexBestColor[j] = auxColor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果三个顶点都已可见,提前退出
|
// 如果三个顶点都已可见,提前退出
|
||||||
if (vertexVisible[0] && vertexVisible[1] && vertexVisible[2])
|
if (vertexVisible[0] && vertexVisible[1] && vertexVisible[2])
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma omp critical (vertex_visibility)
|
#pragma omp critical (vertex_visibility)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < 3; ++j) {
|
for (int j = 0; j < 3; ++j) {
|
||||||
VIndex vi = face[j];
|
VIndex vi = face[j];
|
||||||
if (vi < m_vertexColors.size() && vertexVisible[j]) {
|
if (vi < m_vertexColors.size() && vertexVisible[j]) {
|
||||||
m_vertexColors[vi].visibleInAnyView = true;
|
m_vertexColors[vi].visibleInAnyView = true;
|
||||||
m_vertexColors[vi].mainColor = vertexBestColor[j];
|
m_vertexColors[vi].mainColor = vertexBestColor[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 空洞填充与合成 ==========
|
// ========== 空洞填充与合成 ==========
|
||||||
cv::Mat filledLowFreq = lowFreqPatch.clone();
|
cv::Mat filledLowFreq = lowFreqPatch.clone();
|
||||||
@@ -16784,8 +16784,8 @@ if (hasLowFreqViews && (!vertexVisible[0] || !vertexVisible[1] || !vertexVisible
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cv::Mat finalPatch = filledLowFreq * 0.7f + mainFloat * 0.3f;
|
cv::Mat finalPatch = filledLowFreq * 0.2f + mainFloat * 0.8f;
|
||||||
// cv::Mat finalPatch = filledLowFreq;
|
// cv::Mat finalPatch = mainFloat;
|
||||||
|
|
||||||
// 钳制到 [0, 1]
|
// 钳制到 [0, 1]
|
||||||
cv::Mat clampedPatch;
|
cv::Mat clampedPatch;
|
||||||
|
|||||||
Reference in new issue
Block a user