簡體   English   中英

使用imwrite進行閾值處理后如何在opencv中保存圖像

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

我試圖在閾值處理后使用 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 循環內。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM