2017-11-17 13 views
0

私はPythonを初めて使用しています。 TensorFlowの画像からテキストを認識しようとしています。端末にpython gen.pyを実行しようとすると、TypeErrorが表示されます。それはあなたのコードのように見えるTypeError:/: 'NoneType'と 'float'に対してサポートされていないオペランドタイプ

 
Traceback (most recent call last): 
    File "gen.py", line 287, in 
    for img_idx, (im, c, p) in enumerate(im_gen): 
    File "gen.py", line 277, in generate_ims 
    yield generate_im(random.choice(char_ims), num_bg_images) 
    File "gen.py", line 239, in generate_im 
    bg = generate_bg(num_bg_images) 
    File "gen.py", line 226, in generate_bg 
    bg = cv2.imread(fname, cv2.IMREAD_GRAYSCALE)/255. 
TypeError: unsupported operand type(s) for /: 'NoneType' and 'float' 

答えて

0

は、そのパス上の開いている画像

bg = cv2.imread(fname, cv2.IMREAD_GRAYSCALE)/255 

はcv2.imreadメソッドはNoneを返されないことはできません。

それはまた、あなたは、ファイルが

import os 
# <your code...> 
if !os.path.isfile(fname): 
    raise Exception("File doesn't exist") 

image = cv2.imread(fname, cv2.IMREAD_GRAYSCALE) 
if image is not None: 
    bg = image/255 
が存在することを確認するために最初にosモジュールをインポートすることができます最初

image = cv2.imread(fname, cv2.IMREAD_GRAYSCALE) 
if image is not None: 
    bg = image/255 

画像を取得する方が良いでしょう

関連する問題