Spaces:
Running
Running
fix file save
Browse files- face_mesh3d.py +15 -1
face_mesh3d.py
CHANGED
|
@@ -5,6 +5,17 @@ from glibvision.cv2_utils import pil_to_bgr_image
|
|
| 5 |
|
| 6 |
from mp_utils import get_pixel_cordinate_list,extract_landmark,get_pixel_cordinate,get_normalized_xyz
|
| 7 |
import mp_triangles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def process_image3d(image,smooth_mesh,depto_ratio,inner_eyes,inner_mouth):
|
| 9 |
|
| 10 |
mp_image,face_landmarker_result = extract_landmark(image)
|
|
@@ -35,7 +46,10 @@ def process_image3d(image,smooth_mesh,depto_ratio,inner_eyes,inner_mouth):
|
|
| 35 |
|
| 36 |
# PolyDataオブジェクトの作成
|
| 37 |
mesh = pv.PolyData(vertices, faces)
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
texture = pv.Texture(np.array(image, dtype=np.uint8))
|
| 41 |
uv_coords = np.array(uv,dtype="float32")
|
|
|
|
| 5 |
|
| 6 |
from mp_utils import get_pixel_cordinate_list,extract_landmark,get_pixel_cordinate,get_normalized_xyz
|
| 7 |
import mp_triangles
|
| 8 |
+
import io
|
| 9 |
+
import hashlib
|
| 10 |
+
import os
|
| 11 |
+
def get_image_id(image):
|
| 12 |
+
buffer = io.BytesIO()
|
| 13 |
+
image.save(buffer, format='PNG')
|
| 14 |
+
hash_object = hashlib.sha256(buffer.getvalue())
|
| 15 |
+
hex_dig = hash_object.hexdigest()
|
| 16 |
+
unique_id = hex_dig[:32]
|
| 17 |
+
return unique_id
|
| 18 |
+
|
| 19 |
def process_image3d(image,smooth_mesh,depto_ratio,inner_eyes,inner_mouth):
|
| 20 |
|
| 21 |
mp_image,face_landmarker_result = extract_landmark(image)
|
|
|
|
| 46 |
|
| 47 |
# PolyDataオブジェクトの作成
|
| 48 |
mesh = pv.PolyData(vertices, faces)
|
| 49 |
+
|
| 50 |
+
id = get_image_id(image)
|
| 51 |
+
os.makedirs("files",exist_ok=True)
|
| 52 |
+
path = f"files/{id}.gltf"#TODO uniq file
|
| 53 |
|
| 54 |
texture = pv.Texture(np.array(image, dtype=np.uint8))
|
| 55 |
uv_coords = np.array(uv,dtype="float32")
|