logo

这段代码哪里错了?

2019-01-25 16:24
H
fe15

想做一个图像识别,使其检测到汉字后在串行终端输出该汉字,但是程序报错

import time, sensor, image
from image import SEARCH_EX, SEARCH_DS
sensor.reset()
sensor.set_contrast(1)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.QQVGA)
sensor.set_pixformat(sensor.GRAYSCALE)
templates = ["/jin.pgm"] #保存多个模板
clock = time.clock()
while (True):
    clock.tick()
    img = sensor.snapshot()
    for t in templates:
        template = image.Image(t)
        r = img.find_template(template, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
        if r:
            img.draw_rectangle(r, color = (255,0,0))
            print(t[1:4]) #打印模板名字
        if t in ['jin.pgm']
           print('晋')
        else:
           print("error")
I
网红小智智 星瞳科技

if后面没有冒号