标签:get 大于 dict art pen rect ola 电脑 not
电脑好的可以试试,比opencv效果好多了,毕竟训练模型都有60mb,速度慢。
代码:
import cv2 import dlib def CatchPICFromVideo(camera_idx): cv2.namedWindow("image",0) #qcv2.resizeWindow("image", 1600, 900) # 设置长和宽 # 视频来源,可以来自一段已存好的视频,也可以直接来自USB摄像头 cap = cv2.VideoCapture(camera_idx) num = 0 while cap.isOpened(): ok, frame1 = cap.read() # 读取一帧数据 scale_percent = 10 # percent of original size 缩小到原来25% width = int(frame1.shape[1] * scale_percent / 100) height = int(frame1.shape[0] * scale_percent / 100) dim = (width, height) frame = cv2.resize(frame1, dim, interpolation=cv2.INTER_AREA) if not ok: break gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 人脸分类器 detector = dlib.get_frontal_face_detector() # 获取人脸检测器 predictor = dlib.shape_predictor( "shape_predictor_68_face_landmarks.dat" ) color = (0, 255, 0) # 定义绘制颜色 dets = detector(gray, 1) if len(dets) > 0: # 大于0则检测到人脸 for face in dets: shape = predictor(frame, face) # 寻找人脸的68个标定点 chang = [] kuan = [] # 遍历所有点,打印出其坐标,并圈出来 for pt in shape.parts(): #pt_pos = (pt.x, pt.y) chang.append(pt.x) kuan.append(pt.y) #cv2.circle(img, pt_pos, 1, (0, 255, 0), 1) num += 1 #if num > catch_pic_num: # 如果超过指定最大保存数量退出循环 #break # 画出矩形框 x1 = max(chang) x2 = min(chang) y1 = max(kuan) y2 = min(kuan) cv2.rectangle(frame, (x2, y2), (x1, y1), color, 2) #cv2.rectangle(frame, (x - 10, y - 10), (x + w + 10, y + h + 10), color, 2) # 显示当前捕捉到了多少人脸图片了,这样站在那里被拍摄时心里有个数,不用两眼一抹黑傻等着 #font = cv2.FONT_HERSHEY_SIMPLEX #cv2.putText(frame ,‘num:%d‘ % (num) ,(x2 + 30, y2 + 30), font, 1, (255 ,0 ,255) ,4) # 超过指定最大保存数量结束程序 #if num > catch_pic_num: #break # 显示图像 cv2.imshow("image", frame) c = cv2.waitKey(1) if c & 0xFF == ord(‘q‘): break # 释放摄像头并销毁所有窗口 cap.release() cv2.destroyAllWindows() print(CatchPICFromVideo(r‘H:\renwu__opencv\zhaopian\IMG_1502.MOV‘))
直接卡死了。。就不放效果图了。
Python 用dlib来实现视频人脸检测 (很卡,我电脑带不动,卡死了。。)我的是轻薄本
标签:get 大于 dict art pen rect ola 电脑 not
原文地址:https://www.cnblogs.com/aotumandaren/p/13860262.html