Skip to content

Commit

Permalink
Add bin
Browse files Browse the repository at this point in the history
  • Loading branch information
iitzco committed Aug 23, 2018
1 parent d2d4c33 commit 4204c8e
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 87 deletions.
112 changes: 112 additions & 0 deletions bin/faced
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)
5 changes: 1 addition & 4 deletions faced/detector.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ def predict(self, frame, thresh=0.85):

return bboxes


def _absolute_bboxes(self, pred, frame, thresh):
img_h, img_w, _ = frame.shape
p, x, y, w, h = pred
Expand All @@ -81,7 +80,6 @@ def _absolute_bboxes(self, pred, frame, thresh):

return ret


def _nonmax_supression(self, bboxes, thresh=0.2):
SUPPRESSED = 1
NON_SUPPRESSED = 2
Expand Down Expand Up @@ -177,6 +175,5 @@ def predict(self, frame):

y = int(y*img_h)
h = int(h*img_h)

return x, y, w, h

return x, y, w, h
26 changes: 0 additions & 26 deletions img_client.py

This file was deleted.

Binary file removed imgs/test.jpeg
Binary file not shown.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Binary file removed video.mp4
Binary file not shown.
57 changes: 0 additions & 57 deletions video_client.py

This file was deleted.

0 comments on commit 4204c8e

Please sign in to comment.