def match(image, templates, threshold, flip, exclude_regions):
"""Look for TEMPLATES in IMAGE and return the bounding boxes of
the matches. Options may be provided after each TEMPLATE.
Example::
histonets match http://foo.bar/tmpl1 -th 50 http://foo.bar/tmpl2 -th 95
\b
- TEMPLATE is a path to a local (file://) or remote (http://, https://)
image file of the template to look for."""
# TODO: Click invoke fails at testing time, but not at runtime :(
# template options should be a list of the same length that templates
none_list = [None] * len(templates)
args = (
Image.get_images(templates), # pipeline does not invoke the decorator
threshold or none_list,
flip or none_list,
exclude_regions or none_list,
)
if len(set(len(x) for x in args)) != 1:
raise click.BadParameter('Some templates or options are missing.')
image_templates = []
for (template_image, template_threshold, template_flip,
template_exclude_regions) in zip(*args):
mask = None
if template_exclude_regions:
try:
mask = ~get_mask_polygons(template_exclude_regions,
*template_image.image.shape[:2])
except cv2.error:
raise click.BadParameter('Polygons JSON is malformed.')
image_templates.append({
'image': template_image.image,
'threshold': template_threshold,
'flip': template_flip,
'mask': mask,
})
matches = match_templates(image, image_templates)
return matches.tolist()
评论列表
文章目录