-
大小: 4.17MB文件类型: .zip金币: 1下载: 0 次发布日期: 2023-09-16
- 语言: Python
- 标签:
资源简介
要先安装python,等库函数,这个资源里面已经有好几个包了,尽量在这个解压文件之内运行1.py与facedetect.py
代码片段和文件信息
#coding=utf-8
import numpy as np
import cv2
import time
import sys getopt
from video import create_capture
from common import clock draw_str
def detect(img cascade):
rects = cascade.detectMultiScale(img scaleFactor=1.3 minNeighbors=4 minSize=(30 30)
flags=cv2.CASCADE_SCALE_IMAGE)
if len(rects) == 0:
return []
rects[:2:] += rects[::2]
return rects
def draw_rects(img rects color):
for x1 y1 x2 y2 in rects:
cv2.rectangle(img (x1 y1) (x2 y2) color 2)
if __name__ == ‘__main__‘:
args = {}
cascade_fn = args.get(‘--cascade‘ “haarcascade_frontalface_alt.xml“)
# cascade_fn = args.get(‘--cascade‘ “haarcascade_righteye_2splits.xml“)#yanjing
# cascade_fn = args.get(‘--cascade‘ “haarcascade_fullbody.xml“)
eyes = args.get(‘--eyesed-cascade‘ “haarcascade_eye.xml“)
cascade = cv2.CascadeClassifier(cascade_fn)
eyesed = cv2.CascadeClassifier(eyes)
print cascade_fn
cap = cv2.VideoCapture(0)
while True:
time.sleep(0.10)
# img = cv2.imread(“haha2.jpg“)
# print img.shape
retimg = cap.read()
gray = cv2.cvtColor(img cv2.COLOR_BGR2GRAY)
t = clock()
rects = detect(gray cascade)
vis = img.copy()
draw_rects(vis rects (0 255 0))
# if not eyesed.empty():
# for x1 y1 x2 y2 in rects:
# roi = gray[y1:y2 x1:x2]
# vis_roi = vis[y1:y2 x1:x2]
# subrects = detect(roi.copy() eyesed)
# draw_rects(vis_roi subrects (255 0 0))
subrects = detect(gray eyesed)
draw_rects(vis subrects (255 0 0))
dt = clock() - t
# print dt
draw_str(vis (20 20) ‘time: %.1f ms‘ % (dt*1000))
cv2.imshow(‘facedetect‘ vis)
if cv2.waitKey(5) == 27:
break
cv2.destroyAllWindows()
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-09-24 14:03 face_dete\
文件 1998 2017-09-24 13:53 face_dete\1.py
文件 6938 2016-12-21 18:37 face_dete\common.py
文件 10990 2017-09-24 11:38 face_dete\common.pyc
文件 1849 2017-09-24 13:05 face_dete\facedetect.py
文件 145183 2017-08-14 18:55 face_dete\h.jpg
文件 29368 2017-09-14 20:16 face_dete\h1.jpg
文件 43226 2017-09-14 20:51 face_dete\h2.jpg
目录 0 2017-09-06 18:12 face_dete\haarcascades\
文件 341406 2017-01-31 23:32 face_dete\haarcascades\haarcascade_eye.xm
文件 601661 2017-01-31 23:32 face_dete\haarcascades\haarcascade_eye_tree_eyeglasses.xm
文件 411388 2017-06-30 01:28 face_dete\haarcascades\haarcascade_frontalcatface.xm
文件 382918 2017-06-30 01:28 face_dete\haarcascades\haarcascade_frontalcatface_extended.xm
文件 676709 2017-01-31 23:32 face_dete\haarcascades\haarcascade_frontalface_alt.xm
文件 540616 2017-01-31 23:32 face_dete\haarcascades\haarcascade_frontalface_alt2.xm
文件 2689040 2017-01-31 23:32 face_dete\haarcascades\haarcascade_frontalface_alt_tree.xm
文件 930127 2017-01-31 23:32 face_dete\haarcascades\haarcascade_frontalface_default.xm
文件 476825 2017-01-31 23:32 face_dete\haarcascades\haarcascade_fullbody.xm
文件 195369 2017-01-31 23:32 face_dete\haarcascades\haarcascade_lefteye_2splits.xm
文件 47775 2017-01-31 23:32 face_dete\haarcascades\haarcascade_licence_plate_rus_16stages.xm
文件 395320 2017-01-31 23:32 face_dete\haarcascades\haarcascade_lowerbody.xm
文件 358385 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_eyepair_big.xm
文件 410204 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_eyepair_small.xm
文件 312877 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_leftear.xm
文件 777721 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_lefteye.xm
文件 719806 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_mouth.xm
文件 1585210 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_nose.xm
文件 324727 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_rightear.xm
文件 1383113 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_righteye.xm
文件 1522737 2016-04-20 22:21 face_dete\haarcascades\haarcascade_mcs_upperbody.xm
文件 828514 2017-01-31 23:32 face_dete\haarcascades\haarcascade_profileface.xm
............此处省略33个文件信息
评论
共有 条评论