yfeng95 / PRNet

Joint 3D Face Reconstruction and Dense Alignment with Position Map Regression Network (ECCV 2018)
http://openaccess.thecvf.com/content_ECCV_2018/papers/Yao_Feng_Joint_3D_Face_ECCV_2018_paper.pdf
MIT License
4.95k stars 947 forks source link

Source code `render.py` error #130

Open zhouhao-learning opened 5 years ago

zhouhao-learning commented 5 years ago

When I use your model to predict my image, I save the mat file of the image, then I load the saved mat file and execute the render_texture function of utils/render.py when I get The following error:

IndexError                                Traceback (most recent call last)
<ipython-input-12-67a5eb198033> in <module>
----> 1 imgs = render_texture(vertices,colors,triangles, h,w)

~/sda1/人脸识别/PRNet/utils/render.py in render_texture(vertices, colors, triangles, h, w, c)
     97     depth_buffer = np.zeros([h, w]) - 999999.
     98     # triangle depth: approximate the depth to the average value of z in each vertex(v0, v1, v2), since the vertices are closed to each other
---> 99     tri_depth = (vertices[2, triangles[0,:]] + vertices[2,triangles[1,:]] + vertices[2, triangles[2,:]])/3.
    100     tri_tex = (colors[:, triangles[0,:]] + colors[:,triangles[1,:]] + colors[:, triangles[2,:]])/3.
    101 

IndexError: index 247 is out of bounds for axis 1 with size 3

My code is as follows:

from utils.render import *
from utils.render_app import *
import numpy as np
import scipy.io as scio
import cv2
import matplotlib.pyplot as plt
%matplotlib inline

mat_file = scio.loadmat("images/img_pre/詹姆斯_mesh.mat")
vertices = mat_file['vertices']
colors = mat_file['colors']
triangles = mat_file['triangles']

img = cv2.imread("images/img/詹姆斯.jpg")
h = img.shape[0]
w = img.shape[1]
imgs = render_texture(vertices,colors,triangles, h,w)

I don't understand why it went wrong, because triangles is from the files you provided, how can I solve this error? Can you give me some knowledge? Thank you.

yeldartoktasynov commented 8 months ago

Hello, I had the similar issue. I solved it by providing transpose of the given arrays as it shown in get_depth_image() function in demo.py .: imgs = render_texture(vertices.T,colors.T,triangles.T, h,w).