懒咪学编程


RuntimeError: filter weights array has incorrect shape.

时间:2019-07-04 09:14:07  来源:  作者:myself_oriented  所属栏目:Python

完整代码如下
import cv2
import numpy as np
from scipy import ndimage

kernel133 = np.array([
[-1, -1, -1],
[-1, 8, -1],
[-1, -1, -1]
])

kernel133_D

完整代码如下

import cv2
import numpy as np
from scipy import ndimage

kernel133 = np.array([
    [-1, -1, -1],
    [-1, 8, -1],
    [-1, -1, -1]
])

kernel133_D = np.array([
    [1, 1, 1],
    [1, -8, 1],
    [1, 1, 1]
])

img = cv2.imread('jj.jpg')

img = ndimage.convolve(img, kernel133_D)

cv2.imshow('enhanced', img)
cv2.waitKey(0)

完整的报错如下

Traceback (most recent call last):
  File "D:/Python/测试专用文件夹/opencv测试.py", line 19, in 
    img = ndimage.convolve(img, kernel133_D)
  File "C:UsersyjcAppDataLocalProgramsPythonPython37libsite-packagesscipyndimagefilters.py", line 745, in convolve
    origin, True)
  File "C:UsersyjcAppDataLocalProgramsPythonPython37libsite-packagesscipyndimagefilters.py", line 595, in _correlate_or_convolve
    raise RuntimeError('filter weights array has incorrect shape.')
RuntimeError: filter weights array has incorrect shape.

通过这个文章,我知道了,要加一个

img = cv2.imread('jj.jpg', cv2.IMREAD_GRAYSCALE)

或者

img = cv2.imread('jj.jpg', 0)#0表示加载一张灰度图。

OpenCV_Python API 官方文档学习_ cv2.imread()

cv2.IMREAD_COLOR : 默认使用该种标识。加载一张彩色图片,忽视它的透明度。
cv2.IMREAD_GRAYSCALE : 加载一张灰度图。
cv2.IMREAD_UNCHANGED : 加载图像,包括它的Alpha通道。

原文地址:https://segmentfault.com/a/1190000019658233,作者:myself_oriented

以上就是对RuntimeError: filter weights array has incorrect shape.的相关介绍,希望对您学习opencv,python有所帮助,感谢您关注懒咪IT学习网!

本文地址:https://c.lanmit.com/bianchengkaifa/Python/2030.html

 

推荐Python排行......