-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpersonReidentifier.py
executable file
·56 lines (52 loc) · 2.35 KB
/
personReidentifier.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/local/bin/python3
import time
from os import path
from utils.args import buildArgumentParser
from utils.cmdUtils import buildCmcViewer, buildPersonIdentifier, checkPath
from utils.debugUtils import printv
from utils.persistanceUtils import loadImage, persistImage, persistEmbedding
startTime = time.time()
if __name__ == '__main__':
args = buildArgumentParser().parse_args()
verbose = args.silent
if args.cmc:
buildCmcViewer(args)
else:
identifier = buildPersonIdentifier(args)
if args.video is not None:
identifier.startIdentificationByVideo(args.video)
elif args.camera:
identifier.startIdentificationByCam()
elif args.embedding is not None:
checkPath(args.embedding, "Body image", True)
if args.mtcnn:
raise ValueError(
"You can't generate an embedding using MTCNN. Please, use a body detector and a body embedding generator.")
body = loadImage(args.embedding)
embedding = identifier.getEmbeddingFromBody(body)
if args.savePath is None:
raise FileNotFoundError("Save path is missing. You can set it using --savePath option.")
printv("Saving embedding at %s" % (args.savePath))
persistEmbedding(args.savePath, embedding)
elif args.detection is not None:
checkPath(args.saveFolder, "Detection save folder", False)
checkPath(args.detection, "Image", True)
basename = path.splitext(path.basename(args.detection))[0]
image = loadImage(args.detection)
if args.boundingBox:
detect = identifier.detectFacesInFrame if args.mtcnn else identifier.detectBodiesInFrame
persistImage(
args.saveFolder,
"%s.png" % (basename),
detect(image)
)
else:
detect = identifier.getFacesFromImage if args.mtcnn else identifier.getBodiesFromImage
images = detect(image)
for idx, img in enumerate(images):
persistImage(
args.saveFolder,
"%s-%d.png" % (basename, idx),
img
)
printv("Task finished 🚀. Time elapsed: %s seconds." % (time.time() - startTime))