我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用cv2.NORM_L2。
def extractFeatures(self): if len(self.image) == 0: print 'Warning: No image detected. Features not extracted.' return None else: self.net.blobs['data'].reshape(1, 3, self.crop, self.crop) self.net.blobs['data'].data[...] = self.transformer.preprocess('data', self.image) self.net.forward() features = self.net.blobs[self.layer].data.copy() features = np.reshape(features, (features.shape[0], -1))[0] if cv2.norm(features, cv2.NORM_L2) > 0: features = features / cv2.norm(features, cv2.NORM_L2) return features.tolist()
def normalize_result(webcam, idcard): diff_correy = cv2.norm(settings.COREY_MATRIX, idcard, cv2.NORM_L2) diff_wilde = cv2.norm(settings.WILDE_MATRIX, idcard, cv2.NORM_L2) diff_min = diff_correy if diff_correy < diff_wilde else diff_wilde diff = cv2.norm(webcam, idcard, cv2.NORM_L2) score = float(diff) / float(diff_min) percentage = (1.28 - score * score * score) * 10000 / 128 return { 'percentage': percentage, 'score': score, 'message': utils.matching_message(score) }
def create_vse(vocabulary_path, recognized_visual_words=1000): """Create visual search engine with default configuration.""" ranker = SimpleRanker(hist_comparator=Intersection()) inverted_index = InvertedIndex(ranker=ranker, recognized_visual_words=recognized_visual_words) bag_of_visual_words = BagOfVisualWords(extractor=cv2.xfeatures2d.SURF_create(), matcher=cv2.BFMatcher(normType=cv2.NORM_L2), vocabulary=load(vocabulary_path)) return VisualSearchEngine(inverted_index, bag_of_visual_words)
def build_filters(self, w, h,num_theta, fi, sigma_x, sigma_y, psi): "Get set of filters for GABOR" filters = [] for i in range(num_theta): theta = ((i+1)*1.0 / num_theta) * np.pi for f_var in fi: kernel = self.get_gabor_kernel(w, h,sigma_x, sigma_y, theta, f_var, psi) kernel = 2.0*kernel/kernel.sum() # kernel = cv2.normalize(kernel, kernel, 1.0, 0, cv2.NORM_L2) filters.append(kernel) return filters
def distanceOfFV(self, fv1, fv2): "distance of feature vector 1 and feature vector 2" normset = [] for i in range(len(fv1)): k = fv1[i] p = fv2[i] # k = cv2.normalize(fv1[i],k,1.0,0,norm_type=cv2.NORM_L2) # p = cv2.normalize(fv2[i],p,1.0,0,norm_type=cv2.NORM_L2) normset.append((p-k)**2.0) sums = 0 sums = sum([i.sum() for i in normset]) return mth.sqrt(sums)/100000