我正在尝试保存当前时间的混淆矩阵,但它不起作用,请帮助我保存图像。
rgb = Image.open("confussion_matrix.jpg")
rgb = np.array(rgb)
now = datetime.now()
current_time = now.strftime("%d/%m/%Y_%H:%M:%S")
filename = '%s.png' % (current_time)
cv2.imwrite(filename, rgb)
图像在这里
图像没有保存的原因是因为:
所在的行current_time = now.strftime("%d/%m/%Y_%H:%M:%S")
导致了问题。如果您应该用_
或-
替换:
,它应该可以正常工作。此外,cv2.imwrite((方法也不会抛出错误来识别问题。
这刚才对我很管用。
rgb = Image.open("confussion_matrix.jpg")
rgb = np.array(rgb)
now = datetime.now()
current_time = now.strftime("%d_%m_%Y_%H_%M_%S")
filename = '%s.png' % current_time
if not cv2.imwrite(filename, rgb):
raise Exception("Could not write image")