回答編集履歴

2

より適した解決法に変更

2021/09/10 02:40

投稿

potapotapotato
potapotapotato

スコア13

test CHANGED
@@ -1,4 +1,6 @@
1
+ cv2.floodFillの使い方及び、表示方法にエラーが出ていました。
2
+
1
- 回りくどいですがcv2.imreadで読み取った画像をPIL imageに変換してもともとの処理をして、ndarryに戻しました。
3
+ 下記のように直したところ無事、ndarrayで読み込んだ画像を使用して色塗ができました。
2
4
 
3
5
 
4
6
 
@@ -8,29 +10,45 @@
8
10
 
9
11
  import cv2
10
12
 
13
+
14
+
15
+ # Opening the image (R prefixed to
16
+
17
+ # string in order to deal with '\'
18
+
11
- import numpy as np
19
+ # in paths)
20
+
21
+ img = cv2.imread("sample.png")
12
22
 
13
23
 
14
24
 
15
- img = cv2.imread("C:/aa/a.png")
25
+ # Coordinates of the pixel whose value
16
26
 
17
- img = Image.fromarray(img)
27
+ # would be used as seed
18
28
 
19
-
20
-
21
- seed = (0, 0)
29
+ seed = (263, 70)
22
30
 
23
31
 
24
32
 
25
- rep_value = (255, 255, 255)
33
+ # Pixel Value which would be used for
26
34
 
27
-
35
+ # replacement
28
36
 
29
- ImageDraw.floodfill(img, seed, rep_value, thresh=50)
37
+ newVal = (255, 255, 255)
30
38
 
31
39
 
32
40
 
41
+ # Calling the floodfill() function and
42
+
43
+ # passing it image, seed, value and
44
+
45
+ # thresh as arguments
46
+
47
+ cv2.floodFill(img, None, seed, newVal)
48
+
49
+
50
+
33
- img = np.array(img)
51
+ # Displaying the image
34
52
 
35
53
  cv2.imshow('a',img)
36
54
 

1

誤字の修正

2021/09/10 02:40

投稿

potapotapotato
potapotapotato

スコア13

test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
 
14
14
 
15
- img = cv2.imread("C:/Users/nishikawa/Desktop/aa/kuro.png")
15
+ img = cv2.imread("C:/aa/a.png")
16
16
 
17
17
  img = Image.fromarray(img)
18
18