Example #1
0
def main(image_filename, cascade_filename, res_filename, use_multiscale = False):
	image = imageio.read(image_filename)

	haar_classifier = parse_haar.parse_haar_xml(cascade_filename)
	print str(haar_classifier)


	# parameters
	scale_factor = 1.2
	min_size = (40, 40)

	# process image
	detected_faces = []
	if use_multiscale:
		detected_faces = detect_faces_multiscale(image, haar_classifier, scale_factor, min_size)
	else:
		detected_faces = detect_faces(image, haar_classifier)

	res = visualisation.draw_faces(image, detected_faces)
	imageio.write(res_filename, res, 3)
Example #2
0
def run_detector(block_size, implementation, image_filename, cascade_filename, res_filename_prefix):
	from blip.simulator import interpreter
	from blip.support import imageio
	import violajones.reference

	# first load the cascade
	cascade = violajones.parse_haar.parse_haar_xml(cascade_filename)
	print cascade

	image = imageio.read(image_filename)
	if not image: raise Exception('image %s not found or not supported'%image_filename)

	print 'XXX histogram equalisation is not implemented yet, use violajones impl'
	print '    before executing simulator'
	image = violajones.reference.equalizeHist(image)
	im_size = len(image[0]), len(image)

	pe_dim = [s//b for s,b in zip(im_size, block_size)]

	args = {'haar_classifier':cascade, 'pe_dim':pe_dim}
	# now execute the codegen
	code = Code()
	code.set_generator(implementation, block_size, args)
	#print '# instructions: %i'%(code.instr_size())

	sim = interpreter.Interpreter(code, image, block_size, 4)
	sim.run()

	detections_pixmap = sim.gen_output_image(1) # result is saved in first buffer

	# convert the number of rejections in the stages to detections
	detections = convert_pixelmap_to_detections(detections_pixmap, cascade.size)
	print 'detections:', detections
	detections_im = visualisation.draw_faces(image, detections)

	imageio.write(res_filename_prefix + '_pixmap.png', detections_pixmap, 1)
	imageio.write(res_filename_prefix + '.png', detections_im, 3)