缓冲区数据类型不能是numba中的缓冲区

2024-09-29 23:25:26 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图转换一个双边过滤器,我写了运行在我的GPU上通过numba,但我似乎无法让它工作!我得到了错误

TypeError: Buffer dtype cannot be buffer, have dtype: array(float64, 2d, A)

从下面的代码

 @vectorize([(float64[:,:], float64[:,:])], target='cuda')
def apply_filter(img, filteredImage):

    imh, imw = img.shape[:2]
    hd = int((diameter - 1) / 2)

    for h in range(hd, imh - hd):
        for w in range(hd, imw - hd):
            Wp = 0
            filteredPixel = 0
            radius = diameter // 2
            for x in range(0, diameter):
                for y in range(0, diameter):

                    currentX = w - (radius - x)
                    cureentY = h - (radius - y)

                    intensityDifferent = img[currentX][cureentY] - img[w][h]
                    intensity = (1.0/ (2 * math.pi * (sIntesity ** 2))* math.exp(-(intensityDifferent ** 2) / (2 * sIntesity ** 2)))
                    foo = (currentX - w) ** 2 + (cureentY - h) ** 2
                    distance = cmath.sqrt(foo)
                    smoothing = (1.0 / (2 * math.pi * (sSpace ** 2))) * math.exp( -(distance.real ** 2) / (2 * sSpace ** 2))
                    weight = intensity * smoothing
                    filteredPixel += img[currentX][cureentY] * weight
                    Wp += weight

            filteredImage[h][w] = int(round(filteredPixel / Wp))


if __name__ == "__main__":
    src = cv2.imread("messy2.png", cv2.IMREAD_GRAYSCALE)
    src = src.astype(np.float64)
    filtered_image_own = np.zeros(src.shape)
    apply_filter(src, filtered_image_own)
    filtered_image_own = filtered_image_own.astype(np.uint8) 
    cv2.imwrite("filtered_image4.png", filtered_image_own)

我环顾四周,没有发现任何无用的东西,除了这个错误可能是因为传递了一个列表?但是我的两个参数都是2D数组,签名应该是正确的。为什么我会犯这个错误


Tags: inimagesrcimgfor错误rangemath

热门问题