0
非常简单的代码。一切正常。我将hls_binary和gradx放入comb_binary的方法中。'jumpy.ndarray'对象在jupyter笔记本中第二次运行后无法调用
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