Esempio n. 1
0
def postload_commands(ibs, back):
    """
    Postload commands deal with a specific ibeis database

    ibeis --db PZ_MTEST --occur "*All Images" --query 1
    ibeis --db PZ_MTEST --occur "*All Images" --query-intra

    """
    if ut.NOT_QUIET:
        print('\n[main_cmd] postload_commands')
    if params.args.view_database_directory:
        print('got arg --vdd')
        vdd(ibs)
    if params.args.set_default_dbdir:
        sysres.set_default_dbdir(ibs.get_dbdir())
    if params.args.update_query_cfg is not None:
        # Set query parameters from command line using the --cfg flag
        cfgdict = ut.parse_cfgstr_list(params.args.update_query_cfg)
        print('Custom cfgdict specified')
        print(ut.repr2(cfgdict))
        ibs.update_query_cfg(**cfgdict)
    if params.args.edit_notes:
        ut.editfile(ibs.get_dbnotes_fpath(ensure=True))
    if params.args.delete_cache:
        ibs.delete_cache()
    if params.args.delete_cache_complete:
        ibs.delete_cache(delete_imagesets=True)
    if params.args.delete_query_cache:
        ibs.delete_qres_cache()
    if params.args.set_all_species is not None:
        ibs._overwrite_all_annot_species_to(params.args.set_all_species)
    if params.args.dump_schema:
        ibs.db.print_schema()

    if ut.get_argflag('--ipynb'):
        back.launch_ipy_notebook()

    select_imgsetid = ut.get_argval(('--select-imgsetid', '--imgsetid', '--occur', '--gsid'), None)
    if select_imgsetid is not None:
        print('\n+ --- CMD SELECT IMGSETID=%r ---' % (select_imgsetid,))
        # Whoa: this doesnt work. weird.
        #back.select_imgsetid(select_imgsetid)
        # This might be the root of gui problems
        #back.front._change_imageset(select_imgsetid)
        back.front.select_imageset_tab(select_imgsetid)
        print('L ___ CMD SELECT IMGSETID=%r ___\n' % (select_imgsetid,))
    # Send commands to GUIBack
    if params.args.select_aid is not None:
        if back is not None:
            try:
                ibsfuncs.assert_valid_aids(ibs, (params.args.select_aid,))
            except AssertionError:
                print('Valid RIDs are: %r' % (ibs.get_valid_aids(),))
                raise
            back.select_aid(params.args.select_aid)
    if params.args.select_gid is not None:
        back.select_gid(params.args.select_gid)
    if params.args.select_nid is not None:
        back.select_nid(params.args.select_nid)

    select_name = ut.get_argval('--select-name')
    if select_name is not None:
        import ibeis.gui.guiheaders as gh
        back.ibswgt.select_table_indicies_from_text(gh.NAMES_TREE, select_name,
                                                    allow_table_change=True)

    if ut.get_argflag(('--intra-occur-query', '--query-intra-occur', '--query-intra')):
        back.special_query_funcs['intra_occurrence'](cfgdict={'use_k_padding': False})

    qaid_list = ut.get_argval(('--query-aid', '--query'), type_=list, default=None)

    if qaid_list is not None:
        #qaid_list = params.args.query_aid
        # fix stride case
        if len(qaid_list) == 1 and isinstance(qaid_list[0], tuple):
            qaid_list = list(qaid_list[0])
        daids_mode = ut.get_argval('--daids-mode', type_=str, default=const.VS_EXEMPLARS_KEY)
        back.compute_queries(qaid_list=qaid_list, daids_mode=daids_mode, ranks_top=10)

    if ut.get_argflag('--inc-query'):
        back.incremental_query()

    if ut.get_argflag(('--dbinfo', '--display_dbinfo')):
        back.display_dbinfo()
        pass

    aidcmd = ut.get_argval('--aidcmd', default=None)
    aid = ut.get_argval('--aid', type_=int, default=1)
    if aidcmd:
        #aidcmd = 'Interact image'
        metadata = ibs.get_annot_lazy_dict(aid)
        annot_context_options = metadata['annot_context_options']
        aidcmd_dict = dict(annot_context_options)
        print('aidcmd_dict = %s' % (ut.repr3(aidcmd_dict),))
        command = aidcmd_dict[aidcmd]
        command()
        #import utool
        #utool.embed()
        #back.start_web_server_parallel()

    if ut.get_argflag('--start-web'):
        back.start_web_server_parallel()

    if ut.get_argflag('--name-tab'):
        from ibeis.gui.guiheaders import NAMES_TREE
        back.front.set_table_tab(NAMES_TREE)
        view = back.front.views[NAMES_TREE]
        model = view.model()
        view._set_sort(model.col_name_list.index('nAids'), col_sort_reverse=True)

    if ut.get_argflag('--graph'):
        back.make_qt_graph_interface()

    screengrab_fpath = ut.get_argval('--screengrab')
    if screengrab_fpath:
        from guitool.__PYQT__.QtGui import QPixmap
        from PyQt4.QtTest import QTest
        from PyQt4.QtCore import Qt
        fpath = ut.truepath(screengrab_fpath)
        import guitool
        #ut.embed()
        timer2 = guitool.__PYQT__.QtCore.QTimer()
        done = [1000]

        def delayed_screenshot_func():
            if done[0] == 500:
                #back.mainwin.menubar.triggered.emit(back.mainwin.menuFile)
                print('Mouseclick')
                QTest.mouseClick(back.mainwin.menuFile, Qt.LeftButton)
                # This works
                #QTest.mouseClick(back.front.import_button, Qt.LeftButton)
            if done[0] == 1:
                timer2.stop()
                print('screengrab to %r' % (fpath,))
                screenimg = QPixmap.grabWindow(back.mainwin.winId())
                screenimg.save(fpath, 'jpg')
                ut.startfile(fpath)
                print('lub dub2')
            done[0] -= 1
            return None
        CLICK_FILE_MENU = True
        if CLICK_FILE_MENU:
            #ut.embed()
            #QTest::keyClick(menu, Qt::Key_Down)
            pass
        timer2.delayed_screenshot_func = delayed_screenshot_func
        timer2.timeout.connect(timer2.delayed_screenshot_func)
        timer2.start(1)
        back.mainwin.timer2 = timer2
        guitool.activate_qwindow(back.mainwin)
        #QPixmap.grabWindow(back.mainwin.winId()).save(fpath, 'jpg')
        #ut.startfile(fpath)
        #ut.embed()
        pass

    if params.args.postload_exit:
        print('[main_cmd] postload exit')
        sys.exit(0)
Esempio n. 2
0
def get_annot_texts(ibs, aid_list, **kwargs):
    """ Add each type of text_list to the strings list

    Args:
        ibs (IBEISController):  ibeis controller object
        aid_list (int):  list of annotation ids

    Returns:
        list: annotation_text_list

    CommandLine:
        python -m ibeis.viz.viz_helpers --test-get_annot_texts

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.viz.viz_helpers import *  # NOQA
        >>> import ibeis
        >>> import collections
        >>> ibs = ibeis.opendb('testdb1')
        >>> # Default all kwargs to true
        >>> class KwargsProxy(object):
        ...    def get(self, a, b):
        ...        return True
        >>> kwargs_proxy = KwargsProxy()
        >>> aid_list = ibs.get_valid_aids()[::3]
        >>> # execute function
        >>> annotation_text_list = get_annot_texts(ibs, aid_list, kwargs_proxy=kwargs_proxy)
        >>> # verify results
        >>> result = ut.list_str(annotation_text_list)
        >>> print(result)
        [
            'aid1, gname=easy1.JPG, name=____, nid=-1, , nGt=0, quality=UNKNOWN, yaw=None',
            'aid4, gname=hard1.JPG, name=____, nid=-4, , nGt=0, quality=UNKNOWN, yaw=None',
            'aid7, gname=jeff.png, name=jeff, nid=3, EX, nGt=0, quality=UNKNOWN, yaw=None',
            'aid10, gname=occl2.JPG, name=occl, nid=5, EX, nGt=0, quality=UNKNOWN, yaw=None',
            'aid13, gname=zebra.jpg, name=zebra, nid=7, EX, nGt=0, quality=UNKNOWN, yaw=None',
        ]
    """
    # HACK FOR TEST
    if 'kwargs_proxy' in kwargs:
        kwargs = kwargs['kwargs_proxy']
    try:
        ibsfuncs.assert_valid_aids(ibs, aid_list)
        assert ut.isiterable(aid_list), 'input must be iterable'
        assert all([isinstance(aid, ut.VALID_INT_TYPES) for aid in aid_list]), 'invalid input'
    except AssertionError as ex:
        ut.printex(ex, 'invalid input', 'viz', key_list=['aid_list'])
        raise
    texts_list = []  # list of lists of texts
    if kwargs.get('show_aidstr', True):
        aidstr_list = get_aidstrs(aid_list)
        texts_list.append(aidstr_list)
    if kwargs.get('show_gname', False):
        gname_list = ibs.get_annot_image_names(aid_list)
        texts_list.append(['gname=%s' % gname for gname in gname_list])
    if kwargs.get('show_name', True):
        name_list = ibs.get_annot_names(aid_list)
        texts_list.append(['name=%s' % name for name in name_list])
    if kwargs.get('show_nid', False):
        nid_list = ibs.get_annot_name_rowids(aid_list)
        texts_list.append(['nid=%d' % nid for nid in nid_list])
    if kwargs.get('show_exemplar', True):
        flag_list = ibs.get_annot_exemplar_flags(aid_list)
        texts_list.append(['EX' if flag else '' for flag in flag_list])
    if kwargs.get('show_num_gt', True):
        # FIXME: This should be num_groundtruth with respect to the currently
        # allowed annotations
        nGt_list = ibs.get_annot_num_groundtruth(aid_list)
        texts_list.append(['nGt=%r' % nGt for nGt in nGt_list])
    if kwargs.get('show_quality_text', False):
        qualtext_list = ibs.get_annot_quality_texts(aid_list)
        texts_list.append(list(map(lambda text: 'quality=%s' % text, qualtext_list)))
    if kwargs.get('show_yawtext', False):
        # FIXME: This should be num_groundtruth with respect to the currently
        # allowed annotations
        yawtext_list = ibs.get_annot_yaw_texts(aid_list)
        texts_list.append(list(map(lambda text: 'yaw=%s' % text, yawtext_list)))
    # zip them up to get a tuple for each chip and join the fields
    if len(texts_list) > 0:
        annotation_text_list = [', '.join(tup) for tup in zip(*texts_list)]
    else:
        # no texts were specified return empty string for each input
        annotation_text_list = [''] * len(aid_list)
    return annotation_text_list
Esempio n. 3
0
def get_annot_texts(ibs, aid_list, **kwargs):
    """ Add each type of text_list to the strings list

    Args:
        ibs (IBEISController):  ibeis controller object
        aid_list (int):  list of annotation ids

    Returns:
        list: annotation_text_list

    CommandLine:
        python -m ibeis.viz.viz_helpers --test-get_annot_texts

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.viz.viz_helpers import *  # NOQA
        >>> import ibeis
        >>> import collections
        >>> ibs = ibeis.opendb('testdb1')
        >>> # Default all kwargs to true
        >>> class KwargsProxy(object):
        ...    def get(self, a, b):
        ...        return True
        >>> kwargs_proxy = KwargsProxy()
        >>> aid_list = ibs.get_valid_aids()[::3]
        >>> # execute function
        >>> annotation_text_list = get_annot_texts(ibs, aid_list, kwargs_proxy=kwargs_proxy)
        >>> # verify results
        >>> result = ut.repr2(annotation_text_list, nl=1)
        >>> print(result)
        [
            'aid1, gname=easy1.JPG, name=____, nid=-1, , nGt=0, quality=UNKNOWN, view=left',
            'aid4, gname=hard1.JPG, name=____, nid=-4, , nGt=0, quality=UNKNOWN, view=left',
            'aid7, gname=jeff.png, name=jeff, nid=3, EX, nGt=0, quality=UNKNOWN, view=unknown',
            'aid10, gname=occl2.JPG, name=occl, nid=5, EX, nGt=0, quality=UNKNOWN, view=left',
            'aid13, gname=zebra.jpg, name=zebra, nid=7, EX, nGt=0, quality=UNKNOWN, view=unknown',
        ]
    """
    # HACK FOR TEST
    if 'kwargs_proxy' in kwargs:
        kwargs = kwargs['kwargs_proxy']
    try:
        ibsfuncs.assert_valid_aids(ibs, aid_list)
        assert ut.isiterable(aid_list), 'input must be iterable'
        assert all([isinstance(aid, ut.VALID_INT_TYPES) for aid in aid_list]), 'invalid input'
    except AssertionError as ex:
        ut.printex(ex, 'invalid input', 'viz', key_list=['aid_list'])
        raise
    texts_list = []  # list of lists of texts
    if kwargs.get('show_aidstr', True):
        aidstr_list = get_aidstrs(aid_list)
        texts_list.append(aidstr_list)
    if kwargs.get('show_gname', False):
        gname_list = ibs.get_annot_image_names(aid_list)
        texts_list.append(['gname=%s' % gname for gname in gname_list])
    if kwargs.get('show_name', True):
        name_list = ibs.get_annot_names(aid_list)
        texts_list.append(['name=%s' % name for name in name_list])
    if kwargs.get('show_nid', False):
        nid_list = ibs.get_annot_name_rowids(aid_list)
        texts_list.append(['nid=%d' % nid for nid in nid_list])
    if kwargs.get('show_exemplar', True):
        flag_list = ibs.get_annot_exemplar_flags(aid_list)
        texts_list.append(['EX' if flag else '' for flag in flag_list])
    if kwargs.get('show_num_gt', True):
        # FIXME: This should be num_groundtruth with respect to the currently
        # allowed annotations
        nGt_list = ibs.get_annot_num_groundtruth(aid_list)
        texts_list.append(['nGt=%r' % nGt for nGt in nGt_list])
    if kwargs.get('show_quality_text', False):
        qualtext_list = ibs.get_annot_quality_texts(aid_list)
        texts_list.append(list(map(lambda text: 'quality=%s' % text, qualtext_list)))
    if kwargs.get('show_viewcode', False):
        # FIXME: This should be num_groundtruth with respect to the currently
        # allowed annotations
        viewcode_list = ibs.get_annot_viewpoint_code(aid_list)
        texts_list.append(list(map(lambda text: 'view=%s' % text, viewcode_list)))
    # zip them up to get a tuple for each chip and join the fields
    if len(texts_list) > 0:
        annotation_text_list = [', '.join(tup) for tup in zip(*texts_list)]
    else:
        # no texts were specified return empty string for each input
        annotation_text_list = [''] * len(aid_list)
    return annotation_text_list
Esempio n. 4
0
def postload_commands(ibs, back):
    """
    Postload commands deal with a specific ibeis database

    ibeis --db PZ_MTEST --occur "*All Images" --query 1
    ibeis --db PZ_MTEST --occur "*All Images" --query-intra

    """
    if ut.NOT_QUIET:
        print('\n[main_cmd] postload_commands')
    if params.args.view_database_directory:
        print('got arg --vdd')
        vdd(ibs)
    if params.args.set_default_dbdir:
        sysres.set_default_dbdir(ibs.get_dbdir())
    if params.args.update_query_cfg is not None:
        # Set query parameters from command line using the --cfg flag
        cfgdict = ut.parse_cfgstr_list(params.args.update_query_cfg)
        print('Custom cfgdict specified')
        print(ut.dict_str(cfgdict))
        ibs.update_query_cfg(**cfgdict)
        #print(ibs.cfg.query_cfg.get_cfgstr())
    if params.args.edit_notes:
        ut.editfile(ibs.get_dbnotes_fpath(ensure=True))
    if params.args.delete_cache:
        ibs.delete_cache()
    if params.args.delete_cache_complete:
        ibs.delete_cache(delete_chips=True, delete_imagesets=True)
    if params.args.delete_query_cache:
        ibs.delete_qres_cache()
    if params.args.set_all_species is not None:
        ibs._overwrite_all_annot_species_to(params.args.set_all_species)
    if params.args.dump_schema:
        ibs.db.print_schema()
    # DEPRICATE
    if params.args.set_notes is not None:
        ibs.set_dbnotes(params.args.set_notes)
    if params.args.set_aids_as_hard is not None:
        aid_list = params.args.set_aids_as_hard
        ibs.set_annot_is_hard(aid_list, [True] * len(aid_list))
    #/DEPRICATE

    if ut.get_argflag('--ipynb'):
        back.launch_ipy_notebook()

    select_imgsetid = ut.get_argval(('--select-imgsetid', '--imgsetid', '--occur'), None)
    if select_imgsetid is not None:
        print('\n+ --- CMD SELECT EID=%r ---' % (select_imgsetid,))
        # Whoa: this doesnt work. weird.
        #back.select_imgsetid(select_imgsetid)
        # This might be the root of gui problems
        #back.front._change_imageset(select_imgsetid)
        back.front.select_imageset_tab(select_imgsetid)
        print('L ___ CMD SELECT EID=%r ___\n' % (select_imgsetid,))
    # Send commands to GUIBack
    if params.args.select_aid is not None:
        if back is not None:
            try:
                ibsfuncs.assert_valid_aids(ibs, (params.args.select_aid,))
            except AssertionError:
                print('Valid RIDs are: %r' % (ibs.get_valid_aids(),))
                raise
            back.select_aid(params.args.select_aid)
    if params.args.select_gid is not None:
        back.select_gid(params.args.select_gid)
    if params.args.select_nid is not None:
        back.select_nid(params.args.select_nid)

    select_name = ut.get_argval('--select-name')
    if select_name is not None:
        import ibeis.gui.guiheaders as gh
        back.ibswgt.select_table_indicies_from_text(gh.NAMES_TREE, select_name,
                                                    allow_table_change=True)

    if ut.get_argflag(('--intra-occur-query', '--query-intra-occur', '--query-intra')):
        back.special_query_funcs['intra_occurrence'](cfgdict={'use_k_padding': False})

    qaid_list = ut.get_argval(('--query-aid', '--query'), type_=list, default=None)

    if qaid_list is not None:
        #qaid_list = params.args.query_aid
        # fix stride case
        if len(qaid_list) == 1 and isinstance(qaid_list[0], tuple):
            qaid_list = list(qaid_list[0])
        daids_mode = ut.get_argval('--daids-mode', type_=str, default=const.VS_EXEMPLARS_KEY)
        back.compute_queries(qaid_list=qaid_list, daids_mode=daids_mode, ranks_lt=10)

    if ut.get_argflag('--inc-query'):
        back.incremental_query()

    if ut.get_argflag(('--dbinfo', '--display_dbinfo')):
        back.display_dbinfo()
        pass

    aidcmd = ut.get_argval('--aidcmd', default=None)
    aid = ut.get_argval('--aid', type_=int, default=1)
    if aidcmd:
        #aidcmd = 'Interact image'
        metadata = ibs.get_annot_lazy_dict(aid)
        annot_context_options = metadata['annot_context_options']
        aidcmd_dict = dict(annot_context_options)
        print('aidcmd_dict = %s' % (ut.repr3(aidcmd_dict),))
        command = aidcmd_dict[aidcmd]
        command()
        #import utool
        #utool.embed()
        #back.start_web_server_parallel()

    if ut.get_argflag('--start-web'):
        back.start_web_server_parallel()

    screengrab_fpath = ut.get_argval('--screengrab')
    if screengrab_fpath:
        from guitool.__PYQT__.QtGui import QPixmap
        from PyQt4.QtTest import QTest
        from PyQt4.QtCore import Qt
        fpath = ut.truepath(screengrab_fpath)
        import guitool
        #ut.embed()
        timer2 = guitool.__PYQT__.QtCore.QTimer()
        done = [1000]
        def delayed_screenshot_func():
            if done[0] == 500:
                #back.mainwin.menubar.triggered.emit(back.mainwin.menuFile)
                print('Mouseclick')
                QTest.mouseClick(back.mainwin.menuFile, Qt.LeftButton)
                # This works
                #QTest.mouseClick(back.front.import_button, Qt.LeftButton)
            if done[0] == 1:
                timer2.stop()
                print('screengrab to %r' % (fpath,))
                screenimg = QPixmap.grabWindow(back.mainwin.winId())
                screenimg.save(fpath, 'jpg')
                ut.startfile(fpath)
                print('lub dub2')
            done[0] -= 1
            return None
        CLICK_FILE_MENU = True
        if CLICK_FILE_MENU:
            #ut.embed()
            #QTest::keyClick(menu, Qt::Key_Down)
            pass
        timer2.delayed_screenshot_func = delayed_screenshot_func
        timer2.timeout.connect(timer2.delayed_screenshot_func)
        timer2.start(1)
        back.mainwin.timer2 = timer2
        guitool.activate_qwindow(back.mainwin)
        #QPixmap.grabWindow(back.mainwin.winId()).save(fpath, 'jpg')
        #ut.startfile(fpath)
        #ut.embed()
        pass

    if params.args.postload_exit:
        print('[main_cmd] postload exit')
        sys.exit(0)