From d1a5815cb927de6d04e21686a2fd84d400df38f9 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sat, 28 Mar 2015 23:16:54 -0400 Subject: [PATCH] Added default upsampling amount to detector.run(). Also moved the new example code into face_detector.py and added some comments. --- python_examples/face_detector.py | 17 +++++++++++++++-- python_examples/face_detector_scores_idx.py | 13 ------------- tools/python/src/object_detection.cpp | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) delete mode 100644 python_examples/face_detector_scores_idx.py diff --git a/python_examples/face_detector.py b/python_examples/face_detector.py index 317cf72fc..2401bdf85 100755 --- a/python_examples/face_detector.py +++ b/python_examples/face_detector.py @@ -51,11 +51,24 @@ for f in sys.argv[1:]: # faces. dets = detector(img, 1) print("Number of faces detected: {}".format(len(dets))) - for k, d in enumerate(dets): + for i, d in enumerate(dets): print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format( - k, d.left(), d.top(), d.right(), d.bottom())) + i, d.left(), d.top(), d.right(), d.bottom())) win.clear_overlay() win.set_image(img) win.add_overlay(dets) dlib.hit_enter_to_continue() + + +# Finally, if you really want to you can ask the detector to tell you the score +# for each detection. The score is bigger for more confident detections. +# Also, the idx tells you which of the face sub-detectors matched. This can be +# used to broadly identify faces in different orientations. +if (len(sys.argv[1:]) > 0): + img = io.imread(sys.argv[1]) + dets, scores, idx = detector.run(img, 1) + for i, d in enumerate(dets): + print("Detection {}, score: {}, face_type:{}".format( + d, scores[i], idx[i])) + diff --git a/python_examples/face_detector_scores_idx.py b/python_examples/face_detector_scores_idx.py deleted file mode 100644 index 4156bfcb1..000000000 --- a/python_examples/face_detector_scores_idx.py +++ /dev/null @@ -1,13 +0,0 @@ - -from PIL import Image -import numpy as np -import dlib - -img = np.array(Image.open('../examples/faces/2008_002506.jpg')) -detector = dlib.get_frontal_face_detector() - -dets, scores, idx = detector.run(img, 1) - -for i, d in enumerate(dets): - print d, scores[i], idx[i] - diff --git a/tools/python/src/object_detection.cpp b/tools/python/src/object_detection.cpp index 09a785c0c..1f5ae7cd5 100644 --- a/tools/python/src/object_detection.cpp +++ b/tools/python/src/object_detection.cpp @@ -354,7 +354,7 @@ ensures \n\ detector. If you don't know how many times you want to upsample then \n\ don't provide a value for upsample_num_times and an appropriate \n\ default will be used.") - .def("run", run_rect_detector, (arg("image"), arg("upsample_num_times")), + .def("run", run_rect_detector, (arg("image"), arg("upsample_num_times")=0), "requires \n\ - image is a numpy ndarray containing either an 8bit grayscale or RGB \n\ image. \n\