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