当前位置: 首页>>代码示例>>Python>>正文


Python cv2.norm方法代码示例

本文整理汇总了Python中cv2.norm方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.norm方法的具体用法?Python cv2.norm怎么用?Python cv2.norm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cv2的用法示例。


在下文中一共展示了cv2.norm方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def main():
	capture = cv2.VideoCapture(0)
	_, image = capture.read()
	previous = image.copy()
	
	
	while (cv2.waitKey(1) < 0):
		_, image = capture.read()
		diff = cv2.absdiff(image, previous)
		#image = cv2.flip(image, 3)
		#image = cv2.norm(image)
		_, diff = cv2.threshold(diff, 32, 0, cv2.THRESH_TOZERO)
		_, diff = cv2.threshold(diff, 0, 255, cv2.THRESH_BINARY)
		
		diff = cv2.medianBlur(diff, 5)
		
		cv2.imshow('video', diff)
		previous = image.copy()
		
	capture.release()
	cv2.destroyAllWindows() 
开发者ID:petern3,项目名称:crop_row_detection,代码行数:23,代码来源:camera_test.py

示例2: __rotate_image_size_corrected

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def __rotate_image_size_corrected(image, angle):
    # Calculate max size for the rotated template and image offset
    image_size_height, image_size_width = image.shape
    image_center_x = image_size_width // 2
    image_center_y = image_size_height // 2

    # Create rotation matrix
    rotation_matrix = cv2.getRotationMatrix2D((image_center_x, image_center_y), -angle, 1)

    # Apply offset
    new_image_size = int(math.ceil(cv2.norm((image_size_height, image_size_width), normType=cv2.NORM_L2)))
    rotation_matrix[0, 2] += (new_image_size - image_size_width) / 2
    rotation_matrix[1, 2] += (new_image_size - image_size_height) / 2

    # Apply rotation to the template
    image_rotated = cv2.warpAffine(image, rotation_matrix, (new_image_size, new_image_size))
    return image_rotated 
开发者ID:microsoft,项目名称:AI-Robot-Challenge-Lab,代码行数:19,代码来源:cv_detection_right_hand.py

示例3: del_duplicates

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def del_duplicates(pts):
    """Delete one of two potential facelet centers stored in pts if they are too close to each other."""
    delta = width / 12  # width is defined global in grabcolors()
    dele = True
    while dele:
        dele = False
        r = range(len(pts))
        for i in r:
            for j in r[i + 1:]:
                if np.linalg.norm(pts[i] - pts[j]) < delta:
                    del pts[j]
                    dele = True
                if dele:
                    break
            if dele:
                break 
开发者ID:hkociemba,项目名称:RubiksCube-TwophaseSolver,代码行数:18,代码来源:vision2.py

示例4: facelets

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def facelets(pts, med):
    """Separate the candidates into edge and corner facelets by their distance from the medoid."""
    ed = []
    co = []
    if med[0] == 0:
        return co, ed  # no edgefacelets detected
    # find shortest distance
    dmin = 10000
    for p in pts:
        d = np.linalg.norm(p - med)
        if 1 < d < dmin:
            dmin = d
    # edgefacelets should be in a distance not more than dmin*1.3
    for p in pts:
        d = np.linalg.norm(p - med)
        if dmin - 1 < d < dmin * 1.3:
            ed.append(p)
    # now find the corner facelets
    for p in pts:
        d = np.linalg.norm(p - med)
        if dmin * 1.3 < d < dmin * 1.7:
            co.append(p)
    return co, ed 
开发者ID:hkociemba,项目名称:RubiksCube-TwophaseSolver,代码行数:25,代码来源:vision2.py

示例5: filter_matrix_corners_homography

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def filter_matrix_corners_homography(pts, max, matrix) -> (float, List):
        '''
        Compute the images of the image corners and of its center (i.e. the points you get when you apply the homography to those corners and center),
        and verify that they make sense, i.e. are they inside the image canvas (if you expect them to be)? Are they well separated from each other?
        Return a distance and a list of the transformed points
        '''

        # Transform the 4 corners thanks to the transformation matrix calculated
        transformed_pts = cv2.perspectiveTransform(pts, matrix)

        # Compute the difference between original and modified position of points
        dist = round(cv2.norm(pts - transformed_pts, cv2.NORM_L2) / max, 10)  # sqrt((X1-X2)²+(Y1-Y2)²+...)

        # Totally an heuristic (geometry based):
        if dist < 0.20:
            return dist, transformed_pts
        else:
            return 1, transformed_pts 
开发者ID:CIRCL,项目名称:douglas-quaid,代码行数:20,代码来源:distance_ransac_orb.py

示例6: filter_matrix_corners_affine

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def filter_matrix_corners_affine(pts, max, matrix) -> (float, List):
        '''
        Compute the images of the image corners and of its center (i.e. the points you get when you apply the homography to those corners and center),
        and verify that they make sense, i.e. are they inside the image canvas (if you expect them to be)? Are they well separated from each other?
        Return a distance and a list of the transformed points
        '''

        # Make affine transformation
        add_row = np.array([[0, 0, 1]])
        affine_matrix = np.concatenate((matrix, add_row), axis=0)
        transformed_pts_affine = cv2.perspectiveTransform(pts, affine_matrix)

        # Affine distance
        tmp_dist_affine = round(cv2.norm(pts - transformed_pts_affine, cv2.NORM_L2) / max, 10)  # sqrt((X1-X2)²+(Y1-Y2)²+...)

        # Totally an heuristic (geometry based):
        if tmp_dist_affine < 0.20:
            return tmp_dist_affine, transformed_pts_affine
        else:
            return 1, transformed_pts_affine 
开发者ID:CIRCL,项目名称:douglas-quaid,代码行数:22,代码来源:distance_ransac_orb.py

示例7: calculate_distance

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def calculate_distance(self, image, template, scale):
        """Calculate distance."""
        piece_loc = self.find_piece(image, template, scale)
        logger.debug('Piece location: %s', piece_loc)

        if not piece_loc:
            return None

        board_center = self.find_board_center(image, piece_loc, scale)
        logger.debug('Board center location: %s', board_center)

        if not board_center:
            return None

        if self.results_path is not None:
            cv.rectangle(image, piece_loc, piece_loc, (255, 0, 0), 1)
            cv.rectangle(image, board_center, board_center, (255, 0, 0), 1)
            filename = '{}.png'.format(int(time.time()))
            cv.imwrite(os.path.join(self.results_path, filename), image)

        return cv.norm(piece_loc, board_center) 
开发者ID:microdog,项目名称:wechat_automated_jump_game,代码行数:23,代码来源:solver.py

示例8: is_picture

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def is_picture(self):
        sampling_interval = int(math.floor(self.scene_length / 5))
        sampling_frames = list(range(self.start_frame_no + sampling_interval,
                                     self.end_frame_no - sampling_interval + 1, sampling_interval))
        frames = []
        for frame_no in sampling_frames:
            self.video.set(cv2.CAP_PROP_POS_FRAMES, frame_no)
            ret, frame = self.video.read()
            frames.append(frame)

        diff = 0
        n_diff = 0
        for frame, next_frame in zip(frames, frames[1:]):
            diff += cv2.norm(frame, next_frame, cv2.NORM_L1)  # abs diff
            n_diff += 1
        diff /= n_diff
        self.debugging_info[4] = round(diff, 0)

        return diff < 3000000 
开发者ID:youngwoo-yoon,项目名称:youtube-gesture-dataset,代码行数:21,代码来源:clip_filter.py

示例9: medoid

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def medoid(pts):
    """The mediod is the point with the smallest summed distance from the other points.
    This is a candidate for the center facelet."""
    res = np.array([0.0, 0.0])
    smin = 100000
    for i in pts:
        s = 0
        for j in pts:
            s += np.linalg.norm(i - j)
        if s < smin:
            smin = s
            res = i

    return res 
开发者ID:hkociemba,项目名称:RubiksCube-TwophaseSolver,代码行数:16,代码来源:vision2.py

示例10: mirr_facelet

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def mirr_facelet(co, ed, med):
    """If we have detected a facelet position, the point reflection at the center also gives a facelet position.
     We can use this position in case the other facelet was not detected directly."""
    aef = []
    acf = []
    for p in ed:
        pa = 2 * med - p
        aef.append(pa)
    for p in co:
        pa = 2 * med - p
        acf.append(pa)

    # delete duplicates
    delta = width / 12  # width is defined global in grabcolors()
    for k in range(len(aef) - 1, -1, -1):
        for p in ed:
            if np.linalg.norm(aef[k] - p) < delta:
                del aef[k]
                break

    for k in range(len(acf) - 1, -1, -1):
        for p in co:
            if np.linalg.norm(acf[k] - p) < delta:
                del acf[k]
                break

    return acf, aef 
开发者ID:hkociemba,项目名称:RubiksCube-TwophaseSolver,代码行数:29,代码来源:vision2.py

示例11: compute_matrix_pictures_corners

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def compute_matrix_pictures_corners():
        # Get the size of the current matching picture
        # TODO : Store somewhere the shape of the uploaded picture ?
        # h, w, d = pic1.image.shape
        # TODO : For now, just take a random size picture
        h, w, d = 1000, 1000, 3

        # Get the position of the 4 corners of the current matching picture
        pts = np.float32([[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0]]).reshape(-1, 1, 2)
        max = 4 * cv2.norm(np.float32([[w, h]]), cv2.NORM_L2)

        return pts, max 
开发者ID:CIRCL,项目名称:douglas-quaid,代码行数:14,代码来源:distance_ransac_orb.py

示例12: _calc_reprojection_error

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def _calc_reprojection_error(self,figure_size=(8,8),save_dir=None):
        """
        Util function to Plot reprojection error
        """
        reprojection_error = []
        for i in range(len(self.calibration_df)):
            imgpoints2, _ = cv2.projectPoints(self.calibration_df.obj_points[i], self.calibration_df.rvecs[i], self.calibration_df.tvecs[i], self.camera_matrix, self.dist_coefs)
            temp_error = cv2.norm(self.calibration_df.img_points[i],imgpoints2, cv2.NORM_L2)/len(imgpoints2)
            reprojection_error.append(temp_error)
        self.calibration_df['reprojection_error'] = pd.Series(reprojection_error)
        avg_error = np.sum(np.array(reprojection_error))/len(self.calibration_df.obj_points)
        x = [os.path.basename(p) for p in self.calibration_df.image_names]
        y_mean = [avg_error]*len(self.calibration_df.image_names)
        fig,ax = plt.subplots()
        fig.set_figwidth(figure_size[0])
        fig.set_figheight(figure_size[1])
        # Plot the data
        ax.scatter(x,reprojection_error,label='Reprojection error', marker='o') #plot before
        # Plot the average line
        ax.plot(x,y_mean, label='Mean Reprojection error', linestyle='--')
        # Make a legend
        ax.legend(loc='upper right')
        for tick in ax.get_xticklabels():
            tick.set_rotation(90)
        # name x and y axis
        ax.set_title("Reprojection_error plot")
        ax.set_xlabel("Image_names")
        ax.set_ylabel("Reprojection error in pixels")
        
        if save_dir:
            plt.savefig(os.path.join(save_dir,"reprojection_error.png"))
        
        plt.show()
        print("The Mean Reprojection Error in pixels is:  {}".format(avg_error)) 
开发者ID:Abhijit-2592,项目名称:camera_calibration_API,代码行数:36,代码来源:camera_calibration.py

示例13: init

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
def init(self,first_frame,bbox):
        bbox=np.array(bbox).astype(np.int64)
        x,y,w,h=tuple(bbox)
        self._scale_factor=min(1,round(10*self.config.img_scale_target_diagonal/cv2.norm(np.array([w,h])))/10.)
        self._center=(self._scale_factor*(x+(w-1)/2),self._scale_factor*(y+(h-1)/2))
        self.w,self.h=int(w*self._scale_factor),int(h*self._scale_factor)
        self._target_sz=(self.w,self.h)

        img=cv2.resize(first_frame,None,fx=self._scale_factor,fy=self._scale_factor)
        if self.config.color_space=='lab':
            img=cv2.cvtColor(img,cv2.COLOR_BGR2Lab)
        elif self.config.color_space=='hsv':
            img=cv2.cvtColor(img,cv2.COLOR_BGR2HSV)
            img[:, :, 0] = (img[:, :, 0] * 256 / 180)
            img = img.astype(np.uint8)
        else:
            pass

        surr_sz=(int(np.floor(self.config.surr_win_factor*self.w)),int(np.floor(self.config.surr_win_factor*self.h)))
        surr_rect=pos2rect(self._center,surr_sz,(img.shape[1],img.shape[0]))
        obj_rect_surr=pos2rect(self._center,self._target_sz,(img.shape[1],img.shape[0]))
        obj_rect_surr=(obj_rect_surr[0]-surr_rect[0],
                    obj_rect_surr[1]-surr_rect[1],
                    obj_rect_surr[2],obj_rect_surr[3])
        surr_win=get_sub_window(img,self._center,surr_sz)
        self.bin_mapping=get_bin_mapping(self.config.num_bins)
        self.prob_lut_,prob_map=get_foreground_background_probs(surr_win,obj_rect_surr,
                                self.config.num_bins,self.bin_mapping)
        self._prob_lut_distractor=copy.deepcopy(self.prob_lut_)
        self._prob_lut_masked=copy.deepcopy(self.prob_lut_)
        self.adaptive_threshold_=get_adaptive_threshold(prob_map,obj_rect_surr)
        self.target_pos_history.append((self._center[0]/self._scale_factor,self._center[1]/self._scale_factor))
        self.target_sz_history.append((self._target_sz[0]/self._scale_factor,self._target_sz[1]/self._scale_factor)) 
开发者ID:fengyang95,项目名称:pyCFTrackers,代码行数:35,代码来源:dat.py

示例14: normalize_result

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import norm [as 别名]
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)
    } 
开发者ID:maddevsio,项目名称:idmatch,代码行数:14,代码来源:core.py


注:本文中的cv2.norm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。