Python cv2.NORM_HAMMING Examples
The following are 20
code examples of cv2.NORM_HAMMING().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cv2
, or try the search function
.
Example #1
Source File: find_obj.py From OpenCV-Python-Tutorial with MIT License | 10 votes |
def init_feature(name): chunks = name.split('-') if chunks[0] == 'sift': detector = cv2.xfeatures2d.SIFT_create() norm = cv2.NORM_L2 elif chunks[0] == 'surf': detector = cv2.xfeatures2d.SURF_create(800) norm = cv2.NORM_L2 elif chunks[0] == 'orb': detector = cv2.ORB_create(400) norm = cv2.NORM_HAMMING elif chunks[0] == 'akaze': detector = cv2.AKAZE_create() norm = cv2.NORM_HAMMING elif chunks[0] == 'brisk': detector = cv2.BRISK_create() norm = cv2.NORM_HAMMING else: return None, None if 'flann' in chunks: if norm == cv2.NORM_L2: flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) else: flann_params= dict(algorithm = FLANN_INDEX_LSH, table_number = 6, # 12 key_size = 12, # 20 multi_probe_level = 1) #2 matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329) else: matcher = cv2.BFMatcher(norm) return detector, matcher
Example #2
Source File: find_obj.py From PyCV-time with MIT License | 6 votes |
def init_feature(name): chunks = name.split('-') if chunks[0] == 'sift': detector = cv2.SIFT() norm = cv2.NORM_L2 elif chunks[0] == 'surf': detector = cv2.SURF(800) norm = cv2.NORM_L2 elif chunks[0] == 'orb': detector = cv2.ORB(400) norm = cv2.NORM_HAMMING else: return None, None if 'flann' in chunks: if norm == cv2.NORM_L2: flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) else: flann_params= dict(algorithm = FLANN_INDEX_LSH, table_number = 6, # 12 key_size = 12, # 20 multi_probe_level = 1) #2 matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329) else: matcher = cv2.BFMatcher(norm) return detector, matcher
Example #3
Source File: find_obj.py From ImageAnalysis with MIT License | 6 votes |
def init_feature(name): chunks = name.split('-') if chunks[0] == 'sift': detector = cv2.SIFT() norm = cv2.NORM_L2 elif chunks[0] == 'surf': detector = cv2.SURF(400) norm = cv2.NORM_L2 elif chunks[0] == 'orb': detector = cv2.ORB(400) norm = cv2.NORM_HAMMING else: return None, None if 'flann' in chunks: if norm == cv2.NORM_L2: flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) else: flann_params= dict(algorithm = FLANN_INDEX_LSH, table_number = 6, # 12 key_size = 12, # 20 multi_probe_level = 1) #2 matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329) else: matcher = cv2.BFMatcher(norm) return detector, matcher
Example #4
Source File: keypoint_matching_contrib.py From Airtest with Apache License 2.0 | 6 votes |
def init_detector(self): """Init keypoint detector object.""" # BRIEF is a feature descriptor, recommand CenSurE as a fast detector: if check_cv_version_is_new(): # OpenCV3/4, star/brief is in contrib module, you need to compile it seperately. try: self.star_detector = cv2.xfeatures2d.StarDetector_create() self.brief_extractor = cv2.xfeatures2d.BriefDescriptorExtractor_create() except: import traceback traceback.print_exc() print("to use %s, you should build contrib with opencv3.0" % self.METHOD_NAME) raise NoModuleError("There is no %s module in your OpenCV environment !" % self.METHOD_NAME) else: # OpenCV2.x self.star_detector = cv2.FeatureDetector_create("STAR") self.brief_extractor = cv2.DescriptorExtractor_create("BRIEF") # create BFMatcher object: self.matcher = cv2.BFMatcher(cv2.NORM_L1) # cv2.NORM_L1 cv2.NORM_L2 cv2.NORM_HAMMING(not useable)
Example #5
Source File: descriptors.py From hfnet with MIT License | 6 votes |
def matching(desc1, desc2, do_ratio_test=False, cross_check=True): if desc1.dtype == np.bool and desc2.dtype == np.bool: desc1, desc2 = np.packbits(desc1, axis=1), np.packbits(desc2, axis=1) norm = cv2.NORM_HAMMING else: desc1, desc2 = np.float32(desc1), np.float32(desc2) norm = cv2.NORM_L2 if do_ratio_test: matches = [] matcher = cv2.BFMatcher(norm) for m, n in matcher.knnMatch(desc1, desc2, k=2): m.distance = 1.0 if (n.distance == 0) else m.distance / n.distance matches.append(m) else: matcher = cv2.BFMatcher(norm, crossCheck=cross_check) matches = matcher.match(desc1, desc2) return matches_cv2np(matches)
Example #6
Source File: feature_matcher.py From pyslam with GNU General Public License v3.0 | 6 votes |
def __init__(self, norm_type=cv2.NORM_HAMMING, cross_check = False, ratio_test=kRatioTest, type = FeatureMatcherTypes.FLANN): super().__init__(norm_type=norm_type, cross_check=cross_check, ratio_test=ratio_test, type=type) if norm_type == cv2.NORM_HAMMING: # FLANN parameters for binary descriptors FLANN_INDEX_LSH = 6 self.index_params= dict(algorithm = FLANN_INDEX_LSH, # Multi-Probe LSH: Efficient Indexing for High-Dimensional Similarity Search table_number = 6, # 12 key_size = 12, # 20 multi_probe_level = 1) # 2 if norm_type == cv2.NORM_L2: # FLANN parameters for float descriptors FLANN_INDEX_KDTREE = 1 self.index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 4) self.search_params = dict(checks=32) # or pass empty dictionary self.matcher = cv2.FlannBasedMatcher(self.index_params, self.search_params) self.matcher_name = 'FlannFeatureMatcher'
Example #7
Source File: findobj.py From airtest with BSD 3-Clause "New" or "Revised" License | 6 votes |
def init_feature(name): chunks = name.split('-') if chunks[0] == 'sift': detector = cv2.SIFT() norm = cv2.NORM_L2 elif chunks[0] == 'surf': detector = cv2.SURF(800) norm = cv2.NORM_L2 elif chunks[0] == 'orb': detector = cv2.ORB(400) norm = cv2.NORM_HAMMING else: return None, None if 'flann' in chunks: if norm == cv2.NORM_L2: flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) else: flann_params= dict(algorithm = FLANN_INDEX_LSH, table_number = 6, # 12 key_size = 12, # 20 multi_probe_level = 1) #2 matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329) else: matcher = cv2.BFMatcher(norm) return detector, matcher
Example #8
Source File: find_obj.py From airtest with BSD 3-Clause "New" or "Revised" License | 6 votes |
def init_feature(name): chunks = name.split('-') if chunks[0] == 'sift': detector = cv2.SIFT() norm = cv2.NORM_L2 elif chunks[0] == 'surf': detector = cv2.SURF(800) norm = cv2.NORM_L2 elif chunks[0] == 'orb': detector = cv2.ORB(400) norm = cv2.NORM_HAMMING else: return None, None if 'flann' in chunks: if norm == cv2.NORM_L2: flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) else: flann_params= dict(algorithm = FLANN_INDEX_LSH, table_number = 6, # 12 key_size = 12, # 20 multi_probe_level = 1) #2 matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329) else: matcher = cv2.BFMatcher(norm) return detector, matcher
Example #9
Source File: find_obj.py From PyCV-time with MIT License | 5 votes |
def init_feature(name): chunks = name.split('-') if chunks[0] == 'sift': detector = cv2.xfeatures2d.SIFT() norm = cv2.NORM_L2 elif chunks[0] == 'surf': detector = cv2.xfeatures2d.SURF(800) norm = cv2.NORM_L2 elif chunks[0] == 'orb': detector = cv2.ORB(400) norm = cv2.NORM_HAMMING elif chunks[0] == 'akaze': detector = cv2.AKAZE() norm = cv2.NORM_HAMMING elif chunks[0] == 'brisk': detector = cv2.BRISK() norm = cv2.NORM_HAMMING else: return None, None if 'flann' in chunks: if norm == cv2.NORM_L2: flann_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5) else: flann_params= dict(algorithm = FLANN_INDEX_LSH, table_number = 6, # 12 key_size = 12, # 20 multi_probe_level = 1) #2 matcher = cv2.FlannBasedMatcher(flann_params, {}) # bug : need to pass empty dict (#1329) else: matcher = cv2.BFMatcher(norm) return detector, matcher
Example #10
Source File: feature_matcher.py From pyslam with GNU General Public License v3.0 | 5 votes |
def __init__(self, norm_type=cv2.NORM_HAMMING, cross_check = False, ratio_test=kRatioTest, type = FeatureMatcherTypes.BF): super().__init__(norm_type=norm_type, cross_check=cross_check, ratio_test=ratio_test, type=type) self.matcher = cv2.BFMatcher(norm_type, cross_check) self.matcher_name = 'BfFeatureMatcher' # Flann Matcher
Example #11
Source File: feature_matcher.py From pyslam with GNU General Public License v3.0 | 5 votes |
def __init__(self, norm_type=cv2.NORM_HAMMING, cross_check = False, ratio_test=kRatioTest, type = FeatureMatcherTypes.BF): self.type = type self.norm_type = norm_type self.cross_check = cross_check # apply cross check self.matches = [] self.ratio_test = ratio_test self.matcher = None self.matcher_name = '' # input: des1 = queryDescriptors, des2= trainDescriptors # output: idx1, idx2 (vectors of corresponding indexes in des1 and des2, respectively)
Example #12
Source File: feature_matcher.py From pyslam with GNU General Public License v3.0 | 5 votes |
def feature_matcher_factory(norm_type=cv2.NORM_HAMMING, cross_check=False, ratio_test=kRatioTest, type=FeatureMatcherTypes.FLANN): if type == FeatureMatcherTypes.BF: return BfFeatureMatcher(norm_type=norm_type, cross_check=cross_check, ratio_test=ratio_test, type=type) if type == FeatureMatcherTypes.FLANN: return FlannFeatureMatcher(norm_type=norm_type, cross_check=cross_check, ratio_test=ratio_test, type=type) return None
Example #13
Source File: keypoint_matching.py From Airtest with Apache License 2.0 | 5 votes |
def init_detector(self): """Init keypoint detector object.""" self.detector = cv2.ORB_create() # create BFMatcher object: self.matcher = cv2.BFMatcher(cv2.NORM_HAMMING) # cv2.NORM_L1 cv2.NORM_L2 cv2.NORM_HAMMING(not useable)
Example #14
Source File: keypoint_matching.py From Airtest with Apache License 2.0 | 5 votes |
def init_detector(self): """Init keypoint detector object.""" self.detector = cv2.AKAZE_create() # create BFMatcher object: self.matcher = cv2.BFMatcher(cv2.NORM_L1) # cv2.NORM_L1 cv2.NORM_L2 cv2.NORM_HAMMING(not useable)
Example #15
Source File: keypoint_matching.py From Airtest with Apache License 2.0 | 5 votes |
def init_detector(self): """Init keypoint detector object.""" self.detector = cv2.BRISK_create() # create BFMatcher object: self.matcher = cv2.BFMatcher(cv2.NORM_HAMMING) # cv2.NORM_L1 cv2.NORM_L2 cv2.NORM_HAMMING(not useable)
Example #16
Source File: keypoint_base.py From Airtest with Apache License 2.0 | 5 votes |
def init_detector(self): """Init keypoint detector object.""" self.detector = cv2.KAZE_create() # create BFMatcher object: self.matcher = cv2.BFMatcher(cv2.NORM_L1) # cv2.NORM_L1 cv2.NORM_L2 cv2.NORM_HAMMING(not useable)
Example #17
Source File: ftlib.py From sea_ice_drift with GNU General Public License v3.0 | 5 votes |
def _get_matches(descriptors1, descriptors2, matcher, norm, verbose): ''' Match keypoints using BFMatcher with cv2.NORM_HAMMING ''' t0 = time.time() bf = matcher(norm) matches = bf.knnMatch(descriptors1, descriptors2, k=2) t1 = time.time() if verbose: print('Keypoints matched', t1 - t0) return matches
Example #18
Source File: ftlib.py From sea_ice_drift with GNU General Public License v3.0 | 5 votes |
def get_match_coords(keyPoints1, descriptors1, keyPoints2, descriptors2, matcher=cv2.BFMatcher, norm=cv2.NORM_HAMMING, ratio_test=0.7, verbose=True, **kwargs): ''' Filter matching keypoints and convert to X,Y coordinates Parameters ---------- keyPoints1 : list - keypoints on img1 from find_key_points() descriptors1 : list - descriptors on img1 from find_key_points() keyPoints2 : list - keypoints on img2 from find_key_points() descriptors2 : list - descriptors on img2 from find_key_points() matcher : matcher from CV2 norm : int - type of distance ratio_test : float - Lowe ratio verbose : bool - print some output ? Returns ------- x1, y1, x2, y2 : coordinates of start and end of displacement [pixels] ''' matches = _get_matches(descriptors1, descriptors2, matcher, norm, verbose) x1, y1, x2, y2 = _filter_matches(matches, ratio_test, keyPoints1, keyPoints2, verbose) return x1, y1, x2, y2
Example #19
Source File: warp_model.py From IkaLog with Apache License 2.0 | 4 votes |
def __init__(self): if hasattr(self, 'trained') and self.trained: return super(WarpFilterModel, self).__init__() for lang in Localization.get_game_languages(): model_filename = IkaUtils.get_path( 'data', 'webcam_calibration.%s.model' % lang) if os.path.exists(model_filename): break self.detector = cv2.AKAZE_create() self.norm = cv2.NORM_HAMMING self.matcher = cv2.BFMatcher(self.norm) try: self.loadModelFromFile(model_filename) num_keypoints = len(self.calibration_image_keypoints) IkaUtils.dprint('%s: Loaded model data\n %s (%d keypoints)' % (self, model_filename, num_keypoints)) except: IkaUtils.dprint('%s: Could not load model data. Trying to rebuild...' % self) calibration_image = cv2.imread('camera/ika_usbcam/Pause.png', 0) self.calibration_image_size = calibration_image.shape[:2] calibration_image_hight, calibration_image_width = \ calibration_image.shape[ :2] self.calibration_image_keypoints, self.calibration_image_descriptors = \ self.detector.detectAndCompute( calibration_image, None) print(self.calibration_image_keypoints) print(self.calibration_image_descriptors) model_filename = IkaUtils.get_path( 'data', 'webcam_calibration.%s.model' % Localization.get_game_languages()[0] ) self.saveModelToFile(model_filename) IkaUtils.dprint('%s: Created model %s' % (self, model_filename)) self.trained = True
Example #20
Source File: matcher.py From ImageAnalysis with MIT License | 4 votes |
def configure(): global detect_scale global the_matcher global max_distance global min_pairs detect_scale = detector_node.getFloat('scale') detector_str = detector_node.getString('detector') if detector_str == 'SIFT' or detector_str == 'SURF': norm = cv2.NORM_L2 max_distance = 270.0 elif detector_str == 'ORB' or detector_str == 'Star': norm = cv2.NORM_HAMMING max_distance = 64 else: log("Detector not specified or not known:", detector_str) quit() # work around a feature/bug: flann enums don't exist FLANN_INDEX_KDTREE = 1 FLANN_INDEX_LSH = 6 if norm == cv2.NORM_L2: flann_params = { 'algorithm': FLANN_INDEX_KDTREE, 'trees': 5 } else: flann_params = { 'algorithm': FLANN_INDEX_LSH, 'table_number': 6, # 12 'key_size': 12, # 20 'multi_probe_level': 1 #2 } search_params = { 'checks': 100 } the_matcher = cv2.FlannBasedMatcher(flann_params, search_params) min_pairs = matcher_node.getFloat('min_pairs') # Iterate through all the matches for the specified image and # delete keypoints that don't satisfy the homography (or # fundamental) relationship. Returns true if match set is clean, false # if keypoints were removed. # # Notice: this tends to eliminate matches that aren't all on the # same plane, so if the scene has a lot of depth, this could knock # out a lot of good matches.