我尝试在阈值设置后使用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"])
答案 0 :(得分:1)
我认为您想保存脱粒图像。 cv2.imwrite(args["image"], thresh)
应该在for循环内。
答案 1 :(得分:0)
在docs中,函数标头为:
cv2.imwrite(文件名,图像)
将其向后移动,只需更改
cv2.imwrite(gray, args["image"])
到
cv2.imwrite(args["image"], gray)