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


Python cv2.INTER_LANCZOS4屬性代碼示例

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


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

示例1: _resize_cv2

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def _resize_cv2(img, size, interpolation):
    img = img.transpose((1, 2, 0))
    if interpolation == PIL.Image.NEAREST:
        cv_interpolation = cv2.INTER_NEAREST
    elif interpolation == PIL.Image.BILINEAR:
        cv_interpolation = cv2.INTER_LINEAR
    elif interpolation == PIL.Image.BICUBIC:
        cv_interpolation = cv2.INTER_CUBIC
    elif interpolation == PIL.Image.LANCZOS:
        cv_interpolation = cv2.INTER_LANCZOS4
    H, W = size
    img = cv2.resize(img, dsize=(W, H), interpolation=cv_interpolation)

    # If input is a grayscale image, cv2 returns a two-dimentional array.
    if len(img.shape) == 2:
        img = img[:, :, np.newaxis]
    return img.transpose((2, 0, 1)) 
開發者ID:pfnet-research,項目名稱:chainer-compiler,代碼行數:19,代碼來源:resize.py

示例2: _resize

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def _resize(image, t_width=None, t_height=None, verbose=False):
    if verbose:
        print('RESIZING WITH t_width = %r and t_height = %r' % (t_width, t_height, ))
    height, width = image.shape[:2]
    if t_width is None and t_height is None:
        return image
    elif t_width is not None and t_height is not None:
        pass
    elif t_width is None:
        t_width = (width / height) * float(t_height)
    elif t_height is None:
        t_height = (height / width) * float(t_width)
    t_width, t_height = float(t_width), float(t_height)
    t_width, t_height = int(np.around(t_width)), int(np.around(t_height))
    assert t_width > 0 and t_height > 0, 'target size too small'
    assert t_width <= width * 10 and t_height <= height * 10, 'target size too large (capped at 1000%)'
    # interpolation = cv2.INTER_LANCZOS4
    interpolation = cv2.INTER_LINEAR
    return cv2.resize(image, (t_width, t_height), interpolation=interpolation) 
開發者ID:Erotemic,項目名稱:ibeis,代碼行數:21,代碼來源:detectfuncs.py

示例3: read_square_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def read_square_image(file, cam, boxsize, type):
    # from file
    if type == 'IMAGE':
        oriImg = cv2.imread(file)
    # from webcam
    elif type == 'WEBCAM':
        _, oriImg = cam.read()

    scale = boxsize / (oriImg.shape[0] * 1.0)
    imageToTest = cv2.resize(oriImg, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_LANCZOS4)

    output_img = np.ones((boxsize, boxsize, 3)) * 128

    if imageToTest.shape[1] < boxsize:
        offset = imageToTest.shape[1] % 2
        output_img[:, int(boxsize/2-math.ceil(imageToTest.shape[1]/2)):int(boxsize/2+math.ceil(imageToTest.shape[1]/2)+offset), :] = imageToTest
    else:
        output_img = imageToTest[:, int(imageToTest.shape[1]/2-boxsize/2):int(imageToTest.shape[1]/2+boxsize/2), :]
    return output_img 
開發者ID:timctho,項目名稱:convolutional-pose-machines-tensorflow,代碼行數:21,代碼來源:utils.py

示例4: _crop

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def _crop(self, img, box, out_size):
        # convert box to 0-indexed and center based [y, x, h, w]
        box = np.array([
            box[1] - 1 + (box[3] - 1) / 2,
            box[0] - 1 + (box[2] - 1) / 2,
            box[3], box[2]], dtype=np.float32)
        center, target_sz = box[:2], box[2:]

        context = self.context * np.sum(target_sz)
        size = np.sqrt(np.prod(target_sz + context))
        size *= out_size / self.exemplar_sz

        avg_color = np.mean(img, axis=(0, 1), dtype=float)
        interp = np.random.choice([
            cv2.INTER_LINEAR,
            cv2.INTER_CUBIC,
            cv2.INTER_AREA,
            cv2.INTER_NEAREST,
            cv2.INTER_LANCZOS4])
        patch = ops.crop_and_resize(
            img, center, size, out_size,
            border_value=avg_color, interp=interp)
        
        return patch 
開發者ID:huanglianghua,項目名稱:siamfc-pytorch,代碼行數:26,代碼來源:transforms.py

示例5: main

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def main():
    imageOne = cv2.imread("../data/4.1.04.tiff", 1)

    areaInter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_AREA)
    cubicInter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_CUBIC)
    linearInter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_LINEAR)
    nearestInter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_NEAREST)
    lancz0s4Inter = cv2.resize(imageOne, None, fx=3, fy=3, interpolation=cv2.INTER_LANCZOS4)

    cv2.imshow("Area Interpolation Image", areaInter)
    cv2.imshow("Cubic Interpolation Image", cubicInter)
    cv2.imshow("Linear Interpolation Image", linearInter)
    cv2.imshow("Nearest Interpolation Image", nearestInter)
    cv2.imshow("LANCZ0S4 Interpolation Image", lancz0s4Inter)

    cv2.waitKey(0)
    cv2.destroyAllWindows() 
開發者ID:amarlearning,項目名稱:Finger-Detection-and-Tracking,代碼行數:19,代碼來源:Scaling.py

示例6: process_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def process_image(img_id):
    if 'Pan-Sharpen_' in img_id:
        img_id = img_id.split('Pan-Sharpen_')[1]
    img = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'Pan-Sharpen', 'Pan-Sharpen_' + img_id+'.tif'))
    nir = img[:, :, 3:]
    img = img[:, :, :3]
    np.clip(img, None, threshold, out=img)
    img = np.floor_divide(img, threshold / 255).astype('uint8')
    cv2.imwrite(path.join(test_png, img_id + '.png'), img, [cv2.IMWRITE_PNG_COMPRESSION, 9])

    img2 = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'MS', 'MS_' + img_id+'.tif'))
    img2 = np.rollaxis(img2, 0, 3)
    img2 = cv2.resize(img2, (900, 900), interpolation=cv2.INTER_LANCZOS4)
    
    img_0_3_5 = (np.clip(img2[..., [0, 3, 5]], None, (2000, 3000, 3000)) / (np.array([2000, 3000, 3000]) / 255)).astype('uint8')
    cv2.imwrite(path.join(test_png2, img_id + '.png'), img_0_3_5, [cv2.IMWRITE_PNG_COMPRESSION, 9])
    
    pan = io.imread(path.join(test_dir, '_'.join(img_id.split('_')[:4]), 'PAN', 'PAN_' + img_id+'.tif'))
    pan = pan[..., np.newaxis]
    img_pan_6_7 = np.concatenate([pan, img2[..., 7:], nir], axis=2)
    img_pan_6_7 = (np.clip(img_pan_6_7, None, (3000, 5000, 5000)) / (np.array([3000, 5000, 5000]) / 255)).astype('uint8')
    cv2.imwrite(path.join(test_png3, img_id + '.png'), img_pan_6_7, [cv2.IMWRITE_PNG_COMPRESSION, 9]) 
開發者ID:SpaceNetChallenge,項目名稱:SpaceNet_Off_Nadir_Solutions,代碼行數:24,代碼來源:convert_test.py

示例7: resize

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def resize(img,size,interpolation=cv2.INTER_LINEAR):
    '''
    cv2.INTER_NEAREST      最鄰近插值點法
    cv2.INTER_LINEAR        雙線性插值法
    cv2.INTER_AREA         鄰域像素再取樣插補
    cv2.INTER_CUBIC        雙立方插補,4*4大小的補點
    cv2.INTER_LANCZOS4     8x8像素鄰域的Lanczos插值
    '''
    h, w = img.shape[:2]
    if np.min((w,h)) ==size:
        return img
    if w >= h:
        res = cv2.resize(img,(int(size*w/h), size),interpolation=interpolation)
    else:
        res = cv2.resize(img,(size, int(size*h/w)),interpolation=interpolation)
    return res 
開發者ID:HypoX64,項目名稱:DeepMosaics,代碼行數:18,代碼來源:image_processing.py

示例8: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def __init__(
        self,
        in_dir: Path,
        out_dir: Path,
        max_size: int = None,
        clear_exif: bool = True,
        grayscale: bool = False,
        expand_dims: bool = True,
        interpolation=cv2.INTER_LANCZOS4,
    ):
        """@TODO: Docs. Contribution is welcome."""
        self.in_dir = in_dir
        self.out_dir = out_dir
        self.grayscale = grayscale
        self.expand_dims = expand_dims
        self.max_size = max_size
        self.clear_exif = clear_exif
        self.interpolation = interpolation 
開發者ID:catalyst-team,項目名稱:catalyst,代碼行數:20,代碼來源:process_images.py

示例9: rotate_about_center

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def rotate_about_center(src, angle, scale=1.):
    """
    Rotate images based on there centers
        :param src: one image (opencv format)
        :param angle: rotated angle
        :param scale: re-scaling images [default: 1.]
    """
    w = src.shape[1]
    h = src.shape[0]
    rangle = np.deg2rad(angle)  # angle in radians
    # now calculate new image width and height
    nw = (abs(np.sin(rangle)*h) + abs(np.cos(rangle)*w))*scale
    nh = (abs(np.cos(rangle)*h) + abs(np.sin(rangle)*w))*scale
    # ask opencv for the rotation matrix
    rot_mat = cv2.getRotationMatrix2D((nw*0.5, nh*0.5), angle, scale)
    # calculate the move from the old center to the new center combined
    # with the rotation
    rot_move = np.dot(rot_mat, np.array([(nw-w)*0.5, (nh-h)*0.5,0]))
    # the move only affects the translation, so update the translation
    # part of the transform
    rot_mat[0,2] += rot_move[0]
    rot_mat[1,2] += rot_move[1]
    return cv2.warpAffine(src, rot_mat, (int(math.ceil(nw)), int(math.ceil(nh))), flags=cv2.INTER_LANCZOS4) 
開發者ID:driving-behavior,項目名稱:DBNet,代碼行數:25,代碼來源:las2fmap.py

示例10: _resize_subtract_mean

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def _resize_subtract_mean(image, insize, rgb_mean):
    interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4]
    interp_method = interp_methods[random.randrange(5)]
    image = cv2.resize(image, (insize, insize), interpolation=interp_method)
    image = image.astype(np.float32)
    image -= rgb_mean
    return image.transpose(2, 0, 1) 
開發者ID:zllrunning,項目名稱:hand-detection.PyTorch,代碼行數:9,代碼來源:data_augment.py

示例11: resize_dataset_image

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def resize_dataset_image(img, out_w=256, out_h=256):
    img2 = copy_to_cpu(img)
    img2 = img2.transpose((1, 2, 0))
    img2 = cv2.resize(img2, (out_h, out_w), cv2.INTER_LANCZOS4)
    img2 = img2.transpose((2, 0, 1))
    try:
        if type(img) == cupy.core.core.ndarray:
            img2 = cuda.to_gpu(img2)
    except:
        pass
    return img2

# b, ch, w, h 
開發者ID:pfnet-research,項目名稱:chainer-stylegan,代碼行數:15,代碼來源:image_processing.py

示例12: preproc_for_test

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def preproc_for_test(image, insize, mean):
    interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4]
    interp_method = interp_methods[random.randrange(5)]
    image = cv2.resize(image, (insize[0], insize[1]),interpolation=interp_method)
    image = image.astype(np.float32)
    image -= mean
    return image.transpose(2, 0, 1) 
開發者ID:ShuangXieIrene,項目名稱:ssds.pytorch,代碼行數:9,代碼來源:data_augment.py

示例13: __init__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def __init__(self,
                 height,
                 width,
                 interpolation_modes=[cv2.INTER_NEAREST,
                                      cv2.INTER_LINEAR,
                                      cv2.INTER_CUBIC,
                                      cv2.INTER_AREA,
                                      cv2.INTER_LANCZOS4],
                 box_filter=None,
                 labels_format={'class_id': 0, 'xmin': 1, 'ymin': 2, 'xmax': 3, 'ymax': 4}):
        '''
        Arguments:
            height (int): The desired height of the output image in pixels.
            width (int): The desired width of the output image in pixels.
            interpolation_modes (list/tuple, optional): A list/tuple of integers
                that represent valid OpenCV interpolation modes. For example,
                integers 0 through 5 are valid interpolation modes.
            box_filter (BoxFilter, optional): Only relevant if ground truth bounding boxes are given.
                A `BoxFilter` object to filter out bounding boxes that don't meet the given criteria
                after the transformation. Refer to the `BoxFilter` documentation for details. If `None`,
                the validity of the bounding boxes is not checked.
            labels_format (dict, optional): A dictionary that defines which index in the last axis of the labels
                of an image contains which bounding box coordinate. The dictionary maps at least the keywords
                'xmin', 'ymin', 'xmax', and 'ymax' to their respective indices within last axis of the labels array.
        '''
        if not (isinstance(interpolation_modes, (list, tuple))):
            raise ValueError("`interpolation_mode` must be a list or tuple.")
        self.height = height
        self.width = width
        self.interpolation_modes = interpolation_modes
        self.box_filter = box_filter
        self.labels_format = labels_format
        self.resize = Resize(height=self.height,
                             width=self.width,
                             box_filter=self.box_filter,
                             labels_format=self.labels_format) 
開發者ID:pierluigiferrari,項目名稱:data_generator_object_detection_2d,代碼行數:38,代碼來源:object_detection_2d_geometric_ops.py

示例14: preproc_for_test

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def preproc_for_test(image, input_size, mean, std):
    interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4]
    interp_method = interp_methods[random.randrange(5)]
    image = cv2.resize(image, input_size,interpolation=interp_method)
    image = image.astype(np.float32)
    image = image[:,:,::-1]
    image /= 255.
    if mean is not None:
        image -= mean
    if std is not None:
        image /= std
    return image.transpose(2, 0, 1) 
開發者ID:ruinmessi,項目名稱:ASFF,代碼行數:14,代碼來源:data_augment.py

示例15: __call__

# 需要導入模塊: import cv2 [as 別名]
# 或者: from cv2 import INTER_LANCZOS4 [as 別名]
def __call__(self, img, res, input_size):

        interp_methods = [cv2.INTER_LINEAR, cv2.INTER_CUBIC, cv2.INTER_AREA, cv2.INTER_NEAREST, cv2.INTER_LANCZOS4]
        interp_method = interp_methods[0]
        img = cv2.resize(np.array(img), input_size,
                        interpolation = interp_method).astype(np.float32)
        img = img[:,:,::-1]
        img /= 255.
        if self.means is not None:
            img -= self.means
        if self.std is not None:
            img /= self.std
        img = img.transpose(self.swap)
        img = np.ascontiguousarray(img, dtype=np.float32)
        return torch.from_numpy(img), torch.zeros(1,5) 
開發者ID:ruinmessi,項目名稱:ASFF,代碼行數:17,代碼來源:data_augment.py


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