Example #1
0
def gridsearch_addWeighted():
    r"""
    CommandLine:
        python -m vtool.blend --test-gridsearch_addWeighted --show

    Example:
        >>> # GRIDSEARCH
        >>> from vtool.blend import *  # NOQA
        >>> gridsearch_addWeighted()
        >>> ut.show_if_requested()
    """
    import cv2
    import vtool as vt

    def test_func(src1, src2, alpha=1.0, **kwargs):
        beta = 1.0 - alpha
        src1 = vt.rectify_to_float01(src1)
        src2 = vt.rectify_to_float01(src2)
        dst = np.empty(src1.shape, dtype=src1.dtype)
        cv2.addWeighted(src1=src1,
                        src2=src2,
                        dst=dst,
                        alpha=alpha,
                        beta=beta,
                        dtype=-1,
                        **kwargs)
        return dst

    img1, img2 = testdata_blend()
    args = img1, img2 = vt.make_channels_comparable(img1, img2)
    param_info = ut.ParamInfoList(
        'blend_params',
        [
            ut.ParamInfo('alpha', .8, varyvals=np.linspace(0, 1.0,
                                                           5).tolist()),
            #ut.ParamInfo('beta', .8,
            ut.ParamInfo('gamma', .0, varyvals=np.linspace(0, 1.0,
                                                           5).tolist()),
            #varyvals=[.0],))
            #ut.ParamInfo('gamma', .8, 'alpha=',
            #             varyvals=np.linspace(0, 1.0, 9).tolist()),
        ])
    gridsearch_image_function(param_info, test_func, args)
from six.moves import map
import six  # NOQA
from wbia import constants as const
from wbia.init import sysres
from wbia.algo.hots import hstypes

print, rrr, profile = ut.inject2(__name__)
logger = logging.getLogger('wbia')

DCVS_DEFAULT = ut.ParamInfoList(
    'distinctivness',
    [
        ut.ParamInfo('dcvs_power', 1.0, 'p', varyvals=[0.5, 1.0, 1.5, 2.0]),
        ut.ParamInfo(
            'dcvs_min_clip', 0.2, 'mn', varyvals=[0.2, 0.02, 0.03][0:1]),
        ut.ParamInfo('dcvs_max_clip',
                     0.5,
                     'mx',
                     varyvals=[0.05, 0.3, 0.4, 0.45, 0.5, 1.0][1:4]),
        ut.ParamInfo('dcvs_K', 5, 'dcvsK', varyvals=[5, 7, 15][0:1]),
    ],
)

DISTINCTIVENESS_NORMALIZER_CACHE = {}
BASELINE_DISTINCTIVNESS_URLS = {
    # TODO: Populate
    'zebra_grevys': const.ZIPPED_URLS.GZ_DISTINCTIVE,
    'zebra_plains': const.ZIPPED_URLS.PZ_DISTINCTIVE,
}
PUBLISH_DIR = ut.unixpath('~/Dropbox/IBEIS')
Example #3
0
#import six
#from six import next
import cv2
import numpy as np
import utool as ut
from vtool import patch as ptool
from vtool import keypoint as ktool
print, rrr, profile = ut.inject2(__name__, '[cov]', DEBUG=False)

# TODO: integrate more
COVKPTS_DEFAULT = ut.ParamInfoList('coverage_kpts', [
    ut.ParamInfo('cov_agg_mode', 'max'),
    ut.ParamInfo('cov_blur_ksize', (5, 5)),
    ut.ParamInfo('cov_blur_on', True),
    ut.ParamInfo('cov_blur_sigma', 5.0),
    ut.ParamInfo('cov_remove_scale', True),
    ut.ParamInfo('cov_remove_shape', True),
    ut.ParamInfo('cov_scale_factor', .3),
    ut.ParamInfo('cov_size_penalty_frac', .1),
    ut.ParamInfo('cov_size_penalty_on', True),
    ut.ParamInfo('cov_size_penalty_power', .5),
])


@profile
#@ut.memprof
def make_kpts_coverage_mask(kpts,
                            chipsize,
                            weights=None,
                            return_patch=False,
                            patch=None,
                            resize=False,
Example #4
0
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from six.moves import zip, range, map  # NOQA
import numpy as np
import utool as ut
import cv2
from vtool import coverage_kpts
print, print_, profile = ut.inject2(__name__, '[covgrid]', DEBUG=False)


# TODO: integrate more
COVGRID_DEFAULT = ut.ParamInfoList('coverage_grid', [
    ut.ParamInfo('pxl_per_bin', 10, 'ppb', varyvals=[20, 5, 1]),
    ut.ParamInfo('grid_steps', 3, 'stps', varyvals=[1, 3, 7]),
    ut.ParamInfo('grid_sigma', 1.6, 'sigma', varyvals=[1.0, 1.6]),
])


def make_grid_coverage_mask(kpts, chipsize, weights, pxl_per_bin=4,
                            grid_steps=1, resize=False, out=None, grid_sigma=1.6):
    r"""
    Args:
        kpts (ndarray[float32_t, ndim=2]):  keypoint
        chipsize (tuple):  width, height
        weights (ndarray[float32_t, ndim=1]):
        pxl_per_bin (float):
        grid_steps (int):

    Returns:
        ndarray: weightgrid
Example #5
0
def gridsearch_chipextract():
    r"""
    CommandLine:
        python -m vtool.chip --test-gridsearch_chipextract --show

    Example:
        >>> # GRIDSEARCH
        >>> from vtool.chip import *  # NOQA
        >>> gridsearch_chipextract()
        >>> ut.show_if_requested()
    """
    import cv2
    test_func = extract_chip_from_img
    if False:
        gpath = ut.grab_test_imgpath('carl.jpg')
        bbox = (100, 3, 100, 100)
        theta = 0.0
        new_size = (58, 34)
    else:
        gpath = '/media/raid/work/GZ_Master1/_ibsdb/images/1524525d-2131-8770-d27c-3a5f9922e9e9.jpg'
        bbox = (450, 373, 2062, 1124)
        theta = 0.0
        old_size = bbox[2:4]
        #target_area = 700 ** 2
        target_area = 1200**2
        new_size = get_scaled_sizes_with_area(target_area, [old_size])[0]
        print('old_size = %r' % (old_size, ))
        print('new_size = %r' % (new_size, ))
        #new_size = (677, 369)
    imgBGR = gtool.imread(gpath)
    args = (imgBGR, bbox, theta, new_size)
    param_info = ut.ParamInfoList(
        'extract_params',
        [
            ut.ParamInfo(
                'interpolation',
                cv2.INTER_LANCZOS4,
                varyvals=[
                    cv2.INTER_LANCZOS4,
                    cv2.INTER_CUBIC,
                    cv2.INTER_LINEAR,
                    cv2.INTER_NEAREST,
                    #cv2.INTER_AREA
                ],
            )
        ])
    show_func = None
    # Generalize
    import plottool as pt
    pt.imshow(imgBGR)  # HACK
    cfgdict_list, cfglbl_list = param_info.get_gridsearch_input(
        defaultslice=slice(0, 10))
    fnum = pt.ensure_fnum(None)
    if show_func is None:
        show_func = pt.imshow
    lbl = ut.get_funcname(test_func)
    cfgresult_list = [
        test_func(*args, **cfgdict)
        for cfgdict in ut.ProgressIter(cfgdict_list, lbl=lbl)
    ]
    onclick_func = None
    ut.interact_gridsearch_result_images(show_func,
                                         cfgdict_list,
                                         cfglbl_list,
                                         cfgresult_list,
                                         fnum=fnum,
                                         figtitle=lbl,
                                         unpack=False,
                                         max_plots=25,
                                         onclick_func=onclick_func)
    pt.iup()