logo

请问openmv接收到数据后,怎样继续运行后面的代码?谢谢了

2021-03-26 11:50
8
pt6u
import sensor, time, image, pyb
from pyb import UART
from pyb import Pin, ExtInt

uart = UART(3, 115200)

while(True):
    if uart.any():
        a=uart.readline().decode().strip()
        print(a)

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) # Let new settings take affect.
sensor.skip_frames(time = 5000) #等待5s


#SUB = "s1"
NUM_SUBJECTS = 2 #图像库中不同人数,一共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)

print(num) # num为当前最匹配的人的编号。
uart.write(str(num)+'\r\n')

我在串口助手上发0给openmv,串行终端读到了0,然后就停在了那一步,我想问一下怎样修改代码,可以让openmv接收到数据后,能继续运行后面的人脸识别程序

2021-03-26 14:11
I
网红小智智 星瞳科技

你的第一个死循环永远不会停止。12行之后的代码,永远不会运行。

2021-03-26 17:30
8
pt6u

@kidswong999 那请问我是应该用break跳出循环还是其他方法,麻烦你啦