Last active
December 18, 2019 19:15
-
-
Save atotto/c1ccbfa44ee70a476816f6389834945e to your computer and use it in GitHub Desktop.
object detector with dlib
This file contains hidden or 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 dlib | |
| import cv2 | |
| detector = dlib.simple_object_detector("detector.svm") | |
| cap = cv2.VideoCapture(0) | |
| while(True): | |
| # Capture frame-by-frame | |
| ret, frame = cap.read() | |
| frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | |
| dets = detector(frame) | |
| for d in dets: | |
| cv2.rectangle(frame, (d.left(), d.top()), (d.right(), d.bottom()), (0, 0, 255), 2) | |
| # Display the resulting frame | |
| cv2.imshow("frame",frame) | |
| if cv2.waitKey(1) & 0xFF == ord('q'): | |
| break | |
| # When everything done, release the capture | |
| cap.release() | |
| cv2.destroyAllWindows() |
This file contains hidden or 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 dlib | |
| img_dir = "." | |
| options = dlib.simple_object_detector_training_options() | |
| options.add_left_right_image_flips = False | |
| options.C = 5 | |
| options.num_threads = 2 | |
| options.be_verbose = True | |
| training_xml_path = os.path.join(img_dir, "training.xml") | |
| testing_xml_path = os.path.join(img_dir, "testing.xml") | |
| dlib.train_simple_object_detector(training_xml_path, "detector.svm", options) | |
| print("") | |
| print("Training accuracy: {}".format( | |
| dlib.test_simple_object_detector(training_xml_path, "detector.svm"))) | |
| print("Testing accuracy: {}".format( | |
| dlib.test_simple_object_detector(testing_xml_path, "detector.svm"))) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
setup
face detection(dlib example):
object detection: