欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

python将处理好的图像保存到指定目录下的方法

时间:2021-02-05 09:40:00|栏目:Python代码|点击:

原始图像绝对路径的图像名存储在一个txt文件中,下面的程序实现的功能是按照txt文件的顺序,依次将图片读取然后进行处理,最后将处理之后的图像保存在指定的路径下:

# Read in the image to be detected
# 原始图像均保存在binaries.txt文件中,将包含绝对目录的图像名提取出来并写到txt文件的程序见上一篇博客
f = open("/home/shenruixue/image_test/binaries.txt")
line = f.readline()

while line:
 count_times += 1
 line = line[:-1] # 除去末尾的换行符
 print line
 print '***********************************************************'
 image = caffe.io.load_image(line)
  

 # start time
 start = time.clock()

# 此处做一系列的处理
# 。。。。。。
# 。。。。。。
# 此处做一系列的处理

 # end time
 end = time.clock()
 sum_time += (end - start)

 # draw the image
 plt.imshow(image)

 
 print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'
# 指定处理之后的图像的保存目录
 pre_savename = '/home/shenruixue/image_test_result/'
 print (str(count_times))
# 将从txt中读取的一行字符串(包含绝对路径的图像名)进行处理,只留存最后的图像名的字符串部分,去掉绝对路径部分的字符串
# 并将自己指定的目录与原始的图像名这两个字符串连接起来,然后进行保存
 savename = os.path.join(pre_savename, line[28:]) 
 print 'line is '
 print line
 print 'savename is '
 print savename
 savefig(savename)
 #io.imsave(savename, image)
# 继续读取下一行的图像名称
 line = f.readline() 
 print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'


 plt.pause(1)
 plt.close() 

print('Running time: %s s' %sum_time)
print('Deal with images: %s 张' %count_times)
print('mean time: %s s' %(sum_time / count_times))

上一篇:Python cookbook(数据结构与算法)找到最大或最小的N个元素实现方法示例

栏    目:Python代码

下一篇:Python遍历文件夹 处理json文件的方法

本文标题:python将处理好的图像保存到指定目录下的方法

本文地址:http://www.codeinn.net/misctech/57679.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有