def find_all_template(im_source, im_search, threshold=<NUM_LIT:0.5>, maxcnt=<NUM_LIT:0>, rgb=False, bgremove=False):
<EOL>method = cv2.TM_CCOEFF_NORMED<EOL>if rgb:<EOL><INDENT>s_bgr = cv2.split(im_search) <EOL>i_bgr = cv2.split(im_source)<EOL>weight = (<NUM_LIT>, <NUM_LIT>, <NUM_LIT>)<EOL>resbgr = [<NUM_LIT:0>, <NUM_LIT:0>, <NUM_LIT:0>]<EOL>for i in range(<NUM_LIT:3>): <EOL><INDENT>resbgr[i] = cv2.matchTemplate(i_bgr[i], s_bgr[i], method)<EOL><DEDENT>res = resbgr[<NUM_LIT:0>]*weight[<NUM_LIT:0>] + resbgr[<NUM_LIT:1>]*weight[<NUM_LIT:1>] + resbgr[<NUM_LIT:2>]*weight[<NUM_LIT:2>]<EOL><DEDENT>else:<EOL><INDENT>s_gray = cv2.cvtColor(im_search, cv2.COLOR_BGR2GRAY)<EOL>i_gray = cv2.cvtColor(im_source, cv2.COLOR_BGR2GRAY)<EOL>if bgremove:<EOL><INDENT>s_gray = cv2.Canny(s_gray, <NUM_LIT:100>, <NUM_LIT:200>)<EOL>i_gray = cv2.Canny(i_gray, <NUM_LIT:100>, <NUM_LIT:200>)<EOL><DEDENT>res = cv2.matchTemplate(i_gray, s_gray, method)<EOL><DEDENT>w, h = im_search.shape[<NUM_LIT:1>], im_search.shape[<NUM_LIT:0>]<EOL>result = []<EOL>while True:<EOL><INDENT>min_val, max_val, min_loc, max_loc = cv2.minMaxLoc(res)<EOL>if method in [cv2.TM_SQDIFF, cv2.TM_SQDIFF_NORMED]:<EOL><INDENT>top_left = min_loc<EOL><DEDENT>else:<EOL><INDENT>top_left = max_loc<EOL><DEDENT>if DEBUG: <EOL><INDENT>print('<STR_LIT>' %(threshold, max_val)) <EOL><DEDENT>if max_val < threshold:<EOL><INDENT>break<EOL><DEDENT>middle_point = (top_left[<NUM_LIT:0>]+w/<NUM_LIT:2>, top_left[<NUM_LIT:1>]+h/<NUM_LIT:2>)<EOL>result.append(dict(<EOL>result=middle_point,<EOL>rectangle=(top_left, (top_left[<NUM_LIT:0>], top_left[<NUM_LIT:1>] + h), (top_left[<NUM_LIT:0>] + w, top_left[<NUM_LIT:1>]), (top_left[<NUM_LIT:0>] + w, top_left[<NUM_LIT:1>] + h)),<EOL>confidence=max_val<EOL>))<EOL>if maxcnt and len(result) >= maxcnt:<EOL><INDENT>break<EOL><DEDENT>cv2.floodFill(res, None, max_loc, (-<NUM_LIT:1000>,), max_val-threshold+<NUM_LIT:0.1>, <NUM_LIT:1>, flags=cv2.FLOODFILL_FIXED_RANGE)<EOL><DEDENT>return result<EOL>
Locate image position with cv2.templateFind

Use pixel match to find pictures.

Args:
    im_source(string): 图像、素材
    im_search(string): 需要查找的图片
    threshold: 阈值，当相识度小于该阈值的时候，就忽略掉

Returns:
    A tuple of found [(point, score), ...]

Raises:
    IOError: when file read error