【问题标题】:Writing image in in directory in opensv code在opensv代码中的目录中写入图像
【发布时间】:2018-10-23 10:57:16
【问题描述】:

我正在尝试在我的 opencv 代码中编写图像,如果我在没有目录的情况下编写这很好。但是当我尝试写入目录时,它运行但不写入目录。

for i in xrange(3):
    path = 'resultImages/result'
    print os.path.join(path,str(i),'.png')
    cv.imwrite(os.path.join(path,str(i),'.png'),images[i*3+2])

这里有什么问题吗?

我推荐了OpenCV - Saving images to a particular folder of choice,但没有任何帮助。

【问题讨论】:

  • 如果resultImages在自动保存图片的目录中,尝试把'/'放在resultImages前面('/resultImages/result')
  • 确保你的 dirpath 存在。
  • @Silencer: 目录路径在那里,也尝试了('/resultImages/result') 但没有运气
  • 您是否尝试使用完整路径? 'D:/..../result'
  • 尝试使用os.path.exists(path) 来检查路径是否存在...还有os.path.join(path,str(i),'.png') 这应该给出类似resultImages/result/0/.png 的内容,它应该是类似os.path.join(path,str(i)+'.png') 的内容

标签: python opencv


【解决方案1】:

问题是由于您使用".png" 作为os.path.join() 函数内的子目录

尝试将其更改为:

for i in xrange(3):
    path = 'resultImages/result'
    print os.path.join(path,str(i) + '.png')
    cv.imwrite(os.path.join(path,str(i) +'.png'),images[i*3+2])

希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-25
    • 1970-01-01
    • 2012-12-15
    • 2020-12-25
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 1970-01-01
    相关资源
    最近更新 更多