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


Python cv2.INTER_AREA属性代码示例

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


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

示例1: prepare

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def prepare(input):
    # preprocessing the image input
    clean = cv2.fastNlMeansDenoising(input)
    ret, tresh = cv2.threshold(clean, 127, 1, cv2.THRESH_BINARY_INV)
    img = crop(tresh)

    # 40x10 image as a flatten array
    flatten_img = cv2.resize(img, (40, 10), interpolation=cv2.INTER_AREA).flatten()

    # resize to 400x100
    resized = cv2.resize(img, (400, 100), interpolation=cv2.INTER_AREA)
    columns = np.sum(resized, axis=0)  # sum of all columns
    lines = np.sum(resized, axis=1)  # sum of all lines

    h, w = img.shape
    aspect = w / h

    return [*flatten_img, *columns, *lines, aspect] 
开发者ID:gnbaron,项目名称:signature-recognition,代码行数:20,代码来源:preprocessor.py

示例2: read_images

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def read_images(src, tag=None, set=None):
    files = os.listdir(src)
    images = []
    if set is not None:
        set = read_set(set)
    for f in files:
        if tag and f.find(tag) == -1:
            continue
        if set is not None:
            if int(f.split('.')[0]) not in set:
                continue
        image = (cv2.imread(os.path.join(src, f))[:, :, ::-1] / 255.0).astype(np.float32)
        longer_edge = min(image.shape[0], image.shape[1])
        for i in range(4):
            sx = random.randrange(0, image.shape[0] - longer_edge + 1)
            sy = random.randrange(0, image.shape[1] - longer_edge + 1)
            new_image = image[sx:sx + longer_edge, sy:sy + longer_edge]
            patch = cv2.resize(new_image, dsize=(80, 80), interpolation=cv2.INTER_AREA)
            for j in range(4):
                target_size = 64
                ssx = random.randrange(0, patch.shape[0] - target_size)
                ssy = random.randrange(0, patch.shape[1] - target_size)
                images.append(patch[ssx:ssx + target_size, ssy:ssy + target_size])
    return images 
开发者ID:yuanming-hu,项目名称:exposure,代码行数:26,代码来源:histogram_intersection.py

示例3: imresample

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def imresample(img, sz):
    im_data = cv2.resize(img, (sz[1], sz[0]), interpolation=cv2.INTER_AREA) #@UndefinedVariable
    return im_data

    # This method is kept for debugging purpose
#     h=img.shape[0]
#     w=img.shape[1]
#     hs, ws = sz
#     dx = float(w) / ws
#     dy = float(h) / hs
#     im_data = np.zeros((hs,ws,3))
#     for a1 in range(0,hs):
#         for a2 in range(0,ws):
#             for a3 in range(0,3):
#                 im_data[a1,a2,a3] = img[int(floor(a1*dy)),int(floor(a2*dx)),a3]
#     return im_data 
开发者ID:deepinsight,项目名称:insightface,代码行数:18,代码来源:detect_face.py

示例4: seek

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def seek(self, frame_id=None):
        """Update the current frame to the given frame_id, otherwise advances by 1 frame"""
        if frame_id is None:
            frame_id = self.frame_id + 1
        if frame_id < 0:
            frame_id = 0
            self.paused = True
        if frame_id >= self.n_frames:
            frame_id = self.n_frames - 1
            self.paused = True
        self.update_quality(self.frame_id, frame_id, self.quality)
        self.frame = cv2.resize(
            derp.util.decode_jpg(self.topics["camera"][frame_id].jpg),
            None,
            fx=self.scale,
            fy=self.scale,
            interpolation=cv2.INTER_AREA,
        )
        self.frame_id = frame_id
        return True 
开发者ID:notkarol,项目名称:derplearning,代码行数:22,代码来源:label.py

示例5: read_image_pair

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def read_image_pair(pair_path, resize_or_crop=None, image_size=(256,256)):
    image_blur = cv2.imread(pair_path[0], cv2.IMREAD_COLOR)
    image_blur = image_blur / 255.0 * 2.0 - 1.0
    image_real = cv2.imread(pair_path[1], cv2.IMREAD_COLOR)
    image_real = image_real / 255.0 * 2.0 - 1.0

    if resize_or_crop != None: 
        assert image_size != None

    if resize_or_crop == 'resize':
        image_blur = cv2.resize(image_blur, image_size, interpolation=cv2.INTER_AREA)
        image_real = cv2.resize(image_real, image_size, interpolation=cv2.INTER_AREA)
    elif resize_or_crop == 'crop':
        image_blur = cv2.crop(image_blur, image_size)
        image_real = cv2.crop(image_real, image_size)
    else:
        raise

    if np.size(np.shape(image_blur)) == 3:
        image_blur = np.expand_dims(image_blur, axis=0)
    if np.size(np.shape(image_real)) == 3:
        image_real = np.expand_dims(image_real, axis=0)
    image_blur = np.array(image_blur, dtype=np.float32)
    image_real = np.array(image_real, dtype=np.float32)
    return image_blur, image_real 
开发者ID:LeeDoYup,项目名称:DeblurGAN-tf,代码行数:27,代码来源:data_loader.py

示例6: read_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def read_image(path, resize_or_crop=None, image_size=(256,256)):
    image = cv2.imread(path, cv2.IMREAD_COLOR)
    image = image/255.0 * 2.0 - 1.0

    assert resize_or_crop != None
    assert image_size != None

    if resize_or_crop == 'resize':
        image = cv2.resize(image, image_size, interpolation=cv2.INTER_AREA)
    elif resize_or_crop == 'crop':
        image = cv2.crop(image, image_size)

    if np.size(np.shape(image)) == 3: 
        image = np.expand_dims(image, axis=0)

    image = np.array(image, dtype=np.float32)
    return image 
开发者ID:LeeDoYup,项目名称:DeblurGAN-tf,代码行数:19,代码来源:data_loader.py

示例7: resize

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def resize(image, width=None, height=None, inter=cv2.INTER_AREA):
    # Grab the image size
    (h, w) = image.shape[:2]

    # If both the width and height are None, then return the original image
    if width is None and height is None:
        return image

    # Check to see if the width is None
    if width is None:
        # Calculate the ratio of the height and construct the dimensions
        r = height / float(h)
        dim = (int(w * r), height)

    # Otherwise, the height is None
    else:
        # Calculate the ratio of the width and construct the dimensions
        r = width / float(w)
        dim = (width, int(h * r))

    # Resize the image
    resized = cv2.resize(image, dim, interpolation=inter)

    # Return the resized image
    return resized 
开发者ID:hsSam,项目名称:PracticalPythonAndOpenCV_CaseStudies,代码行数:27,代码来源:imutils.py

示例8: get_mnist_data

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def get_mnist_data(is_train, image_size, batchsize):
    ds = MNISTCh('train' if is_train else 'test', shuffle=True)

    if is_train:
        augs = [
            imgaug.RandomApplyAug(imgaug.RandomResize((0.8, 1.2), (0.8, 1.2)), 0.3),
            imgaug.RandomApplyAug(imgaug.RotationAndCropValid(15), 0.5),
            imgaug.RandomApplyAug(imgaug.SaltPepperNoise(white_prob=0.01, black_prob=0.01), 0.25),
            imgaug.Resize((224, 224), cv2.INTER_AREA)
        ]
        ds = AugmentImageComponent(ds, augs)
        ds = PrefetchData(ds, 128*10, multiprocessing.cpu_count())
        ds = BatchData(ds, batchsize)
        ds = PrefetchData(ds, 256, 4)
    else:
        # no augmentation, only resizing
        augs = [
            imgaug.Resize((image_size, image_size), cv2.INTER_CUBIC),
        ]
        ds = AugmentImageComponent(ds, augs)
        ds = BatchData(ds, batchsize)
        ds = PrefetchData(ds, 20, 2)
    return ds 
开发者ID:ildoonet,项目名称:tf-lcnn,代码行数:25,代码来源:data_feeder.py

示例9: get_heatmap

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def get_heatmap(self, target_size):
        heatmap = np.zeros((CocoMetadata.__coco_parts, self.height, self.width), dtype=np.float32)

        for joints in self.joint_list:
            for idx, point in enumerate(joints):
                if point[0] < 0 or point[1] < 0:
                    continue
                CocoMetadata.put_heatmap(heatmap, idx, point, self.sigma)

        heatmap = heatmap.transpose((1, 2, 0))

        # background
        heatmap[:, :, -1] = np.clip(1 - np.amax(heatmap, axis=2), 0.0, 1.0)

        if target_size:
            heatmap = cv2.resize(heatmap, target_size, interpolation=cv2.INTER_AREA)

        return heatmap.astype(np.float16) 
开发者ID:SrikanthVelpuri,项目名称:tf-pose,代码行数:20,代码来源:pose_dataset.py

示例10: _resize

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def _resize(img, shape):
        """Resize the specified image.

        :param img: image to resize
        :param shape: desired shape in the format (rows, columns)
        :return: resized image
        """
        if not (OPENCV_AVAILABLE or PILLOW_AVAILABLE):
            raise ValueError('No image library backend found.'' Install either '
                             'OpenCV or Pillow to support image processing.')

        if OPENCV_AVAILABLE:
            return cv2.resize(img, shape, interpolation=cv2.INTER_AREA)

        if PILLOW_AVAILABLE:
            return np.array(PIL.Image.fromarray(img).resize(shape))

        raise NotImplementedError 
开发者ID:microsoft,项目名称:MazeExplorer,代码行数:20,代码来源:vizdoom_gym.py

示例11: observation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def observation(self, obs):
        if self._key is None:
            frame = obs
        else:
            frame = obs[self._key]

        if self._grayscale:
            frame = cv2.cvtColor(frame, cv2.COLOR_RGB2GRAY)
        frame = cv2.resize(
            frame, (self._width, self._height), interpolation=cv2.INTER_AREA
        )
        if self._grayscale:
            frame = np.expand_dims(frame, -1)

        if self._key is None:
            obs = frame
        else:
            obs = obs.copy()
            obs[self._key] = frame
        return obs 
开发者ID:keiohta,项目名称:tf2rl,代码行数:22,代码来源:atari_wrapper.py

示例12: custom_hashing

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def custom_hashing(image, hash_size=8):
    image = cv2.resize(image, (hash_size + 1, hash_size), cv2.INTER_AREA)
    pixel = []
    [rows, cols] = image.shape
    for i in range(0, rows):
        for j in range(0, cols):
            pixel.append(image.item(i, j))
    pixels = list(pixel)

    difference = []
    for row in range(hash_size - 1):
        for col in range(hash_size - 1):
            pixel_left = image.item(row, col)
            pixel_right = image.item(row, col + 1)
            difference.append(pixel_left > pixel_right)
    decimal_value = 0
    hex_string = []
    for index, value in enumerate(difference):
        if value:
            decimal_value += 2 ** (index % 8)
        if (index % 8) == 7:
            hex_string.append(hex(decimal_value)[2:].rjust(2, "0"))
            decimal_value = 0
    return "".join(hex_string) 
开发者ID:0xPrateek,项目名称:Photoroid,代码行数:26,代码来源:new_algo.py

示例13: process_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def process_image(self, img):
        assert self._bot + self._top < img.shape[0], "Overcrop! bot + top crop >= image height!"
        assert self._right + self._left < img.shape[1], "Overcrop! right + left crop >= image width!"

        bot, right = self._bot, self._right
        if self._bot <= 0:
            bot = -(img.shape[0] + 10)
        if self._right <= 0:
            right = -(img.shape[1] + 10)
        img = img[self._top:-bot, self._left:-right]

        if self.flip:
            img = img[::-1, ::-1]

        if (self.height, self.width) != img.shape[:2]:
            return cv2.resize(img, (self.width, self.height), interpolation=cv2.INTER_AREA)
        return img 
开发者ID:SudeepDasari,项目名称:visual_foresight,代码行数:19,代码来源:topic_utils.py

示例14: _modify_observation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def _modify_observation(self, observation):
        # convert color to grayscale using luma component
        observation = (
            observation[:, :, 0] * 0.299 + observation[:, :, 1] * 0.587 +
            observation[:, :, 2] * 0.114
        )

        observation = cv2.resize(
            observation, (84, 110), interpolation=cv2.INTER_AREA
        )
        observation = observation[18:102, :]
        assert observation.shape == (84, 84)

        # convert to values between 0 and 1
        observation = np.array(observation, dtype=np.uint8)

        return observation 
开发者ID:NervanaSystems,项目名称:ngraph-python,代码行数:19,代码来源:gym_wrapper.py

示例15: letterbox

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import INTER_AREA [as 别名]
def letterbox(img, new_shape=416, color=(128, 128, 128), mode='auto', interp=cv2.INTER_AREA):
    # Resize a rectangular image to a 32 pixel multiple rectangle
    # https://github.com/ultralytics/yolov3/issues/232
    shape = img.shape[:2]  # current shape [height, width]

    if isinstance(new_shape, int):
        r = float(new_shape) / max(shape)  # ratio  = new / old
    else:
        r = max(new_shape) / max(shape)
    ratio = r, r  # width, height ratios
    new_unpad = (int(round(shape[1] * r)), int(round(shape[0] * r)))

    # Compute padding https://github.com/ultralytics/yolov3/issues/232
    if mode is 'auto':  # minimum rectangle
        dw = np.mod(new_shape - new_unpad[0], 32) / 2  # width padding
        dh = np.mod(new_shape - new_unpad[1], 32) / 2  # height padding
    elif mode is 'square':  # square
        dw = (new_shape - new_unpad[0]) / 2  # width padding
        dh = (new_shape - new_unpad[1]) / 2  # height padding
    elif mode is 'rect':  # square
        dw = (new_shape[1] - new_unpad[0]) / 2  # width padding
        dh = (new_shape[0] - new_unpad[1]) / 2  # height padding
    elif mode is 'scaleFill':
        dw, dh = 0.0, 0.0
        new_unpad = (new_shape, new_shape)
        ratio = new_shape / shape[1], new_shape / shape[0]  # width, height ratios

    if shape[::-1] != new_unpad:  # resize
        img = cv2.resize(img, new_unpad, interpolation=interp)  # INTER_AREA is better, INTER_LINEAR is faster
    top, bottom = int(round(dh - 0.1)), int(round(dh + 0.1))
    left, right = int(round(dw - 0.1)), int(round(dw + 0.1))
    img = cv2.copyMakeBorder(img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color)  # add border
    return img, ratio, dw, dh 
开发者ID:zbyuan,项目名称:pruning_yolov3,代码行数:35,代码来源:datasets.py


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