質問編集履歴

2

エラー文を記載しました。

2021/10/24 05:35

投稿

lovely
lovely

スコア28

test CHANGED
@@ -1 +1 @@
1
- Python threshold() 輪郭検出
1
+ Python threshold() 二値化
test CHANGED
@@ -24,10 +24,44 @@
24
24
 
25
25
  img=cv2.threshold(img,100,200,cv2.THRESH_BINARY_INV) #1
26
26
 
27
- plp.imshow(img,gmap="gray")
27
+ plp.imshow(img,cmap="gray")
28
28
 
29
29
  ```
30
30
 
31
31
 
32
32
 
33
33
  また、あるサイトには#1の最後に[1]を付ければよいと書いてあったのですがこれはどういう意味ですか?
34
+
35
+
36
+
37
+ エラー文
38
+
39
+ VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray
40
+
41
+ x = np.array(x, subok=True, copy=copy)
42
+
43
+ Traceback (most recent call last):
44
+
45
+ File "c:\Practice\trying.py", line 10, in <module>
46
+
47
+ plp.imshow(img,cmap="gray")
48
+
49
+ File "C:\Users\c7not\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\pyplot.py", line
50
+
51
+ 2903, in imshow
52
+
53
+ __ret = gca().imshow(
54
+
55
+ File "C:\Users\c7not\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\__init__.py", line 1361, in inner
56
+
57
+ return func(ax, *map(sanitize_sequence, args), **kwargs)
58
+
59
+ File "C:\Users\c7not\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\axes\_axes.py", line 5609, in imshow
60
+
61
+ im.set_data(X)
62
+
63
+ File "C:\Users\c7not\AppData\Local\Programs\Python\Python39\lib\site-packages\matplotlib\image.py", line 700, in set_data
64
+
65
+ raise TypeError("Image data of dtype {} cannot be converted to "
66
+
67
+ TypeError: Image data of dtype object cannot be converted to float

1

コードに抜けている部分があったので修正しました。

2021/10/24 05:35

投稿

lovely
lovely

スコア28

test CHANGED
File without changes
test CHANGED
@@ -20,6 +20,8 @@
20
20
 
21
21
  img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
22
22
 
23
+ img=cv2.GaussianBlur(img,(7,7),0)
24
+
23
25
  img=cv2.threshold(img,100,200,cv2.THRESH_BINARY_INV) #1
24
26
 
25
27
  plp.imshow(img,gmap="gray")