回答編集履歴
2
d
answer
CHANGED
@@ -13,20 +13,21 @@
|
|
13
13
|
import cv2
|
14
14
|
import numpy as np
|
15
15
|
|
16
|
-
input_dir = Path('input')
|
16
|
+
input_dir = Path('input')
|
17
17
|
output_dir = Path('output')
|
18
18
|
output_dir.mkdir(exist_ok=True)
|
19
19
|
|
20
|
-
before = (0, 0, 255)
|
20
|
+
before = (0, 0, 255)
|
21
|
-
after = (0, 0, 1)
|
21
|
+
after = (0, 0, 1)
|
22
22
|
|
23
23
|
for img_path in input_dir.iterdir():
|
24
24
|
# 画像を読み込む。
|
25
25
|
img = cv2.imread(str(img_path))
|
26
26
|
|
27
|
-
#
|
27
|
+
# (0, 0, 255) を (1, 0, 0) に置換する。
|
28
28
|
idx_to_replace = (img == before).all(axis=2)
|
29
29
|
img[idx_to_replace] = after
|
30
|
+
img[~idx_to_replace] = (0, 0, 0)
|
30
31
|
|
31
32
|
# 保存する。
|
32
33
|
save_path = output_dir / img_path.name
|
1
d
answer
CHANGED
@@ -13,7 +13,7 @@
|
|
13
13
|
import cv2
|
14
14
|
import numpy as np
|
15
15
|
|
16
|
-
input_dir = Path('input')
|
16
|
+
input_dir = Path('input') # 入力ディレクトリのパス、画像以外のファイルがない前提
|
17
17
|
output_dir = Path('output')
|
18
18
|
output_dir.mkdir(exist_ok=True)
|
19
19
|
|