【发布时间】:2019-06-10 10:23:00
【问题描述】:
我正在尝试运行我在 GitHub 上找到的行分段代码。当程序到达这行代码时:
def invert(im):
im = abs(255 - im)
im = im / 255
return im
def enhance(im):
kernel = np.ones((5, 5), np.uint8)
im = cv2.erode(im, kernel, iterations=1)
kernel = np.ones((15, 15), np.uint8)
im = cv2.dilate(im, kernel, iterations=1)
return im
im = cv2.imread(filename, 0)
imbw = sauvola.binarize(im, [20, 20], 128, 0.3)
im = invert(im)
im = enhance(im)
hist = cv2.reduce(im, 1, cv2.REDUCE_SUM, dtype=cv2.CV_32F)
我收到此错误:
错误:OpenCV(3.4.1) C:\projects\opencv-python\opencv\modules\core\src\matrix_operations.cpp:1111: 错误:(-210) 函数中不支持输入和输出数组格式的组合cv::reduce
我已经尝试了所有可用于 cv2.reduce() 函数的 dtype 值。我还尝试使用 numpy 更改图像的数据类型。但是,我仍然遇到同样的错误。
完整代码:https://github.com/smeucci/LineSegm/blob/master/python/linesegm/lib/linelocalization.py#L41
【问题讨论】:
-
您的示例中真的需要
imbw = sauvola.binarize(im, [20, 20], 128, 0.3)吗?我没有实现(很可能在你的仓库中),但我认为不需要,因为你不使用imbw。写了我的答案,因为没有那行代码。
标签: python opencv image-segmentation