import eos
import numpy as np
import utils.read_pts
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import cv2
def main():
landmarks = utils.read_pts.readPts("./img/image_0010.pts")
image_width = 1280 # Make sure to adjust these when using your own images!
image_height = 1024
model = eos.morphablemodel.load_model("./data/sfm_shape_3448.bin")
blendshapes = eos.morphablemodel.load_blendshapes(
"./data/expression_blendshapes_3448.bin")
morphablemodel_with_expressions = \
eos.morphablemodel.MorphableModel(model.get_shape_model(), blendshapes,
eos.morphablemodel.PcaModel(),
model.get_texture_coordinates())
landmark_mapper = eos.core.LandmarkMapper("./data/ibug_to_sfm.txt")
edge_topology = eos.morphablemodel.load_edge_topology(
"./data/sfm_3448_edge_topology.json")
contour_landmarks = eos.fitting.ContourLandmarks.load(
"./data/ibug_to_sfm.txt")
model_contour = eos.fitting.ModelContour.load(
"./data/sfm_model_contours.json")
(mesh, pose, shape_coeffs, blendshape_coeffs) = \
eos.fitting.fit_shape_and_pose(morphablemodel_with_expressions,
landmarks, landmark_mapper, image_width,
image_height, edge_topology,
contour_landmarks, model_contour)
vertices = np.array(mesh.vertices)
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(vertices[:, 0], vertices[:, 1], vertices[:, 2])
plt.show()
image = cv2.imread("./img/image_0010.png")
image_copy = image.copy()
for landmark in landmarks:
cv2.circle(image_copy, tuple(landmark.coordinates.astype(np.uint32)),
1, (0, 255, 0), -1)
isomap = eos.render.extract_texture(mesh, pose, image)
isomap = cv2.flip(isomap, 0)
cv2.imwrite("./output/image_0010.png", isomap)
cv2.imshow("image", image_copy)
cv2.imshow("", isomap)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == "__main__":
main()
萨里大学EOS示例
猜你喜欢
转载自blog.csdn.net/zhaoyin214/article/details/82423276
今日推荐
周排行