2017-02-09 1 views
0

매우 간단한 코드입니다. 모든 것이 잘 작동했습니다. 나는 hls_binary와 gradx를 comb_binary의 메소드에 넣었다.'numpy.ndarray'객체는 jupyter notebook에서 두 번째 실행 후 호출 할 수 없습니다.

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

관련 문제