欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

如何通過(guò)python實(shí)現(xiàn)人臉識(shí)別驗(yàn)證-創(chuàng)新互聯(lián)

這篇文章主要介紹了如何通過(guò)python實(shí)現(xiàn)人臉識(shí)別驗(yàn)證,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比沈陽(yáng)網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式沈陽(yáng)網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋沈陽(yáng)地區(qū)。費(fèi)用合理售后完善,十年實(shí)體公司更值得信賴。

直接上代碼,此案例是根據(jù)https://github.com/caibojian/face_login修改的,識(shí)別率不怎么好,有時(shí)擋了半個(gè)臉還是成功的

# -*- coding: utf-8 -*-
# __author__="maple"
"""
       ┏┓   ┏┓
      ┏┛┻━━━┛┻┓
      ┃   ☃   ┃
      ┃ ┳┛ ┗┳ ┃
      ┃   ┻   ┃
      ┗━┓   ┏━┛
        ┃   ┗━━━┓
        ┃ 神獸保佑  ┣┓
        ┃ 永無(wú)BUG!  ┏┛
        ┗┓┓┏━┳┓┏┛
         ┃┫┫ ┃┫┫
         ┗┻┛ ┗┻┛
"""
import base64
import cv2
import time
from io import BytesIO
from tensorflow import keras
from PIL import Image
from pymongo import MongoClient
import tensorflow as tf
import face_recognition
import numpy as np
#mongodb連接
conn = MongoClient('mongodb://root:123@localhost:27017/')
db = conn.myface #連接mydb數(shù)據(jù)庫(kù),沒(méi)有則自動(dòng)創(chuàng)建
user_face = db.user_face #使用test_set集合,沒(méi)有則自動(dòng)創(chuàng)建
face_images = db.face_images


lables = []
datas = []
INPUT_NODE = 128
LATER1_NODE = 200
OUTPUT_NODE = 0
TRAIN_DATA_SIZE = 0
TEST_DATA_SIZE = 0


def generateds():
  get_out_put_node()
  train_x, train_y, test_x, test_y = np.array(datas),np.array(lables),np.array(datas),np.array(lables)
  return train_x, train_y, test_x, test_y

def get_out_put_node():
  for item in face_images.find():
    lables.append(item['user_id'])
    datas.append(item['face_encoding'])
  OUTPUT_NODE = len(set(lables))
  TRAIN_DATA_SIZE = len(lables)
  TEST_DATA_SIZE = len(lables)
  return OUTPUT_NODE, TRAIN_DATA_SIZE, TEST_DATA_SIZE

# 驗(yàn)證臉部信息
def predict_image(image):
  model = tf.keras.models.load_model('face_model.h6',compile=False)
  face_encode = face_recognition.face_encodings(image)
  result = []
  for j in range(len(face_encode)):
    predictions1 = model.predict(np.array(face_encode[j]).reshape(1, 128))
    print(predictions1)
    if np.max(predictions1[0]) > 0.90:
      print(np.argmax(predictions1[0]).dtype)
      pred_user = user_face.find_one({'id': int(np.argmax(predictions1[0]))})
      print('第%d張臉是%s' % (j+1, pred_user['user_name']))
      result.append(pred_user['user_name'])
  return result

# 保存臉部信息
def save_face(pic_path,uid):
  image = face_recognition.load_image_file(pic_path)
  face_encode = face_recognition.face_encodings(image)
  print(face_encode[0].shape)
  if(len(face_encode) == 1):
    face_image = {
      'user_id': uid,
      'face_encoding':face_encode[0].tolist()
    }
    face_images.insert_one(face_image)

# 訓(xùn)練臉部信息
def train_face():
  train_x, train_y, test_x, test_y = generateds()
  dataset = tf.data.Dataset.from_tensor_slices((train_x, train_y))
  dataset = dataset.batch(32)
  dataset = dataset.repeat()
  OUTPUT_NODE, TRAIN_DATA_SIZE, TEST_DATA_SIZE = get_out_put_node()
  model = keras.Sequential([
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(128, activation=tf.nn.relu),
    keras.layers.Dense(OUTPUT_NODE, activation=tf.nn.softmax)
  ])

  model.compile(optimizer=tf.compat.v1.train.AdamOptimizer(),
        loss='sparse_categorical_crossentropy',
        metrics=['accuracy'])
  steps_per_epoch = 30
  if steps_per_epoch > len(train_x):
    steps_per_epoch = len(train_x)
  model.fit(dataset, epochs=10, steps_per_epoch=steps_per_epoch)

  model.save('face_model.h6')



def register_face(user):
  if user_face.find({"user_name": user}).count() > 0:
    print("用戶已存在")
    return
  video_capture=cv2.VideoCapture(0)
  # 在MongoDB中使用sort()方法對(duì)數(shù)據(jù)進(jìn)行排序,sort()方法可以通過(guò)參數(shù)指定排序的字段,并使用 1 和 -1 來(lái)指定排序的方式,其中 1 為升序,-1為降序。
  finds = user_face.find().sort([("id", -1)]).limit(1)
  uid = 0
  if finds.count() > 0:
    uid = finds[0]['id'] + 1
  print(uid)
  user_info = {
    'id': uid,
    'user_name': user,
    'create_time': time.time(),
    'update_time': time.time()
  }
  user_face.insert_one(user_info)

  while 1:
    # 獲取一幀視頻
    ret, frame = video_capture.read()
    # 窗口顯示
    cv2.imshow('Video',frame)
    # 調(diào)整角度后連續(xù)拍5張圖片
    if cv2.waitKey(1) & 0xFF == ord('q'):
      for i in range(1,6):
        cv2.imwrite('Myface{}.jpg'.format(i), frame)
        with open('Myface{}.jpg'.format(i),"rb")as f:
          img=f.read()
          img_data = BytesIO(img)
          im = Image.open(img_data)
          im = im.convert('RGB')
          imgArray = np.array(im)
          faces = face_recognition.face_locations(imgArray)
          save_face('Myface{}.jpg'.format(i),uid)
      break

  train_face()
  video_capture.release()
  cv2.destroyAllWindows()


def rec_face():
  video_capture = cv2.VideoCapture(0)
  while 1:
    # 獲取一幀視頻
    ret, frame = video_capture.read()
    # 窗口顯示
    cv2.imshow('Video',frame)
    # 驗(yàn)證人臉的5照片
    if cv2.waitKey(1) & 0xFF == ord('q'):
      for i in range(1,6):
        cv2.imwrite('recface{}.jpg'.format(i), frame)
      break

  res = []
  for i in range(1, 6):
    with open('recface{}.jpg'.format(i),"rb")as f:
      img=f.read()
      img_data = BytesIO(img)
      im = Image.open(img_data)
      im = im.convert('RGB')
      imgArray = np.array(im)
      predict = predict_image(imgArray)
      if predict:
        res.extend(predict)

  b = set(res) # {2, 3}
  if len(b) == 1 and len(res) >= 3:
    print(" 驗(yàn)證成功")
  else:
    print(" 驗(yàn)證失敗")

if __name__ == '__main__':
  register_face("maple")
  rec_face()

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)頁(yè)標(biāo)題:如何通過(guò)python實(shí)現(xiàn)人臉識(shí)別驗(yàn)證-創(chuàng)新互聯(lián)
本文地址:http://aaarwkj.com/article26/coiscg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄定制網(wǎng)站、網(wǎng)站導(dǎo)航、品牌網(wǎng)站建設(shè)、Google移動(dòng)網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

成都app開(kāi)發(fā)公司

網(wǎng)站設(shè)計(jì)公司知識(shí)

日韩永久免费av网站| 18以下的人禁止看的视频| 欧美日韩在线国产一区| 亚洲偷拍自拍在线观看| 少妇特黄a一区二区三区| 亚洲奇米精品一区二区| 亚洲成人久久久久久久| 国产蜜臀视频一区二区三区| 国产av麻豆全部免费| 精品亚洲一区二区三区四| 小草少妇视频免费看视频| 久久精品国产一区电影| 三级av电影中文字幕| 一区二区三区午夜激情| 国产三级在线dvd观看| 神马免费午夜福利剧场| 最新国产不卡一区二区| 草草视频在线观看网站| av国语对白在线观看| 国产传媒视频在线免费观看| 亚洲精品污一区二区三区| 精品国产91乱码一区二区三区 | 中文字幕亚洲精品99| 国产精品人一区二区三区| 人人狠狠综合久久亚洲| 国产精品一级性生活片| 九九在线精品视频免费| 在线观看国产小视频不卡| 久久综合午夜福利视频| 国产91九色蝌蚪在线观看| 日本师生三片在线观看| 中文字幕日韩精品国产| 亚洲天堂国产中文在线| 中文字幕熟妇人妻av在线| 日本一区二区不卡高清| 亚洲高清无毛一区二区| 亚洲色图视频免费观看| 末满18周岁禁止观看| 西西美女掰开阴让你看| 国产看片色网站亚洲av| 色哟哟网站在线观看入口|