pythonとOpenCVを使用して複数の物体を検出するテンプレートマッチングの下記サンプルですが
import cv2 import numpy as np #画像をグレースケールで読み込む img = cv2.imread("img.png", 0) temp = cv2.imread("mark.png", 0) #マッチングテンプレートを実行 result = cv2.matchTemplate(img, temp, cv2.TM_CCOEFF_NORMED) #類似度の設定(0~1) threshold = 0.9 #検出結果から検出領域の位置を取得 loc = np.where(result >= threshold) #検出領域を四角で囲んで保存 result = cv2.imread("img.png") w, h = temp.shape[::-1] for top_left in zip(*loc[::-1]): bottom_right = (top_left[0] + w, top_left[1] + h) cv2.rectangle(result,top_left, bottom_right, (255, 0, 0), 2) cv2.imwrite("result2.png", result)
expected an indented block と出て bottom_right の部分が色付けされます、何が原因でしょうか?
質問を編集して、コードを ``` で囲んでください。囲まないとインデックスが崩れてしまいます。