Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在使用imwrite进行阈值化后在opencv中保存图像_Python_Opencv_Threshold - Fatal编程技术网

Python 如何在使用imwrite进行阈值化后在opencv中保存图像

Python 如何在使用imwrite进行阈值化后在opencv中保存图像,python,opencv,threshold,Python,Opencv,Threshold,我正在尝试使用cv2.imwrite在阈值化后保存图像,但它没有保存图像。下面是我正在使用的代码: import necessary packages ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", required = True, help = "Path to the image to be thresholded") ap.add_argument("-t", "--threshold", typ

我正在尝试使用cv2.imwrite在阈值化后保存图像,但它没有保存图像。下面是我正在使用的代码:

import necessary packages

ap = argparse.ArgumentParser()

ap.add_argument("-i", "--image", required = True,
    help = "Path to the image to be thresholded")

ap.add_argument("-t", "--threshold", type = int, default = 128,
    help = "Threshold value")

args = vars(ap.parse_args())

image = cv2.imread(args["image"])

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

methods = [("THRESH_BINARY", cv2.THRESH_BINARY)]

for (threshName, threshMethod) in methods:

    (T, thresh) = cv2.threshold(gray, args["threshold"], 255, threshMethod)

    cv2.imshow(threshName, thresh)

    cv2.waitKey(0)

cv2.imwrite(gray, args["image"])

我想你想保存thresh图像
cv2.imwrite(args[“image”],thresh)
应该在for循环中。

cv2.imwrite(args[“image”],灰色)
--文件名在前。代码运行…但图像不会保存。