3D Hair Reconstruction
Reconstructs 3D hair from a photo of a person.
1. Getting a token
Getting a token
2. Choice of photo
Choose a photo of a person.
Note: The quality of the photo must be a good resolution.
Note: Hair should be clearly visible.
Note: So far, we are unable to work well with ponytails and pigtails.
3. Reconstruct 3D Hair
Make a request by sending your chosen photo. Make sure you are using the mode you really need. 'card'
mode is used by default.
token="ENTER_YOUR_TOKEN"
image_path="ENTER_IMAGE_PATH"
curl -X 'POST' \
'https://api.metahumansdk.io/hair_recon/run_pipeline' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F "token=$token" \
-F "image_bytes=@$image_path;type=image/png" > hair.glb \
-F 'mode=card'
import requests
token = "ENTER_YOUR_TOKEN"
image_path = "ENTER_IMAGE_PATH"
if __name__ == "__main__":
service_url = "https://api.metahumansdk.io/hair_recon"
service_headers = {"accept": "application/json"}
files = {
"token": (None, token),
"image_bytes": ("image", open(image_path, "rb"), "image/png"),
"mode": (None, "card") # card or volume
}
response_config = requests.post(service_url + "/run_pipeline", headers=service_headers, files=files, stream=True)
with open("hair.glb", "wb") as f:
f.write(response_config.content)
The expected result is the hair.glb
file.
4. Check GLB model
Check saved file in GLB viewer (for example in Blender).
Examples of results
Open in Blender
Example rendering
Rendering in Blender
5. Visualization with head
In order to get a 3D model of the head with hair, we will use GLB Constructor:
GLB Constructor currently supports only hair involume
mode
At this step it is assumed that you have already received uv.png
and head_config.json
from 3D Face Reconstruction tab.
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 'head_uv=@uv.png;type=image/png' \
-F 'head_config=@head_config.json;type=application/json' \
-F 'custom_models=@hair.glb;type=image/png' \
-F 'add_facs=true' > head.glb
import io
import json
import requests
token = "ENTER_YOUR_TOKEN"
if __name__ == "__main__":
service_url = "https://api.metahumansdk.io/glb_const"
service_headers = {'accept': 'application/json'}
with open('uv.png', 'rb') as out:
head_uv = out.read()
with open('head_config.json', 'r') as out:
head_config = json.loads(out.read())
with open('hair.glb', 'rb') as out:
custom_hair = out.read()
files = {
'token': (None, token),
'head_uv': ('head_model', head_uv, 'image/png'),
'head_config': ('head_config', json.dumps(head_config), 'application/json'),
'custom_models': ('custom_models', io.BytesIO(custom_hair), 'application/json'),
'add_facs': (None, True),
}
response = requests.post(service_url + "/assemble", headers=service_headers, files=files)
assert (response.status_code == 200)
with open("head.glb", "wb") as f:
f.write(response.content)
After the completed stages, you get a glb model head.glb
.
Result: