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 = ["/yii.pgm","/er.pgm"]
template1 = image.Image("/yii.pgm")
template2 = image.Image("/er.pgm")
clock = time.clock()
while (True):
clock.tick()
a= 0
img = sensor.snapshot()
for t in templates:
template = image.Image(t)
r = img.find_template(template, 0.70, step=4, search=SEARCH_EX)
if (r) :
img.draw_rectangle(r)
if t = '/yii.pgm':
a = 1
elif t = '/er.pgm':
a = 2
print('任务数字已接受')
time.sleep_ms(5000)
if a = 1:
r1 = img.find_template(template1, 0.70, step=4, search=SEARCH_EX)
if (r1) :
print('目标数字1已找到')
img.draw_rectangle(r1)
print(cx, cy)
if (cx>80) :
print(cx)
else :
print(cx)
elif a = 2:
r2 = img.find_template(template2, 0.70, step=4, search=SEARCH_EX)
if (r2) :
print('目标数字2已找到')
img.draw_rectangle(r2)
print(cx, cy)
if (cx>80) :
print(cx)
else :
print(cx)!
请在这里粘贴代码