python將處理好的影象儲存到指定目錄下
# 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))