如何正确使用cv2实现高斯模糊?

2024-06-16 11:41:17 发布

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

我得到以下错误

error                                     Traceback (most recent call last)
<ipython-input-10-2d3a348b0b9b> in <module>()
     25 
     26 #gaussian blur (sigma = 1)
---> 27 gaus_blur1 = cv2.GaussianBlur(img,(0,0), 1, 1)
     28 cv2_imshow(gaus_blur1[2000])
     29 

error: OpenCV(4.1.2) /io/opencv/modules/core/src/matrix.cpp:757: error: (-215:Assertion failed) dims <= 2 && step[0] > 0 in function 'locateROI'

当我试着去做的时候

for k in range (7165):
  img[k] = cv2.imread('/content/FIGURE/figure' + str(k) +'.png', 1) 
                                    #storing images into array of integers

img_neg = 255 - img    #taking the negative

#cv2_imshow(img_neg[2000])

#voxel form

#gaussian blur (sigma = 1)
gaus_blur1 = cv2.GaussianBlur(img_neg,(0,0), 1, 1)

大多数在线解决方案都提到没有从文件夹中正确读取图像,但事实并非如此,我尝试绘制了一些图像,数据集正是这样。你有什么想法吗


Tags: in图像img错误errorgaussiancv2sigma
1条回答
网友
1楼 · 发布于 2024-06-16 11:41:17

虽然您的问题中缺少上下文仍然不太清楚,但您似乎试图模糊图像的数组,而不是一个二维图像

单独模糊每个图像:

# could be some other structure than dicts, but it's not clear from the question
img = {}  
gaus_blur = {}

for k in range(7165):
    image = cv2.imread("/content/FIGURE/figure" + str(k) + ".png", 1)
    img[k] = image  # store original image
    gaus_blur[k] = cv2.GaussianBlur(255 - image, (0, 0), 1, 1)  # store inverse blurred image


相关问题 更多 >