Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added test.py, updated requirements.txt #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
thop==0.0.31.post2005241907
joblib==1.0.1
torchvision==0.10.0+cu111
torchvision>=0.10.0+cu111
tqdm==4.50.2
torch==1.9.0+cu111
torch>=1.9.0+cu111
matplotlib==3.3.2
requests==2.25.1
numpy==1.20.3
opencv_python==4.5.2.52
scipy==1.5.2
scipy>=1.5.2
pandas==1.1.3
seaborn==0.11.1
onnx==1.9.0
Expand Down
43 changes: 43 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from face_detector import YoloDetector
import numpy as np
from PIL import Image
import cv2

def show_results(img, xywh, landmarks):
h,w,c = img.shape
tl = 5 or round(0.2 * (h + w) / 2) + 1 # line/font thickness

n = 0
for i in xywh:
x1 =i[0]
y1 = i[1]
x2 = i[2]
y2 = i[3]
cv2.rectangle(img, (x1,y1), (x2, y2), (0,255,0), thickness=tl, lineType=cv2.LINE_AA)

clors = [(255,0,0),(0,255,0),(0,0,255),(255,255,0),(0,255,255)]

c=0
for j in landmarks[n]:
cv2.circle(img, (j[0],j[1]), tl+1, clors[c], -1)
c=c+1

tf = max(tl - 1, 1) # font thickness
cv2.putText(img, 'Face {0}'.format(n), (x1, y1 - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
n=n+1

return img
# gpu=-1 means use cpu, gpu=n where n is gpu device id
model = YoloDetector(target_size=720,gpu=-1,min_face=90)
img = cv2.imread('test_image.jpg')
orgimg = np.array(img)
bboxes,points = model.predict(orgimg)

faces = show_results(img,bboxes,points)
win_name = "visualization"
#Named window for fit-to-window
cv2.namedWindow(win_name, cv2.WINDOW_NORMAL)
cv2.imshow(win_name,faces)
cv2.waitKey(0)
cv2.destroyAllWindows()