|
24 | 24 | # the path to this faces folder as a command line argument so we will know |
25 | 25 | # where it is. |
26 | 26 | if (len(sys.argv) != 2): |
27 | | - print "Give the path to the examples/faces directory as the argument to this" |
28 | | - print "program. For example, if you are in the python_examples folder then " |
29 | | - print "execute this program by running:" |
30 | | - print " ./train_object_detector.py ../examples/faces" |
| 27 | + print("Give the path to the examples/faces directory as the argument to this") |
| 28 | + print("program. For example, if you are in the python_examples folder then ") |
| 29 | + print("execute this program by running:") |
| 30 | + print(" ./train_object_detector.py ../examples/faces") |
31 | 31 | exit() |
32 | 32 | faces_folder = sys.argv[1] |
33 | 33 |
|
|
59 | 59 | # images with boxes. To see how to use it read the tools/imglab/README.txt |
60 | 60 | # file. But for this example, we just use the training.xml file included with |
61 | 61 | # dlib. |
62 | | -dlib.train_simple_object_detector(faces_folder+"/training.xml","detector.svm", options) |
| 62 | +dlib.train_simple_object_detector(faces_folder+"/training.xml", "detector.svm", options) |
63 | 63 |
|
64 | 64 |
|
65 | 65 |
|
66 | 66 | # Now that we have a face detector we can test it. The first statement tests |
67 | | -# it on the training data. It will print the precision, recall, and then |
| 67 | +# it on the training data. It will print(the precision, recall, and then) |
68 | 68 | # average precision. |
69 | | -print "\ntraining accuracy:", dlib.test_simple_object_detector(faces_folder+"/training.xml", "detector.svm") |
| 69 | +print("\ntraining accuracy:", dlib.test_simple_object_detector(faces_folder+"/training.xml", "detector.svm")) |
70 | 70 | # However, to get an idea if it really worked without overfitting we need to |
71 | 71 | # run it on images it wasn't trained on. The next line does this. Happily, we |
72 | 72 | # see that the object detector works perfectly on the testing images. |
73 | | -print "testing accuracy: ", dlib.test_simple_object_detector(faces_folder+"/testing.xml", "detector.svm") |
| 73 | +print("testing accuracy: ", dlib.test_simple_object_detector(faces_folder+"/testing.xml", "detector.svm")) |
74 | 74 |
|
75 | 75 |
|
76 | 76 |
|
|
84 | 84 |
|
85 | 85 | # Now let's run the detector over the images in the faces folder and display the |
86 | 86 | # results. |
87 | | -print "\nShowing detections on the images in the faces folder..." |
| 87 | +print("\nShowing detections on the images in the faces folder...") |
88 | 88 | win = dlib.image_window() |
89 | 89 | for f in glob.glob(faces_folder+"/*.jpg"): |
90 | | - print "processing file:", f |
| 90 | + print("processing file:", f) |
91 | 91 | img = io.imread(f) |
92 | 92 | dets = detector(img) |
93 | | - print "number of faces detected:", len(dets) |
| 93 | + print("number of faces detected:", len(dets)) |
94 | 94 | for d in dets: |
95 | | - print " detection position left,top,right,bottom:", d.left(), d.top(), d.right(), d.bottom() |
| 95 | + print(" detection position left,top,right,bottom:", d.left(), d.top(), d.right(), d.bottom()) |
96 | 96 |
|
97 | 97 | win.clear_overlay() |
98 | 98 | win.set_image(img) |
|
0 commit comments