forked from Erotemic/ibeis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_devcmds_ibeis.py
189 lines (157 loc) · 5.97 KB
/
_devcmds_ibeis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# This is supposed to be pristine, it turns out to be mostly clutter
from __future__ import absolute_import, division, print_function
import six
from _devscript import devcmd
from six.moves import zip
from os.path import split, join, expanduser
from plottool import draw_func2 as df2
import numpy as np
import utool
import vtool.keypoint as ktool
from ibeis import sysres
from ibeis.dev import ibsfuncs
from ibeis.viz import interact
from ibeis.ingest import ingest_hsdb
@devcmd
def vdd(ibs=None, qaid_list=None):
utool.view_directory(ibs.get_dbdir())
@devcmd('show')
def show_aids(ibs, qaid_list):
for aid in qaid_list:
interact.ishow_chip(ibs, aid, fnum=df2.next_fnum())
@devcmd()
def change_names(ibs, qaid_list):
#next_name = utool.get_arg('--name', str, default='<name>_the_<species>')
next_name = utool.get_arg('--name', str, default='glob')
for aid in qaid_list:
ibs.print_name_table()
#(nid,) = ibs.add_names((next_name,))
ibs.set_annot_names(aid, next_name)
ibs.print_name_table()
ibs.print_annotation_table()
# FIXME:
#new_nid = ibs.get_name_nids(next_name, ensure=False)
#if back is not None:
#back.select_nid(new_nid)
@devcmd('query')
def query_aids(ibs, qaid_list):
qaid2_qres = ibs.query_all(qaid_list)
for qaid in qaid_list:
qres = qaid2_qres[qaid]
interact.ishow_qres(ibs, qres, fnum=df2.next_fnum(), annote_mode=1)
return qaid2_qres
@devcmd('sver')
def sver_aids(ibs, qaid_list):
qaid2_qres = ibs.query_all(qaid_list)
for qaid in qaid_list:
qres = qaid2_qres[qaid]
aid2 = qres.get_top_aids()[0]
interact.ishow_sver(ibs, qaid, aid2, fnum=df2.next_fnum(), annote_mode=1)
return qaid2_qres
@devcmd('cfg')
def printcfg(ibs, qaid_list):
ibs.cfg.printme3()
print(ibs.cfg.query_cfg.get_cfgstr())
@devcmd('list_dbs')
def list_dbs(*args):
ibsdb_list = sysres.get_ibsdb_list()
print('IBEIS Databases:')
print('\n'.join(ibsdb_list))
@devcmd('list_hsdbs')
def list_unconverted_hsdbs(*args):
needs_convert_hsdbs = ingest_hsdb.get_unconverted_hsdbs()
print('NEEDS CONVERSION:')
print('\n'.join(needs_convert_hsdbs))
@devcmd('convert')
def convert_hsdbs(*args):
ingest_hsdb.ingest_unconverted_hsdbs_in_workdir()
@devcmd
def delete_all_feats(ibs, *args):
ibsfuncs.delete_all_features(ibs)
@devcmd
def delete_all_chips(ibs, *args):
ibsfuncs.delete_all_chips(ibs)
MOTHERS_VIEWPOINT_EXPORT_PAIRS = [
[117, 115],
[72, 70],
[45, 43],
]
GZ_VIEWPOINT_EXPORT_PAIRS = [
[495, 559],
[558, 152],
]
def export(ibs, aid_pairs=None):
"""
3 - 4 different animals
2 views of each
matching keypoint coordinates on each annotation
"""
if aid_pairs is None:
if ibs.get_dbname() == 'PZ_MOTHERS':
aid_pair_list = MOTHERS_VIEWPOINT_EXPORT_PAIRS
if ibs.get_dbname() == 'GZ_ALL':
aid_pair_list = GZ_VIEWPOINT_EXPORT_PAIRS
ibs.update_query_cfg(ratio_thresh=1.6)
export_path = expanduser('~/Dropbox/Assignments/dataset')
#utool.view_directory(export_path)
# MOTHERS EG:
for aid_pair in aid_pair_list:
qaid2_qres = ibs.query_intra_encounter(aid_pair)
#ibeis.viz.show_qres(ibs, qaid2_qres.values()[1]); df2.iup()
mrids_list = []
mkpts_list = []
for qaid, qres in six.iteritems(qaid2_qres):
print('Getting kpts from %r' % qaid)
#qres.show_top(ibs)
posrid_list = utool.ensure_iterable(qres.get_classified_pos())
mrids_list.extend([(qaid, posrid) for posrid in posrid_list])
mkpts_list.extend(qres.get_matching_keypoints(ibs, posrid_list))
mkey2_kpts = {}
for mrids_tup, mkpts_tup in zip(mrids_list, mkpts_list):
assert len(mrids_tup) == 2, 'must be a match tuple'
mrids_ = np.array(mrids_tup)
sortx = mrids_.argsort()
mrids_ = mrids_[sortx]
mkpts_ = np.array(mkpts_tup)[sortx]
if sortx[0] == 0:
pass
mkey = tuple(mrids_.tolist())
try:
kpts_list = mkey2_kpts[mkey]
print('append to mkey=%r' % (mkey,))
except KeyError:
print('new mkey=%r' % (mkey,))
kpts_list = []
kpts_list.append(mkpts_)
mkey2_kpts[mkey] = kpts_list
mkeys_list = mkey2_kpts.keys()
mkeys_keypoints = mkey2_kpts.values()
for mkeys, mkpts_list in zip(mkeys_list, mkeys_keypoints):
print(mkeys)
print(len(kpts_list))
kpts1_m = np.vstack([mkpts[0] for mkpts in mkpts_list])
kpts2_m = np.vstack([mkpts[1] for mkpts in mkpts_list])
match_lines = [
repr(
(
tuple(kp1[ktool.LOC_DIMS].tolist()),
tuple(kp2[ktool.LOC_DIMS].tolist()),
)
) + ', '
for kp1, kp2 in zip(kpts1_m, kpts2_m)]
mcpaths_list = ibs.get_annot_cpaths(mkeys)
fnames_list = map(lambda x: split(x)[1], mcpaths_list)
for path in mcpaths_list:
utool.copy(path, export_path)
header_lines = ['# Exported keypoint matches (might be duplicates matches)',
'# matching_aids = %r' % (mkey,)]
header_lines += ['# img%d = %r' % (count, fname) for count, fname in enumerate(fnames_list)]
header_lines += ['# LINE FORMAT: match_pts = [(img1_xy, img2_xy) ... ]']
header_text = '\n'.join(header_lines)
match_text = '\n'.join(['match_pts = ['] + match_lines + [']'])
matchfile_text = '\n'.join([header_text, match_text])
matchfile_name = ('match_aids(%d,%d).txt' % mkey)
matchfile_path = join(export_path, matchfile_name)
utool.write_to(matchfile_path, matchfile_text)
print(header_text)
print(utool.truncate_str(match_text, maxlen=500))