回答編集履歴

3

 

2023/06/23 00:29

投稿

退会済みユーザー
test CHANGED
@@ -34,41 +34,17 @@
34
34
  # ブランクイメージを作る
35
35
  img = np.zeros((30,30))
36
36
 
37
- # 線を引く
38
- # REF:http://labs.eecs.tottori-u.ac.jp/sd/Member/oyamada/OpenCV/html/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.html#id4
39
- img = cv2.drawContours(img ,[area_1], -1, 255, 1)
40
- img = cv2.drawContours(img ,[area_2], -1, 255, 1)
41
-
42
- # 様子見
43
- cv2.imshow("img(intermediate1)",img)
44
- cv2.waitKey()
45
- cv2.destroyAllWindows()
46
-
47
- # やっぱり塗りつぶす
37
+ # 塗りつぶす
48
38
  img = cv2.drawContours(img ,[area_1], -1, 255, -1)
49
39
  img = cv2.drawContours(img ,[area_2], -1, 255, -1)
50
-
51
- # 様子見
52
- cv2.imshow("img(intermediate2)",img)
53
- cv2.waitKey()
54
- cv2.destroyAllWindows()
55
40
 
56
41
  # 座標を知りたい
57
42
  # REF:http://labs.eecs.tottori-u.ac.jp/sd/Member/oyamada/OpenCV/html/py_tutorials/py_imgproc/py_contours/py_contours_begin/py_contours_begin.html#id5
58
43
  cnts, _ = cv2.findContours(img.astype(np.uint8),cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
59
44
 
60
-
61
45
  # 様子見
62
46
  cnts = np.asarray(cnts).squeeze()
63
47
  for cnt in cnts:
64
48
  print(cnt)
65
-
66
- # # 画像が小さすぎてわかりにくい
67
- # # REF:http://labs.eecs.tottori-u.ac.jp/sd/Member/oyamada/OpenCV/html/py_tutorials/py_gui/py_drawing_functions/py_drawing_functions.html#id5
68
- # img = cv2.circle(img,tuple(cnt),1,(192),1)
69
-
70
- # cv2.imshow("img(intermediate3)",img)
71
- # cv2.waitKey()
72
- # cv2.destroyAllWindows()
73
49
  ```
74
50
 

2

強調したくはなかった

2023/06/23 00:26

投稿

退会済みユーザー
test CHANGED
@@ -2,7 +2,9 @@
2
2
  いまさらですが…。
3
3
  しかもコメント欄で「モルフォロジー変換云々」とっぽいことを言っていたくせに、いざ実装する段階では普通に塗りつぶしで検知するという暴挙に出ております。
4
4
 
5
+ 追記:
5
6
  適当な座標データがないので試していませんが、[ヒエラルキーの値](https://docs.opencv.org/4.x/d9/d8b/tutorial_py_contours_hierarchy.html)を考慮してDrawContoursしてFindContoursをすれば、内側の空白(琵琶湖みたいな構造)も残せるはずです。
7
+
6
8
  ---
7
9
 
8
10
  ```Plaintext

1

ヒエラルキー!

2023/06/23 00:25

投稿

退会済みユーザー
test CHANGED
@@ -1,6 +1,9 @@
1
1
  > fourteenlengthさんから別解が入るかも、を期待します。
2
2
  いまさらですが…。
3
3
  しかもコメント欄で「モルフォロジー変換云々」とっぽいことを言っていたくせに、いざ実装する段階では普通に塗りつぶしで検知するという暴挙に出ております。
4
+
5
+ 適当な座標データがないので試していませんが、[ヒエラルキーの値](https://docs.opencv.org/4.x/d9/d8b/tutorial_py_contours_hierarchy.html)を考慮してDrawContoursしてFindContoursをすれば、内側の空白(琵琶湖みたいな構造)も残せるはずです。
6
+ ---
4
7
 
5
8
  ```Plaintext
6
9
  [10 0]