回答編集履歴
2
test
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
if 'cmap' in option and option['cmap'] == 'gray':
|
12
12
|
img = cv2.imread(img, cv2.IMREAD_GRAYSCALE)
|
13
13
|
else:
|
14
|
-
img = cv2.imread(img)
|
14
|
+
img = cv2.cvtColor(cv2.imread(img), cv2.COLOR_BGR2RGB)
|
15
15
|
|
16
16
|
plt.imshow(img, **option)
|
17
17
|
plt.gcf().canvas.mpl_connect('key_press_event', close_figure)
|
1
test
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
-
一旦、`matplotlib.pyplot.imshow()` を実行してから内部の `numpy ndarray` を取り出して、それを `cv2.imshow()` で表示します。
|
2
|
-
|
1
|
+
`{'cmap': 'gray'}` の指定は grayscale で画像を読み込む(`cv2.imread()`)という意味だと思いましたので、その様にしています。
|
3
2
|
```python
|
4
3
|
import cv2
|
5
4
|
from matplotlib import pyplot as plt
|
5
|
+
|
6
|
+
def close_figure(event):
|
7
|
+
if event.key == 'escape':
|
8
|
+
plt.close(event.canvas.figure)
|
6
9
|
|
7
10
|
def showImg(window_name, img, option={}):
|
8
11
|
if 'cmap' in option and option['cmap'] == 'gray':
|
@@ -10,15 +13,11 @@
|
|
10
13
|
else:
|
11
14
|
img = cv2.imread(img)
|
12
15
|
|
13
|
-
|
16
|
+
plt.imshow(img, **option)
|
14
|
-
c
|
17
|
+
plt.gcf().canvas.mpl_connect('key_press_event', close_figure)
|
15
|
-
|
18
|
+
plt.show()
|
16
19
|
|
17
|
-
while True:
|
18
|
-
if cv2.waitKey(10) == 27: break
|
19
|
-
cv2.destroyWindow(window_name)
|
20
|
-
|
21
|
-
img = '/path/to/image
|
20
|
+
img = '/path/to/image'
|
22
21
|
|
23
22
|
# オプションなし
|
24
23
|
showImg('test', img)
|