1. 程式人生 > >python將處理好的影象儲存到指定目錄下

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處理影象儲存指定目錄

原始影象絕對路徑的影象名儲存在一個txt檔案中,下面的程式實現的功能是按照txt檔案的順序,依次將圖片讀取然後進行處理,最後將處理之後的影象儲存在指定的路徑下: # Read in the image to be detected # 原始影象均儲存在binaries

利用python os模塊搜索指定目錄包含指定字符的文件

指定 and clas listdir 函數 () bsp 權限 利用 Python內置的os模塊也可以直接調用操作系統提供的接口函數。 os.listdir()可以列出給定目錄下的文件和下級目錄 os.path.isfile()方法可以驗證該文件是否真的存在,註意這裏需要

Python學習13_Python指令碼實現查詢指定目錄包含指定關鍵字的檔案

#!/usr/bin/python # coding:utf8 import os     # 判斷檔案中是否包含關鍵字,是則將檔案路徑打印出來 def is_file_contain_word(file_list, query_word):     for _file in

python列出指定目錄的所有目錄和文件

log imp roo pla pytho pos dsw .py src import os import docx def scanfile(rootdir): result = [] for f in os.walk(rootdir):

定時應用日誌移動到指定目錄

pri gpo parameter $1 san sof 16px 定時同步 then 定時經日誌輸出到指定目錄,並打包 1 #!/bin/bash 2 3 backupLog() 4 { 5 FROMDIR=$1; 6 TODIR=$2;

shell腳本第二篇——指定目錄大於200K的文件移動到/tmp

-i .sh ext 輸入 for ont 文件移動 print vim shell腳本第二篇——將指定目錄下大於200K的文件移動到/tmp下# vim /tmp/files.sh #!/bin/bash #將指定目錄下大於200K的文件移動到/tmp下 read

python基礎:匹配指定目錄符合規則的文件,打印文件全路徑

python# -*- coding:utf-8 -*- #遍歷目錄樹 import os,fnmatch def all_files(root, patterns=‘*‘, single_level=False, yield_folder=False): # 將模式從字符串中取出放入列表中

python——查詢linux指定目錄所有的空目錄

pac 方法 6.5 AC 查詢 argv sys.argv 目錄名 env 1 #!/usr/bin/env python3 2 # -*- coding: utf-8 -*- 3 #*******查詢指定目錄中的空目錄********* 4 #執行方法:pyt

指定目錄的檔案打tar包,不包括此目錄

package com.jttx.other.jtp; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArch

python獲取指定目錄的所有指定字尾的檔名

分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow 也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!        

Python3之儲存資料到指定目錄的檔案中

程式碼 import os def save(html, path): ''' 以檔案形式儲存資料 :param html: 要儲存的資料 :param path: 要儲存資料的路徑 :return: ''' # 判斷目錄是否存

python獲取指定目錄所有檔名os.walk和os.listdir

python獲取指定目錄下所有檔名os.walk和os.listdir 覺得有用的話,歡迎一起討論相互學習~Follow Me os.walk 返回指定路徑下所有檔案和子資料夾中所有檔案列表 其中資料夾下路徑如下: import os def file_name_walk(file_

王權富貴:讀取指定目錄的所有檔名(不保持字尾)文字處理

import os import os.path as osp rootdir = "C:\YSRVOC\VOCdevkit\VOC2007\JPEGImages" file_object = open('C:\YSRVOC\VOCdevkit\VOC2007\ImageSets\Main/tr

android 建立檔案和建立資料夾、assets檔案複製到指定目錄

1.獲取APP當前目錄路徑: public String getPath(){ File fileDire = getFilesDir();//獲取../data/應用的包名/fil

python選取指定目錄與子目錄的所有指定的檔案

import os import os.path def getListFiles(path): ret = [] for root, dirs, files in os.walk(path): for filespath in files:

DOS命令FOR批處理COPY指定目錄檔案到指定目錄

這段時間,俺把自己寫的Qt小專案的執行結果都截了個圖sample.png儲存,可是要想更新到git上的時候發現問題了,專案很多個,這要一個個COPY也還是有點工作量的。 思來想去,印象中DOS命令應該有

Python獲取指定目錄檔案數量及總大小

import os totalSize = 0 fileNum = 0 dirNum = 0 def visitDir(path): global totalSize glob

使用python讀取指定目錄指定型別檔案

準備工作:設定指定的路徑,使用os.listdir() 方法獲取路徑下所有的檔案 import os path = "d:\\data" # 設定路徑 dirs = os.listdir(path)

python指令碼程式設計:批量修改指定目錄內檔名

有的時候經常用到這個功能,批量修改視訊或者圖片的名字,按照數字編號等等,自己用python指令碼解決,輕量級又方便。 簡單版 對單個目錄下檔案字尾名 demo.py #coding:ut

python——一張影象分割為九張

附:python3.6.4+sublime Text安裝及配置點選開啟連結這個編譯器真是相見恨晚啊啊啊啊啊from PIL import Image import sys def fill_image