mirror of
https://github.com/opencv/opencv.git
synced 2024-11-28 21:20:18 +08:00
Merge pull request #2578 from akrynski:patch-1
This commit is contained in:
commit
92db6786a9
@ -81,9 +81,32 @@ def CropFace(image, eye_left=(0,0), eye_right=(0,0), offset_pct=(0.2,0.2), dest_
|
||||
image = image.resize(dest_sz, Image.ANTIALIAS)
|
||||
return image
|
||||
|
||||
def readFileNames():
|
||||
try:
|
||||
inFile = open('path_to_created_csv_file.csv')
|
||||
except:
|
||||
raise IOError('There is no file named path_to_created_csv_file.csv in current directory.')
|
||||
return False
|
||||
|
||||
picPath = []
|
||||
picIndex = []
|
||||
|
||||
for line in inFile.readlines():
|
||||
if line != '':
|
||||
fields = line.rstrip().split(';')
|
||||
picPath.append(fields[0])
|
||||
picIndex.append(int(fields[1]))
|
||||
|
||||
return (picPath, picIndex)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
image = Image.open("arnie.jpg")
|
||||
CropFace(image, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.1,0.1), dest_sz=(200,200)).save("arnie_10_10_200_200.jpg")
|
||||
CropFace(image, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.2,0.2), dest_sz=(200,200)).save("arnie_20_20_200_200.jpg")
|
||||
CropFace(image, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.3,0.3), dest_sz=(200,200)).save("arnie_30_30_200_200.jpg")
|
||||
CropFace(image, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.2,0.2)).save("arnie_20_20_70_70.jpg")
|
||||
[images, indexes]=readFileNames()
|
||||
if not os.path.exists("modified"):
|
||||
os.makedirs("modified")
|
||||
for img in images:
|
||||
image = Image.open(img)
|
||||
CropFace(image, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.1,0.1), dest_sz=(200,200)).save("modified/"+img.rstrip().split('/')[1]+"_10_10_200_200.jpg")
|
||||
CropFace(image, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.2,0.2), dest_sz=(200,200)).save("modified/"+img.rstrip().split('/')[1]+"_20_20_200_200.jpg")
|
||||
CropFace(image, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.3,0.3), dest_sz=(200,200)).save("modified/"+img.rstrip().split('/')[1]+"_30_30_200_200.jpg")
|
||||
CropFace(image, eye_left=(252,364), eye_right=(420,366), offset_pct=(0.2,0.2)).save("modified/"+img.rstrip().split('/')[1]+"_20_20_70_70.jpg")
|
||||
|
Loading…
Reference in New Issue
Block a user