为了提高训练精确度,将数据源按尺寸裁剪
文件路径:~/caffe/examples/myfile/st_0622_cor.txt
文件内容:
图片路径:/home/data/re
py脚本:
#!/usr/bin/env python
import os
from PIL import Image
for line in open('st_0622_cor.txt'):
name=line[:line.rfind('g')+1]
arrow=line[line.rfind('g')+2:]
split=arrow.split()
left=split[0]
top=split[1]
right=split[2]
bottom=split[3]
#print(name)
#print(arrow)
#print(split)
Imgfile='/home/data/re/train/'+name
im=Image.open(Imgfile)
x=int(left)
y=int(top)
w=int(right)
b=int(bottom)
box=(x,y,w,b)
region=im.crop(box)
prefix = name[:name.rfind('.')]
region.save("/home/data/newre/train/%s.jpg" % (prefix))