2017-02-09 9 views
0

非常に単純なコードです。すべてうまくいった。私は、comb_binaryのメソッドにhls_binaryとgradxを入れました。'numpy.ndarray'オブジェクトはjupyterノートブックで2回目の実行後に呼び出すことができません

image = mpimg.imread('test_images/test4.jpg') 
comb_binary = comb_binary(image) 
f, (ax1, ax2) = plt.subplots(1, 2, figsize=(28,16)) 
ax1.imshow(image2) 
ax1.set_title('A', fontsize=20) 
ax2.imshow(comb_binary, cmap = 'gray') 
ax2.set_title('B', fontsize=20) 

しかし、私はノートブックのセルが、私はこのエラーに実行される再実行した場合:

'numpy.ndarray' object is not callable 

1回目。それは動作します:再び enter image description here

を実行し、そのセル:ここ enter image description here

は、念のために、すべてのメソッドの定義です:

def abs_sobel_thresh(img, orient, sobel_kernel, thresh): 
    gray = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY) 
    if orient == 'x': 
     sobel = cv2.Sobel(gray, cv2.CV_64F, 1, 0) 
    else: 
     sobel = cv2.Sobel(gray, cv2.CV_64F, 0, 1) 
    abs_sobel = np.absolute(sobel) 
    scaled_sobel = np.uint8(255*abs_sobel/np.max(abs_sobel)) 
    grad_binary = np.zeros_like(scaled_sobel) 
    grad_binary[(scaled_sobel >= thresh[0]) & (scaled_sobel <= thresh[1])] = 1 
    return grad_binary 

def hls_select(img, thresh): 
    hls = cv2.cvtColor(img, cv2.COLOR_RGB2HLS) 
    s_channel = hls[:,:,2] 
    hls_binary = np.zeros_like(s_channel) 
    hls_binary[(s_channel > thresh[0]) & (s_channel <= thresh[1])] = 1 
    return hls_binary 

def comb_binary(image): 
    gradx = abs_sobel_thresh(image, orient='x', sobel_kernel=9, thresh=(20, 100)) 
    hls_binary = hls_select(image, thresh=(170, 255)) 
    combined_binary_final = np.zeros_like(gradx) 
    combined_binary_final[(hls_binary == 1) | (gradx == 1)] = 1 
    return combined_binary_final 

答えて

3

あなたはjupyter内のセルを評価するたびに、それはそれらを実行します以前のコマンドから構築された環境内のコマンド。だから、次のような行があるとき:

comb_binary = comb_binary(image) 

初めてのことすべてが良いです。 comb_binary(関数)をその結果と置き換えるだけです。今度はcomb_binaryはnumpyの配列です。しかし、セルをもう一度実行しようとすると、comb_binaryはnumpy配列になります。関数ではありません。

comb_binary = comb_binary(image) 
comb_binary = comb_binary(image) 

そして、あなたは、ほとんどの場合;-)で動作するようにことを期待していない:それはあなたが書かれたかのように同じです。

+0

ああ、どのように私は愚かです。申し訳ありませんが、新しいソフトウェアです。だから、私はこの問題を避けるためにいくつかの異なる変数名を使う必要があると思います。 – Patrick

+0

@パトリック - それを心配しないでください。このことは私たち全員に起こります。私は以前に定義された名前を再利用するLONG jupyter文書でこの問題にぶつかってきました...これは、直前のコード行を表示しないので少し混乱します。 – mgilson

関連する問題