image - 如何生成纹理映射图像?

标签 image opencv image-processing mapping textures

我想将图像放置/包裹到 3D 对象中。为了让事情变得简单和快速,我不想使用(和学习)3D 库,而是想使用映射图像。映射图像以这种方式使用:

mapping usage

因此,您为每个对象生成一次映射图像,并对所有要包装的图像使用相同的映射。

我的问题是如何生成此类映射图像(给定 3D 模型)?由于我不知道术语,因此我的搜索失败了。对不起,如果我使用了错误的行话。

您可以在下面看到工作流程的描述。
enter image description here
我有对象的 3D 模型和输入图像,我想生成可用于生成纹理图像的映射图像。

我什至不知道从哪里开始,欢迎任何指点。

更多信息

我最初的想法是使用外部程序以某种方式包装身份映射(见下文)。我在 Photoshop 中生成了水平和垂直渐变图像,只是为了查看是否可以使用 photoshop 生成的图像进行映射。结果看起来不太好。我不抱希望,但值得一试。

输入
enter image description here

映射(x 和 y),它们只是调整图像的大小,它们不会做任何花哨的事情。
enter image description here enter image description here

结果
enter image description here
如您所见,有很多工件。我通过扭曲渐变生成的自定义映射图像看起来更糟。

这里有一些关于映射的更多信息:http://www.imagemagick.org/Usage/mapping/#distortion_maps

我正在使用 OpenCV remap() 函数进行映射。

最佳答案

如果我理解你在这里,你想在 2D 中完成所有这些?

为每个立方体表面调用 warpPerspective() 比使用 remap() 更成功

伪代码大纲:

// for each surface:
//  get the desired src and dst polygon
//  the src one is your texture-image, so that's:
     vector<Point> p_src(4), p_dst(4); 
     p_src[0] = Point(0,0); 
     p_src[1] = Point(0,src.rows-1); 
     p_src[2] = Point(src.cols-1,0);
     p_src[3] = Point(src.cols-1,src.rows-1);
// the dst poly is the one you want textured, a 3d->2d projection of the cube surface.
// sorry, you've got to do that on your own ;(
// let's say, you've come up with this for the cube - top:
     p_dst[0] = Point(15,15); 
     p_dst[1] = Point(44,19); 
     p_dst[2] = Point(56,30);
     p_dst[3] = Point(33,44);

// now you need the projection matrix to transform from one to another:
Mat proj = getPerspectiveTransform( p_src, p_dst );

// finally, you can warp your texture to the dst-polygon:
warpPerspective(src, dst, proj, dst.size());

如果你能拿到“学习 Opencv”这本书,它在第 170 页左右有描述。

警告的最后一句话,因为你在提示人工制品,- 是的,它看起来很俗气,“真正的”3d 引擎在这里做了很多工作,子像素-uv 映射,过滤, mipmapping 等。如果您希望它看起来不错,请考虑使用“真实”的东西。

顺便说一句,opencv 内置了很好的 opengl 支持

关于image - 如何生成纹理映射图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14878467/

相关文章:

c# - IHTMLImgElement 到 byte[]

css - 使用 rails 设置背景图像 css

android - Eclipse - 无法解析方法 NewStringUTF()

python - Pytesseract image_to_data 无法读取我的图像中的数字

javascript - 当使用 javascript 更改时,浏览器是否缓存图像 src

python - 使用 pygtk 设置图像在窗口中的位置

python - 如何在应用轮廓后从图像中提取文本

python - 如何使用 OpenCV VideoWriter 将视频保存到特定目录 -- python

python - Python OPenCV Hough Circle需要很长时间才能从网络摄像头加载图像

c++ - 使用 cvShowImage() 显示滞后视频