質問編集履歴
3
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|
2
試したことを修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,6 +29,8 @@
|
|
29
29
|
|
30
30
|
|
31
31
|
ここに問題に対して試したことを記載してください。
|
32
|
+
|
33
|
+
```python
|
32
34
|
|
33
35
|
import cv2
|
34
36
|
|
@@ -108,9 +110,15 @@
|
|
108
110
|
|
109
111
|
plt.show()
|
110
112
|
|
113
|
+
```
|
114
|
+
|
111
115
|
|
112
116
|
|
113
117
|
上記のコードを使い、画像の1部を切り出し、一つの画像を白黒反転させ、もう一枚の画像を白黒反転させた画像と同じサイズで切り取り、合成させました。そしたら、エラーが出てしまいました。
|
118
|
+
|
119
|
+
```python
|
120
|
+
|
121
|
+
|
114
122
|
|
115
123
|
Traceback (most recent call last):
|
116
124
|
|
@@ -119,6 +127,8 @@
|
|
119
127
|
dst = cv2.addWeighted(src1, 1, src2, 1, 0)
|
120
128
|
|
121
129
|
cv2.error: OpenCV(3.4.1) C:\projects\opencv-python\opencv\modules\core\src\arithm.cpp:659: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function cv::arithm_op
|
130
|
+
|
131
|
+
```
|
122
132
|
|
123
133
|
|
124
134
|
|
1
試したことを修正しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -30,6 +30,98 @@
|
|
30
30
|
|
31
31
|
ここに問題に対して試したことを記載してください。
|
32
32
|
|
33
|
+
import cv2
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
filename_li = ["Q1-4.jpg", "Q1-5.jpg", ]
|
38
|
+
|
39
|
+
img_li = []
|
40
|
+
|
41
|
+
for i in filename_li:
|
42
|
+
|
43
|
+
img = cv2.imread(i, 0) # 第二引数を 0 にすることでグレースケールで読み込む
|
44
|
+
|
45
|
+
img_float = np.float32(img) # cv2.phaseCorrelate で指定されている型に変換
|
46
|
+
|
47
|
+
img_li.append(img_float)
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
dxdy_li = []
|
54
|
+
|
55
|
+
for img in img_li[1:]:
|
56
|
+
|
57
|
+
d, etc = cv2.phaseCorrelate(img, img_li[0]) # d にx方向およびy方向のズレが格納されている
|
58
|
+
|
59
|
+
dx, dy = d
|
60
|
+
|
61
|
+
dxdy_li.append([dx, dy])
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
rows, cols = img_li[0].shape
|
66
|
+
|
67
|
+
img_after_li = [img_li[0]]
|
68
|
+
|
69
|
+
for dxdy, img in zip(dxdy_li, img_li[1:]):
|
70
|
+
|
71
|
+
dx, dy = dxdy
|
72
|
+
|
73
|
+
M = np.float32([[1, 0, dx],[0, 1, dy]])
|
74
|
+
|
75
|
+
img = cv2.warpAffine(img, M, (cols,rows))
|
76
|
+
|
77
|
+
img_after_li.append(img)
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
fig = plt.figure(figsize = (6, 6))
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
subplot_li = [321, 323, 325]
|
86
|
+
|
87
|
+
for subplot, img in zip(subplot_li, img_li):
|
88
|
+
|
89
|
+
ax = fig.add_subplot(subplot)
|
90
|
+
|
91
|
+
ax.imshow(img)
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
subplot_after_li = [322, 324, 326]
|
96
|
+
|
97
|
+
for subplot_after, img_after in zip(subplot_after_li, img_after_li):
|
98
|
+
|
99
|
+
ax = fig.add_subplot(subplot_after)
|
100
|
+
|
101
|
+
ax.imshow(img_after)
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
cv2.imwrite("test1031-1.jpg",img_after)
|
106
|
+
|
107
|
+
plt.savefig('test.jpg', format = 'jpg')
|
108
|
+
|
109
|
+
plt.show()
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
上記のコードを使い、画像の1部を切り出し、一つの画像を白黒反転させ、もう一枚の画像を白黒反転させた画像と同じサイズで切り取り、合成させました。そしたら、エラーが出てしまいました。
|
114
|
+
|
115
|
+
Traceback (most recent call last):
|
116
|
+
|
117
|
+
File "C:\Python36\cutkumiawase.py", line 4, in <module>
|
118
|
+
|
119
|
+
dst = cv2.addWeighted(src1, 1, src2, 1, 0)
|
120
|
+
|
121
|
+
cv2.error: OpenCV(3.4.1) C:\projects\opencv-python\opencv\modules\core\src\arithm.cpp:659: error: (-209) The operation is neither 'array op array' (where arrays have the same size and the same number of channels), nor 'array op scalar', nor 'scalar op array' in function cv::arithm_op
|
122
|
+
|
123
|
+
|
124
|
+
|
33
125
|
|
34
126
|
|
35
127
|
### 補足情報(FW/ツールのバージョンなど)
|