diff --git a/README.md b/README.md index 97beaa4..f13eeb8 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,5 @@ $ pip3 install face_recognition # This installs dlib as its dependency * **mirror\_facedetect.py** to detect faces in the webcam * **face\_ident.py** to identify the actual person from their faces * **gen\_encoding.py** to generate `.face` files from images +* **display\_faces.py** to put rectangles on the faces of a picture +* **paint\_stuff.py** to draw rectangles by mouse on a custom background image diff --git a/display.py b/display.py index d3db5a1..bb33897 100755 --- a/display.py +++ b/display.py @@ -1,10 +1,15 @@ #!/usr/bin/env python3 import sys + +argc=len(sys.argv) + +if argc<2: + print("usage: %s image_file" % sys.argv[0]) + exit(-1) + import cv2 import numpy -assert(len(sys.argv)>=2) - # Load the image file into an ndarray image=cv2.imread(sys.argv[1],cv2.IMREAD_UNCHANGED); diff --git a/display_faces.py b/display_faces.py new file mode 100755 index 0000000..28d369b --- /dev/null +++ b/display_faces.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +import sys + +argc=len(sys.argv) + +if argc<2: + print("usage: %s image_file" % sys.argv[0]) + exit(-1) + +import face_recognition as fr +import numpy as np +import cv2 + +image=fr.load_image_file(sys.argv[1]) # This is for face detection +cvimg=cv2.imread(sys.argv[1],cv2.IMREAD_UNCHANGED) +faces=fr.face_locations(image) + +for top,right,bottom,left in faces: + cvimg=cv2.rectangle(cvimg,(left,top),(right,bottom),(0,0xFF,0),3) + +cv2.imshow("Results from face detector",cvimg) +cv2.waitKey(0) diff --git a/gen_encoding.py b/gen_encoding.py index 3c2db49..a135295 100755 --- a/gen_encoding.py +++ b/gen_encoding.py @@ -8,10 +8,6 @@ print("usage: %s input_file [output_file]" % sys.argv[0]) exit(-1) -import numpy as np -import face_recognition as fr -import csv - input_filename=sys.argv[1] output_filename="" if argc>=3: @@ -22,6 +18,10 @@ output_filename='.'.join(parts) print("output data to `%s'" % output_filename) +import numpy as np +import face_recognition as fr +import csv + image=fr.load_image_file(input_filename) encoding=fr.face_encodings(image)[0] # Now write the data to the output file diff --git a/paint_stuff.py b/paint_stuff.py new file mode 100755 index 0000000..5b7d291 --- /dev/null +++ b/paint_stuff.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 +import sys + +argc=len(sys.argv) + +if argc<2: + print("usage: %s background_image" % sys.argv[0]) + exit(-1) + +img_fname=sys.argv[1] + +import cv2 +import numpy as np + +x0=0 +y0=0 +flag=False + +img=cv2.imread(img_fname,cv2.IMREAD_UNCHANGED) + +win="~Put some rectangles~" + +def mouse_handler(event,x,y,flags,param): + global x0,y0,flag + if event==cv2.EVENT_LBUTTONDOWN: + print("Start drawing") + flag=True + x0=x + y0=y + elif event==cv2.EVENT_MOUSEMOVE: + if flag: + tmp=np.array(img,copy=True) # Make a copy from it + cv2.rectangle(tmp,(x0,y0),(x,y),(0,0xFF,0),3) + cv2.imshow(win,tmp) + elif event==cv2.EVENT_LBUTTONUP: + flag=False + print("Rectangle between (%d,%d) and (%d,%d)" % (x0,y0,x,y)) + cv2.rectangle(img,(x0,y0),(x,y),(0,0xFF,0),3) + cv2.imshow(win,img) + +cv2.namedWindow(win) +cv2.setMouseCallback(win,mouse_handler) +cv2.imshow(win,img) +cv2.waitKey(0)