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


Python cv2.Scharr方法代码示例

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


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

示例1: compute_gradient

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Scharr [as 别名]
def compute_gradient(img, use_scharr=True):
    if use_scharr:
        norm_factor = 32
        gradx = cv2.Scharr(img, cv2.CV_32F, 1, 0, scale=1.0/norm_factor)
        grady = cv2.Scharr(img, cv2.CV_32F, 0, 1, scale=1.0/norm_factor)
    else:
        kx = cv2.getDerivKernels(1, 0, ksize=1, normalize=True)
        ky = cv2.getDerivKernels(0, 1, ksize=1, normalize=True)
        gradx = cv2.sepFilter2D(img, cv2.CV_32F, kx[0], kx[1])
        grady = cv2.sepFilter2D(img, cv2.CV_32F, ky[0], ky[1])
    
    gradient = np.dstack([gradx, grady])
    return gradient 
开发者ID:uzh-rpg,项目名称:rpg_davis_simulator,代码行数:15,代码来源:dataset_utils.py

示例2: from_gradient

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Scharr [as 别名]
def from_gradient(gray):
        fieldx = cv2.Scharr(gray, cv2.CV_32F, 1, 0) / 15.36
        fieldy = cv2.Scharr(gray, cv2.CV_32F, 0, 1) / 15.36

        return VectorField(fieldx, fieldy) 
开发者ID:matteo-ronchetti,项目名称:Pointillism,代码行数:7,代码来源:vector_field.py

示例3: main

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Scharr [as 别名]
def main():
    image = cv2.imread("../data/5.1.11.tiff", 0)
    cv2.imshow("Orignal Image", image)

    # Laplacian High Pass Filter
    lap_filter = cv2.Laplacian(image, ddepth=-1, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
    cv2.imshow("Laplacian Filter", lap_filter)

    # Sobel High Pass Filter
    sobelx_filter = cv2.Sobel(image, ddepth=-1, dx=2, dy=0, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
    cv2.imshow("Sobel X Filter", sobelx_filter)

    sobely_filter = cv2.Sobel(image, ddepth=-1, dx=0, dy=2, ksize=7, scale=1, borderType=cv2.BORDER_DEFAULT)
    cv2.imshow("Sobel Y Filter", sobely_filter)

    sobel_filter = sobelx_filter + sobely_filter
    cv2.imshow("Sobel Filter", sobel_filter)

    # Scharr High Pass Filter Implementation
    scharrx_filter = cv2.Scharr(image, ddepth=-1, dx=1, dy=0, scale=1, borderType=cv2.BORDER_DEFAULT)
    cv2.imshow("Scharr X Filter", scharrx_filter)

    scharry_filter = cv2.Scharr(image, ddepth=-1, dx=0, dy=1, scale=1, borderType=cv2.BORDER_DEFAULT)
    cv2.imshow("Scharr Y Filter", scharry_filter)

    scharr_filter = scharrx_filter + scharry_filter
    cv2.imshow("Scharr Filter", scharr_filter)

    cv2.waitKey(0)
    cv2.destroyAllWindows() 
开发者ID:amarlearning,项目名称:Finger-Detection-and-Tracking,代码行数:32,代码来源:HighPassFilter.py

示例4: scharr_filter

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import Scharr [as 别名]
def scharr_filter(img, dx, dy, scale):
    """This is a filtering method used to identify and highlight gradient edges/features using the 1st derivative.
       Typically used to identify gradients along the x-axis (dx = 1, dy = 0) and y-axis (dx = 0, dy = 1) independently.
       Performance is quite similar to Sobel filter. Used to detect edges / changes in pixel intensity. ddepth = -1
       specifies that the dimensions of output image will be the same as the input image.

    Inputs:
    gray_img = Grayscale image data
    dx       = derivative of x to analyze (1-3)
    dy       = derivative of x to analyze (1-3)
    scale    = scaling factor applied (multiplied) to computed Scharr values (scale = 1 is unscaled)

    Returns:
    sr_img   = Scharr filtered image

    :param img: numpy.ndarray
    :param dx: int
    :param dy: int
    :param scale: int
    :return sr_img: numpy.ndarray
    """

    sr_img = cv2.Scharr(src=img, ddepth=-1, dx=dx, dy=dy, scale=scale)
    params.device += 1
    if params.debug == 'print':
        name = os.path.join(params.debug_outdir, str(params.device))
        name += '_sr_img_dx' + str(dx) + '_dy' + str(dy) + '_scale' + str(scale) + '.png'
        print_image(sr_img, name)
    elif params.debug == 'plot':
        plot_image(sr_img, cmap='gray')
    return sr_img 
开发者ID:danforthcenter,项目名称:plantcv,代码行数:33,代码来源:scharr_filter.py


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