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

Python實(shí)現(xiàn)人臉識(shí)別并進(jìn)行視頻跟蹤打碼

 更新時(shí)間:2024年04月08日 11:46:03   作者:輕松學(xué)Python  
這篇文章主要為大家詳細(xì)介紹了如何利用Python實(shí)現(xiàn)人臉識(shí)別并進(jìn)行視頻跟蹤打碼效果,羞羞的畫(huà)面統(tǒng)統(tǒng)打上馬賽克,感興趣的小伙伴可以了解一下

前言

事情是這樣的,昨天去表弟家,用了下他的電腦,不小心點(diǎn)到了他硬盤(pán)里隱藏的秘密,本來(lái)我只需要用幾分鐘電腦的,害得我硬是在電腦旁坐了幾個(gè)小時(shí)~

還好他爸媽不在家,不然表弟又要被打一頓!

為了防止表弟的秘密被發(fā)現(xiàn),從而被賞賜一頓男女混合雙打,于是我用Python把他所有的視頻都給打上了萬(wàn)惡的馬賽克。

我想,表弟肯定會(huì)感謝我的!

準(zhǔn)備工作

話(huà)不多少,我們直接開(kāi)始操作!

首先需要一些素材,大家可以自己準(zhǔn)備

這個(gè)是要用的工具

代碼實(shí)戰(zhàn)

使用的模塊

import cv2
import face_recognition
import matplotlib.pyplot as plt
# %matplotlib inline # 在 jupyter 中使用的時(shí)候,去掉注釋
import ffmpy3
import subprocess
import os
from PIL import Image

將視頻轉(zhuǎn)為音頻

def video2mp3(file_name):
    outfile_name = file_name.split('.')[0] + '.mp3'
    cmd = 'ffmpeg -i ' + file_name + ' -f mp3 ' + outfile_name
    print(cmd)
    subprocess.call(cmd, shell=True)

視頻添加音頻

def video_add_mp3(file_name, mp3_file):
    outfile_name = file_name.split('.')[0] + '-f.mp4'
    subprocess.call('ffmpeg -i ' + file_name
                    + ' -i ' + mp3_file + ' -strict -2 -f mp4 '
                    + outfile_name, shell=True)

主要代碼

def mask_video(input_video, output_video, mask_path='mask.jpg'):
    # 打碼圖片
    # 完整源碼、視頻講解
    # Python學(xué)習(xí)交流群:708525271
    # 直接加它領(lǐng)取
    mask = cv2.imread(mask_path)
    # 讀取視頻
    cap = cv2.VideoCapture(input_video)
    # 讀取視頻參數(shù),fps、width、heigth
    CV_CAP_PROP_FPS = 5
    CV_CAP_PROP_FRAME_WIDTH = 3
    CV_CAP_PROP_FRAME_HEIGHT = 4
    v_fps = cap.get(CV_CAP_PROP_FPS)
    v_width = cap.get(CV_CAP_PROP_FRAME_WIDTH)
    v_height = cap.get(CV_CAP_PROP_FRAME_HEIGHT)
    # 設(shè)置寫(xiě)視頻參數(shù),格式為 mp4
    size = (int(v_width), int(v_height))
    fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
    out = cv2.VideoWriter(output_video, fourcc, v_fps, size)
 
    # 已知人臉
    known_image = face_recognition.load_image_file("tmr.jpg")
    biden_encoding = face_recognition.face_encodings(known_image)[0]
    # 讀取視頻
    cap = cv2.VideoCapture(input_video)
    while (cap.isOpened()):
        ret, frame = cap.read()
        if ret:
            # 檢測(cè)人臉
            face_locations = face_recognition.face_locations(frame)
            # print(face_locations)
            # 檢測(cè)每一個(gè)人臉
            for (top_right_y, top_right_x, left_bottom_y, left_bottom_x) in face_locations:
                unknown_image = frame[top_right_y - 50:left_bottom_y + 50, left_bottom_x - 50:top_right_x + 50]
                print(face_recognition.face_encodings(unknown_image))
                if face_recognition.face_encodings(unknown_image) != []:
                    unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
 
                    # 對(duì)比結(jié)果
                    results = face_recognition.compare_faces([biden_encoding], unknown_encoding)
                    # 是仝卓,就將打碼貼圖。
                    if results[0] == True:
                        mask = cv2.resize(mask, (top_right_x - left_bottom_x, left_bottom_y - top_right_y))
                        frame[top_right_y:left_bottom_y, left_bottom_x:top_right_x] = mask
            # 寫(xiě)入視頻
            out.write(frame)
        else:
            break

將音頻保存為cut.mp3

video2mp3(file_name='cut.mp4')

處理視頻,自動(dòng)打碼,輸出視頻為output.mp4

mask_video(input_video='cut.mp4', output_video='output.mp4')

為 output.mp4 處理好的視頻添加聲音

video_add_mp3(file_name='output.mp4', mp3_file='cut.mp3')

到此這篇關(guān)于Python實(shí)現(xiàn)人臉識(shí)別并進(jìn)行視頻跟蹤打碼的文章就介紹到這了,更多相關(guān)Python人臉識(shí)別內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

海原县| 祁阳县| 同心县| 嘉禾县| 双流县| 正定县| 靖远县| 依兰县| 洪洞县| 抚远县| 黄大仙区| 英超| 元朗区| 紫金县| 三江| 建宁县| 康保县| 开化县| 禄劝| 黑水县| 林西县| 盐边县| 焦作市| 岳西县| 乌拉特前旗| 来宾市| 名山县| 当涂县| 神农架林区| 曲周县| 蚌埠市| 巨野县| 潜山县| 大名县| 吴桥县| 扎赉特旗| 辉南县| 师宗县| 禄劝| 永和县| 阳城县|