-
-
Save 46bit/d49f6fd44b9e690a6ac5 to your computer and use it in GitHub Desktop.
| import sys, cv2 | |
| # Refactored https://realpython.com/blog/python/face-recognition-with-python/ | |
| def cascade_detect(cascade, image): | |
| gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | |
| return cascade.detectMultiScale( | |
| gray_image, | |
| scaleFactor = 1.15, | |
| minNeighbors = 5, | |
| minSize = (30, 30), | |
| flags = cv2.cv.CV_HAAR_SCALE_IMAGE | |
| ) | |
| def detections_draw(image, detections): | |
| for (x, y, w, h) in detections: | |
| print "({0}, {1}, {2}, {3})".format(x, y, w, h) | |
| cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 2) | |
| def main(argv = None): | |
| if argv is None: | |
| argv = sys.argv | |
| cascade_path = sys.argv[1] | |
| image_path = sys.argv[2] | |
| result_path = sys.argv[3] if len(sys.argv) > 3 else None | |
| cascade = cv2.CascadeClassifier(cascade_path) | |
| image = cv2.imread(image_path) | |
| if image is None: | |
| print "ERROR: Image did not load." | |
| return 2 | |
| detections = cascade_detect(cascade, image) | |
| detections_draw(image, detections) | |
| print "Found {0} objects!".format(len(detections)) | |
| if result_path is None: | |
| cv2.imshow("Objects found", image) | |
| cv2.waitKey(0) | |
| else: | |
| cv2.imwrite(result_path, image) | |
| if __name__ == "__main__": | |
| sys.exit(main()) |
@mjhea0: Sure! :)
Thanks for this...
Am doing something like this but for finger prints. i have a database of images that i want to filter out images that are not finger prints. Is there a haar cascade file like haarcascade_frontalface_default.xml for finger prints detection?
Thanks for this.... Currently I am doing for face recognition. Can anyone please help me for that ?
I get a couple errors with this, am I missing something (sorry bit of a nube):
sys.exit(main()) error which is not giving me the error code, though seems to be something to do with the 'cascade_path' & 'cascade', though I am passing "haarcascade_frontalface_default.xml" directly in the project folder?
Previous example project that this was re-factored from works fine?
Any suggestion would be great, thanks.
can you help me to run this python file
how can in run this file
I am getting error in this code , I run the code like (python fac-de.py abc.jpg haarcascade_frontalface_default.xml)
The error bellow:
python fac-de.py abc.jpg haarcascade_frontalface_default.xml
File "", line 1
python fac-de.py abc.jpg haarcascade_frontalface_default.xml
^
SyntaxError: invalid syntax
thank you for this great work
I am getting error in this code , I run the code like (python fac-de.py abc.jpg haarcascade_frontalface_default.xml)
The error bellow:python fac-de.py abc.jpg haarcascade_frontalface_default.xml
File "", line 1
python fac-de.py abc.jpg haarcascade_frontalface_default.xml
^
SyntaxError: invalid syntax
You need to have those files (image,xml and execute file) in same folder, after that you can see the result.
hi
thanks for your codes, how I should define the identification codes here?
Thanks! https://realpython.com/blog/python/face-recognition-with-python/#comment-1832471108
I'd love to update the post with this code. We'll def. give you credit. Thoughts?