Closed WRY0627 closed 1 year ago
你好我之前的问题解决了,但是生成的深度图背景颜色希望是白色,我之前的思路是将背景颜色直接设成白色,但是这样会使面部中相同的颜色值同样进行转化。请问有没有什么方法可以解决这个问题呢? 生成深度图的代码如下: rend_depth, rend_img = renderer.render_cvcam(mesh_dirname, K, Rt, rend_size=(h, w)) rend_depth_vis = rend_depth - np.min(rend_depth[rend_depth!=0]) rend_depth_vis = (rend_depth_vis / np.max(rend_depth_vis) * 255).astype(np.uint8) 生成结果如图所示:
已收到
由于只想要深度信息,因此将demo_mview_projection.ipynb中的部分代码进行修改注释,并参考 https://github.com/zhuhao-nju/facescape/issues/42 得到深度图。具体代码如下:
import os os.environ['PYOPENGL_PLATFORM'] = 'osmesa' import sys, cv2, json import numpy as np import src.renderer as renderer import src.utility as util import matplotlib.pyplot as plt from PIL import Image
scale=0.1 test_num=1.1
read params
with open("../samples/sample_mview_data/4_anger/params.json", 'r') as f: params = json.load(f)
K = np.array(params['%d_K' % test_num]) Rt = np.array(params['%d_Rt' % test_num]) dist = np.array(params['%d_distortion' % test_num], dtype = np.float64) h_src = params['%d_height' % test_num] w_src = params['%d_width' % test_num]
h, w = int(h_src scale), int(w_src scale) K[:2,:] = K[:2,:] * scale
src_img = cv2.imread("/home/ps/workspace/SSD/wry/Facescape/facescape/samples/sample_mview_data/4_anger")
src_img = cv2.resize(src_img, (w, h))
undist_img = cv2.undistort(src_img, K, dist)
mesh_dirname = "../samples/sample_mview_data/4_anger.ply" depth_map, rend_img = renderer.render_cvcam(mesh_dirname, K, Rt) depth_map_array = np.array(depth_map)
project and show
cv2.imwrite('/home/ps/workspace/SSD/demo_output/out.jpg', depth_map)
depth_map = Image.fromarray(depth_map_array).convert('L') print(type(depth_map))
depth_map = np.asarray(depth_map)
print(type(depth_map))
depth_map = np.array(depth_map) print(depth_map) depth_map[depth_map!=0] = depth_map[depth_map!=0] - np.min(depth_map[depth_map!=0]) # move min to 0 depth_map = (depth_map / np.max(depth_map) * 255).astype(np.uint8) # scale max to 255 depth_map = 255 - depth_map # inverse depth_map as your example cv2.imwrite('/home/ps/workspace/SSD/wry/Facescape/facescape/demo_output/out7.jpg', depth_map)
但最终保存的深度图如图: 请问这是什么问题造成的呢?