From: Alexander Mordvintsev Date: Mon, 11 Jul 2011 09:21:27 +0000 (+0000) Subject: faster detection and timing in facedetect.py X-Git-Tag: accepted/tizen/6.0/unified/20201030.111113~6680 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0217ae3a70b45129ab08fc2fa0712c6a096ffd2c;p=platform%2Fupstream%2Fopencv.git faster detection and timing in facedetect.py --- diff --git a/samples/python2/facedetect.py b/samples/python2/facedetect.py index ca85b14..1dd0528 100644 --- a/samples/python2/facedetect.py +++ b/samples/python2/facedetect.py @@ -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 ] [--nested-cascade ] [] ''' 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: