Advertisement
Guest User

Untitled

a guest
Aug 18th, 2016
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.00 KB | None | 0 0
  1. import os
  2. import sys
  3. import glob
  4. import dlib
  5. from skimage import io
  6.  
  7.  
  8. if len(sys.argv) != 4:
  9.         print(
  10.         "Give the path to the faces directory as the argument to this "
  11.         "program with training and test xml files in order. For example: \n"
  12.         "    ./train_object_detector_modified.py ../faces ../faces/training.xml ../faces/testing.xml")
  13.     exit()
  14. faces_folder = sys.argv[1]
  15. training_xml_path = sys.argv[2]
  16. testing_xml_path = sys.argv[3]
  17.  
  18. options = dlib.simple_object_detector_training_options()
  19. options.add_left_right_image_flips = True
  20. options.C = 5
  21. options.num_threads = 8
  22. options.be_verbose = True
  23.  
  24. dlib.train_simple_object_detector(training_xml_path, "detector.svm", options)
  25. print 'training end'
  26.  
  27. print("")  # Print blank line to create gap from previous output
  28. print("Training accuracy: {}".format(
  29.     dlib.test_simple_object_detector(training_xml_path, "detector.svm")))
  30.  
  31. print("Testing accuracy: {}".format(
  32.     dlib.test_simple_object_detector(testing_xml_path, "detector.svm")))
  33.  
  34.  
  35. '''
  36. # Now let's use the detector as you would in a normal application.  First we
  37. # will load it from disk.
  38. detector = dlib.simple_object_detector("detector.svm")
  39.  
  40. # We can look at the HOG filter we learned.  It should look like a face.  Neat!
  41. win_det = dlib.image_window()
  42. win_det.set_image(detector)
  43.  
  44. # Now let's run the detector over the images in the faces folder and display the
  45. # results.
  46. print("Showing detections on the images in the faces folder...")
  47. win = dlib.image_window()
  48. for f in glob.glob(os.path.join(faces_folder, "*.jpg")):
  49.    print("Processing file: {}".format(f))
  50.    img = io.imread(f)
  51.    dets = detector(img)
  52.    print("Number of faces detected: {}".format(len(dets)))
  53.    for k, d in enumerate(dets):
  54.        print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format(
  55.            k, d.left(), d.top(), d.right(), d.bottom()))
  56.  
  57.    win.clear_overlay()
  58.    win.set_image(img)
  59.    win.add_overlay(dets)
  60.    dlib.hit_enter_to_continue()
  61. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement