-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jsonfl.py
36 lines (25 loc) · 820 Bytes
/
Jsonfl.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import numpy as np
import os
import json
from json import JSONEncoder
import face_recognition
class NumpyArrayEncoder(JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
return JSONEncoder.default(self, obj)
data = []
for b in os.listdir('photos'):
for p in os.listdir(f'photos/{b}'):
name = p.split(".")[0]
path = f"photos/{b}/{p}"
pic = face_recognition.load_image_file(path)
encode_pic = face_recognition.face_encodings(pic)[0]
d = {'name': name,
'path': path,
'dir': b,
'encode': encode_pic}
data.append(d)
encodedNumpyData = json.dumps(data, cls=NumpyArrayEncoder)
with open("sample.json", "w") as outfile:
outfile.write(encodedNumpyData)