cli.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:histonets-cv 作者: sul-cidr 项目源码 文件源码
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()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号