简体   繁体   English

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

[英]How to save image in opencv after thresholding using imwrite

I'm trying to save an image using cv2.imwrite after thresholding but it doesnt save the image.我试图在阈值处理后使用 cv2.imwrite 保存图像,但它不保存图像。 below is the code I'm using:下面是我正在使用的代码:

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"])

I think you want to save the thresh image.我想你想保存 thresh 图像。 cv2.imwrite(args["image"], thresh) should be inside the for loop. cv2.imwrite(args["image"], thresh)应该在 for 循环内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM