Skip to content

Commit

Permalink
Fix for texture mapping into destination image
Browse files Browse the repository at this point in the history
The [0, 1] uv space was mistakenly mapped to [-1, 511], so in the case where a y uv-coord was exactly 0.0 it would produce a crash.
It's now correctly mapped to [0, 511] (or whatever the texture map resolution is).
Also the mapping was only done for y, but it should be done for x and y, which I added now.

Coincidentially, this seems to fix the "black line" isomap bug (#4), so I uncommented the fix.
There will still a few "black" pixels appear around the mouth, which is just because no uv coordinates map there.

This fix also makes "square" isomaps work, i.e. when the whole isomap is filled with data, without any borders.

It seems like the last row and col of the isomaps don't get filled now, I think this could be because the lookup with Point2f(...) does floor and not round. We can ignore this for now.

Thanks to @PhilippKopp for spotting this and helping fix it!
  • Loading branch information
patrikhuber committed May 5, 2017
1 parent f129619 commit 6875e08
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions include/eos/render/texture_extraction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,9 @@ inline cv::Mat extract_texture(core::Mesh mesh, cv::Mat affine_camera_matrix, cv
res = Mat(affine_camera_matrix * Mat(vec));
src_tri[2] = Vec2f(res[0], res[1]);

dst_tri[0] = cv::Point2f(isomap.cols*mesh.texcoords[triangle_indices[0]][0], isomap.rows*mesh.texcoords[triangle_indices[0]][1] - 1.0f);
dst_tri[1] = cv::Point2f(isomap.cols*mesh.texcoords[triangle_indices[1]][0], isomap.rows*mesh.texcoords[triangle_indices[1]][1] - 1.0f);
dst_tri[2] = cv::Point2f(isomap.cols*mesh.texcoords[triangle_indices[2]][0], isomap.rows*mesh.texcoords[triangle_indices[2]][1] - 1.0f);
dst_tri[0] = cv::Point2f((isomap.cols - 1)*mesh.texcoords[triangle_indices[0]][0], (isomap.rows - 1)*mesh.texcoords[triangle_indices[0]][1]);
dst_tri[1] = cv::Point2f((isomap.cols - 1)*mesh.texcoords[triangle_indices[1]][0], (isomap.rows - 1)*mesh.texcoords[triangle_indices[1]][1]);
dst_tri[2] = cv::Point2f((isomap.cols - 1)*mesh.texcoords[triangle_indices[2]][0], (isomap.rows - 1)*mesh.texcoords[triangle_indices[2]][1]);

// We now have the source triangles in the image and the source triangle in the isomap
// We use the inverse/ backward mapping approach, so we want to find the corresponding texel (texture-pixel) for each pixel in the isomap
Expand Down Expand Up @@ -345,10 +345,11 @@ inline cv::Mat extract_texture(core::Mesh mesh, cv::Mat affine_camera_matrix, cv
}

// Workaround for the black line in the isomap (see GitHub issue #4):
if (mesh.texcoords.size() <= 3448)
/* if (mesh.texcoords.size() <= 3448)
{
isomap = detail::interpolate_black_line(isomap);
}
*/

return isomap;
};
Expand Down

0 comments on commit 6875e08

Please sign in to comment.