def get_thread_thumb_info(bbox_list, theta_list, thumbsize, img_size): r""" Args: bbox_list (list): theta_list (list): thumbsize (?): img_size (?): CommandLine: python -m guitool.api_thumb_delegate --test-get_thread_thumb_info Example: >>> # ENABLE_DOCTEST >>> from guitool.api_thumb_delegate import * # NOQA >>> # build test data >>> bbox_list = [(100, 50, 400, 200)] >>> theta_list = [0] >>> thumbsize = 128 >>> img_size = 600, 300 >>> # execute function >>> result = get_thread_thumb_info(bbox_list, theta_list, thumbsize, img_size) >>> # verify results >>> print(result) ((128, 64), [[[21, 11], [107, 11], [107, 53], [21, 53], [21, 11]]]) """ theta_list = [theta_list] if not ut.is_listlike(theta_list) else theta_list max_dsize = (thumbsize, thumbsize) dsize, sx, sy = vt.resized_clamped_thumb_dims(img_size, max_dsize) # Compute new verts list new_verts_list = list(vt.scaled_verts_from_bbox_gen(bbox_list, theta_list, sx, sy)) return dsize, new_verts_list
def nosql_draw2(check_func, match): from matplotlib.backends.backend_agg import FigureCanvas try: from matplotlib.backends.backend_agg import Figure except ImportError: from matplotlib.figure import Figure was_interactive = mpl.is_interactive() if was_interactive: mpl.interactive(False) # fnum = 32 fig = Figure() canvas = FigureCanvas(fig) # NOQA # fig.clf() ax = fig.add_subplot(1, 1, 1) if check_func is not None and check_func(): return ax, xywh1, xywh2 = match.show(ax=ax) if check_func is not None and check_func(): return savekw = { # 'dpi' : 60, 'dpi': 80, } axes_extents = pt.extract_axes_extents(fig) # assert len(axes_extents) == 1, 'more than one axes' extent = axes_extents[0] with io.BytesIO() as stream: # This call takes 23% - 15% of the time depending on settings fig.savefig(stream, bbox_inches=extent, **savekw) stream.seek(0) data = np.fromstring(stream.getvalue(), dtype=np.uint8) if check_func is not None and check_func(): return pt.plt.close(fig) image = cv2.imdecode(data, 1) thumbsize = 221 max_dsize = (thumbsize, thumbsize) dsize, sx, sy = vt.resized_clamped_thumb_dims( vt.get_size(image), max_dsize) if check_func is not None and check_func(): return image = vt.resize(image, dsize) vt.imwrite(fpath, image) if check_func is not None and check_func(): return
def draw_thumb_helper(tup): thumbsize, gpath, orient, bbox_list, theta_list = tup # time consuming # img = vt.imread(gpath, orient=orient) img = vt.imread(gpath) (gh, gw) = img.shape[0:2] img_size = (gw, gh) if isinstance(thumbsize, int): max_dsize = (thumbsize, thumbsize) dsize, sx, sy = vt.resized_clamped_thumb_dims(img_size, max_dsize) elif isinstance(thumbsize, tuple) and len(thumbsize) == 2: th, tw = thumbsize dsize, sx, sy = thumbsize, tw / gw, th / gh else: raise ValueError('Incompatible thumbsize') new_verts_list = list(vt.scaled_verts_from_bbox_gen(bbox_list, theta_list, sx, sy)) # ----------------- # Actual computation thumb = vt.resize(img, dsize) orange_bgr = (0, 128, 255) for new_verts in new_verts_list: thumb = vt.draw_verts(thumb, new_verts, color=orange_bgr, thickness=2) width, height = dsize return thumb, width, height
def nosql_draw(check_func, rchip1_fpath, rchip2_fpath, kpts1, kpts2): # This gets executed in the child thread and does drawing async style #from matplotlib.backends.backend_pdf import FigureCanvasPdf as FigureCanvas #from matplotlib.backends.backend_pdf import Figure #from matplotlib.backends.backend_svg import FigureCanvas #from matplotlib.backends.backend_svg import Figure from matplotlib.backends.backend_agg import FigureCanvas try: from matplotlib.backends.backend_agg import Figure except ImportError: from matplotlib.figure import Figure kpts1_ = vt.offset_kpts(kpts1, (0, 0), (resize_factor, resize_factor)) kpts2_ = vt.offset_kpts(kpts2, (0, 0), (resize_factor, resize_factor)) #from matplotlib.figure import Figure if check_func is not None and check_func(): return rchip1 = vt.imread(rchip1_fpath) rchip1 = vt.resize_image_by_scale(rchip1, resize_factor) if check_func is not None and check_func(): return rchip2 = vt.imread(rchip2_fpath) rchip2 = vt.resize_image_by_scale(rchip2, resize_factor) if check_func is not None and check_func(): return try: idx = cm.daid2_idx[daid] fm = cm.fm_list[idx] fsv = None if cm.fsv_list is None else cm.fsv_list[idx] fs = None if fsv is None else fsv.prod(axis=1) except KeyError: fm = [] fs = None fsv = None maxnum = 200 if fs is not None and len(fs) > maxnum: # HACK TO ONLY SHOW TOP MATCHES sortx = fs.argsort()[::-1] fm = fm.take(sortx[:maxnum], axis=0) fs = fs.take(sortx[:maxnum], axis=0) was_interactive = mpl.is_interactive() if was_interactive: mpl.interactive(False) #fnum = 32 fig = Figure() canvas = FigureCanvas(fig) # NOQA #fig.clf() ax = fig.add_subplot(1, 1, 1) if check_func is not None and check_func(): return #fig = pt.plt.figure(fnum) #H1 = np.eye(3) #H2 = np.eye(3) #H1[0, 0] = .5 #H1[1, 1] = .5 #H2[0, 0] = .5 #H2[1, 1] = .5 ax, xywh1, xywh2 = pt.show_chipmatch2(rchip1, rchip2, kpts1_, kpts2_, fm, fs=fs, colorbar_=False, ax=ax) if check_func is not None and check_func(): return savekw = { # 'dpi' : 60, 'dpi' : 80, } axes_extents = pt.extract_axes_extents(fig) #assert len(axes_extents) == 1, 'more than one axes' extent = axes_extents[0] with io.BytesIO() as stream: # This call takes 23% - 15% of the time depending on settings fig.savefig(stream, bbox_inches=extent, **savekw) stream.seek(0) data = np.fromstring(stream.getvalue(), dtype=np.uint8) if check_func is not None and check_func(): return pt.plt.close(fig) image = cv2.imdecode(data, 1) thumbsize = 221 max_dsize = (thumbsize, thumbsize) dsize, sx, sy = vt.resized_clamped_thumb_dims(vt.get_size(image), max_dsize) if check_func is not None and check_func(): return image = vt.resize(image, dsize) vt.imwrite(fpath, image) if check_func is not None and check_func(): return