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


Python cv2.MORPH_GRADIENT属性代码示例

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


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

示例1: recognize_text

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import MORPH_GRADIENT [as 别名]
def recognize_text(original):
    idcard = original
    # gray = cv2.cvtColor(idcard, cv2.COLOR_BGR2GRAY)

    # Morphological gradient:
    kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (5, 5))
    opening = cv2.morphologyEx(idcard, cv2.MORPH_GRADIENT, kernel)

    # Binarization
    ret, binarization = cv2.threshold(opening, 0.0, 255.0, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

    # Connected horizontally oriented regions
    kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (9, 1))
    connected = cv2.morphologyEx(binarization, cv2.MORPH_CLOSE, kernel)

    # find countours
    _, contours, hierarchy = cv2.findContours(
        connected, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE
    )
    return contours, hierarchy 
开发者ID:maddevsio,项目名称:idmatch,代码行数:22,代码来源:idcardocr.py

示例2: morphological_gradient

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import MORPH_GRADIENT [as 别名]
def morphological_gradient(image, kernel_type, kernel_size):
    """Applies the morfological gradient to the image with the specified kernel type and size"""

    kernel = build_kernel(kernel_type, kernel_size)
    morph_gradient = cv2.morphologyEx(image, cv2.MORPH_GRADIENT, kernel)
    return morph_gradient


# This function closes and opens the image 
开发者ID:PacktPublishing,项目名称:Mastering-OpenCV-4-with-Python,代码行数:11,代码来源:morphological_operations.py

示例3: detect_textarea

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import MORPH_GRADIENT [as 别名]
def detect_textarea(self, arg):
        textarea = []
        small = cv2.cvtColor(arg, cv2.COLOR_RGB2GRAY)
        height, width, _ = arg.shape

        kernel = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (3, 3))
        grad = cv2.morphologyEx(small, cv2.MORPH_GRADIENT, kernel)

        _, bw = cv2.threshold(
            grad, 0.0, 255.0, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

        kernel = cv2.getStructuringElement(
            cv2.MORPH_RECT, (10, 1))  # for historical docs
        connected = cv2.morphologyEx(bw, cv2.MORPH_CLOSE, kernel)
        contours, _ = cv2.findContours(
            connected.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)

        mask = np.zeros(bw.shape, dtype=np.uint8)

        for idx in range(len(contours)):
            x, y, w, h = cv2.boundingRect(contours[idx])
            # print x,y,w,h
            mask[y:y+h, x:x+w] = 0
            cv2.drawContours(mask, contours, idx, (255, 255, 255), -1)
            r = float(cv2.countNonZero(mask[y:y+h, x:x+w])) / (w * h)

            if r > 0.45 and (width*0.9) > w > 15 and (height*0.5) > h > 15:
                textarea.append([x, y, x+w-1, y+h-1])
                cv2.rectangle(arg, (x, y), (x+w-1, y+h-1), (0, 0, 255), 2)

        if len(textarea) > 1:
            textarea = self.filter_noisebox(textarea, height, width)

        return textarea, arg, height, width 
开发者ID:OCR-D,项目名称:ocrd_anybaseocr,代码行数:36,代码来源:ocrd_anybaseocr_cropping.py


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