質問編集履歴
2
_を.に変更し実行した結果。
test
CHANGED
File without changes
|
test
CHANGED
@@ -143,3 +143,77 @@
|
|
143
143
|
実行結果
|
144
144
|
|
145
145
|
![イメージ説明](9446307c2bd23081d051156b1e3aa477.png)
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
|
150
|
+
|
151
|
+
_を.に書き換え実行した結果
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
```python3
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
import cv2
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
img = cv2 . imread ( "person.jpg" )
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
cv2 . imshow("window",img )
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
cv2 . waitKey ()
|
172
|
+
|
173
|
+
cv2 . destroyAllWindows()
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
cv2 . imwrite ( "person",img)
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
#%matplotlib inline
|
184
|
+
|
185
|
+
import cv2
|
186
|
+
|
187
|
+
import matplotlib . pyplot as plt
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
img = cv2 . imread ("person",img)
|
194
|
+
|
195
|
+
# 高さ
|
196
|
+
|
197
|
+
height = img . shape [ 0 ]
|
198
|
+
|
199
|
+
# 幅
|
200
|
+
|
201
|
+
width = img . shape [ 1 ]
|
202
|
+
|
203
|
+
# 高さ・幅を150pixelずつ取り除く
|
204
|
+
|
205
|
+
trim.img = img [ 150 : height , 150 : width ]
|
206
|
+
|
207
|
+
#matplotlibで表示する場合はRGBからBGRに変換
|
208
|
+
|
209
|
+
trim.img = cv2.cvtColor (trim.img , cv2.COLOR.RGB2BGR)
|
210
|
+
|
211
|
+
plt . imshow (trim.img)
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
plt.show()
|
216
|
+
|
217
|
+
```出力結果
|
218
|
+
|
219
|
+
![イメージ説明](4263251893a94686f2c1b95672e56bd0.png)
|
1
一部コメントアウト、コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -67,3 +67,79 @@
|
|
67
67
|
|
68
68
|
|
69
69
|
![イメージ説明](66f66e128e72f1a22099f950b3e136ac.png)
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
修正点:
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
%matplotlib inlineをコメントアウト、plt.show()を最後の行に追加
|
78
|
+
|
79
|
+
```python3
|
80
|
+
|
81
|
+
import cv2
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
img = cv2 . imread ( "person.jpg" )
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
cv2 . imshow("window",img )
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
cv2 . waitKey ()
|
94
|
+
|
95
|
+
cv2 . destroyAllWindows()
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
cv2 . imwrite ( "person",img)
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
#%matplotlib inline
|
106
|
+
|
107
|
+
import cv2
|
108
|
+
|
109
|
+
import matplotlib . pyplot as plt
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
img = cv2 . imread ("person",img)
|
116
|
+
|
117
|
+
# 高さ
|
118
|
+
|
119
|
+
height = img . shape [ 0 ]
|
120
|
+
|
121
|
+
# 幅
|
122
|
+
|
123
|
+
width = img . shape [ 1 ]
|
124
|
+
|
125
|
+
# 高さ・幅を150pixelずつ取り除く
|
126
|
+
|
127
|
+
trim _ img = img [ 150 : height , 150 : width ]
|
128
|
+
|
129
|
+
#matplotlibで表示する場合はRGBからBGRに変換
|
130
|
+
|
131
|
+
trim _ img = cv2 . cvtColor ( trim _ img , cv2 . COLOR _ RGB2BGR )
|
132
|
+
|
133
|
+
plt . imshow ( trim _ img )
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
plt.show()
|
138
|
+
|
139
|
+
```
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
実行結果
|
144
|
+
|
145
|
+
![イメージ説明](9446307c2bd23081d051156b1e3aa477.png)
|