質問編集履歴

1

プログラムの編集

2019/10/29 05:10

投稿

stylenanda
stylenanda

スコア10

test CHANGED
File without changes
test CHANGED
@@ -1 +1,89 @@
1
- [リンク内容](http://clientver2.hatenablog.com/entry/2015/11/12/004034)![イメージ説明](daf6b1e4c9c985a4ad66299c7945dc80.jpeg)
1
+ http://clientver2.hatenablog.com/entry/2015/11/12/004034
2
+
3
+
4
+
5
+
6
+
7
+ ```python
8
+
9
+ import cv2,matplotlib
10
+
11
+ import numpy as np
12
+
13
+ import matplotlib.pyplot as plt
14
+
15
+
16
+
17
+ image1 = cv2.imread('free1.jpg',0)
18
+
19
+ image2 = cv2.imread('free2.jpg',0)
20
+
21
+
22
+
23
+ def SSD(image1, image2):
24
+
25
+ vec1, vec2 = image1.reshape(-1), image2.reshape(-1)
26
+
27
+ return np.sum((vec1 - vec2) ** 2)
28
+
29
+
30
+
31
+ def matching(image1, image2):
32
+
33
+ image = image1.astype(np.double)
34
+
35
+ pattern = image2.astype(np.double)
36
+
37
+ height1, width1 = image.shape
38
+
39
+ height2, width2 = pattern.shape
40
+
41
+ output = np.ones(image.shape) * 10000
42
+
43
+
44
+
45
+ for i in range(height2 / 2, height1 - height2 / 2):
46
+
47
+ for j in range(width2 / 2, width1 - width2 / 2):
48
+
49
+ score = SSD(image[i-height2/2:i+height2/2+1, j-width2/2:j+width2/2+1], pattern)
50
+
51
+ output[i,j] = score
52
+
53
+
54
+
55
+ maxidx = np.unravel_index(output.argmin(), output.shape)
56
+
57
+
58
+
59
+ result = cv2.cvtColor(image1, cv2.COLOR_GRAY2RGB)
60
+
61
+ cv2.rectangle(result, (maxidx[1] - width2 / 2, maxidx[0] - height2 / 2), (maxidx[1] + width2, maxidx[0] + height2), (0,255,0), 1)
62
+
63
+ cv2.imshow("matching", result)
64
+
65
+
66
+
67
+ cv2.waitKey(0)
68
+
69
+ print(matching)
70
+
71
+ ```
72
+
73
+
74
+
75
+ プログラミングで二枚の画像の移動量を相関係数を用いて出力したいのですが、エラーはならないのですが移動量をしりたいです。
76
+
77
+
78
+
79
+ ```ここに言語を入力
80
+
81
+ <function matching at 0x000001F0D40498C8>
82
+
83
+ ```
84
+
85
+
86
+
87
+
88
+
89
+ このようなエラーが出ます。エラーの意味が分からないのですが、最終的に移動量を出したいので、修正すればいい箇所を教えていただきたいです。