-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdetect.py
48 lines (38 loc) · 1.47 KB
/
detect.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
#########################################################################
# File Name: detect.py
# Author: Henry Ma
# mail: [email protected]
# Create Time: 2021年02月04日 星期四 15时55分20秒
#########################################################################
# !/usr/bin/python
# -*- coding:utf-8 -*-
from builtins import *
import cv2
import numpy as np
from mtcnn import mtcnn
if __name__ == '__main__':
model = mtcnn()
#---------------------------------------#
# 设置检测门限
#---------------------------------------#
threshold = [0.5, 0.6, 0.7]
#---------------------------------------#
# 读取图片
#---------------------------------------#
img = cv2.imread('img/test.jpg')
temp_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
#-------------------------------------#
# 将图片传入并检测
#-------------------------------------#
rectangles = model.detectFace(temp_img, threshold)
draw = img.copy()
for rectangle in rectangles:
W = int(rectangle[2]) - int(rectangle[0])
H = int(rectangle[3]) - int(rectangle[1])
cv2.rectangle(draw, (int(rectangle[0]), int(rectangle[1])),
(int(rectangle[2]), int(rectangle[3])), (0, 0, 255), 2)
for i in range(5, 15, 2):
cv2.circle(draw, (int(rectangle[i + 0]), int(rectangle[i + 1])), 1, (255, 0, 0), 4)
cv2.imwrite("img/out.jpg", draw)
cv2.imshow("test", draw)
c = cv2.waitKey(0)