-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* README.md: Corresponding introductions added * display.py: Optimized in argument parsing * gen_encoding.py: Optimized * display_faces.py: Created for putting rectangles on faces * paint_stuff.py: Allow users to paint green rectangles on pictures Here are why and how to optimize argument parsing in Python: As we know, we load a number of modules to in order to simplify the procedure, but loading process is time-consuming. But Python allows us to import modules whenever we want. Therefore I let the program parse the arguments first before loading other large modules, and this is a time-saving solution for invalid command line argument. Just a note, though TL;DR
- Loading branch information
Showing
5 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |