資料介紹
描述
理念的起源
在過(guò)去的幾年里,我很難在早上醒來(lái)。我嘗試了許多解決方案,例如警報(bào)和強(qiáng)迫自己起床并開(kāi)始行動(dòng),但都沒(méi)有奏效。我決定想出一個(gè)解決方案來(lái)解決所有問(wèn)題,如果我在鬧鐘響起 5 分鐘后沒(méi)有起床,這個(gè)設(shè)備會(huì)在我頭上放一個(gè)枕頭。
電子產(chǎn)品
我使用的最終電子設(shè)備非常簡(jiǎn)單。它由一個(gè) Raspberry Pi 3 B、一個(gè) Raspberry Pi 相機(jī)、3 條公對(duì)母跳線、一個(gè)微型伺服器和一個(gè)電池組組成。
我將伺服引腳連接到樹(shù)莓派上的引腳 4、6 和 11。我還將相機(jī)插入 Raspberry Pi 上的帶狀電纜的小插槽。
代碼
在詳細(xì)介紹我的項(xiàng)目的代碼和面部識(shí)別部分之前,我想在 Youtube 上向cytrontech 大喊大叫,因?yàn)樗l(fā)布了這個(gè)視頻,展示了如何使用 Opencv 進(jìn)行基本的面部識(shí)別。
在我開(kāi)始使用我的 Raspberry Pi 之前,我確保安裝了最新版本的 Raspberry Pi OS 的新映像。然后我開(kāi)始下載opencv以便開(kāi)始處理圖像。一旦我確認(rèn)我已經(jīng)下載了 opencv 并且完全是最新的,我就開(kāi)始瀏覽 cytrontech 視頻。
代碼部分由四個(gè)文件組成,其中兩個(gè)與原始視頻中的相同。
import cv2
name = 'Suad' #replace with your name
cam = cv2.VideoCapture(0)
cv2.namedWindow("press space to take a photo", cv2.WINDOW_NORMAL)
cv2.resizeWindow("press space to take a photo", 500, 300)
img_counter = 0
while True:
ret, frame = cam.read()
if not ret:
print("failed to grab frame")
break
cv2.imshow("press space to take a photo", frame)
k = cv2.waitKey(1)
if k%256 == 27:
# ESC pressed
print("Escape hit, closing…")
break
elif k%256 == 32:
# SPACE pressed
img_name = "dataset/"+ name +"/image_{}.jpg".format(img_counter)
cv2.imwrite(img_name, frame)
print("{} written!".format(img_name))
img_counter += 1
cam.release()
cv2.destroyAllWindows()
這是第一個(gè)名為 face_shot.py 的文件。它用于拍攝您的臉部照片并收集數(shù)據(jù)以訓(xùn)練模型。
#! /usr/bin/python
# import the necessary packages
from imutils import paths
import face_recognition
#import argparse
import pickle
import cv2
import os
# our images are located in the dataset folder
print("[INFO] start processing faces…")
imagePaths = list(paths.list_images("dataset"))
# initialize the list of known encodings and known names
knownEncodings = []
knownNames = []
# loop over the image paths
for (i, imagePath) in enumerate(imagePaths):
# extract the person name from the image path
print("[INFO] processing image {}/{}".format(i + 1,
len(imagePaths)))
name = imagePath.split(os.path.sep)[–2]
# load the input image and convert it from RGB (OpenCV ordering)
# to dlib ordering (RGB)
image = cv2.imread(imagePath)
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
# detect the (x, y)-coordinates of the bounding boxes
# corresponding to each face in the input image
boxes = face_recognition.face_locations(rgb,
model="hog")
# compute the facial embedding for the face
encodings = face_recognition.face_encodings(rgb, boxes)
# loop over the encodings
for encoding in encodings:
# add each encoding + name to our set of known names and
# encodings
knownEncodings.append(encoding)
knownNames.append(name)
# dump the facial encodings + names to disk
print("[INFO] serializing encodings…")
data = {"encodings": knownEncodings, "names": knownNames}
f = open("encodings.pickle", "wb")
f.write(pickle.dumps(data))
f.close()
這是名為 train_model.py 的第二個(gè)文件。它用于根據(jù)您使用 face_shot.py 拍攝的圖像來(lái)訓(xùn)練模型。
#! /usr/bin/python
# import the necessary packages
from datetime import datetime
import servo_move
from imutils.video import VideoStream
from imutils.video import FPS
import face_recognition
import imutils
import pickle
import time
import cv2
now = datetime.now()
da_time = datetime(2021, 4, 7, 12, 35, 00)
x = 0
#Initialize 'currentname' to trigger only when a new person is identified.
currentname = "unknown"
#Determine faces from encodings.pickle file model created from train_model.py
encodingsP = "encodings.pickle"
#use this xml file
#https://github.com/opencv/opencv/blob/master/data/haarcascades/haarcascade_frontalface_default.xml
cascade = "haarcascade_frontalface_default.xml"
# load the known faces and embeddings along with OpenCV's Haar
# cascade for face detection
print("[INFO] loading encodings + face detector…")
data = pickle.loads(open(encodingsP, "rb").read())
detector = cv2.CascadeClassifier(cascade)
# initialize the video stream and allow the camera sensor to warm up
print("[INFO] starting video stream…")
vs = VideoStream(src=0).start()
#vs = VideoStream(usePiCamera=True).start()
time.sleep(2.0)
# start the FPS counter
fps = FPS().start()
# loop over frames from the video file stream
while True:
# grab the frame from the threaded video stream and resize it
# to 500px (to speedup processing)
frame = vs.read()
frame = imutils.resize(frame, width=500)
# convert the input frame from (1) BGR to grayscale (for face
# detection) and (2) from BGR to RGB (for face recognition)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# detect faces in the grayscale frame
rects = detector.detectMultiScale(gray, scaleFactor=1.1,
minNeighbors=5, minSize=(30, 30),
flags=cv2.CASCADE_SCALE_IMAGE)
# OpenCV returns bounding box coordinates in (x, y, w, h) order
# but we need them in (top, right, bottom, left) order, so we
# need to do a bit of reordering
boxes = [(y, x + w, y + h, x) for (x, y, w, h) in rects]
# compute the facial embeddings for each face bounding box
encodings = face_recognition.face_encodings(rgb, boxes)
names = []
# loop over the facial embeddings
for encoding in encodings:
# attempt to match each face in the input image to our known
# encodings
matches = face_recognition.compare_faces(data["encodings"],
encoding)
name = "Unknown" #if face is not recognized, then print Unknown
# check to see if we have found a match
if True in matches:
# find the indexes of all matched faces then initialize a
# dictionary to count the total number of times each face
# was matched
matchedIdxs = [i for (i, b) in enumerate(matches) if b]
counts = {}
# loop over the matched indexes and maintain a count for
# each recognized face face
for i in matchedIdxs:
name = data["names"][i]
counts[name] = counts.get(name, 0) + 1
# determine the recognized face with the largest number
# of votes (note: in the event of an unlikely tie Python
# will select first entry in the dictionary)
name = max(counts, key=counts.get)
#If someone in your dataset is identified, print their name on the screen
if currentname != name:
currentname = name
print(currentname)
# update the list of names
names.append(name)
# loop over the recognized faces
for ((top, right, bottom, left), name) in zip(boxes, names):
# draw the predicted face name on the image – color is in BGR
cv2.rectangle(frame, (left, top), (right, bottom),
(0, 255, 0), 2)
y = top - 15 if top - 15 > 15 else top + 15
cv2.putText(frame, name, (left, y), cv2.FONT_HERSHEY_SIMPLEX,
.8, (255, 0, 0), 2)
# display the image to our screen
cv2.imshow("Facial Recognition is Running", frame)
key = cv2.waitKey(1) & 0xFF
# quit when 'q' key is pressed
if key == ord("q"):
break
# update the FPS counter
fps.update()
current_time = datetime.now()
if (currentname == "will") and (current_time.time() > da_time.time()) and (x == 0):
exec(open("servo_move.py").read())
x = 1
# stop the timer and display FPS information
fps.stop()
print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
# do a bit of cleanup
cv2.destroyAllWindows()
vs.stop()
這是視頻中名為 face_rec.py 的第三個(gè)也是最后一個(gè)文件。它是您想要實(shí)際啟動(dòng)面部識(shí)別軟件時(shí)運(yùn)行的文件。我只添加了幾行代碼,它們是:
from datetime import datetime
import servo_move
now = datetime.now()
da_time = datetime(2021, 4, 7, 12, 35, 00)
x = 0
current_time = datetime.now()
if (currentname == "will") and (current_time.time() > da_time.time()) and (x = = 0):
exec(open("servo_move.py").read())
x = 1
這些代碼行檢查當(dāng)前時(shí)間是否為上午 7:35,即鬧鐘響后 5 分鐘。如果是并且我的臉在那里,那么它會(huì)執(zhí)行一個(gè)名為servo_move.py 的文件。
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
servo1 = GPIO.PWM(11,50)
servo1.start(0)
servo1.ChangeDutyCycle(12)
time.sleep(2)
servo1.ChangeDutyCycle(2)
time.sleep(0.5)
servo1.ChangeDutyCycle(0)
servo1.stop()
GPIO.cleanup()
這是servo_move.py。它使伺服器移動(dòng) 180 度然后向后移動(dòng)。
制造
我必須制作的第一件作品是在我的電子部分展示的“電子板”。它只是一塊木頭,一切都依賴于它。
這是一個(gè)非常簡(jiǎn)單的設(shè)計(jì),只是一些木頭與我 3D 打印的一些鉸鏈相連。我想說(shuō)鉸鏈不是我自己設(shè)計(jì)的,它們是guppyk在 thingiverse 上制作的。我使用的鉸鏈和它們的許多變體可以在這里下載。
我會(huì)做什么不同
這個(gè)項(xiàng)目最終確實(shí)按預(yù)期工作,但這并不意味著我不會(huì)改變某些方面。如果我再做一次,我會(huì)把木頭噴漆成黑色,這樣膠帶和零件就不會(huì)那么突出了。我也會(huì)制作一個(gè)更永久的電子板版本。
- 浮油警報(bào)開(kāi)源分享
- 健康警報(bào)開(kāi)源項(xiàng)目
- 運(yùn)動(dòng)感應(yīng)警報(bào)開(kāi)源分享
- 溫度警報(bào)設(shè)備開(kāi)源案例
- Burgler防盜警報(bào)設(shè)備開(kāi)源
- 火警警報(bào)開(kāi)源分享
- 交貨警報(bào)系統(tǒng)開(kāi)源分享
- CPU壓力水平警報(bào)開(kāi)源分享
- MiMaMori家庭安全警報(bào)開(kāi)源分享
- 火災(zāi)警報(bào)開(kāi)源項(xiàng)目
- 點(diǎn)亮蜂鳴器警報(bào)開(kāi)源項(xiàng)目
- 警報(bào)系統(tǒng)開(kāi)源分享
- 自動(dòng)消毒與消毒警報(bào)開(kāi)源
- 能量警報(bào)器開(kāi)源分享
- 電子設(shè)備中高功率器件的強(qiáng)迫風(fēng)冷散熱設(shè)計(jì) 67次下載
- 電子警報(bào)器電路圖分享 923次閱讀
- 報(bào)警器電路圖分享 1123次閱讀
- 利用開(kāi)源軟件的最佳實(shí)踐 464次閱讀
- 如何使用IC555創(chuàng)建6個(gè)有趣的警報(bào)器和警報(bào)音效發(fā)生器電路 4071次閱讀
- 前沿開(kāi)源技術(shù)領(lǐng)域的開(kāi)源大數(shù)據(jù)一一解讀 1005次閱讀
- 制冷系統(tǒng)高壓警報(bào)的原因及排除方法 1.9w次閱讀
- 如何實(shí)現(xiàn)自己的DFU 1843次閱讀
- 筆記本電腦的警報(bào)電路圖 2844次閱讀
- 一種低成本的電子警報(bào)器電路圖 2975次閱讀
- 使用LED作為模擬輸出的汽車警報(bào)模擬器電路 1738次閱讀
- 單片機(jī)驅(qū)動(dòng)蜂鳴器產(chǎn)生警報(bào)聲的設(shè)計(jì) 5596次閱讀
- 地震警報(bào)器制作詳解 1w次閱讀
- NASA的開(kāi)源軟件是什么?NASA的開(kāi)源軟件的詳細(xì)分析 7186次閱讀
- 11個(gè)機(jī)器學(xué)習(xí)開(kāi)源項(xiàng)目 2767次閱讀
- 復(fù)古手環(huán):用開(kāi)源硬件打造你自己的可穿戴設(shè)備 1.1w次閱讀
下載排行
本周
- 1山景DSP芯片AP8248A2數(shù)據(jù)手冊(cè)
- 1.06 MB | 532次下載 | 免費(fèi)
- 2RK3399完整板原理圖(支持平板,盒子VR)
- 3.28 MB | 339次下載 | 免費(fèi)
- 3TC358743XBG評(píng)估板參考手冊(cè)
- 1.36 MB | 330次下載 | 免費(fèi)
- 4DFM軟件使用教程
- 0.84 MB | 295次下載 | 免費(fèi)
- 5元宇宙深度解析—未來(lái)的未來(lái)-風(fēng)口還是泡沫
- 6.40 MB | 227次下載 | 免費(fèi)
- 6迪文DGUS開(kāi)發(fā)指南
- 31.67 MB | 194次下載 | 免費(fèi)
- 7元宇宙底層硬件系列報(bào)告
- 13.42 MB | 182次下載 | 免費(fèi)
- 8FP5207XR-G1中文應(yīng)用手冊(cè)
- 1.09 MB | 178次下載 | 免費(fèi)
本月
- 1OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 2555集成電路應(yīng)用800例(新編版)
- 0.00 MB | 33566次下載 | 免費(fèi)
- 3接口電路圖大全
- 未知 | 30323次下載 | 免費(fèi)
- 4開(kāi)關(guān)電源設(shè)計(jì)實(shí)例指南
- 未知 | 21549次下載 | 免費(fèi)
- 5電氣工程師手冊(cè)免費(fèi)下載(新編第二版pdf電子書)
- 0.00 MB | 15349次下載 | 免費(fèi)
- 6數(shù)字電路基礎(chǔ)pdf(下載)
- 未知 | 13750次下載 | 免費(fèi)
- 7電子制作實(shí)例集錦 下載
- 未知 | 8113次下載 | 免費(fèi)
- 8《LED驅(qū)動(dòng)電路設(shè)計(jì)》 溫德?tīng)栔?/a>
- 0.00 MB | 6656次下載 | 免費(fèi)
總榜
- 1matlab軟件下載入口
- 未知 | 935054次下載 | 免費(fèi)
- 2protel99se軟件下載(可英文版轉(zhuǎn)中文版)
- 78.1 MB | 537798次下載 | 免費(fèi)
- 3MATLAB 7.1 下載 (含軟件介紹)
- 未知 | 420027次下載 | 免費(fèi)
- 4OrCAD10.5下載OrCAD10.5中文版軟件
- 0.00 MB | 234315次下載 | 免費(fèi)
- 5Altium DXP2002下載入口
- 未知 | 233046次下載 | 免費(fèi)
- 6電路仿真軟件multisim 10.0免費(fèi)下載
- 340992 | 191187次下載 | 免費(fèi)
- 7十天學(xué)會(huì)AVR單片機(jī)與C語(yǔ)言視頻教程 下載
- 158M | 183279次下載 | 免費(fèi)
- 8proe5.0野火版下載(中文版免費(fèi)下載)
- 未知 | 138040次下載 | 免費(fèi)
評(píng)論
查看更多