Commit d1a5815c authored by Davis King's avatar Davis King

Added default upsampling amount to detector.run(). Also moved the

new example code into face_detector.py and added some comments.
parent 35b74d1b
...@@ -51,11 +51,24 @@ for f in sys.argv[1:]: ...@@ -51,11 +51,24 @@ for f in sys.argv[1:]:
# faces. # faces.
dets = detector(img, 1) dets = detector(img, 1)
print("Number of faces detected: {}".format(len(dets))) 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( 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.clear_overlay()
win.set_image(img) win.set_image(img)
win.add_overlay(dets) win.add_overlay(dets)
dlib.hit_enter_to_continue() 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]))
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]
...@@ -354,7 +354,7 @@ ensures \n\ ...@@ -354,7 +354,7 @@ ensures \n\
detector. If you don't know how many times you want to upsample then \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\ don't provide a value for upsample_num_times and an appropriate \n\
default will be used.") 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\ "requires \n\
- image is a numpy ndarray containing either an 8bit grayscale or RGB \n\ - image is a numpy ndarray containing either an 8bit grayscale or RGB \n\
image. \n\ image. \n\
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment