Как сохранить изображение в opencv после установки порога с помощью imwrite - PullRequest
1 голос
/ 23 апреля 2019

Я пытаюсь сохранить изображение с помощью 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"])

1 Ответ

1 голос
/ 23 апреля 2019

Я думаю, вы хотите сохранить изображение обмолота. cv2.imwrite(args["image"], thresh) должно быть внутри цикла for.

...