Beispiel #1
0
def generate_detections(ibs, gid_list, species, **detectkw):
    """ detectkw can be: save_detection_images, save_scales, draw_supressed,
        detection_width, detection_height, percentage_left, percentage_top,
        nms_margin_percentage

        Yeilds tuples of image ids and bounding boxes
    """
    #
    # Resize to a standard image size prior to detection
    src_gpath_list = list(imap(str, ibs.get_image_detectpaths(gid_list)))
    utool.close_pool()

    # Get sizes of the original and resized images for final scale correction
    neww_list = [gtool.open_image_size(gpath)[0] for gpath in src_gpath_list]
    oldw_list = [oldw for (oldw, oldh) in ibs.get_image_sizes(gid_list)]
    scale_list = [oldw / neww for oldw, neww in izip(oldw_list, neww_list)]

    # Detect on scaled images
    ibs.cfg.other_cfg.ensure_attr('detect_use_chunks', True)
    use_chunks = ibs.cfg.other_cfg.detect_use_chunks

    generator = detect_species_bboxes(src_gpath_list, species,
                                      use_chunks=use_chunks, **detectkw)

    for gid, scale, (bboxes, confidences, img_conf) in izip(gid_list, scale_list, generator):
        # Unscale results
        unscaled_bboxes = [_scale_bbox(bbox_, scale) for bbox_ in bboxes]
        for index in xrange(len(unscaled_bboxes)):
            bbox = unscaled_bboxes[index]
            confidence = float(confidences[index])
            yield gid, bbox, confidence, img_conf
def testdata_matcher(fname1='easy1.png', fname2='easy2.png'):
    """"
    fname1 = 'easy1.png'
    fname2 = 'hard3.png'

    python -m vtool.test_constrained_matching --test-visualize_matches --show

    Args:
        fname1 (str): (default = 'easy1.png')
        fname2 (str): (default = 'easy2.png')

    Returns:
        ?: testtup

    CommandLine:
        python -m vtool.test_constrained_matching --test-testdata_matcher

    Example:
        >>> # DISABLE_DOCTEST
        >>> from vtool.test_constrained_matching import *  # NOQA
        >>> fname1 = 'easy1.png'
        >>> fname2 = 'easy2.png'
        >>> testtup = testdata_matcher(fname1, fname2)
        >>> result = ('testtup = %s' % (str(testtup),))
        >>> print(result)
    """
    import utool as ut
    #import vtool as vt
    from vtool import image as gtool
    from vtool import features as feattool
    fpath1 = ut.grab_test_imgpath(fname1)
    fpath2 = ut.grab_test_imgpath(fname2)
    featkw = dict(rotation_invariance=True)
    kpts1, vecs1 = feattool.extract_features(fpath1, **featkw)
    kpts2, vecs2 = feattool.extract_features(fpath2, **featkw)
    #if featkw['rotation_invariance']:
    #    print('ori stats 1 ' + ut.get_stats_str(vt.get_oris(kpts2)))
    #    print('ori stats 2 ' + ut.get_stats_str(vt.get_oris(kpts1)))
    rchip1 = gtool.imread(fpath1)
    rchip2 = gtool.imread(fpath2)
    #chip1_shape = vt.gtool.open_image_size(fpath1)
    chip2_shape = gtool.open_image_size(fpath2)
    dlen_sqrd2 = chip2_shape[0] ** 2 + chip2_shape[1]
    testtup = (rchip1, rchip2, kpts1, vecs1, kpts2, vecs2, dlen_sqrd2)
    return testtup
Beispiel #3
0
def testdata_matcher(fname1='easy1.png', fname2='easy2.png'):
    """"
    fname1 = 'easy1.png'
    fname2 = 'hard3.png'

    python -m vtool.test_constrained_matching --test-visualize_matches --show

    Args:
        fname1 (str): (default = 'easy1.png')
        fname2 (str): (default = 'easy2.png')

    Returns:
        ?: testtup

    CommandLine:
        python -m vtool.test_constrained_matching --test-testdata_matcher

    Example:
        >>> # DISABLE_DOCTEST
        >>> from vtool.test_constrained_matching import *  # NOQA
        >>> fname1 = 'easy1.png'
        >>> fname2 = 'easy2.png'
        >>> testtup = testdata_matcher(fname1, fname2)
        >>> result = ('testtup = %s' % (str(testtup),))
        >>> print(result)
    """
    import utool as ut
    #import vtool as vt
    from vtool import image as gtool
    from vtool import features as feattool
    fpath1 = ut.grab_test_imgpath(fname1)
    fpath2 = ut.grab_test_imgpath(fname2)
    featkw = dict(rotation_invariance=True)
    kpts1, vecs1 = feattool.extract_features(fpath1, **featkw)
    kpts2, vecs2 = feattool.extract_features(fpath2, **featkw)
    #if featkw['rotation_invariance']:
    #    print('ori stats 1 ' + ut.get_stats_str(vt.get_oris(kpts2)))
    #    print('ori stats 2 ' + ut.get_stats_str(vt.get_oris(kpts1)))
    rchip1 = gtool.imread(fpath1)
    rchip2 = gtool.imread(fpath2)
    #chip1_shape = vt.gtool.open_image_size(fpath1)
    chip2_shape = gtool.open_image_size(fpath2)
    dlen_sqrd2 = chip2_shape[0]**2 + chip2_shape[1]
    testtup = (rchip1, rchip2, kpts1, vecs1, kpts2, vecs2, dlen_sqrd2)
    return testtup
def testdata_matcher(fname1='easy1.png', fname2='easy2.png'):
    """"
    fname1 = 'easy1.png'
    fname2 = 'hard3.png'

    annot1 = Annot(fpath1)
    annot2 = Annot(fpath2)
    """
    import utool as ut
    from vtool import image as gtool
    from vtool import features as feattool
    fpath1 = ut.grab_test_imgpath(fname1)
    fpath2 = ut.grab_test_imgpath(fname2)
    kpts1, vecs1 = feattool.extract_features(fpath1)
    kpts2, vecs2 = feattool.extract_features(fpath2)
    rchip1 = gtool.imread(fpath1)
    rchip2 = gtool.imread(fpath2)
    #chip1_shape = vt.gtool.open_image_size(fpath1)
    chip2_shape = gtool.open_image_size(fpath2)
    dlen_sqrd2 = chip2_shape[0]**2 + chip2_shape[1]**2
    testtup = (rchip1, rchip2, kpts1, vecs1, kpts2, vecs2, dlen_sqrd2)

    return testtup
Beispiel #5
0
def testdata_matcher(fname1="easy1.png", fname2="easy2.png"):
    """"
    fname1 = 'easy1.png'
    fname2 = 'hard3.png'

    annot1 = Annot(fpath1)
    annot2 = Annot(fpath2)
    """
    import utool as ut
    from vtool import image as gtool
    from vtool import features as feattool

    fpath1 = ut.grab_test_imgpath(fname1)
    fpath2 = ut.grab_test_imgpath(fname2)
    kpts1, vecs1 = feattool.extract_features(fpath1)
    kpts2, vecs2 = feattool.extract_features(fpath2)
    rchip1 = gtool.imread(fpath1)
    rchip2 = gtool.imread(fpath2)
    # chip1_shape = vt.gtool.open_image_size(fpath1)
    chip2_shape = gtool.open_image_size(fpath2)
    dlen_sqrd2 = chip2_shape[0] ** 2 + chip2_shape[1] ** 2
    testtup = (rchip1, rchip2, kpts1, vecs1, kpts2, vecs2, dlen_sqrd2)

    return testtup