-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencodeGenerator.py
More file actions
64 lines (51 loc) · 2 KB
/
encodeGenerator.py
File metadata and controls
64 lines (51 loc) · 2 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import cv2
import face_recognition
import pickle
import os
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from firebase_admin import storage
cred = credentials.Certificate("serviceAccKey.json")
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://realtimerecognizer-ac6e4-default-rtdb.firebaseio.com/',
'storageBucket': 'realtimerecognizer-ac6e4.appspot.com'
})
folderPath = 'ImageLib'
modePathList = os.listdir(folderPath)
imageList = []
peopleID = []
for path in modePathList:
imageList.append(cv2.imread(os.path.join(folderPath, path)))
peopleID.append(os.path.splitext(path)[0])
fileName = f'{folderPath}/{path}'
bucket = storage.bucket()
blob = bucket.blob(fileName)
blob.upload_from_filename(fileName)
# Untuk mengecek list file / gambar pada folder |
# |
# print(path) |
# print(os.path.splitext(path)[0]) |
# |
# Untuk mengecek list file / gambar pada folder |
print(peopleID)
# print("Encoded image -> successfully encoded")
def findEncodings(imageList):
encodeList = []
for faceImg in imageList:
faceImg = cv2.cvtColor(faceImg, cv2.COLOR_BGR2RGB)
encode = face_recognition.face_encodings(faceImg)[0]
encodeList.append(encode)
return encodeList
print("Encoding is starting ...") # encodeListKnown = peopleFaceList
peopleFaceList = findEncodings(imageList) # print(peopleFaceList)
print(peopleFaceList)
# sudah bisa jadi gapapa gak di print lagi, next taro di pickle
# ketika kita save ke file (1. encodingnya) (2. nama ID encodings)
peopleFaceListWithId = [peopleFaceList, peopleID]
print("Encoded successfully")
# generate pickle file
pickleFile = open("EncodeFile.p", 'wb')
pickle.dump(peopleFaceListWithId, pickleFile)
pickleFile.close()
print("Picked successfully saved")