def debug_nnindexer(nnindexer): r""" Makes sure the indexer has valid SIFT descriptors """ # FIXME: they might not agree if data has been added / removed init_data, extra_data = nnindexer.flann.get_indexed_data() with ut.Indenter('[NNINDEX_DEBUG]'): print('extra_data = %r' % (extra_data,)) print('init_data = %r' % (init_data,)) print('nnindexer.max_distance_sqrd = %r' % (nnindexer.max_distance_sqrd,)) data_agrees = nnindexer.idx2_vec is nnindexer.flann.get_indexed_data()[0] if data_agrees: print('indexed_data agrees') assert vt.check_sift_validity(init_data), 'bad SIFT properties' assert data_agrees, 'indexed data does not agree'
def _assert_siftvec(sift): import vtool as vt assert vt.check_sift_validity(sift)
def detect_feats(img_fpath, use_adaptive_scale=False, nogravity_hack=False, **kwargs): r""" driver function for detecting hessian affine keypoints from an image path. extra parameters can be passed to the hessian affine detector by using kwargs. Args: img_fpath (str): image file path on disk use_adaptive_scale (bool): nogravity_hack (bool): Kwargs: numberOfScales (int) : default=3 threshold (float) : default=5.33333333333 edgeEigenValueRatio (float) : default=10.0 border (int) : default=5 maxIterations (int) : default=16 convergenceThreshold (float) : default=0.05 smmWindowSize (int) : default=19 mrSize (float) : default=5.19615242271 spatialBins (int) : default=4 orientationBins (int) : default=8 maxBinValue (float) : default=0.2 initialSigma (float) : default=1.6 patchSize (int) : default=41 scale_min (float) : default=-1.0 scale_max (float) : default=-1.0 rotation_invariance (bool) : default=False affine_invariance (bool) : default=True Returns: tuple : (kpts, vecs) CommandLine: python -m pyhesaff detect_feats python -m pyhesaff detect_feats --show python -m pyhesaff detect_feats --show --fname star.png python -m pyhesaff detect_feats --show --fname zebra.jpg python -m pyhesaff detect_feats --show --fname lena.png python -m pyhesaff detect_feats --show --fname carl.jpg python -m pyhesaff detect_feats --show --fname lena.png --ri python -m pyhesaff detect_feats --show --fname lena.png --ai python -m pyhesaff detect_feats --show --fname easy1.png --no-ai python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --numberOfScales=1 --verbose python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --scale-max=100 --verbose python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --scale-min=20 --verbose python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --scale-min=100 --verbose python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --scale-max=20 --verbose python -m vtool.test_constrained_matching visualize_matches --show python -m vtool.tests.dummy testdata_ratio_matches --show python -m pyhesaff detect_feats --show --fname easy1.png --ai \ --verbose --rebuild-hesaff --scale-min=35 --scale-max=40 --no-rmbuild python -m pyhesaff detect_feats --show --fname easy1.png --ai \ --verbose --scale-min=35 --scale-max=40& python -m pyhesaff detect_feats --show --fname easy1.png --no-ai \ --verbose --scale-min=35 --scale-max=40& python -m pyhesaff detect_feats --show --fname easy1.png --no-ai \ --verbose --scale-max=40 --darken .5 python -m pyhesaff detect_feats --show --fname easy1.png --no-ai \ --verbose --scale-max=30 --darken .5 python -m pyhesaff detect_feats --show --fname easy1.png --ai \ --verbose --scale-max=30 --darken .5 # DENSE KEYPOINTS python -m pyhesaff detect_feats --show --fname lena.png \ --no-affine-invariance --numberOfScales=1 --maxPyramidLevels=1 \ --use_dense --dense_stride=64 python -m pyhesaff detect_feats --show --fname lena.png \ --no-affine-invariance --numberOfScales=1 --maxPyramidLevels=1 \ --use_dense --dense_stride=64 --rotation-invariance python -m pyhesaff detect_feats --show --fname lena.png \ --affine-invariance --numberOfScales=1 --maxPyramidLevels=1 \ --use_dense --dense_stride=64 python -m pyhesaff detect_feats --show --fname lena.png \ --no-affine-invariance --numberOfScales=3 \ --maxPyramidLevels=2 --use_dense --dense_stride=32 python -m pyhesaff detect_feats --show --only_count=False Example0: >>> # ENABLE_DOCTEST >>> # Test simple detect >>> from pyhesaff._pyhesaff import * # NOQA >>> import plottool as pt >>> import utool as ut >>> import vtool as vt >>> TAU = 2 * np.pi >>> fpath = ut.grab_test_imgpath(ut.get_argval('--fname', default='lena.png')) >>> theta = ut.get_argval('--theta', float, 0) # TAU * 3 / 8) >>> img_fpath = vt.rotate_image_ondisk(fpath, theta) >>> kwargs = argparse_hesaff_params() >>> print('kwargs = %r' % (kwargs,)) >>> (kpts_list, vecs_list) = detect_feats(img_fpath, **kwargs) >>> kpts = kpts_list >>> vecs = vecs_list >>> # Show keypoints >>> imgBGR = vt.imread(img_fpath) >>> ut.quit_if_noshow() >>> pt.interact_keypoints.ishow_keypoints(imgBGR, kpts, vecs, ori=True, ell_alpha=.4, color='distinct') >>> pt.set_figtitle('Detect Kpts in Image') >>> pt.show_if_requested() """ if __DEBUG__: print('[hes] Detecting Keypoints') print('[hes] use_adaptive_scale=%r' % (use_adaptive_scale, )) print('[hes] nogravity_hack=%r' % (nogravity_hack, )) print('[hes] kwargs=%s' % (ut.dict_str(kwargs), )) # Load image hesaff_ptr = _new_fpath_hesaff(img_fpath, **kwargs) if __DEBUG__: print('[hes] detect') # Get num detected nKpts = HESAFF_CLIB.detect(hesaff_ptr) if __DEBUG__: print('[hes] allocate') # Allocate arrays kpts = alloc_kpts(nKpts) vecs = alloc_vecs(nKpts) if __DEBUG__: print('[hes] export') # Populate arrays HESAFF_CLIB.exportArrays(hesaff_ptr, nKpts, kpts, vecs) HESAFF_CLIB.free_hesaff(hesaff_ptr) if __DEBUG__: import vtool as vt assert vt.check_sift_validity(vecs) if use_adaptive_scale: # Adapt scale if requested if __DEBUG__: print('[hes] adapt_scale') kpts, vecs = adapt_scale(img_fpath, kpts) if nogravity_hack: if __DEBUG__: print('[hes] adapt_rotation') kpts, vecs = vtool_adapt_rotation(img_fpath, kpts) return kpts, vecs
def detect_feats(img_fpath, use_adaptive_scale=False, nogravity_hack=False, **kwargs): r""" driver function for detecting hessian affine keypoints from an image path. extra parameters can be passed to the hessian affine detector by using kwargs. Args: img_fpath (str): image file path on disk use_adaptive_scale (bool): nogravity_hack (bool): Kwargs: numberOfScales (int) : default=3 threshold (float) : default=5.33333333333 edgeEigenValueRatio (float) : default=10.0 border (int) : default=5 maxIterations (int) : default=16 convergenceThreshold (float) : default=0.05 smmWindowSize (int) : default=19 mrSize (float) : default=5.19615242271 spatialBins (int) : default=4 orientationBins (int) : default=8 maxBinValue (float) : default=0.2 initialSigma (float) : default=1.6 patchSize (int) : default=41 scale_min (float) : default=-1.0 scale_max (float) : default=-1.0 rotation_invariance (bool) : default=False affine_invariance (bool) : default=True Returns: tuple : (kpts, vecs) CommandLine: python -m pyhesaff detect_feats python -m pyhesaff detect_feats --show python -m pyhesaff detect_feats --show --fname star.png python -m pyhesaff detect_feats --show --fname lena.png python -m pyhesaff detect_feats --show --fname carl.jpg python -m pyhesaff detect_feats --show --fname lena.png --ri python -m pyhesaff detect_feats --show --fname lena.png --ai python -m pyhesaff detect_feats --show --fname easy1.png --no-ai python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --numberOfScales=1 --verbose python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --scale-max=100 --verbose python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --scale-min=20 --verbose python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --scale-min=100 --verbose python -m pyhesaff detect_feats --show --fname easy1.png --no-ai --scale-max=20 --verbose python -m vtool.test_constrained_matching visualize_matches --show python -m vtool.tests.dummy testdata_ratio_matches --show python -m pyhesaff detect_feats --show --fname easy1.png --ai \ --verbose --rebuild-hesaff --scale-min=35 --scale-max=40 --no-rmbuild python -m pyhesaff detect_feats --show --fname easy1.png --ai \ --verbose --scale-min=35 --scale-max=40& python -m pyhesaff detect_feats --show --fname easy1.png --no-ai \ --verbose --scale-min=35 --scale-max=40& python -m pyhesaff detect_feats --show --fname easy1.png --no-ai \ --verbose --scale-max=40 --darken .5 python -m pyhesaff detect_feats --show --fname easy1.png --no-ai \ --verbose --scale-max=30 --darken .5 python -m pyhesaff detect_feats --show --fname easy1.png --ai \ --verbose --scale-max=30 --darken .5 # DENSE KEYPOINTS python -m pyhesaff detect_feats --show --fname lena.png \ --no-affine-invariance --numberOfScales=1 --maxPyramidLevels=1 \ --use_dense --dense_stride=64 python -m pyhesaff detect_feats --show --fname lena.png \ --no-affine-invariance --numberOfScales=1 --maxPyramidLevels=1 \ --use_dense --dense_stride=64 --rotation-invariance python -m pyhesaff detect_feats --show --fname lena.png \ --affine-invariance --numberOfScales=1 --maxPyramidLevels=1 \ --use_dense --dense_stride=64 python -m pyhesaff detect_feats --show --fname lena.png \ --no-affine-invariance --numberOfScales=3 \ --maxPyramidLevels=2 --use_dense --dense_stride=32 python -m pyhesaff detect_feats --show --only_count=False Example0: >>> # ENABLE_DOCTEST >>> # Test simple detect >>> from pyhesaff._pyhesaff import * # NOQA >>> import plottool as pt >>> import utool as ut >>> import vtool as vt >>> TAU = 2 * np.pi >>> fpath = ut.grab_test_imgpath(ut.get_argval('--fname', default='lena.png')) >>> theta = ut.get_argval('--theta', float, 0) # TAU * 3 / 8) >>> img_fpath = vt.rotate_image_ondisk(fpath, theta) >>> kwargs = argparse_hesaff_params() >>> (kpts_list, vecs_list) = detect_feats(img_fpath, **kwargs) >>> kpts = kpts_list >>> vecs = vecs_list >>> # Show keypoints >>> imgBGR = vt.imread(img_fpath) >>> ut.quit_if_noshow() >>> pt.interact_keypoints.ishow_keypoints(imgBGR, kpts, vecs, ori=True, ell_alpha=.4, color='distinct') >>> pt.set_figtitle('Detect Kpts in Image') >>> pt.show_if_requested() """ if __DEBUG__: print('[hes] Detecting Keypoints') print('[hes] use_adaptive_scale=%r' % (use_adaptive_scale,)) print('[hes] nogravity_hack=%r' % (nogravity_hack,)) print('[hes] kwargs=%s' % (ut.dict_str(kwargs),)) # Load image hesaff_ptr = _new_fpath_hesaff(img_fpath, **kwargs) if __DEBUG__: print('[hes] detect') # Get num detected nKpts = HESAFF_CLIB.detect(hesaff_ptr) if __DEBUG__: print('[hes] allocate') # Allocate arrays kpts = alloc_kpts(nKpts) vecs = alloc_vecs(nKpts) if __DEBUG__: print('[hes] export') # Populate arrays HESAFF_CLIB.exportArrays(hesaff_ptr, nKpts, kpts, vecs) HESAFF_CLIB.free_hesaff(hesaff_ptr) if __DEBUG__: import vtool as vt assert vt.check_sift_validity(vecs) if use_adaptive_scale: # Adapt scale if requested if __DEBUG__: print('[hes] adapt_scale') kpts, vecs = adapt_scale(img_fpath, kpts) if nogravity_hack: if __DEBUG__: print('[hes] adapt_rotation') kpts, vecs = vtool_adapt_rotation(img_fpath, kpts) return kpts, vecs