最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python使用mediapiple+opencv識別視頻人臉的實(shí)現(xiàn)

 更新時間:2022年03月24日 15:36:06   作者:拼命_小李  
本文主要介紹了python使用mediapiple+opencv識別視頻人臉,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

1、安裝

pip install mediapipe

2、代碼實(shí)現(xiàn)

# -*- 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
# 繪制人臉畫像的點(diǎn)和線的大小粗細(xì)及顏色(默認(rèn)為白色)
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()

效果

3、更新 mediapiple+threadpool+opencv實(shí)現(xiàn)圖片人臉采集效率高于dlib

# -*- 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()
 

到此這篇關(guān)于python使用mediapiple+opencv識別視頻人臉的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)mediapiple opencv識別視頻人臉內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 解決Python下json.loads()中文字符出錯的問題

    解決Python下json.loads()中文字符出錯的問題

    今天小編就為大家分享一篇解決Python下json.loads()中文字符出錯的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-12-12
  • 教你實(shí)現(xiàn)Ubuntu安裝Python

    教你實(shí)現(xiàn)Ubuntu安裝Python

    這篇文章主要為大家介紹了Ubuntu安裝Python的實(shí)現(xiàn)過程詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-06-06
  • pandas常用表連接merge/concat/join/append詳解

    pandas常用表連接merge/concat/join/append詳解

    使用python的pandas庫可以很容易幫你搞定,而且性能也是很出色的;百萬級的表關(guān)聯(lián),可以秒出,本文給大家分享pandas常用表連接merge/concat/join/append詳解,感興趣的朋友跟隨小編一起看看吧
    2023-02-02
  • python飛機(jī)大戰(zhàn)pygame游戲之?dāng)硻C(jī)出場實(shí)現(xiàn)方法詳解

    python飛機(jī)大戰(zhàn)pygame游戲之?dāng)硻C(jī)出場實(shí)現(xiàn)方法詳解

    這篇文章主要介紹了python飛機(jī)大戰(zhàn)pygame游戲之?dāng)硻C(jī)出場實(shí)現(xiàn)方法,結(jié)合實(shí)例形式詳細(xì)分析了Python使用pygame模塊實(shí)現(xiàn)飛機(jī)大戰(zhàn)游戲中敵機(jī)出場相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
    2019-12-12
  • Pandas中GroupBy具體用法詳解

    Pandas中GroupBy具體用法詳解

    pandas中的DF數(shù)據(jù)類型可以像數(shù)據(jù)庫表格一樣進(jìn)行g(shù)roupby操作。通常來說groupby操作可以分為三部分:分割數(shù)據(jù),應(yīng)用變換和和合并數(shù)據(jù)。本文就詳細(xì)的來介紹一下,感興趣的可以了解一下
    2021-07-07
  • 僅用50行Python代碼實(shí)現(xiàn)一個簡單的代理服務(wù)器

    僅用50行Python代碼實(shí)現(xiàn)一個簡單的代理服務(wù)器

    這篇文章主要介紹了僅用50行Python代碼實(shí)現(xiàn)一個簡單的代理服務(wù)器,利用最簡單的client->proxy->forward原理在socket模塊下編寫,需要的朋友可以參考下
    2015-04-04
  • Python及Django框架生成二維碼的方法分析

    Python及Django框架生成二維碼的方法分析

    這篇文章主要介紹了Python及Django框架生成二維碼的方法,結(jié)合實(shí)例形式分析了Python及Django框架使用qrcode包實(shí)現(xiàn)二維碼生成功能的相關(guān)操作技巧,需要的朋友可以參考下
    2018-01-01
  • Python執(zhí)行JS代碼的三種方式

    Python執(zhí)行JS代碼的三種方式

    以前的數(shù)據(jù)靠買,現(xiàn)在的數(shù)據(jù)靠爬”,越來越多的學(xué)者通過網(wǎng)絡(luò)爬蟲來獲取數(shù)據(jù),但是做爬蟲的人都知道,現(xiàn)在的很多網(wǎng)站都在和我們斗智斗勇,防護(hù)普遍越來越好,破解JS加密只是第一步,之后就是如何在我們的Python代碼中直接執(zhí)行JS,下面介紹一下幾種Python中執(zhí)行JS代碼的方法
    2024-01-01
  • Python應(yīng)用實(shí)現(xiàn)處理excel數(shù)據(jù)過程解析

    Python應(yīng)用實(shí)現(xiàn)處理excel數(shù)據(jù)過程解析

    這篇文章主要介紹了Python應(yīng)用實(shí)現(xiàn)處理excel數(shù)據(jù)過程解析,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下
    2020-06-06
  • python 畫條形圖(柱狀圖)實(shí)例

    python 畫條形圖(柱狀圖)實(shí)例

    這篇文章主要介紹了python 畫條形圖(柱狀圖)實(shí)例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04

最新評論

调兵山市| 罗田县| 汉中市| 古交市| 和田市| 乐安县| 织金县| 商南县| 宜昌市| 高安市| 灵丘县| 苗栗市| 漠河县| 富裕县| 车险| 五原县| 河北省| 揭东县| 刚察县| 永年县| 桃园县| 巴塘县| 上虞市| 安泽县| 西平县| 双城市| 平潭县| 平江县| 仲巴县| 康保县| 莲花县| 茶陵县| 辽宁省| 上饶市| 堆龙德庆县| 新郑市| 利辛县| 缙云县| 平顶山市| 台南县| 清苑县|