forked from iitzco/faced
-
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.
- Loading branch information
Showing
7 changed files
with
114 additions
and
87 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#!/usr/bin/env python | ||
|
||
import cv2 | ||
import sys | ||
import os | ||
import time | ||
|
||
from faced import FaceDetector | ||
from faced.utils import annotate_image | ||
|
||
|
||
def is_video(filename): | ||
exts = ( | ||
'.264', '.3g2', '.3gp', '.3gp2', '.3gpp', '.3gpp2', '.3mm', '.3p2', '.60d', '.787', '.89', '.aaf', '.aec', '.aep', '.aepx', | ||
'.aet', '.aetx', '.ajp', '.ale', '.am', '.amc', '.amv', '.amx', '.anim', '.aqt', '.arcut', '.arf', '.asf', '.asx', '.avb', | ||
'.avc', '.avd', '.avi', '.avp', '.avs', '.avs', '.avv', '.axm', '.bdm', '.bdmv', '.bdt2', '.bdt3', '.bik', '.bin', '.bix', | ||
'.bmk', '.bnp', '.box', '.bs4', '.bsf', '.bvr', '.byu', '.camproj', '.camrec', '.camv', '.ced', '.cel', '.cine', '.cip', | ||
'.clpi', '.cmmp', '.cmmtpl', '.cmproj', '.cmrec', '.cpi', '.cst', '.cvc', '.cx3', '.d2v', '.d3v', '.dat', '.dav', '.dce', | ||
'.dck', '.dcr', '.dcr', '.ddat', '.dif', '.dir', '.divx', '.dlx', '.dmb', '.dmsd', '.dmsd3d', '.dmsm', '.dmsm3d', '.dmss', | ||
'.dmx', '.dnc', '.dpa', '.dpg', '.dream', '.dsy', '.dv', '.dv-avi', '.dv4', '.dvdmedia', '.dvr', '.dvr-ms', '.dvx', '.dxr', | ||
'.dzm', '.dzp', '.dzt', '.edl', '.evo', '.eye', '.ezt', '.f4p', '.f4v', '.fbr', '.fbr', '.fbz', '.fcp', '.fcproject', | ||
'.ffd', '.flc', '.flh', '.fli', '.flv', '.flx', '.gfp', '.gl', '.gom', '.grasp', '.gts', '.gvi', '.gvp', '.h264', '.hdmov', | ||
'.hkm', '.ifo', '.imovieproj', '.imovieproject', '.ircp', '.irf', '.ism', '.ismc', '.ismv', '.iva', '.ivf', '.ivr', '.ivs', | ||
'.izz', '.izzy', '.jss', '.jts', '.jtv', '.k3g', '.kmv', '.ktn', '.lrec', '.lsf', '.lsx', '.m15', '.m1pg', '.m1v', '.m21', | ||
'.m21', '.m2a', '.m2p', '.m2t', '.m2ts', '.m2v', '.m4e', '.m4u', '.m4v', '.m75', '.mani', '.meta', '.mgv', '.mj2', '.mjp', | ||
'.mjpg', '.mk3d', '.mkv', '.mmv', '.mnv', '.mob', '.mod', '.modd', '.moff', '.moi', '.moov', '.mov', '.movie', '.mp21', | ||
'.mp21', '.mp2v', '.mp4', '.mp4v', '.mpe', '.mpeg', '.mpeg1', '.mpeg4', '.mpf', '.mpg', '.mpg2', '.mpgindex', '.mpl', | ||
'.mpl', '.mpls', '.mpsub', '.mpv', '.mpv2', '.mqv', '.msdvd', '.mse', '.msh', '.mswmm', '.mts', '.mtv', '.mvb', '.mvc', | ||
'.mvd', '.mve', '.mvex', '.mvp', '.mvp', '.mvy', '.mxf', '.mxv', '.mys', '.ncor', '.nsv', '.nut', '.nuv', '.nvc', '.ogm', | ||
'.ogv', '.ogx', '.osp', '.otrkey', '.pac', '.par', '.pds', '.pgi', '.photoshow', '.piv', '.pjs', '.playlist', '.plproj', | ||
'.pmf', '.pmv', '.pns', '.ppj', '.prel', '.pro', '.prproj', '.prtl', '.psb', '.psh', '.pssd', '.pva', '.pvr', '.pxv', | ||
'.qt', '.qtch', '.qtindex', '.qtl', '.qtm', '.qtz', '.r3d', '.rcd', '.rcproject', '.rdb', '.rec', '.rm', '.rmd', '.rmd', | ||
'.rmp', '.rms', '.rmv', '.rmvb', '.roq', '.rp', '.rsx', '.rts', '.rts', '.rum', '.rv', '.rvid', '.rvl', '.sbk', '.sbt', | ||
'.scc', '.scm', '.scm', '.scn', '.screenflow', '.sec', '.sedprj', '.seq', '.sfd', '.sfvidcap', '.siv', '.smi', '.smi', | ||
'.smil', '.smk', '.sml', '.smv', '.spl', '.sqz', '.srt', '.ssf', '.ssm', '.stl', '.str', '.stx', '.svi', '.swf', '.swi', | ||
'.swt', '.tda3mt', '.tdx', '.thp', '.tivo', '.tix', '.tod', '.tp', '.tp0', '.tpd', '.tpr', '.trp', '.ts', '.tsp', '.ttxt', | ||
'.tvs', '.usf', '.usm', '.vc1', '.vcpf', '.vcr', '.vcv', '.vdo', '.vdr', '.vdx', '.veg','.vem', '.vep', '.vf', '.vft', | ||
'.vfw', '.vfz', '.vgz', '.vid', '.video', '.viewlet', '.viv', '.vivo', '.vlab', '.vob', '.vp3', '.vp6', '.vp7', '.vpj', | ||
'.vro', '.vs4', '.vse', '.vsp', '.w32', '.wcp', '.webm', '.wlmp', '.wm', '.wmd', '.wmmp', '.wmv', '.wmx', '.wot', '.wp3', | ||
'.wpl', '.wtv', '.wve', '.wvx', '.xej', '.xel', '.xesc', '.xfl', '.xlmv', '.xmv', '.xvid', '.y4m', '.yog', '.yuv', '.zeg', | ||
'.zm1', '.zm2', '.zm3', '.zmv' | ||
) | ||
return any((filename.endswith(x) for x in exts)) | ||
|
||
|
||
def run_img(img_path): | ||
face_detector = FaceDetector() | ||
|
||
img = cv2.imread(img_path) | ||
rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) | ||
|
||
bboxes = face_detector.predict(rgb_img) | ||
ann_img = annotate_image(img, bboxes) | ||
|
||
cv2.namedWindow('image', cv2.WINDOW_NORMAL) | ||
cv2.imshow('image',ann_img) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() | ||
|
||
|
||
def run_video(feed): | ||
face_detector = FaceDetector() | ||
|
||
if feed is None: | ||
# From webcam | ||
cap = cv2.VideoCapture(0) | ||
else: | ||
cap = cv2.VideoCapture(feed) | ||
|
||
# Get current width of frame | ||
width = cap.get(cv2.CAP_PROP_FRAME_WIDTH) # float | ||
# Get current height of frame | ||
height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT) # float | ||
fps = cap.get(cv2.CAP_PROP_FPS) # float | ||
|
||
|
||
# Define the codec and create VideoWriter object | ||
# fourcc = cv2.Video.CV_FOURCC(*'X264') | ||
fourcc = cv2.VideoWriter_fourcc(*'MJPG') | ||
out = cv2.VideoWriter("output.avi",fourcc, fps, (int(width),int(height))) | ||
|
||
now = time.time() | ||
while cap.isOpened(): | ||
now = time.time() | ||
# Capture frame-by-frame | ||
ret, frame = cap.read() | ||
|
||
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) | ||
# now = time.time() | ||
bboxes = face_detector.predict(rgb_frame) | ||
# print("FPS: {:0.2f}".format(1 / (time.time() - now))) | ||
ann_frame = annotate_image(frame, bboxes) | ||
|
||
out.write(ann_frame) | ||
|
||
# Display the resulting frame | ||
cv2.imshow('frame', ann_frame) | ||
print("FPS: {:0.2f}".format(1 / (time.time() - now))) | ||
if cv2.waitKey(1) & 0xFF == ord('q'): | ||
break | ||
|
||
# When everything done, release the capture | ||
cap.release() | ||
cv2.destroyAllWindows() | ||
|
||
|
||
if __name__ == "__main__": | ||
path = sys.argv[1] | ||
if is_video(path): | ||
run_video(path) | ||
else: | ||
run_img(path) |
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 was deleted.
Oops, something went wrong.
Binary file not shown.
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 |
---|---|---|
|
@@ -24,6 +24,7 @@ def readme(): | |
author_email='[email protected]', | ||
license='MIT', | ||
packages=['faced'], | ||
scripts=["bin/faced"] | ||
install_requires=required, | ||
python_requires='>3.4', | ||
include_package_data=True, | ||
|
This file was deleted.
Oops, something went wrong.