Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sfm
- import numpy as np
- shape_only = False # or True
- model = sfm.load('C:/Users/glbay/PycharmProjects/3DFaceReconstructionFromMultipleImages/3DMM/sfm_shape_29587.scm', shape_only)
- faces = model.faces
- shape = model.shape
- texture = model.texture
- pcamodel = model.shape.mean
- try:
- file = open("C:/Users/glbay/PycharmProjects/3DFaceReconstructionFromMultipleImages/output/temp.obj" , "r+")
- except IOError:
- file = open("C:/Users/glbay/PycharmProjects/3DFaceReconstructionFromMultipleImages/output/temp.obj", "w")
- file.truncate()
- points = np.array(pcamodel)
- points = points.reshape(3,-1).T
- file.write("#OBJ file created by Bayarjargal.J n#Vertices : " + str(model.numvertices) + "n#Faces : "+ str(model.numfaces) +"n")
- for x, y ,z in points:
- file.write("v " + str(float("{0:.4f}".format(x))) + " " + str(float("{0:.4f}".format(y))) + " " + str(float("{0:.4f}".format(z))) + "n")
- i = 0
- for a , b, c in faces:
- file.write("f " + str(c) + " " + str(b) + " " + str(a) + "n")
- i+=1
- print "FACES WRITTEN : " + str(i)
Add Comment
Please, Sign In to add comment