import sensor, time, image, pyb
import ustruct
from pyb import Pin
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.B128X128) # or sensor.QQVGA (or others)
sensor.set_windowing((92,112))
sensor.skip_frames(10)
sensor.skip_frames(time = 5000) #等待5s
RED_LED_PIN = 1
p_in1 = Pin('P7', Pin.IN, Pin.PULL_UP) #定义p7,p8,p9三个引脚为输入,加上一个上拉电阻
p_in2 = Pin('P8', Pin.IN, Pin.PULL_UP)
a=p_in1.value() #用a,b获取p7,p8两个引脚的值
b=p_in2.value()
NUM_SUBJECTS = 6 #图像库中不同人数,一共6人
NUM_SUBJECTS_IMGS = 20 #每人有20张样本图片
while(True):
NUM_SUBJECTS = 6 #图像库中不同人数,一共6人
NUM_SUBJECTS_IMGS = 20 #每人有20张样本图片
# 拍摄当前人脸。
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("singtown/s%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)
if(pmin>8000):
num=9
print(num) #num为当前最匹配的人的编号。
data = bytearray([0x0b,0x0b,num,0x0d,0x0a])
uart.write(data)这段代码基本上是使用的星瞳科技的分辨不同人脸例程,多了一个串口发送数据,然后让STM32接收。
STM32那边同样的程序,用星瞳科技扫码例程能显示,为什么这个显示不了呢,其实也就是发送的数据不一样嘛,这是为什么呢,是32那边的问题,还是OpenMV这边的问题呢
import sensor, image, time
from pyb import UART
uart = UART(3, 115200)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # can be QVGA on M7...
sensor.skip_frames(30)
sensor.set_auto_gain(False) # must turn this off to prevent image washout...
while(True):
img = sensor.snapshot()
img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
for code in img.find_qrcodes():
print(code)
FH= bytearray([0xb3,0xb3])
uart.write(FH)
uart.write(code.payload())
FH = bytearray([0x0d,0x0a])
uart.write(FH)
time.sleep_ms(1000)这个星瞳科技的扫码例程可以传输数据给32,上面那个分辨人脸的例程传输不了,这是为什么呢,不是只多了一个数据传输吗,32那边程序都没变
看上去OpenMV这里发出去了,估计是和STM32的协议对不上。
你应该先在stm32上只写接受的程序,来判断是否接受到。