Img.find_template function

I use the img.find_template function to find the template, but when looking for multiple templates, the speed will drop, is there any way to improve the efficiency of multiple templates?

Have you tried diamond search ?

Yes, I use the box to find, the code is as follows, I want to know how to improve the efficiency and speed of the search under multiple templates.

r1 = img.find_template(template1, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
r2 = img.find_template(template2, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
r3 = img.find_template(template3, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
r4 = img.find_template(template4, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
r5 = img.find_template(template5, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
r6 = img.find_template(template6, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
r7 = img.find_template(template7, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))


if r1:
img.draw_rectangle(r1)
elif r2:
img.draw_rectangle(r2)
elif r3:
img.draw_rectangle(r3)
elif r4:
img.draw_rectangle(r4)
elif r5:
img.draw_rectangle(r5)
elif r6:
img.draw_rectangle(r6)
elif r7:
img.draw_rectangle(r7)

That’s the exhaustive search, try:

r1 = img.find_template(template1, search=SEARCH_DS)