http://clientver2.hatenablog.com/entry/2015/11/12/004034
python
1import cv2,matplotlib 2import numpy as np 3import matplotlib.pyplot as plt 4 5image1 = cv2.imread('free1.jpg',0) 6image2 = cv2.imread('free2.jpg',0) 7 8def SSD(image1, image2): 9 vec1, vec2 = image1.reshape(-1), image2.reshape(-1) 10 return np.sum((vec1 - vec2) ** 2) 11 12def matching(image1, image2): 13 image = image1.astype(np.double) 14 pattern = image2.astype(np.double) 15 height1, width1 = image.shape 16 height2, width2 = pattern.shape 17 output = np.ones(image.shape) * 10000 18 19 for i in range(height2 / 2, height1 - height2 / 2): 20 for j in range(width2 / 2, width1 - width2 / 2): 21 score = SSD(image[i-height2/2:i+height2/2+1, j-width2/2:j+width2/2+1], pattern) 22 output[i,j] = score 23 24 maxidx = np.unravel_index(output.argmin(), output.shape) 25 26 result = cv2.cvtColor(image1, cv2.COLOR_GRAY2RGB) 27 cv2.rectangle(result, (maxidx[1] - width2 / 2, maxidx[0] - height2 / 2), (maxidx[1] + width2, maxidx[0] + height2), (0,255,0), 1) 28 cv2.imshow("matching", result) 29 30cv2.waitKey(0) 31print(matching)
プログラミングで二枚の画像の移動量を相関係数を用いて出力したいのですが、エラーはならないのですが移動量をしりたいです。
<function matching at 0x000001F0D40498C8>
このようなエラーが出ます。エラーの意味が分からないのですが、最終的に移動量を出したいので、修正すればいい箇所を教えていただきたいです。
あなたの回答
tips
プレビュー