【发布时间】:2016-11-15 12:52:56
【问题描述】:
我试图在分离红色通道后对 BGR 图像进行阈值处理,但是 我的代码总是返回“分段错误”。
import numpy as np
import cv2
def mostrarVentana (titulo, imagen):
print('Mostrando imagen')
cv2.imshow(titulo, imagen)
k = cv2.waitKey(0)
if k == 27: # wait for ESC key to exit
cv2.destroyAllWindows()
img = cv2.imread('RepoImagenes/640x480/P5.jpg', 1) # loading image in BGR
redImg = img[:, :, 2] # extracting red channel
rbin, threshImg = cv2.threshold(redImg, 58, 255, cv2.THRESH_BINARY) # thresholding
mostrarVentana('Binary image', threshImg)
我已阅读有关如何使用 threshold() 函数的文档,但我不知道出了什么问题。我只需要在红色通道上工作,我该如何完成?
我正在使用 python 3.4 和 opencv 3.1.0
【问题讨论】:
-
猜测最有可能是找不到文件...使用调试器查看失败的行,并检查变量。
-
@Photon 图像文件已正确加载,如果我用阈值函数注释该行,那么代码可以正常工作,因为我没有调用 threshImg 变量。
标签: python-3.x opencv threshold