Esempio n. 1
0
def show_chipres(hs, res, cx, fnum=None, pnum=None, sel_fm=[], in_image=False, **kwargs):
    'shows single annotated match result.'
    qcx = res.qcx
    #cx2_score = res.get_cx2_score()
    cx2_fm    = res.get_cx2_fm()
    cx2_fs    = res.get_cx2_fs()
    #cx2_fk    = res.get_cx2_fk()
    #printDBG('[viz.show_chipres()] Showing matches from %s' % (vs_str))
    #printDBG('[viz.show_chipres()] fnum=%r, pnum=%r' % (fnum, pnum))
    # Test valid cx
    printDBG('[viz] show_chipres()')
    if np.isnan(cx):
        nan_img = np.zeros((32, 32), dtype=np.uint8)
        title = '(q%s v %r)' % (hs.cidstr(qcx), cx)
        df2.imshow(nan_img, fnum=fnum, pnum=pnum, title=title)
        return
    fm = cx2_fm[cx]
    fs = cx2_fs[cx]
    #fk = cx2_fk[cx]
    #vs_str = hs.vs_str(qcx, cx)
    # Read query and result info (chips, names, ...)
    if in_image:
        # TODO: rectify build_transform2 with cc2
        # clean up so its not abysmal
        rchip1, rchip2 = [hs.cx2_image(_) for _ in [qcx, cx]]
        kpts1, kpts2   = viz.cx2_imgkpts(hs, [qcx, cx])
    else:
        rchip1, rchip2 = hs.get_chip([qcx, cx])
        kpts1, kpts2   = hs.get_kpts([qcx, cx])

    # Build annotation strings / colors
    lbl1 = 'q' + hs.cidstr(qcx)
    lbl2 = hs.cidstr(cx)
    if in_image:
        # HACK!
        lbl1 = None
        lbl2 = None
    # Draws the chips and keypoint matches
    kwargs_ = dict(fs=fs, lbl1=lbl1, lbl2=lbl2, fnum=fnum,
                   pnum=pnum, vert=hs.prefs.display_cfg.vert)
    kwargs_.update(kwargs)
#    ax, xywh1, xywh2 = df2.show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm, **kwargs_)
    ax, xywh1, xywh2 = show_chipmatch2(rchip1, rchip2, kpts1, kpts2, fm, **kwargs_)
    x1, y1, w1, h1 = xywh1
    x2, y2, w2, h2 = xywh2
    if len(sel_fm) > 0:
        # Draw any selected matches
        _smargs = dict(rect=True, colors=df2.BLUE)
#        df2.draw_fmatch(xywh1, xywh2, kpts1, kpts2, sel_fm, **_smargs)
        draw_fmatch(xywh1, xywh2, kpts1, kpts2, sel_fm, **_smargs)
    offset1 = (x1, y1)
    offset2 = (x2, y2)
    annotate_chipres(hs, res, cx, xywh2=xywh2, in_image=in_image, offset1=offset1, offset2=offset2, **kwargs)
    return ax, xywh1, xywh2
Esempio n. 2
0
def show_chipmatch2(rchip1,
                    rchip2,
                    kpts1,
                    kpts2,
                    fm=None,
                    fs=None,
                    title=None,
                    vert=None,
                    fnum=None,
                    pnum=None,
                    **kwargs):
    '''Draws two chips and the feature matches between them. feature matches
    kpts1 and kpts2 use the (x,y,a,c,d)
    '''
    printDBG('[df2] draw_matches2() fnum=%r, pnum=%r' % (fnum, pnum))
    # get matching keypoints + offset
    (h1, w1) = rchip1.shape[0:2]  # get chip (h, w) dimensions
    (h2, w2) = rchip2.shape[0:2]
    # Stack the compared chips
    match_img, woff, hoff = df2.stack_images(rchip1, rchip2, vert)
    xywh1 = (0, 0, w1, h1)
    xywh2 = (woff, hoff, w2, h2)
    # Show the stacked chips
    fig, ax = df2.imshow(match_img, title=title, fnum=fnum, pnum=pnum)
    # Overlay feature match nnotations
    draw_fmatch(xywh1, xywh2, kpts1, kpts2, fm, fs, **kwargs)

    return ax, xywh1, xywh2
Esempio n. 3
0
def test(hs, cx=0):
    from hsviz import draw_func2 as df2
    import os
    if not 'cx' in vars():
        cx = 0
    # READ IMAGE AND ROI
    cx2_roi = hs.tables.cx2_roi
    cx2_gx = hs.tables.cx2_gx
    gx2_gname = hs.tables.gx2_gname
    #---
    roi_ = cx2_roi[cx]
    gx  = cx2_gx[cx]
    img_fname = gx2_gname[gx]
    img_fpath = os.path.join(hs.dirs.img_dir, img_fname)
    #---
    print('testing segment')
    seg_chip, img_mask = segment(img_fpath, roi_, new_size=None)
    from hsviz import viz
    viz.show_image(hs, gx, fnum=1, pnum=131, title='original', docla=True)
    df2.imshow(img_mask, fnum=1, pnum=132, title='mask')
    df2.imshow(seg_chip, fnum=1, pnum=133, title='segmented')
Esempio n. 4
0
def test(hs, cx=0):
    from hsviz import draw_func2 as df2
    import os
    if not 'cx' in vars():
        cx = 0
    # READ IMAGE AND ROI
    cx2_roi = hs.tables.cx2_roi
    cx2_gx = hs.tables.cx2_gx
    gx2_gname = hs.tables.gx2_gname
    #---
    roi_ = cx2_roi[cx]
    gx = cx2_gx[cx]
    img_fname = gx2_gname[gx]
    img_fpath = os.path.join(hs.dirs.img_dir, img_fname)
    #---
    print('testing segment')
    seg_chip, img_mask = segment(img_fpath, roi_, new_size=None)
    from hsviz import viz
    viz.show_image(hs, gx, fnum=1, pnum=131, title='original', docla=True)
    df2.imshow(img_mask, fnum=1, pnum=132, title='mask')
    df2.imshow(seg_chip, fnum=1, pnum=133, title='segmented')
Esempio n. 5
0
def im(img, fnum=0):
    from hsviz import draw_func2 as df2
    df2.imshow(img, fnum=fnum)
    df2.update()
Esempio n. 6
0
def test_clean_mask(chip_mask):
    from hsviz import draw_func2 as df2
    mask = chip_mask
    print('Cleaning')
    mask2 = clean_mask(mask, 0, 3, .020)
    mask3 = clean_mask(mask, 3, 0, .023)
    mask4 = clean_mask(mask, 3, 3, .025)
    mask5 = clean_mask(mask4, 2, 3, .025)
    mask6 = clean_mask(mask5, 1, 0, .025)
    mask7 = clean_mask(mask6, 1, 0, .025)
    mask8 = clean_mask(mask7, 1, 0, .025)
    mask9 = clean_mask(mask8, 1, 3, .025)
    print('Drawing')
    df2.imshow(mask,  pnum=331)
    df2.imshow(mask2, pnum=332)
    df2.imshow(mask3, pnum=333)
    df2.imshow(mask4, pnum=334)
    df2.imshow(mask5, pnum=335)
    df2.imshow(mask6, pnum=336)
    df2.imshow(mask7, pnum=337)
    df2.imshow(mask8, pnum=338)
    df2.imshow(mask9, pnum=339)
    print('Updating')
    df2.update()
    print('Done')
Esempio n. 7
0
    res = hs.query(cx)
    nTop = 2
    for tx in xrange(nTop):
        cx2 = res.topN_cxs(hs)[tx]
        dstimg1, dstimg2, args_, kwargs_ = test_result_coverage(
            hs, res, cx2, scale_factor)
        test_find_coverage_score(hs, res)
        res.show_chipres(hs, cx2, fnum=fnum)
        df2.set_figtitle('matching viz' + str(tx), incanvas=False)
        fnum += 1

        df2.show_chipmatch2(dstimg1, dstimg2, *args_, fnum=fnum, **kwargs_)
        df2.set_figtitle('matching coverage' + str(tx))
        fnum += 1

    df2.imshow(srcimg, fnum=fnum, heatmap=True)
    df2.set_figtitle('gaussian weights')
    fnum += 1

    df2.imshow(dstimg, fnum=fnum, heatmap=True)
    df2.set_figtitle('chip coverage map')
    fnum += 1

    df2.imshow(dstimg_thresh, fnum=fnum, heatmap=True)
    df2.set_figtitle('thresholded chip coverage map')
    fnum += 1

    viz.show_chip(hs, cx, fnum=fnum)
    df2.set_figtitle('chip', incanvas=False)
    fnum += 1
    exec(viz.df2.present())
Esempio n. 8
0
def im(img, fnum=0):
    from hsviz import draw_func2 as df2
    df2.imshow(img, fnum=fnum)
    df2.update()
Esempio n. 9
0
def test_clean_mask(chip_mask):
    from hsviz import draw_func2 as df2
    mask = chip_mask
    print('Cleaning')
    mask2 = clean_mask(mask, 0, 3, .020)
    mask3 = clean_mask(mask, 3, 0, .023)
    mask4 = clean_mask(mask, 3, 3, .025)
    mask5 = clean_mask(mask4, 2, 3, .025)
    mask6 = clean_mask(mask5, 1, 0, .025)
    mask7 = clean_mask(mask6, 1, 0, .025)
    mask8 = clean_mask(mask7, 1, 0, .025)
    mask9 = clean_mask(mask8, 1, 3, .025)
    print('Drawing')
    df2.imshow(mask, pnum=331)
    df2.imshow(mask2, pnum=332)
    df2.imshow(mask3, pnum=333)
    df2.imshow(mask4, pnum=334)
    df2.imshow(mask5, pnum=335)
    df2.imshow(mask6, pnum=336)
    df2.imshow(mask7, pnum=337)
    df2.imshow(mask8, pnum=338)
    df2.imshow(mask9, pnum=339)
    print('Updating')
    df2.update()
    print('Done')