forked from 610265158/DSFD-tensorflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vis.py
executable file
·76 lines (55 loc) · 1.85 KB
/
vis.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import cv2
import os
import time
import tensorflow as tf
from lib.core.api.face_detector import FaceDetector
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
detector = FaceDetector(['./model/detector.pb'])
def GetFileList(dir, fileList):
newDir = dir
if os.path.isfile(dir):
fileList.append(dir)
elif os.path.isdir(dir):
for s in os.listdir(dir):
# if s == "pts":
# continue
newDir=os.path.join(dir,s)
GetFileList(newDir, fileList)
return fileList
def facedetect():
count = 0
data_dir = 'yourdatadir'
pics = []
GetFileList(data_dir,pics)
pics = [x for x in pics if 'jpg' in x or 'png' in x]
#pics.sort()
for pic in pics:
img=cv2.imread(pic)
img_show = img.copy()
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
star=time.time()
boxes=detector(img,0.5)
#print('one iamge cost %f s'%(time.time()-star))
#print(boxes.shape)
#print(boxes)
################toxml or json
print(boxes.shape[0])
if boxes.shape[0]==0:
print(pic)
for box_index in range(boxes.shape[0]):
bbox = boxes[box_index]
cv2.rectangle(img_show, (int(bbox[0]), int(bbox[1])),
(int(bbox[2]), int(bbox[3])), (255, 0, 0), 4)
# cv2.putText(img_show, str(bbox[4]), (int(bbox[0]), int(bbox[1]) + 30),
# cv2.FONT_HERSHEY_SIMPLEX, 1,
# (255, 0, 255), 2)
#
# cv2.putText(img_show, str(int(bbox[5])), (int(bbox[0]), int(bbox[1]) + 40),
# cv2.FONT_HERSHEY_SIMPLEX, 1,
# (0, 0, 255), 2)
cv2.namedWindow('res',0)
cv2.imshow('res',img_show)
cv2.waitKey(0)
print(count)
if __name__=='__main__':
facedetect()