日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人工智能 > 卷积神经网络 >内容正文

卷积神经网络

Keras之CNN:基于Keras利用cv2建立训练存储卷积神经网络模型(2+1)并调用摄像头进行实时人脸识别

發布時間:2025/3/21 卷积神经网络 67 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Keras之CNN:基于Keras利用cv2建立训练存储卷积神经网络模型(2+1)并调用摄像头进行实时人脸识别 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Keras之CNN:基于Keras利用cv2建立訓練存儲卷積神經網絡模型(2+1)并調用攝像頭進行實時人臉識別

?

?

目錄

輸出結果

設計思路

核心代碼


?

?

?

輸出結果

?

設計思路

?

核心代碼

?

# -*- coding:utf-8 -*- import cv2 from train_model import Model from read_data import read_name_list from timeit import default_timer as timer ### to calculate FPSclass Camera_reader(object):def __init__(self):self.model = Model()self.model.load()self.img_size = 128def build_camera(self):face_cascade = cv2.CascadeClassifier('F:\\Program Files\\Python\\Python36\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_alt.xml') # print(face_cascade) #輸出<CascadeClassifier 000002240244CC70>name_list = read_name_list('F:\\File_Python\\Python_example\\face_recognition_name\\After_cut_picture') # print(name_list)cameraCapture = cv2.VideoCapture(0) success, frame = cameraCapture.read() while success and cv2.waitKey(1) == -1: success, frame = cameraCapture.read()gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) ROI = gray[x:x + w, y:y + h]ROI = cv2.resize(ROI, (self.img_size, self.img_size), interpolation=cv2.INTER_LINEAR) label,prob = self.model.predict(ROI) if prob >0.7: show_name = name_list[label]else:show_name = 'Stranger'cv2.putText(frame, show_name, (x, y - 20), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2) frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.imshow("Camera", frame) cameraCapture.release() cv2.destroyAllWindows() def detect_video(self): face_cascade = cv2.CascadeClassifier('F:\\Program Files\\Python\\Python36\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_alt.xml')name_list = read_name_list('F:\\File_Python\\Python_example\\face_recognition_name\\After_cut_picture')video = cv2.VideoCapture(video_path) ### TODO: will video path other than 0 be used?success, frame = video.read() accum_time = 0curr_fps = 0fps = "FPS: ??" #fps = "FPS: ??"prev_time = timer()while success and cv2.waitKey(1) == -1: success, frame = video.read() gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)faces = face_cascade.detectMultiScale(gray, 1.3, 5)curr_time = timer()exec_time = curr_time - prev_timeprev_time = curr_timeaccum_time = accum_time + exec_timecurr_fps = curr_fps + 1 #1 if accum_time > 1:accum_time = accum_time - 1 #1fps = "FPS: " + str(curr_fps)curr_fps = 0 #0 for (x, y, w, h) in faces: ROI = gray[x:x + w, y:y + h]ROI = cv2.resize(ROI, (self.img_size, self.img_size), interpolation=cv2.INTER_LINEAR) #cv2.INTER_LINEAR圖像尺寸變換的方法,默認的雙線性插值label,prob = self.model.predict(ROI) if prob >0.7: show_name = name_list[label]else:show_name = 'Stranger'cv2.putText(frame, show_name, (x, y - 20), cv2.FONT_HERSHEY_SIMPLEX, 1, 255, 2) frame = cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2) cv2.namedWindow("result", cv2.WINDOW_NORMAL)cv2.imshow("result",frame)if __name__ == '__main__':camera = Camera_reader()camera.build_camera() # video_path='F:/File_Python/Python_example/YOLOv3_use_TF/RunMan1.mp4' # camera.detect_video()

?

?

?

?

總結

以上是生活随笔為你收集整理的Keras之CNN:基于Keras利用cv2建立训练存储卷积神经网络模型(2+1)并调用摄像头进行实时人脸识别的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。