【发布时间】:2020-12-22 23:13:44
【问题描述】:
你好,我正在为一个游戏做纹理打包,想合并法线贴图的 R、G 通道、遮挡贴图(AO 和腔贴图的乘积,但由于我不知道如何乘积OpenCV 中的图像正确我只是使用腔贴图)和 EXR 中的置换贴图。法线和遮挡贴图是 JPEG,而位移是 EXR,所以我想合并它们,同时保持我认为的位深度。此外,我想以受支持的格式导出它,该格式既能保留位深度,又能与 UE4、Unity 等引擎兼容。这是我目前所得到的:
normal = cv2.imread('{subdir}/{code}_4K_Normal.jpg'.format(subdir=subdir, code=code), cv2.IMREAD_UNCHANGED)
ao = cv2.imread('{subdir}/{code}_4K_AO.jpg'.format(subdir=subdir, code=code), cv2.IMREAD_UNCHANGED)
cavity = cv2.imread('{subdir}/{code}_4K_Cavity.jpg'.format(subdir=subdir, code=code), cv2.IMREAD_UNCHANGED)
height = cv2.imread('{subdir}/{code}_4K_Displacement.exr'.format(subdir=subdir, code=code), cv2.IMREAD_ANYCOLOR | cv2.IMREAD_ANYDEPTH)
normal_b, normal_g, normal_r = cv2.split(normal)
ao_b, ao_g, ao_r = cv2.split(ao)
cavity_b, cavity_g, cavity_r = cv2.split(cavity)
height_b, height_g, height_r = cv2.split(height)
noh = cv2.merge((cavity_r, normal_g, normal_r, height_r))
cv2.imwrite('{subdir}/{code}_4K_NOH_2.tga'.format(subdir=subdir, code=code), noh)
但是执行上述操作会给我这个错误:
noh = cv2.merge((cavity_r, normal_g, normal_r, height_r))
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-h4wtvo23\opencv\modules\core\src\merge.dispatch.cpp:129: error: (-215:Assertion failed) mv[i].size == mv[0].size && mv[i].depth() == depth in function 'cv::merge'
以下是我要问的问题:
- 如何合并不同位深度的通道,但仍保持高位深度。
- 将图像导出为适合游戏引擎的良好格式。
【问题讨论】:
-
您将无法使用 TGA 文件保留高位深度,是吗?你希望写什么RGB888 +D32?
-
@MarkSetchell 我当时导出到另一种文件格式没有问题,认为 TGA 足够高。谢谢(你的)信息。将编辑帖子
-
@MarkSetchell 你问的第二个问题是什么意思?对文件格式了解不够。
-
输出文件中需要哪些组件(红色、绿色、蓝色、深度、其他?)以及每个组件应该具有什么位深度?您打算将输出文件用于/与什么一起使用?
-
@MarkSetchell 输出有4个通道,法线的r和g,遮挡的r为b,位移的r为a。如果只有 alpha 通道(位移)处于高位深度,我会更喜欢,尽管我再次知道如何做到这一点。
标签: python opencv image-processing opencv-python