代码如下,将sd卡中某个文件的20张人脸与人脸库中20张人脸进行lbp特征值匹配,在对应list中填写识别人脸的编号,最终统计list中最多元素个数即认为是对应的人脸,在运行第6次时突然报错:NameError: name 'd_now' isn't defined
不会是变量未定义的问题,不然的话第一次循环就会报错,现在问题在于循环至第六次时出现错误,openmv为openmvH7,固件为3.6.7,希望得到官方的解答,谢谢
import sensor, image, time, pyb
from pyb import Pin
red = pyb.LED(1) #初始化led
green = pyb.LED(2)
blue = pyb.LED(3)
sensor.reset() #传感器重置
sensor.set_contrast(3) #感光元件设置
sensor.set_gainceiling(16)
sensor.set_pixformat(sensor.GRAYSCALE) #图像格式为灰度值
sensor.set_framesize(sensor.QQVGA) #图像大小为HQVGA,用于人脸识别
sensor.set_hmirror(True) #水平翻转
sensor.skip_frames(time = 2000) #等待sensor稳定
face_cascade = image.HaarCascade("frontalface", stages=25) #载入人脸识别模型
clock = time.clock() #初始化系统时钟
count=0 #每个人拍50张照片
person=1 #不同编号的人
person_base=1 #数据库人数
person_base_total=2 #数据库总人数
person_base_total_count=0 #数据库总人数(变量)
dist_once=0 #lbp差异值
num_final=0 #最终匹配编号
num_once=0 #单次匹配编号
pmin = 999999 #最小值初始化
def min(pmin, a, s):
global num_once
if a<pmin:
pmin=a
num_once=s
return pmin
def showmax(lt):
index1 = 0 #记录出现次数最多的元素下标
max = 0 #记录最大的元素出现次数
for i in range(len(lt)):
flag = 0 #记录每一个元素出现的次数
for j in range(i+1,len(lt)): #遍历i之后的元素下标
if lt[j] == lt[i]:
flag += 1 #每当发现与自己相同的元素,flag+1
if flag > max: #如果此时元素出现的次数大于最大值,记录此时元素的下标
max = flag
index1 = i
return lt[index1] #返回出现最多的元素
while(True): #系统主循环
clock.tick()
list_now=[0]*20
num_final=0
for s_now in range(1,21):
pmin=99999
num_once=0
img_now=image.Image("now/s%d/%d.pgm"%(1, s_now))
d_now=img_now.find_lbp((0, 0, 81, 81))
for person_base_total_count in range(1,person_base_total+1):
dist_once=0
for s_base in range(1,21):
img_base=image.Image("base/s%d/%d.pgm"%(person_base_total_count, s_base))
d_base=img_base.find_lbp((0, 0, 81, 81))
dist_once += image.match_descriptor(d_now, d_base)
dist_ave=dist_once/20
pmin=min(pmin,dist_ave,person_base_total_count)
list_now[s_now-1]=num_once
print('the number of photo is:',s_now,':',list_now[s_now-1])
print(list_now)
num_final=showmax(list_now)
print('this person is number:',num_final)有时还会出现openmv运行程序时突然断连的情况,感觉不是很稳定,是什么原因啊?
程序脱机运行的时候时而正常,又会有10%的概率在人脸计算的时候死机,导致程序不再运行
希望在论坛里得到官方的解答,程序没有问题,正常运行的时候可以一直运行10分钟不出问题,又会有10%左右的概率在一开始进行人脸计算的时候死机
脱机运行的时候有时候会突然闪两下红灯造成死机
你能上传你的图片集吗?我方便测试。