摄像头人脸检测的树莓派指纹识别系统
程序员文章站
2022-06-24 19:03:06
摄像头人脸检测的树莓派指纹识别系统前言:此项目主要用了摄像头、指纹识别、继电器、Led模块等设备。用于实现智能门锁功能,即摄像头检测到人来之后,打开继电器给指纹模块供电,led显示文字。代码:import binasciiimport serialimport serial.tools.list_portsimport timeimport cv2import Adafruit_GPIO.SPI as SPIimport Adafruit_SSD1306from PIL import I...
摄像头人脸检测的树莓派指纹识别系统
前言:此项目主要用了摄像头、指纹识别、继电器、Led模块等设备。用于实现智能门锁功能,即摄像头检测到人来之后,打开继电器给指纹模块供电,led显示文字。
代码:
import binascii
import serial
import serial.tools.list_ports
import time
import cv2
import Adafruit_GPIO.SPI as SPI
import Adafruit_SSD1306
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
cap = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier(r'haarcascade_frontalface_default.xml')
face_cascade.load('./haarcascade_frontalface_default.xml')
def recv(serial):
while True:
data = serial.read_all()
if data == '':
continue
else:
break
return data
if __name__ == '__main__':
RST = 24
DC = 23
SPI_PORT = 0
SPI_DEVICE = 0
disp = Adafruit_SSD1306.SSD1306_128_32(rst=RST)
disp = Adafruit_SSD1306.SSD1306_128_64(rst=RST)
disp.begin()
width = disp.width
height = disp.height
disp.clear()
disp.display()
image = Image.new('1', (width, height))
draw = ImageDraw.Draw(image)
font = ImageFont.load_default()
draw.text((10,30),'welcome to yjc home',font = font,fill=255)
disp.image(image)
disp.display()
time.sleep(2)
while (True):
ret, frame = cap.read()
faces = face_cascade.detectMultiScale(frame, scaleFactor=1.15, minNeighbors=5, minSize=(5, 5))
for (x,y,w,h) in faces:
cv2.rectangle(frame, (x,y),(x+w, y+h ), (0, 255, 0),2)
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.display()
draw.text((10,30), 'waiting for people', font=font, fill =255)
disp.image(image)
disp.display()
cv2.imshow('face', frame)
if cv2.waitKey(1)& 0xFF == ord('q'):
break
print("waiting for people")
if len(faces)>0:
break
cap.release()
cv2.destroyAllWindows()
serial = serial.Serial('/dev/ttyUSB0', 57600, timeout=0.5) #/dev/ttyUSB0
if serial.isOpen() :
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.display()
draw.text((10,30), 'open suceessful', font = font, fill= 255)
time.sleep(2)
disp.image(image)
disp.display()
else :
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.dispaly()
draw.text((10,30), 'open faild', font = font, fill = 255)
disp.image(image)
disp.display()
while True:
a = 'EF 01 FF FF FF FF 01 00 03 01 00 05'
d = bytes.fromhex(a)
serial.write(d)
time.sleep(1)
data =recv(serial)
if data != b'' :
data_con = str(binascii.b2a_hex(data))[20:22]
if(data_con == '02'):
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.display()
draw.text((20,30),'please enter finger', font=font, fill =255)
disp.image(image)
disp.display()
time.sleep(2)
elif(data_con == '00'):
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.display()
draw.text((20,30),'load suceessful',font = font, fill =255)
disp.image(image)
disp.display()
buff = 'EF 01 FF FF FF FF 01 00 04 02 01 00 08'
buff = bytes.fromhex(buff)
serial.write(buff)
time.sleep(1)
buff_data = recv(serial)
buff_con = str(binascii.b2a_hex(buff_data))[20:22]
if(buff_con == '00'):
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.display()
draw.text((20,30), 'creat feature suceessful',font = font , fill = 255)
disp.image(image)
disp.display()
time.sleep(2)
serch = 'EF 01 FF FF FF FF 01 00 08 04 01 00 00 00 64 00 72'
serch = bytes.fromhex(serch)
serial.write(serch)
time.sleep(1)
serch_data = recv(serial)
serch_con = str(binascii.b2a_hex(serch_data))[20:22]
if (serch_con == '09'):
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.display()
draw.text((10,30),'finger is not matching',font = font,fill =255)
disp.image(image)
disp.display()
time.sleep(2)
elif(serch_con == '00'):
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.display()
draw.text((10,30),'finger is matching',font=font,fill = 255)
disp.image(image)
disp.display()
time.sleep(2)
serial.close()
disp.image(image)
disp.display()
exit()
else:
draw.rectangle((0,0,width,height), outline=0, fill=0)
disp.display()
draw.text((30,30),'faild',font=font,fill = 255)
disp.image(image)
disp.display()
效果展示:
视频后续添加
本文地址:https://blog.csdn.net/qq_45125250/article/details/108866688