五、视频流人脸识别的实现(Python)(recognize_video.py)

1. 代码部分

此代码块为recognize_video.py内的代码

# USAGE
# python recognize_video.py --detector face_detection_model \
#	--embedding-model openface_nn4.small2.v1.t7 \
#	--recognizer output/recognizer.pickle \
#	--le output/le.pickle

# v4_v1解决了多线程中的Exception in thread Thread-7:UnboundLocalError: 
# local variable 'name' referenced before assignment

# 加载必要的包
from imutils.video import VideoStream
from imutils.video import FPS
import numpy as np
import imutils
import pickle
import time
import cv2
import os
import tkinter as tk
import threading
 
def recognize_video():   
    ## 创建识别窗口
    win_rec = tk.Tk()
    win_rec.title('人脸识别')
    win_rec.geometry('300x320')
    var_name = tk.StringVar()        
    var_proba = tk.StringVar()
    var_ans = tk.StringVar()
    
    ## 创建画布用于切换图片   
    canvas1 = tk.Canvas(win_rec, height = 129, width = 183)
    canvas2 = tk.Canvas(win_rec, height = 129, width = 183)
    stop = tk.PhotoImage(file = 'stop.gif')
    welcome = tk.PhotoImage(file = 'welcome.gif')
    canvas1.create_image(0,0, anchor = 'nw', image = stop)
    canvas2.create_image(0,0, anchor = 'nw', image = welcome)
    
    ## 创建Label用于显示人名及匹配度
    tk.Label(win_rec, text = '姓  名:').place(x = 50, y = 50)
    tk.Label(win_rec, text = '匹配度:').place(x = 50, y = 90)
    tk.Label(win_rec, textvariable = var_name).place(x = 100, y = 50)
    tk.Label(win_rec, textvariable = var_proba).place(x = 100, y = 90)
    tk.Label(win_rec, textvariable = var_ans).place(x = 100, y = 130)
    tk.Label(win_rec,
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

吮指原味张

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值