teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

さりげなく差し替え

2017/11/24 10:50

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -14,8 +14,8 @@
14
14
  ... print(img)
15
15
  None
16
16
  >>>
17
- >>> img.height
17
+ >>> img.shape
18
18
  Traceback (most recent call last):
19
19
  File "<stdin>", line 1, in <module>
20
- AttributeError: 'NoneType' object has no attribute 'height'
20
+ AttributeError: 'NoneType' object has no attribute 'shape'
21
21
  ```

1

追記

2017/11/24 10:50

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -1,3 +1,21 @@
1
1
  おそらくimgの読み込みに失敗しています。
2
2
  まずはcv2.imreadの引数を絶対パスにして試してみてください。
3
- それで改善するなら、ファイルの配置が良くないということです。
3
+ それで改善するなら、ファイルの配置が良くないということです。
4
+
5
+ 実験コード
6
+ ---
7
+ ```Python
8
+ >>> import cv2
9
+ >>>
10
+ >>> # もちろん開けないが、エラーにはならない
11
+ ... img = cv2.imread('hogehoge')
12
+ >>>
13
+ >>> # 中身は空っぽ
14
+ ... print(img)
15
+ None
16
+ >>>
17
+ >>> img.height
18
+ Traceback (most recent call last):
19
+ File "<stdin>", line 1, in <module>
20
+ AttributeError: 'NoneType' object has no attribute 'height'
21
+ ```