Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python ';numpy.ndarray和#x27;对象在jupyter笔记本中第二次运行后不可调用_Python_Opencv_Numpy_Computer Vision_Ipython Notebook - Fatal编程技术网

Python ';numpy.ndarray和#x27;对象在jupyter笔记本中第二次运行后不可调用

Python ';numpy.ndarray和#x27;对象在jupyter笔记本中第二次运行后不可调用,python,opencv,numpy,computer-vision,ipython-notebook,Python,Opencv,Numpy,Computer Vision,Ipython Notebook,非常简单的代码。一切都很顺利。我将hls_二进制和gradx放入comb_二进制的方法中 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,

非常简单的代码。一切都很顺利。我将hls_二进制和gradx放入comb_二进制的方法中

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
def abs_sobel_thresh(img、orient、sobel_kernel、thresh):
灰色=cv2.CVT颜色(img,cv2.COLOR\u RGB2GRAY)
如果方向='x':
sobel=cv2.sobel(灰色,cv2.CV_64F,1,0)
其他:
sobel=cv2.sobel(灰色,cv2.CV_64F,0,1)
绝对值=绝对值(绝对值)
缩放比例=np.uint8(255*abs\u-sobel/np.max(abs\u-sobel))
grad_binary=np.类零(缩放的sobel)

grad_binary[(scaled_sobel>=thresh[0])&(scaled_sobel thresh[0])&(s_channel每次计算jupyter中的单元格时,它都会在根据以前的命令构建的环境中运行这些命令。因此,当您有一行类似于:

comb_binary = comb_binary(image)
第一次一切正常。您只需用结果替换
comb\u binary
(函数)。现在
comb\u binary
是一个numpy数组……但是,如果您再次尝试执行单元格,
comb\u binary
现在是一个numpy数组,而不是一个函数。这与您编写的代码相同:

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

在大多数情况下,这是不可能实现的;-)。

每次在jupyter中计算单元格时,它都会在根据以前的命令生成的环境中运行这些命令。因此,当您有一行类似于:

comb_binary = comb_binary(image)
第一次一切正常。您只需用结果替换
comb\u binary
(函数)。现在
comb\u binary
是一个numpy数组……但是,如果您再次尝试执行单元格,
comb\u binary
现在是一个numpy数组,而不是一个函数。这与您编写的代码相同:

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

在大多数情况下,你不会期望这样的结果;-)。

哦,我真是太蠢了。对不起,我刚接触软件。所以,我想我需要使用一些不同的变量名来避免这个问题。@Patrick--别担心。这种事会发生在我们所有人身上。我在使用定义名称的长jupyter文档时遇到了这个问题很久以前……这有点让人困惑,因为你看不到前面的代码行。哦,我真是太蠢了。对不起,我是软件新手。所以,我想我需要使用一些不同的变量名来避免这个问题。@Patrick--别担心。这种事情会发生在我们所有人身上。我遇到了这个问题,因为我使用的是长jupyter文档重复使用一个很久以前定义的名称…这有点令人困惑,因为您没有看到前面的代码行。