【问题标题】:I am trying to save image with time and date but image is not saving我正在尝试使用时间和日期保存图像,但图像未保存
【发布时间】:2021-06-18 04:04:04
【问题描述】:

我正在尝试用当前时间保存混淆矩阵,但它不起作用请帮我保存图像。

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)

image is here

【问题讨论】:

  • 正斜杠...确保那些 directories 存在,或者如果您不想谈论目录,则使用斜杠以外的其他内容。除了下面答案中提到的注意事项。

标签: python opencv


【解决方案1】:

图像未保存的原因是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")

【讨论】:

    猜你喜欢
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多