mirror of
https://github.com/opencv/opencv.git
synced 2024-11-28 21:20:18 +08:00
faster detection and timing in facedetect.py
This commit is contained in:
parent
b5d864f579
commit
0217ae3a70
@ -1,13 +1,14 @@
|
||||
import numpy as np
|
||||
import cv2, cv
|
||||
from video import create_capture
|
||||
from common import clock, draw_str
|
||||
|
||||
help_message = '''
|
||||
USAGE: facedetect.py [--cascade <cascade_fn>] [--nested-cascade <cascade_fn>] [<video_source>]
|
||||
'''
|
||||
|
||||
def detect(img, cascade):
|
||||
rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30))
|
||||
rects = cascade.detectMultiScale(img, scaleFactor=1.3, minNeighbors=4, minSize=(30, 30), flags = cv.CV_HAAR_SCALE_IMAGE)
|
||||
if len(rects) == 0:
|
||||
return []
|
||||
rects[:,2:] += rects[:,:2]
|
||||
@ -37,6 +38,8 @@ if __name__ == '__main__':
|
||||
ret, img = cam.read()
|
||||
gray = cv2.cvtColor(img, cv.CV_BGR2GRAY)
|
||||
gray = cv2.equalizeHist(gray)
|
||||
|
||||
t = clock()
|
||||
rects = detect(gray, cascade)
|
||||
vis = img.copy()
|
||||
draw_rects(vis, rects, (0, 255, 0))
|
||||
@ -45,7 +48,9 @@ if __name__ == '__main__':
|
||||
vis_roi = vis[y1:y2, x1:x2]
|
||||
subrects = detect(roi.copy(), nested)
|
||||
draw_rects(vis_roi, subrects, (255, 0, 0))
|
||||
dt = clock() - t
|
||||
|
||||
draw_str(vis, (20, 20), 'time: %.1f ms' % (dt*1000))
|
||||
cv2.imshow('facedetect', vis)
|
||||
|
||||
if cv2.waitKey(5) == 27:
|
||||
|
Loading…
Reference in New Issue
Block a user