元画像のこれから
これを取り出してみる。
import cv2
import numpy as np
from matplotlib import pyplot as plt
img_rgb = cv2.imread('dq.jpeg')
img_rgb2 = img_rgb.copy()
img_gray = cv2.cvtColor(img_rgb2, cv2.COLOR_BGR2GRAY)
template = cv2.imread('template.png',0)
w, h = template.shape[::-1]
res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where( res >= threshold)
for pt in zip(*loc[::-1]):
cv2.rectangle(img_rgb2, pt, (pt[0] + w, pt[1] + h), (255,0,0), 1)
plt.subplot(121),plt.imshow(img_rgb)
plt.title('Matching Result'), plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(img_rgb2)
plt.title('Detected Point'), plt.xticks([]), plt.yticks([])
plt.show()
おぉ、とりだせた。



0 件のコメント:
コメントを投稿