logo

请问多模板识别,识别到的第n个模版,怎么表示出来

2024-07-22 14:50
6
_6our

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 :

299bddbf-e97d-4e67-a11f-b871899d8b7a.png
请在这里粘贴代码
2024-07-22 20:56
I
网红小智智 星瞳科技

语法错误,是说if后面需要是两个空格。