コード例 #1
0
ファイル: imgproc.py プロジェクト: corwinliu/lab2
def mark(fn, features):
	img = Image.open(fn)
	draw = ImageDraw.Draw(img)
	for (feature, pos) in features.iteritems():
		x = pos['x'] / 100.0 * img.size[0]
		y = pos['y'] / 100.0 * img.size[1]
		draw.rectangle([(x - 1, y - 1), (x + 1, y + 1)],
				outline=(0,0,255), fill=(0,0,0))
	img.save(outname(fn))
コード例 #2
0
ファイル: imgproc.py プロジェクト: corwinliu/lab2
def smile(fn, features):
	img = Image.open(fn)
	draw = ImageDraw.Draw(img)
	MOUTHL = [('mouth_left_corner', 'mouth_lower_lip_left_contour2'),
		  ('mouth_lower_lip_left_contour2', 'mouth_lower_lip_left_contour3'),
		  ('mouth_lower_lip_left_contour3', 'mouth_lower_lip_bottom'),
		  ('mouth_lower_lip_bottom', 'mouth_lower_lip_right_contour3'),
		  ('mouth_lower_lip_right_contour3', 'mouth_lower_lip_right_contour2'),
		  ('mouth_lower_lip_right_contour2', 'mouth_right_corner')]
	MOUTHH = [('mouth_left_corner', 'mouth_upper_lip_left_contour1'),
		  ('mouth_upper_lip_left_contour1', 'mouth_upper_lip_left_contour2'),
		  ('mouth_upper_lip_left_contour2', 'mouth_upper_lip_top'),
		  ('mouth_upper_lip_top', 'mouth_upper_lip_right_contour2'),
		  ('mouth_upper_lip_right_contour2', 'mouth_upper_lip_right_contour1'),
		  ('mouth_upper_lip_right_contour1', 'mouth_right_corner')]

#	for (m1, m2) in MOUTHL + MOUTHH:
#		drawLine(img, draw, features[m1], features[m2])
	yuppb = int(features['contour_chin']['y'] / 100.0 * img.size[1])
	ylowb = int(features['nose_contour_lower_middle']['y'] / 100.0 * img.size[1])
	imgxl = int(features['mouth_left_corner']['x'] / 100.0 * img.size[0])
	imgxr = int(features['mouth_right_corner']['x'] / 100.0 * img.size[0])
	for x in range(imgxl, imgxr):
		imgyh = int(gety(x, MOUTHL, features, img))
		imgyl = int(gety(x, MOUTHH, features, img))
#		for y in range(imgyl, imgyh):
#			draw.point((x, y), fill=(0,0,255))
		rate = genrate(x, imgxl, imgxr)
		newyl = int((imgyl - ylowb) * rate[0] + ylowb)
		newyh = int(yuppb - (yuppb - imgyh) * rate[1])

		color = []
		for y in range(0, img.size[1]):
			color.append(img.getpixel((x, y)))
		for y in range(ylowb, newyl):
			cy = int((y - ylowb) / rate[0] + ylowb)
			draw.point((x, y), fill=color[cy])
		for y in range(newyl, newyh):
			cy = int((y - newyl) / float(newyh - newyl) * (imgyh - imgyl) + imgyl)
			draw.point((x, y), fill=color[cy])
		for y in range(newyh, yuppb):
			cy = int(yuppb - (yuppb - y) / rate[1])
			draw.point((x, y), fill=color[cy])

	img.save(outname(fn))