摄像头人脸检测的树莓派指纹识别系统

本文介绍了一个使用树莓派、摄像头、指纹识别模块和LED显示屏构建的智能门锁系统。该系统通过摄像头检测人脸,继而唤醒指纹识别模块,当检测到人脸或指纹匹配成功时,允许进入。代码中包含了人脸检测、串口通信及与指纹模块交互的实现。
摘要由CSDN通过智能技术生成

摄像头人脸检测的树莓派指纹识别系统

前言:此项目主要用了摄像头、指纹识别、继电器、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()
效果展示:

视频后续添加

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值