def show_image(img, cv_kpts=None, fignum=0, title=None): print('Drawing Image') figure(fignum=fignum, doclf=True, title=title) if not cv_kpts is None: img = cv2.drawKeypoints(img, cv_kpts, flags=cv_flags) imshow(img) set_cmap('gray')
l1_energy = np.sum(mysift) l1_energy2 = np.sum(mysift2) l2_energy = np.sqrt(np.sum(mysift**2)) l2_energy2 = np.sqrt(np.sum(mysift2**2)) print('Occlusion Difference: ') print(' FREAK All : '+str(num_diff))+'/512' print(' FREAK Fine : '+str(num_fine_diff))+'/32' print(' FREAK Coarse: '+str(num_coarse_diff))+'/16' print(' ------------') print(' SIFT L2dist : '+str(l2_sift_dist)+\ ' ( / '+str(l1_energy)+' / '+str(l1_energy2)+' / )') print(' SIFT L1dist : '+str(l1_sift_dist)+\ ' ( / '+str(l2_energy)+' / '+str(l2_energy2)+' / )') # FIGURE 5 figure(5, title='Different Freak Dimensions', doclf=True) hist(diff_dims, bins=512, color=[1,0,0]) ax = gca() ax.set_xlim(0,512) # FIGURE 6 figure(6, title='Freak Descriptor Histograms', doclf=True) hist(np.nonzero(myfreak), bins=512, alpha=.3, color=[0,1,0]) hist(np.nonzero(myfreak2), bins=512, alpha=.3, color=[0,0,1]) ax = gca() ax.set_xlim(0,512) show_all_figures() move_all_figures() try: __IPYTHON__
l1_energy = np.sum(mysift) l1_energy2 = np.sum(mysift2) l2_energy = np.sqrt(np.sum(mysift**2)) l2_energy2 = np.sqrt(np.sum(mysift2**2)) print('Occlusion Difference: ') print(' FREAK All : ' + str(num_diff)) + '/512' print(' FREAK Fine : ' + str(num_fine_diff)) + '/32' print(' FREAK Coarse: ' + str(num_coarse_diff)) + '/16' print(' ------------') print(' SIFT L2dist : '+str(l2_sift_dist)+\ ' ( / '+str(l1_energy)+' / '+str(l1_energy2)+' / )') print(' SIFT L1dist : '+str(l1_sift_dist)+\ ' ( / '+str(l2_energy)+' / '+str(l2_energy2)+' / )') # FIGURE 5 figure(5, title='Different Freak Dimensions', doclf=True) hist(diff_dims, bins=512, color=[1, 0, 0]) ax = gca() ax.set_xlim(0, 512) # FIGURE 6 figure(6, title='Freak Descriptor Histograms', doclf=True) hist(np.nonzero(myfreak), bins=512, alpha=.3, color=[0, 1, 0]) hist(np.nonzero(myfreak2), bins=512, alpha=.3, color=[0, 0, 1]) ax = gca() ax.set_xlim(0, 512) show_all_figures() move_all_figures() try: __IPYTHON__
import cv2 from pylab import * from hotspotter.helpers import Timer, figure import os figure(1, doclf=True, title='SIFT Descriptors') figure(2, doclf=True, title='FREAK Descriptors') # Define Image chip_fpath = 'D:/data/work/PZ_flankhack/images/img-0000001.jpg' # Read Image img_ = cv2.imread(chip_fpath) img = cv2.cvtColor(img_, cv2.COLOR_BGR2GRAY) imshow(img) set_cmap('gray') params = { 'kpts_type' :'SIFT'} # Detect and Extract print('Detect and Extract') kpts_detector3 = cv2.FeatureDetector_create(params['kpts_type']) kpts_detector = cv2.PyramidAdaptedFeatureDetector(kpts_detector3, maxLevel=5) #kpts_detector = cv2.GridAdaptedFeatureDetector(kpts_detector3) # max number of features with Timer(name=params['kpts_type']+' Keypoint Detector'): cv_kpts2 = kpts_detector.detect(img) sift_desc_extractor = cv2.DescriptorExtractor_create('SIFT') freak_desc_extractor = cv2.DescriptorExtractor_create('FREAK') with Timer(name='SIFT Descriptors'): (sift_cv_kpts, sift_cv_desc) = sift_desc_extractor.compute(img, cv_kpts2) with Timer(name='FREAK Descriptors'): (freak_cv_kpts, freak_cv_desc) = freak_desc_extractor.compute(img, cv_kpts2) # Draw print('Draw') figure(1)