當前位置: 首頁>>代碼示例>>Python>>正文


Python cv2.BORDER_DEFAULT屬性代碼示例

本文整理匯總了Python中cv2.BORDER_DEFAULT屬性的典型用法代碼示例。如果您正苦於以下問題:Python cv2.BORDER_DEFAULT屬性的具體用法?Python cv2.BORDER_DEFAULT怎麽用?Python cv2.BORDER_DEFAULT使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在cv2的用法示例。


在下文中一共展示了cv2.BORDER_DEFAULT屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: sobelOperT

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def sobelOperT(self, img, blursize, morphW, morphH):
        '''
            No different with sobelOper ? 
        '''
        blur = cv2.GaussianBlur(img, (blursize, blursize), 0, 0, cv2.BORDER_DEFAULT)

        if len(blur.shape) == 3:
            gray = cv2.cvtColor(blur, cv2.COLOR_RGB2GRAY)
        else:
            gray = blur

        x = cv2.Sobel(gray, cv2.CV_16S, 1, 0, 3)
        absX = cv2.convertScaleAbs(x)
        grad = cv2.addWeighted(absX, 1, 0, 0, 0)

        _, threshold = cv2.threshold(grad, 0, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)

        element = cv2.getStructuringElement(cv2.MORPH_RECT, (morphW, morphH))
        threshold = cv2.morphologyEx(threshold, cv2.MORPH_CLOSE, element)

        return threshold 
開發者ID:SunskyF,項目名稱:EasyPR-python,代碼行數:23,代碼來源:plate_locate.py

示例2: inpaint

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def inpaint(self, missing_value=0):
        """
        Inpaint missing values in depth image.
        :param missing_value: Value to fill in teh depth image.
        """
        # cv2 inpainting doesn't handle the border properly
        # https://stackoverflow.com/questions/25974033/inpainting-depth-map-still-a-black-image-border
        self.img = cv2.copyMakeBorder(self.img, 1, 1, 1, 1, cv2.BORDER_DEFAULT)
        mask = (self.img == missing_value).astype(np.uint8)

        # Scale to keep as float, but has to be in bounds -1:1 to keep opencv happy.
        scale = np.abs(self.img).max()
        self.img = self.img.astype(np.float32) / scale  # Has to be float32, 64 not supported.
        self.img = cv2.inpaint(self.img, mask, 1, cv2.INPAINT_NS)

        # Back to original size and value range.
        self.img = self.img[1:-1, 1:-1]
        self.img = self.img * scale 
開發者ID:dougsm,項目名稱:ggcnn,代碼行數:20,代碼來源:image.py

示例3: resize_to_desired

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def resize_to_desired(input_img):
    h = input_img.shape[0]
    if h < 20:  # pad the image to 20 or 21 pixels height if it is too short
        border = math.ceil((20 - h) / 2)
        new_img = cv2.copyMakeBorder(input_img, top=border, bottom=border, left=0, right=0,
                                     borderType=cv2.BORDER_DEFAULT)
    else:
        new_img = input_img

    return cv2.resize(new_img, (CLS_IMG_WIDTH, CLS_IMG_HEIGHT)) 
開發者ID:bshao001,項目名稱:DmsMsgRcg,代碼行數:12,代碼來源:datapreptools.py

示例4: sobelOper

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def sobelOper(self, img, blursize, morphW, morphH):
        blur = cv2.GaussianBlur(img, (blursize, blursize), 0, 0, cv2.BORDER_DEFAULT)

        if len(blur.shape) == 3:
            gray = cv2.cvtColor(blur, cv2.COLOR_RGB2GRAY)
        else:
            gray = blur

        x = cv2.Sobel(gray, cv2.CV_16S, 1, 0, ksize=3, scale=1, delta=0, borderType=cv2.BORDER_DEFAULT)
        absX = cv2.convertScaleAbs(x)
        grad = cv2.addWeighted(absX, 1, 0, 0, 0)

        _, threshold = cv2.threshold(grad, 0, 255, cv2.THRESH_OTSU + cv2.THRESH_BINARY)

        element = cv2.getStructuringElement(cv2.MORPH_RECT, (morphW, morphH))
        threshold = cv2.morphologyEx(threshold, cv2.MORPH_CLOSE, element)

        return threshold 
開發者ID:SunskyF,項目名稱:EasyPR-python,代碼行數:20,代碼來源:plate_locate.py

示例5: gradients

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def gradients(self):
        """
        Compute gradients of the depth image using Sobel filtesr.
        :return: Gradients in X direction, Gradients in Y diretion, Magnitude of XY gradients.
        """
        grad_x = cv2.Sobel(self.img, cv2.CV_64F, 1, 0, borderType=cv2.BORDER_DEFAULT)
        grad_y = cv2.Sobel(self.img, cv2.CV_64F, 0, 1, borderType=cv2.BORDER_DEFAULT)
        grad = np.sqrt(grad_x ** 2 + grad_y ** 2)

        return DepthImage(grad_x), DepthImage(grad_y), DepthImage(grad) 
開發者ID:dougsm,項目名稱:ggcnn,代碼行數:12,代碼來源:image.py

示例6: process_depth_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def process_depth_image(depth, crop_size, out_size=300, return_mask=False, crop_y_offset=0):
    imh, imw = depth.shape

    with TimeIt('1'):
        # Crop.
        depth_crop = depth[(imh - crop_size) // 2 - crop_y_offset:(imh - crop_size) // 2 + crop_size - crop_y_offset,
                           (imw - crop_size) // 2:(imw - crop_size) // 2 + crop_size]
    # depth_nan_mask = np.isnan(depth_crop).astype(np.uint8)

    # Inpaint
    # OpenCV inpainting does weird things at the border.
    with TimeIt('2'):
        depth_crop = cv2.copyMakeBorder(depth_crop, 1, 1, 1, 1, cv2.BORDER_DEFAULT)
        depth_nan_mask = np.isnan(depth_crop).astype(np.uint8)

    with TimeIt('3'):
        depth_crop[depth_nan_mask==1] = 0

    with TimeIt('4'):
        # Scale to keep as float, but has to be in bounds -1:1 to keep opencv happy.
        depth_scale = np.abs(depth_crop).max()
        depth_crop = depth_crop.astype(np.float32) / depth_scale  # Has to be float32, 64 not supported.

        with TimeIt('Inpainting'):
            depth_crop = cv2.inpaint(depth_crop, depth_nan_mask, 1, cv2.INPAINT_NS)

        # Back to original size and value range.
        depth_crop = depth_crop[1:-1, 1:-1]
        depth_crop = depth_crop * depth_scale

    with TimeIt('5'):
        # Resize
        depth_crop = cv2.resize(depth_crop, (out_size, out_size), cv2.INTER_AREA)

    if return_mask:
        with TimeIt('6'):
            depth_nan_mask = depth_nan_mask[1:-1, 1:-1]
            depth_nan_mask = cv2.resize(depth_nan_mask, (out_size, out_size), cv2.INTER_NEAREST)
        return depth_crop, depth_nan_mask
    else:
        return depth_crop 
開發者ID:dougsm,項目名稱:mvp_grasp,代碼行數:43,代碼來源:ggcnn_torch.py

示例7: main

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [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

示例8: text_detect

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def text_detect(img,ele_size=(8,2)): #
    if len(img.shape)==3:
        img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    img_sobel = cv2.Sobel(img,cv2.CV_8U,1,0)#same as default,None,3,1,0,cv2.BORDER_DEFAULT)
    img_threshold = cv2.threshold(img_sobel,0,255,cv2.THRESH_OTSU+cv2.THRESH_BINARY)
    element = cv2.getStructuringElement(cv2.MORPH_RECT,ele_size)
    img_threshold = cv2.morphologyEx(img_threshold[1],cv2.MORPH_CLOSE,element)
    res = cv2.findContours(img_threshold, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
    if cv2.__version__.split(".")[0] == '3':
        _, contours, hierarchy = res
    else:
        contours, hierarchy = res
    Rect = [cv2.boundingRect(i) for i in contours if i.shape[0]>100]
    RectP = [(int(i[0]-i[2]*0.08),int(i[1]-i[3]*0.08),int(i[0]+i[2]*1.1),int(i[1]+i[3]*1.1)) for i in Rect]
    return RectP 
開發者ID:qzane,項目名稱:text-detection,代碼行數:17,代碼來源:TextDetect.py

示例9: test_box_filter_reflect_101

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def test_box_filter_reflect_101(self):
        I = np.array(range(1, 50)).reshape(7, 7).astype(np.float32)
        r = 2
        ret1 = cv.smooth.box_filter(I, r, normalize=True)
        ret2 = cv2.blur(I, (5,5), borderType=cv2.BORDER_DEFAULT)
        self.assertTrue(np.array_equal(ret1, ret2)) 
開發者ID:lisabug,項目名稱:guided-filter,代碼行數:8,代碼來源:test_box_filter.py

示例10: process_depth_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import BORDER_DEFAULT [as 別名]
def process_depth_image(depth, crop_size, out_size=300, return_mask=False, crop_y_offset=0):
    imh, imw = depth.shape

    with TimeIt('Process Depth Image'):
        with TimeIt('Crop'):
            # Crop.
            depth_crop = depth[(imh - crop_size) // 2 - crop_y_offset:(imh - crop_size) // 2 + crop_size - crop_y_offset,
                               (imw - crop_size) // 2:(imw - crop_size) // 2 + crop_size]

        # Inpaint
        # OpenCV inpainting does weird things at the border.
        with TimeIt('Inpainting_Processing'):
            depth_crop = cv2.copyMakeBorder(depth_crop, 1, 1, 1, 1, cv2.BORDER_DEFAULT)
            depth_nan_mask = np.isnan(depth_crop).astype(np.uint8)

            kernel = np.ones((3, 3),np.uint8)
            depth_nan_mask = cv2.dilate(depth_nan_mask, kernel, iterations=1)

            depth_crop[depth_nan_mask==1] = 0

            # Scale to keep as float, but has to be in bounds -1:1 to keep opencv happy.
            depth_scale = np.abs(depth_crop).max()
            depth_crop = depth_crop.astype(np.float32) / depth_scale  # Has to be float32, 64 not supported.

            with TimeIt('Inpainting'):
                depth_crop = cv2.inpaint(depth_crop, depth_nan_mask, 1, cv2.INPAINT_NS)

            # Back to original size and value range.
            depth_crop = depth_crop[1:-1, 1:-1]
            depth_crop = depth_crop * depth_scale

        with TimeIt('Resizing'):
            # Resize
            depth_crop = cv2.resize(depth_crop, (out_size, out_size), cv2.INTER_AREA)

        if return_mask:
            with TimeIt('Return Mask'):
                depth_nan_mask = depth_nan_mask[1:-1, 1:-1]
                depth_nan_mask = cv2.resize(depth_nan_mask, (out_size, out_size), cv2.INTER_NEAREST)
            return depth_crop, depth_nan_mask
        else:
            return depth_crop 
開發者ID:dougsm,項目名稱:mvp_grasp,代碼行數:44,代碼來源:ggcnn.py


注:本文中的cv2.BORDER_DEFAULT屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。