最近在github中發現了一個有趣的小工具,tiler
github鏈接https://github.com/nuno-faria/tiler
具體介紹請直接去github,這里只分享一下它的使用方法。
需要安裝的庫在requirements.txt中
可以在cmd中定位到此文下直接使用命令
pip3 install -r requirement.txt安裝所需要的庫.
如果安裝報timeout錯誤的話可以使用命令此(設置超時為30s)
pip3 install --timeout 30 -r requirements.txt
使用方法非常簡單
打開文件夾下的conf.py文件
修改主要的三個參數
# out file name OUT = 'out.png' # image to tile (ignored if passed as the 1st arg) IMAGE_TO_TILE = None # folder with tiles (ignored if passed as the 2nd arg) TILES_FOLDER = None
OUT是輸出圖片的文件名,可以為默認。
IMAGE_TO_TILE是需要自己修改的,輸入圖片路徑不可以有中文字符,cv2無法打開此圖片文件導致之后加載圖片報錯
TILES_FOLDER參數,是tiles文件夾下文件夾路徑
TILES_FOLDER參數可以是此文件夾下的這些,當然你也可以自己添加一些。
不過要注意的是conf.py是py文件注意字符串要加' '或“ ”
例如:
TILES_FOLDER = "E:/workSpace/python_bug/tiler-master/tiles/times/gen_times"
測試了一下,我的電腦CPU 酷睿i5 7300U 8GB內存,輸入命令運行程序
>python tiler.py
運行中內存占用比較高,原始圖片1319x742像素
總共跑了大約1分鍾。最終效果:
最終成品還是比較不錯的。
測試圖片(圖片來自百度圖片,侵刪)
參數設置:
DEPTH = 4 # list of rotations, in degrees, to apply over the original image ROTATIONS = [0] ############################# # TILER CONFS # number of colors per image COLOR_DEPTH = 32 # tiles scales (1 = default resolution) RESIZING_SCALES = [0.5,0.4.0.3,0.2,0.1] # number of pixels shifted to create each box (tuple with (x,y)) # if value is None, shift will be done accordingly to tiles dimensions PIXEL_SHIFT = (5,5) # if tiles can overlap OVERLAP_TILES = False # render image as its being built RENDER = False # multiprocessing pool size POOL_SIZE = 4 # out file name OUT = 'min.png' # image to tile (ignored if passed as the 1st arg) IMAGE_TO_TILE = 'E:/workSpace/python_bug/tiler-master/in1.jpg' # folder with tiles (ignored if passed as the 2nd arg) TILES_FOLDER = "E:/workSpace/python_bug/tiler-master/tiles/minecraft"
生成效果
參數設置
# number of divisions per color (R, G and B) # DEPTH = 4 -> 4 * 4 * 4 = 64 colors DEPTH = 128 # list of rotations, in degrees, to apply over the original image ROTATIONS = [0] ############################# # TILER CONFS # number of colors per image COLOR_DEPTH = 128 # tiles scales (1 = default resolution) RESIZING_SCALES = [0.1] # number of pixels shifted to create each box (tuple with (x,y)) # if value is None, shift will be done accordingly to tiles dimensions PIXEL_SHIFT = None # if tiles can overlap OVERLAP_TILES = False # render image as its being built RENDER = False # multiprocessing pool size POOL_SIZE = 4 # out file name OUT = 'min2.png' # image to tile (ignored if passed as the 1st arg) IMAGE_TO_TILE = 'E:/workSpace/python_bug/tiler-master/in1.jpg' # folder with tiles (ignored if passed as the 2nd arg) TILES_FOLDER = "E:/workSpace/python_bug/tiler-master/tiles/minecraft"
生成效果
可以看出DEPTH,COLOR_DEPTH 是控制圖片顏色主要參數。