<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
pip install mediapipe
# -*- coding: utf-8 -*- """ @Time : 2022/3/18 14:43 @Author : liwei @Description: """ import cv2 import mediapipe as mp mp_drawing = mp.solutions.drawing_utils mp_face_mesh = mp.solutions.face_mesh mp_face_detection = mp.solutions.face_detection # 繪製人臉畫像的點和線的大小粗細及顏色(預設為白色) drawing_spec = mp_drawing.DrawingSpec(thickness=1, circle_radius=1) cap = cv2.VideoCapture("E:\video\test\test.mp4")# , cv2.CAP_DSHOW # For webcam input: # cap = cv2.VideoCapture(0) with mp_face_detection.FaceDetection( model_selection=0, min_detection_confidence=0.5) as face_detection: while cap.isOpened(): success, image = cap.read() if not success: print("Ignoring empty camera frame.") # If loading a video, use 'break' instead of 'continue'. break # To improve performance, optionally mark the image as not writeable to # pass by reference. image.flags.writeable = False image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) results = face_detection.process(image) # Draw the face detection annotations on the image. image.flags.writeable = True image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR) if results.detections: box = results.detections[0].location_data.relative_bounding_box xmin = box.xmin ymin = box.ymin width = box.width height = box.height xmax = box.xmin + width ymax = ymin + height cv2.rectangle(image, (int(xmin * image.shape[1]),int(ymin* image.shape[0])), (int(xmax* image.shape[1]), int(ymax* image.shape[0])), (0, 0, 255), 2) # for detection in results.detections: # mp_drawing.draw_detection(image, detection) # Flip the image horizontally for a selfie-view display. cv2.imshow('MediaPipe Face Detection', cv2.flip(image, 1)) if cv2.waitKey(5) & 0xFF == 27: break cap.release()
效果
# -*- coding: utf-8 -*- """ @Time : 2022/3/23 13:43 @Author : liwei @Description: """ import cv2 as cv import mediapipe as mp import os import threadpool mp_drawing = mp.solutions.drawing_utils mp_face_mesh = mp.solutions.face_mesh mp_face_detection = mp.solutions.face_detection savePath = "E:\saveImg\" basePath = "E:\img\clear\20220301\" def cut_face_img(file): # print(basePath + file) img = cv.imread(basePath + file) with mp_face_detection.FaceDetection( model_selection=0, min_detection_confidence=0.5) as face_detection: img.flags.writeable = False image = cv.cvtColor(img, cv.COLOR_RGB2BGR) results = face_detection.process(image) image = cv.cvtColor(image, cv.COLOR_RGB2BGR) image.flags.writeable = True if results.detections: box = results.detections[0].location_data.relative_bounding_box xmin = box.xmin ymin = box.ymin width = box.width height = box.height xmax = box.xmin + width ymax = ymin + height x1, x2, y1, y2 = int(xmax * image.shape[1]), int(xmin * image.shape[1]), int( ymax * image.shape[0]), int(ymin * image.shape[0]) cropped = image[y2:y1, x2:x1] if cropped.shape[1] > 200: cv.imwrite(savePath + file, cropped) print(savePath + file) if __name__ == '__main__': data = os.listdir(basePath) pool = threadpool.ThreadPool(3) requests = threadpool.makeRequests(cut_face_img, data) [pool.putRequest(req) for req in requests] pool.wait()
到此這篇關於python使用mediapiple+opencv識別視訊人臉的實現的文章就介紹到這了,更多相關mediapiple opencv識別視訊人臉內容請搜尋it145.com以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援it145.com!
相關文章
<em>Mac</em>Book项目 2009年学校开始实施<em>Mac</em>Book项目,所有师生配备一本<em>Mac</em>Book,并同步更新了校园无线网络。学校每周进行电脑技术更新,每月发送技术支持资料,极大改变了教学及学习方式。因此2011
2021-06-01 09:32:01
综合看Anker超能充系列的性价比很高,并且与不仅和iPhone12/苹果<em>Mac</em>Book很配,而且适合多设备充电需求的日常使用或差旅场景,不管是安卓还是Switch同样也能用得上它,希望这次分享能给准备购入充电器的小伙伴们有所
2021-06-01 09:31:42
除了L4WUDU与吴亦凡已经多次共事,成为了明面上的厂牌成员,吴亦凡还曾带领20XXCLUB全队参加2020年的一场音乐节,这也是20XXCLUB首次全员合照,王嗣尧Turbo、陈彦希Regi、<em>Mac</em> Ova Seas、林渝植等人全部出场。然而让
2021-06-01 09:31:34
目前应用IPFS的机构:1 谷歌<em>浏览器</em>支持IPFS分布式协议 2 万维网 (历史档案博物馆)数据库 3 火狐<em>浏览器</em>支持 IPFS分布式协议 4 EOS 等数字货币数据存储 5 美国国会图书馆,历史资料永久保存在 IPFS 6 加
2021-06-01 09:31:24
开拓者的车机是兼容苹果和<em>安卓</em>,虽然我不怎么用,但确实兼顾了我家人的很多需求:副驾的门板还配有解锁开关,有的时候老婆开车,下车的时候偶尔会忘记解锁,我在副驾驶可以自己开门:第二排设计很好,不仅配置了一个很大的
2021-06-01 09:30:48
不仅是<em>安卓</em>手机,苹果手机的降价力度也是前所未有了,iPhone12也“跳水价”了,发布价是6799元,如今已经跌至5308元,降价幅度超过1400元,最新定价确认了。iPhone12是苹果首款5G手机,同时也是全球首款5nm芯片的智能机,它
2021-06-01 09:30:45