Created
September 17, 2017 15:33
-
-
Save shyampurk/e336c02d728f6b2f1682ad7855c418c8 to your computer and use it in GitHub Desktop.
This file contains 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 characters
import os | |
import sys | |
import glob | |
import dlib | |
from skimage import io | |
from skimage.draw import polygon_perimeter | |
import traceback |
This file contains 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 characters
detector = dlib.simple_object_detector(detector_svm) |
This file contains 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 characters
options.C = 5 |
This file contains 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 characters
options.num_threads = 4 | |
options.be_verbose = True |
This file contains 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 characters
options = dlib.simple_object_detector_training_options() |
This file contains 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 characters
options.add_left_right_image_flips = True |
This file contains 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 characters
print("Showing detections on the images in the test folder...") | |
win = dlib.image_window() | |
for f in glob.glob(os.path.join(detector_folder, "test/*.jpg")): | |
print("Processing file: {}".format(f)) | |
img = io.imread(f) | |
dets = detector(img) | |
print("Number of objects detected: {}".format(len(dets))) | |
bOverLays = False | |
for k, d in enumerate(dets): | |
print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format( | |
k, d.left(), d.top(), d.right(), d.bottom())) | |
rr,cc = polygon_perimeter([d.top(), d.top(), d.bottom(), d.bottom()], | |
[d.right(), d.left(), d.left(), d.right()]) | |
try: | |
img[rr, cc] = (255, 0, 0) | |
if bOverLays == False: | |
bOverLays = True | |
except: | |
traceback.print_exc() | |
# Save the image detections to a file for future review. | |
if bOverLays == True: | |
io.imsave(f.replace("test/","output/"), img) | |
win.clear_overlay() | |
win.set_image(img) | |
win.add_overlay(dets) | |
dlib.hit_enter_to_continue() |
This file contains 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 characters
print("Testing accuracy: {}".format( | |
dlib.test_simple_object_detector(testing_xml_path, detector_svm))) |
This file contains 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 characters
print("") # Print blank line to create gap from previous output | |
print("Training accuracy: {}".format( | |
dlib.test_simple_object_detector(training_xml_path, detector_svm))) |
This file contains 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 characters
if not os.path.exists(detector_svm): | |
dlib.train_simple_object_detector(training_xml_path, detector_svm, options) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment