3D Face Reconstruction

From a photo of a face, service predicts gender, shape blendshapes, UV face texture, hair color, skin color, the presence of glasses.

1. Getting a token

Getting a token

2. Choice of photo

Choose a photo of a person.

Need a successful image? Download a sample

3. Reconstruct 3D Face

Make a request by sending your chosen photo.

token="ENTER_YOUR_TOKEN"
image_path="ENTER_IMAGE_PATH"

curl -X 'POST' 'https://api.metahumansdk.io/face_recon/run_pipeline' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F "token=$token" \
  -F "image_bytes=@$image_path;type=image/png" > head_config.json

Expected output:

After successful execution of the code, you should receive the following type of json in head_config.json file:

{
  "result": {
    "face": {
      "textureUrl": str,
      "blendShapes": list,
      "blinkCorrectionCoeff": double
    },
    "hair": {
      "color": hex color,
      "type": str
    },
    "skin": {
      "color": hex color
    },
    "accessories": list,
    "gender": str
  }
}

At the moment we have received information about the person. Now let's download the face texture.

4. Download UV face texture

The json we received in the last step contains the url where we can download the texture.

texture_url=$(cat head_config.json | python -c 'import sys, json; print(json.load(sys.stdin)["result"]["face"]["textureUrl"])')

curl -X 'GET' "https://api.metahumansdk.io/face_recon/${texture_url}" > uv.png

After the completed stages, you get a uv texture uv.png and information about the face head_config.json.

5. Visualization

In order to get a 3D model of the head, we will use GLB Constructor:

token="ENTER_YOUR_TOKEN"

curl -X 'POST' 'https://api.metahumansdk.io/glb_const/assemble' \
    -H 'accept: application/json' \
    -H 'Content-Type: multipart/form-data' \
    -F "token=$token" \
    -F '[email protected];type=image/png' \
    -F 'head_config=@head_config.json;type=application/json' \
    -F 'add_facs=true' > head.glb

After the completed stages, you get a glb model head.glb .

image.png
head.glb

To add hair to the head model please follow to 3D Hair Reconstruction.

Last updated