Last active
August 29, 2015 14:08
-
-
Save takamin/10016a6953392a9f2b17 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python | |
| import sys | |
| import cv2 | |
| import numpy as np | |
| print "opencv-" + cv2.__version__ + "\n" | |
| cap = None | |
| image_index = None | |
| cascade_path = sys.argv[1] | |
| if len(sys.argv) > 2: | |
| image_index = 2 | |
| else: | |
| cap = cv2.VideoCapture(0) | |
| cascade = cv2.CascadeClassifier(cascade_path) | |
| image = np.zeros((480,640,3), np.uint8) | |
| while True: | |
| if image_index == None: | |
| cap.read(image) | |
| else: | |
| if image_index < len(sys.argv): | |
| image_path = sys.argv[image_index] | |
| image_index = image_index + 1 | |
| image = cv2.imread(image_path) | |
| else: | |
| image = None | |
| if image == None: | |
| break; | |
| image_gray = cv2.cvtColor(image, cv2.cv.CV_BGR2GRAY) | |
| result = cascade.detectMultiScale(image_gray, scaleFactor=1.1, minNeighbors=3, minSize=(1, 1)) | |
| for rect in result: | |
| cv2.rectangle(image, tuple(rect[0:2]),tuple(rect[0:2]+rect[2:4]), (0,255,0), thickness=2) | |
| cv2.imshow("cascade.py", image) | |
| if image_index == None: | |
| if cv2.waitKey(1) != -1: | |
| break; | |
| else: | |
| if cv2.waitKey(0) == ord('Q'): | |
| break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment