回答編集履歴
2
d
answer
CHANGED
@@ -9,10 +9,10 @@
|
|
9
9
|
```python
|
10
10
|
import cv2
|
11
11
|
|
12
|
-
img = cv2.imread("
|
12
|
+
img = cv2.imread("test.png", cv2.IMREAD_UNCHANGED)
|
13
13
|
print(img.shape) # (288, 432, 3)
|
14
14
|
|
15
|
-
if img.ndim == 3:
|
15
|
+
if img.ndim == 3: # RGBならアルファチャンネル追加
|
16
16
|
img = cv2.cvtColor(img, cv2.COLOR_RGB2RGBA)
|
17
17
|
print(img.shape) # (288, 432, 4)
|
18
18
|
```
|
1
d
answer
CHANGED
@@ -7,12 +7,12 @@
|
|
7
7
|
cvtColor で RGB 画像にアルファチャンネルを付加できます。
|
8
8
|
|
9
9
|
```python
|
10
|
-
|
11
10
|
import cv2
|
12
11
|
|
13
|
-
img = cv2.imread("colorbar3.png")
|
12
|
+
img = cv2.imread("colorbar3.png", cv2.IMREAD_UNCHANGED)
|
14
13
|
print(img.shape) # (288, 432, 3)
|
15
14
|
|
15
|
+
if img.ndim == 3:
|
16
|
-
|
16
|
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2RGBA)
|
17
|
-
print(
|
17
|
+
print(img.shape) # (288, 432, 4)
|
18
18
|
```
|