-
-
Save khaidir/c1caa9839d2e980437aa to your computer and use it in GitHub Desktop.
Revisions
-
npinto revised this gist
Sep 5, 2012 . 25 changed files with 577403 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import time from cv2_detect import detect import cv2 import cv2.cv as cv def draw_rects(img, rects, color): for x1, y1, x2, y2 in rects: cv2.rectangle(img, (x1, y1), (x2, y2), color, 2) def demo(in_fn, out_fn): print ">>> Loading image..." img_color = cv2.imread(in_fn) img_gray = cv2.cvtColor(img_color, cv.CV_RGB2GRAY) img_gray = cv2.equalizeHist(img_gray) print in_fn, img_gray.shape print ">>> Detecting faces..." start = time.time() rects = detect(img_gray) end = time.time() print 'time:', end - start img_out = img_color.copy() draw_rects(img_out, rects, (0, 255, 0)) cv2.imwrite(out_fn, img_out) def main(): demo('pic.jpg', 'pic.detect.jpg') if __name__ == '__main__': main() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ >>> Loading image... pic.jpg (2400, 3600) >>> Detecting faces... time: 8.11453986168 LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed.LoadingSorry, something went wrong. Reload?Sorry, we cannot display this file.Sorry, this file is invalid so it cannot be displayed. -
npinto created this gist
Sep 5, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import cv2 import cv2.cv as cv def detect(img, cascade_fn='haarcascades/haarcascade_frontalface_alt.xml', scaleFactor=1.3, minNeighbors=4, minSize=(20, 20), flags=cv.CV_HAAR_SCALE_IMAGE): cascade = cv2.CascadeClassifier(cascade_fn) rects = cascade.detectMultiScale(img, scaleFactor=scaleFactor, minNeighbors=minNeighbors, minSize=minSize, flags=flags) if len(rects) == 0: return [] rects[:, 2:] += rects[:, :2] return rects