logo

当脱机运行人脸识别代码,LCD屏无任何反应且不能实现识别,重新将摄像头与电脑连接,发现main代码全都乱码。要怎么解决?

2023-03-27 14:58
R
geny_1678804522
# Face recognition with LBP descriptors.
# See Timo Ahonen's "Face Recognition with Local Binary Patterns".
#
# Before running the example:
# 1) Download the AT&T faces database http://www.cl.cam.ac.uk/Research/DTG/attarchive/pub/data/att_faces.zip
# 2) Exract and copy the orl_faces directory to the SD card root.


import sensor, time, image, pyb, lcd
from pyb import UART

uart = UART(3, 115200)
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.GRAYSCALE
sensor.set_framesize(sensor.QQVGA2) # or sensor.QQVGA (or others)

sensor.skip_frames(10) # Let new settings take affect.
lcd.init()
sensor.skip_frames(time = 3000) #等待5s



#SUB = "s1"
NUM_SUBJECTS = 2 #图像库中不同人数,一共6人
NUM_SUBJECTS_IMGS = 20 #每人有20张样本图片

while True:
# 拍摄当前人脸。
    img = sensor.snapshot()
    #img.draw_string(0,0,"hjhjk")
    pyb.LED(2).off()
    lcd.display(img) # 拍照并显示图像。
    #img = sensor.snapshot()
    #img = image.Image("singtown/%s/1.pgm"%(SUB))
    d0 = img.find_lbp((0, 0, img.width(), img.height()))
    #d0为当前人脸的lbp特征
    img = None
    pmin = 999999
    num=0

    def min(pmin, a, s):
        global num
        if a<pmin:
            pmin=a
            num=s
        return pmin

    for s in range(1, NUM_SUBJECTS+1):
        dist = 0
        for i in range(2, NUM_SUBJECTS_IMGS+1):
            img = image.Image("facedb/face%d/%d.pgm"%(s, i))
            d1 = img.find_lbp((0, 0, img.width(), img.height()))
            #d1为第s文件夹中的第i张图片的lbp特征
            dist += image.match_descriptor(d0, d1)#计算d0 d1即样本图像与被检测人脸的特征差异度。

        print("Average dist for subject %d: %d"%(s, dist/NUM_SUBJECTS_IMGS))
        pmin = min(pmin, dist/NUM_SUBJECTS_IMGS, s)#特征差异度越小,被检测人脸与此样本更相似更匹配。
        print(pmin)

    print(num) # num为当前最匹配的人的编号。

    if(dist/NUM_SUBJECTS_IMGS < 10000) :
        pyb.LED(2).on()
        if num == 1:
            imgstr = sensor.snapshot()
            imgstr.draw_string(0,0,"Ms.Pu",0)
            lcd.display(imgstr) # 拍照并显示图像。
            uart.write("1\r\n")
        elif num ==2:
            imgstr = sensor.snapshot()
            imgstr.draw_string(0,0,"Ms.Yuan",0)
            lcd.display(imgstr) # 拍照并显示图像。
            uart.write("2\r\n")
        time.sleep(5)
2023-03-27 15:07
R
geny_1678804522

这个是存放在SD卡里的LCD代码

# LCD显示例程
#
# 注意:要运行这个例子,你需要一个用于OpenMV的LCD扩展板。
#
# LCD扩展板允许您在运行时查看您的OpenMV Cam的帧缓冲区。

import sensor, image, lcd

sensor.reset() # 初始化sensor
sensor.set_pixformat(sensor.RGB565) # or sensor.GRAYSCALE
#设置图像色彩格式,有RGB565色彩图和GRAYSCALE灰度图两种

sensor.set_framesize(sensor.QQVGA2) # 128x160大小的特定液晶屏。
lcd.init() # 初始化lcd屏幕。

while(True):
    lcd.display(sensor.snapshot()) # 拍照并显示图像。
2023-03-27 15:25
I
网红小智智 星瞳科技

把内存卡使用读卡器插到电脑上,格式化为fat32格式,然后重新插到OpenMV上,重新运行脱机的步骤。