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
이 단지의 경우 모든 방법의 정의입니다 :
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
아, 얼마나 어리 석 었니? 죄송합니다. 새로운 소프트웨어입니다. 그래서,이 문제를 피하기 위해 다른 변수 이름을 사용해야 할 것 같습니다. – Patrick
@ 패트릭 - 그것에 대해 걱정하지 마십시오. 이 일은 우리 모두에게 일어납니다. 난 오래 전에 정의 된 이름을 다시 사용하는 LONG jupyter 문서를 가지고이 문제에 부딪 쳤습니다 ... 이전에 코드 행을 보지 않았기 때문에 약간 혼란 스럽습니다. – mgilson