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


Python cv2.copyMakeBorder方法代码示例

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


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

示例1: step

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def step(self, amt=1):
        image = self._capFrame()

        if self.crop:
            image = image[self._cropY + self.yoff:self._ih - self._cropY +
                          self.yoff, self._cropX + self.xoff:self._iw - self._cropX + self.xoff]
        else:
            t, b, l, r = self._pad
            image = cv2.copyMakeBorder(
                image, t, b, l, r, cv2.BORDER_CONSTANT, value=[0, 0, 0])

        resized = cv2.resize(image, (self.width, self.height),
                             interpolation=cv2.INTER_LINEAR)
        if self.mirror:
            resized = cv2.flip(resized, 1)

        for y in range(self.height):
            for x in range(self.width):
                self.layout.set(x, y, tuple(resized[y, x][0:3])) 
开发者ID:ManiacalLabs,项目名称:BiblioPixelAnimations,代码行数:21,代码来源:ScreenGrab.py

示例2: copyMakeBorder

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def copyMakeBorder(src, top, bot, left, right, border_type=cv2.BORDER_CONSTANT, value=0):
    """Pad image border
    Wrapper for cv2.copyMakeBorder that uses mx.nd.NDArray

    Parameters
    ----------
    src : NDArray
        Image in (width, height, channels).
        Others are the same with cv2.copyMakeBorder

    Returns
    -------
    img : NDArray
        padded image
    """
    hdl = NDArrayHandle()
    check_call(_LIB.MXCVcopyMakeBorder(src.handle, ctypes.c_int(top), ctypes.c_int(bot),
                                       ctypes.c_int(left), ctypes.c_int(right),
                                       ctypes.c_int(border_type), ctypes.c_double(value),
                                       ctypes.byref(hdl)))
    return mx.nd.NDArray(hdl) 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:23,代码来源:opencv.py

示例3: split

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def split(self, image, border_type=cv2.BORDER_CONSTANT, value=0):
        assert image.shape[0] == self.image_height
        assert image.shape[1] == self.image_width

        orig_shape_len = len(image.shape)
        image = cv2.copyMakeBorder(image, self.margin_top, self.margin_bottom, self.margin_left, self.margin_right, borderType=border_type, value=value)

        # This check recovers possible lack of last dummy dimension for single-channel images
        if len(image.shape) != orig_shape_len:
            image = np.expand_dims(image, axis=-1)

        tiles = []
        for x, y, tile_width, tile_height in self.crops:
            tile = image[y:y + tile_height, x:x + tile_width].copy()
            assert tile.shape[0] == self.tile_size[0]
            assert tile.shape[1] == self.tile_size[1]

            tiles.append(tile)

        return tiles 
开发者ID:lRomul,项目名称:argus-freesound,代码行数:22,代码来源:tiles.py

示例4: cut_patch

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def cut_patch(self, image: np.ndarray, slice_index, border_type=cv2.BORDER_CONSTANT, value=0):
        assert image.shape[0] == self.image_height
        assert image.shape[1] == self.image_width

        orig_shape_len = len(image.shape)
        image = cv2.copyMakeBorder(image, self.margin_top, self.margin_bottom, self.margin_left, self.margin_right, borderType=border_type, value=value)

        # This check recovers possible lack of last dummy dimension for single-channel images
        if len(image.shape) != orig_shape_len:
            image = np.expand_dims(image, axis=-1)

        x, y, tile_width, tile_height = self.crops[slice_index]

        tile = image[y:y + tile_height, x:x + tile_width].copy()
        assert tile.shape[0] == self.tile_size[0]
        assert tile.shape[1] == self.tile_size[1]
        return tile 
开发者ID:lRomul,项目名称:argus-freesound,代码行数:19,代码来源:tiles.py

示例5: __getitem__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def __getitem__(self, index):
        datafiles = self.files[index]
        image = cv2.imread(datafiles["img"], cv2.IMREAD_COLOR)
        size = image.shape
        name = osp.splitext(osp.basename(datafiles["img"]))[0]
        image = np.asarray(image, np.float32)
        image -= self.mean
        
        img_h, img_w, _ = image.shape
        pad_h = max(self.crop_h - img_h, 0)
        pad_w = max(self.crop_w - img_w, 0)
        if pad_h > 0 or pad_w > 0:
            image = cv2.copyMakeBorder(image, 0, pad_h, 0, 
                pad_w, cv2.BORDER_CONSTANT, 
                value=(0.0, 0.0, 0.0))
        image = image.transpose((2, 0, 1))
        return image, name, size 
开发者ID:speedinghzl,项目名称:pytorch-segmentation-toolbox,代码行数:19,代码来源:datasets.py

示例6: _resize_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def _resize_image(img):
    dst_width = CFG.ARCH.INPUT_SIZE[0]
    dst_height = CFG.ARCH.INPUT_SIZE[1]
    h_old, w_old, _ = img.shape
    height = dst_height
    width = int(w_old * height / h_old)
    if width < dst_width:
        left_padding = int((dst_width - width)/2)
        right_padding = dst_width - width - left_padding
        resized_img = cv2.resize(img, (width, height), interpolation=cv2.INTER_CUBIC)
        resized_img = cv2.copyMakeBorder(resized_img, 0, 0, left_padding, right_padding,
            cv2.BORDER_CONSTANT, value=[255, 255, 255])
    else:
        resized_img = cv2.resize(img, (dst_width, height), interpolation=cv2.INTER_CUBIC)

    return resized_img 
开发者ID:Mingtzge,项目名称:2019-CCF-BDCI-OCR-MCZJ-OCR-IdentificationIDElement,代码行数:18,代码来源:write_tfrecord.py

示例7: __apply_template_matching

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def __apply_template_matching(angle, template, image):
    # Rotate the template
    template_rotated = __rotate_image_size_corrected(template, angle)

    # Apply template matching
    image_templated = cv2.matchTemplate(image, template_rotated, cv2.TM_CCOEFF_NORMED)

    # Correct template matching image size difference
    template_rotated_height, template_rotated_width = template_rotated.shape
    template_half_height = template_rotated_height // 2
    template_half_width = template_rotated_width // 2

    image_templated_inrange_size_corrected = cv2.copyMakeBorder(image_templated, template_half_height, template_half_height, template_half_width, template_half_width, cv2.BORDER_CONSTANT, value=0)

    # Calculate maximum match coefficient
    max_match = numpy.max(image_templated_inrange_size_corrected)

    return (max_match, angle, template_rotated, image_templated_inrange_size_corrected) 
开发者ID:microsoft,项目名称:AI-Robot-Challenge-Lab,代码行数:20,代码来源:cv_detection_right_hand.py

示例8: load_label

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def load_label(self, idx):
        """
        Load label image as 1 x height x width integer array of label indices.
        The leading singleton dimension is required by the loss.
        """
        im = Image.open(self.data_root + self.label_lst[idx])
        label = np.array(im) / 255#cv2.imread(self.data_root + self.label_lst[idx], 0) / 255
        #if self.scales != None:
        #    label = cv2.resize(label, None, None, fx=self.scales[self.scale_ind], fy=self.scales[self.scale_ind], \
        #            interpolation=cv2.INTER_NEAREST)
        #height, width = label.shape[:2]
        #h_off = self.crop_size - height
        #w_off = self.crop_size - width
        #label = cv2.copyMakeBorder(label, 0, max(0, h_off), 0, max(0, w_off), cv2.BORDER_CONSTANT, value=[-1,])
        #label = label[self.h_off:self.h_off+self.height, self.w_off:self.w_off+self.width]
        label = label[np.newaxis, ...]
        if self.flip == 1:
            label = label[:,:,::-1]
        return label 
开发者ID:Andrew-Qibin,项目名称:DSS,代码行数:21,代码来源:sal_data_layer.py

示例9: load_region

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def load_region(self, idx):
        """
        Load label image as 1 x height x width integer array of label indices.
        The leading singleton dimension is required by the loss.
        """
        im = Image.open(self.data_root + self.region_lst[idx])
        region = np.array(im, dtype=np.float32) / 15.0
        #print np.unique(region)
        #if self.scales != None:
        #    label = cv2.resize(label, None, None, fx=self.scales[self.scale_ind], fy=self.scales[self.scale_ind], \
        #            interpolation=cv2.INTER_NEAREST)
        #height, width = label.shape[:2]
        #h_off = self.crop_size - height
        #w_off = self.crop_size - width
        #label = cv2.copyMakeBorder(label, 0, max(0, h_off), 0, max(0, w_off), cv2.BORDER_CONSTANT, value=[-1,])
        region = region[np.newaxis, ...]
        if self.flip == 1:
            region = region[:,:,::-1]
        return region 
开发者ID:Andrew-Qibin,项目名称:DSS,代码行数:21,代码来源:sal_data_layer.py

示例10: PreprocessImage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def PreprocessImage(name, args):
    """Preprocess according to the original author's code."""

    image = cv2.imread(name, 1).astype(np.float32) - args.mean

    if args.resize_dims is not None:
        image = cv2.resize(image, dsize = (args.resize_dims[0], args.resize_dims[1]))

    im_height = image.shape[0]
    im_width = image.shape[1]

    label_margin = 186
    input_image = cv2.copyMakeBorder(image, label_margin, label_margin,
                                     label_margin, label_margin, cv2.BORDER_REFLECT_101)
    input_size = [args.pad_size[1], args.pad_size[0]] # Order is H x W
    margin = [0, input_size[0] - input_image.shape[0],
              0, input_size[1] - input_image.shape[1]]

    input_image = cv2.copyMakeBorder(input_image, margin[0], margin[1], margin[2],
                                     margin[3], cv2.BORDER_REFLECT_101)

    input_image = input_image.transpose([2,0,1]) # To make it C x H x W
    return input_image, im_height, im_width, image 
开发者ID:hmph,项目名称:adversarial-attacks,代码行数:25,代码来源:dilated.py

示例11: label_images

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def label_images(images, labels):
    font = cv.FONT_HERSHEY_SIMPLEX
    new_imgs = []
    for i, img in enumerate(images):
        new_img = ((img.copy() + 1.) * 127.5).astype(np.uint8)
        if new_img.shape[-1] == 3:
            new_img = new_img[..., ::-1]
            new_img = cv.resize(new_img, (100, 100), interpolation=cv.INTER_LINEAR)
            new_img = cv.putText(new_img, str(labels[i]), (10, 30), font, 1, (255, 255, 255), 2, cv.LINE_AA)
            new_img = cv.copyMakeBorder(new_img, top=2, bottom=2, left=2, right=2, borderType=cv.BORDER_CONSTANT,
                                        value=(255, 255, 255))
        else:
            new_img = np.squeeze(new_img)
            new_img = cv.resize(new_img, (100, 100), interpolation=cv.INTER_LINEAR)
            new_img = cv.putText(new_img, str(labels[i]), (10, 30), font, 1, (255), 2, cv.LINE_AA)
            new_img = new_img[..., None]

        new_img = (new_img / 127.5 - 1.0).astype(np.float32)
        new_imgs.append(new_img[..., ::-1])
    return np.stack(new_imgs, axis=0) 
开发者ID:ermongroup,项目名称:generative_adversary,代码行数:22,代码来源:utils.py

示例12: pad_width

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def pad_width(img,
                  stride,
                  pad_value,
                  min_dims):
        h, w, _ = img.shape
        h = min(min_dims[0], h)
        min_dims[0] = math.ceil(min_dims[0] / float(stride)) * stride
        min_dims[1] = max(min_dims[1], w)
        min_dims[1] = math.ceil(min_dims[1] / float(stride)) * stride
        top = int(math.floor((min_dims[0] - h) / 2.0))
        left = int(math.floor((min_dims[1] - w) / 2.0))
        bottom = int(min_dims[0] - h - top)
        right = int(min_dims[1] - w - left)
        pad = [top, left, bottom, right]
        padded_img = cv2.copyMakeBorder(
            src=img,
            top=top,
            bottom=bottom,
            left=left,
            right=right,
            borderType=cv2.BORDER_CONSTANT,
            value=pad_value)
        return padded_img, pad

# --------------------------------------------------------------------------------------------------------------------- 
开发者ID:osmr,项目名称:imgclsmob,代码行数:27,代码来源:coco_hpe2_dataset.py

示例13: inpaint

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [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

示例14: _pad_input_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def _pad_input_image(img, max_steps):
        """pad image to suitable shape"""

        logger.info(msg="_pad_input_image called")
        img_h, img_w, _ = img.shape

        img_pad_h = 0
        if img_h % max_steps > 0:
            img_pad_h = max_steps - img_h % max_steps

        img_pad_w = 0
        if img_w % max_steps > 0:
            img_pad_w = max_steps - img_w % max_steps

        padd_val = np.mean(img, axis=(0, 1)).astype(np.uint8)
        img = cv2.copyMakeBorder(img, 0, img_pad_h, 0, img_pad_w,
                                 cv2.BORDER_CONSTANT, value=padd_val.tolist())
        pad_params = [img_h, img_w, img_pad_h, img_pad_w]

        return img, pad_params 
开发者ID:pymit,项目名称:Rekognition,代码行数:22,代码来源:retina_net.py

示例15: step

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import copyMakeBorder [as 别名]
def step(self, amt=1):
        ret, frame = self._vid.read()

        image = cv2.cvtColor(frame, cv2.COLOR_RGB2BGRA)

        if self.crop:
            image = image[self._cropY + self.yoff:self._ih - self._cropY +
                          self.yoff, self._cropX + self.xoff:self._iw - self._cropX + self.xoff]
        else:
            t, b, l, r = self._pad
            image = cv2.copyMakeBorder(
                image, t, b, l, r, cv2.BORDER_CONSTANT, value=[0, 0, 0])

        resized = cv2.resize(image, (self.width, self.height),
                             interpolation=cv2.INTER_CUBIC)
        if self.mirror:
            resized = cv2.flip(resized, 1)

        for y in range(self.height):
            for x in range(self.width):
                self.layout.set(x, y, tuple(resized[y, x][0:3]))

        if not isinstance(self.videoSource, int):
            self._frameCount += 1
            if self._frameCount >= self._frameTotal:
                self._vid.set(1, 0)  # CV_CAP_PROP_POS_FRAMES
                self._frameCount = 0
                self.animComplete = True 
开发者ID:ManiacalLabs,项目名称:BiblioPixelAnimations,代码行数:30,代码来源:opencv_video.py


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