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


Python cv2.BORDER_TRANSPARENT属性代码示例

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


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

示例1: transformation_points

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def transformation_points(src_img, src_points, dst_img, dst_points):
    src_points = src_points.astype(np.float64)
    dst_points = dst_points.astype(np.float64)

    c1 = np.mean(src_points, axis=0)
    c2 = np.mean(dst_points, axis=0)

    src_points -= c1
    dst_points -= c2

    s1 = np.std(src_points)
    s2 = np.std(dst_points)

    src_points /= s1
    dst_points /= s2

    u, s, vt = np.linalg.svd(src_points.T * dst_points)
    r = (u * vt).T

    m = np.vstack([np.hstack(((s2 / s1) * r, c2.T - (s2 / s1) * r * c1.T)), np.matrix([0., 0., 1.])])

    output = cv2.warpAffine(dst_img, m[:2],
                            (src_img.shape[1], src_img.shape[0]),
                            borderMode=cv2.BORDER_TRANSPARENT,
                            flags=cv2.WARP_INVERSE_MAP)

    return output 
开发者ID:gyp03,项目名称:yry,代码行数:29,代码来源:morpher.py

示例2: tran_matrix

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def tran_matrix(src_img, src_points, dst_img, dst_points):
    h = cv2.findHomography(dst_points, src_points)
    output = cv2.warpAffine(dst_img, h[0][:2], (src_img.shape[1], src_img.shape[0]),
                            borderMode=cv2.BORDER_TRANSPARENT,
                            flags=cv2.WARP_INVERSE_MAP)

    return output 
开发者ID:gyp03,项目名称:yry,代码行数:9,代码来源:morpher.py

示例3: rotoscope

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def rotoscope(self, dst, warp, properties):
        if properties['show'] == False:
            return dst

        corners = properties['corners']

        wRows, wCols, wCh = warp.shape
        rows, cols, ch = dst.shape

        # Apply blur on warp
        kernel = np.ones((5, 5), np.float32) / 25
        warp = cv2.filter2D(warp, -1, kernel)

        # Prepare points to be matched on Affine Transformation
        pts1 = np.float32([[0, 0],[wCols, 0],[0, wRows]])
        pts2 = np.float32(corners) * 2

        # Enlarge image to multisample
        dst = cv2.resize(dst, (cols * 2, rows * 2))

        # Transform image with the Matrix
        M = cv2.getAffineTransform(pts1, pts2)
        cv2.warpAffine(warp, M, (cols * 2, rows * 2), dst, flags=cv2.INTER_AREA, borderMode=cv2.BORDER_TRANSPARENT)

        # Sample back image size
        dst = cv2.resize(dst, (cols, rows))

        return dst 
开发者ID:TrustyJAID,项目名称:Trusty-cogs-archive,代码行数:30,代码来源:trump.py

示例4: warp_im

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def warp_im(im, M, dshape):
    output_im = numpy.zeros(dshape, dtype=im.dtype)
    cv2.warpAffine(
        im,
        M[:2], (dshape[1], dshape[0]),
        dst=output_im,
        borderMode=cv2.BORDER_TRANSPARENT,
        flags=cv2.WARP_INVERSE_MAP)
    return output_im 
开发者ID:vipstone,项目名称:faceai,代码行数:11,代码来源:faceswap.py

示例5: elastic_transform3Dv2

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def elastic_transform3Dv2(self, image, alpha, sigma, alpha_affine, random_state=None):
        """Elastic deformation of images as described in [Simard2003]_ (with modifications).
        .. [Simard2003] Simard, Steinkraus and Platt, "Best Practices for
             Convolutional Neural Networks applied to Visual Document Analysis", in
             Proc. of the International Conference on Document Analysis and
             Recognition, 2003.
         Based on https://gist.github.com/erniejunior/601cdf56d2b424757de5
         From https://www.kaggle.com/bguberfain/elastic-transform-for-data-augmentation
        """
        # affine and deformation must be slice by slice and fixed for slices
        if random_state is None:
            random_state = np.random.RandomState(None)
        shape = image.shape # image is contatenated, the first channel [:,:,:,0] is the image, the second channel 
        # [:,:,:,1] is the mask. The two channel are under the same tranformation.
        shape_size = shape[:-1] # z y x
        # Random affine
        shape_size_aff = shape[1:-1] # y x
        center_square = np.float32(shape_size_aff) // 2
        square_size = min(shape_size_aff) // 3
        pts1 = np.float32([center_square + square_size, [center_square[0]+square_size, center_square[1]-square_size],                           center_square - square_size])
        pts2 = pts1 + random_state.uniform(-alpha_affine, alpha_affine, size=pts1.shape).astype(np.float32)
        M = cv2.getAffineTransform(pts1, pts2)
        new_img = np.zeros_like(image)
        for i in range(shape[0]):
            new_img[i,:,:,0] = cv2.warpAffine(image[i,:,:,0], M, shape_size_aff[::-1],                                               borderMode=cv2.BORDER_CONSTANT, borderValue=0.)
            for j in range(1, 10):
                new_img[i,:,:,j] = cv2.warpAffine(image[i,:,:,j], M, shape_size_aff[::-1], flags=cv2.INTER_NEAREST,                                                  borderMode=cv2.BORDER_TRANSPARENT, borderValue=0)
        dx = gaussian_filter((random_state.rand(*shape[1:-1]) * 2 - 1), sigma) * alpha
        dy = gaussian_filter((random_state.rand(*shape[1:-1]) * 2 - 1), sigma) * alpha
        x, y = np.meshgrid(np.arange(shape_size_aff[1]), np.arange(shape_size_aff[0]))
        indices = np.reshape(y+dy, (-1, 1)), np.reshape(x+dx, (-1, 1))
        new_img2 = np.zeros_like(image)
        for i in range(shape[0]):
            new_img2[i,:,:,0] = map_coordinates(new_img[i,:,:,0], indices, order=1, mode='constant').reshape(shape[1:-1])
            for j in range(1, 10):
                new_img2[i,:,:,j] = map_coordinates(new_img[i,:,:,j], indices, order=0, mode='constant').reshape(shape[1:-1])
        return np.array(new_img2), new_img 
开发者ID:wentaozhu,项目名称:AnatomyNet-for-anatomical-segmentation,代码行数:39,代码来源:baseline3Pool.py

示例6: perspective_transform

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def perspective_transform(img, transformation_matrix, original_shape=None):
    warped = img

    if original_shape is not None:
        if original_shape[0]>0 and original_shape[1]>0:
            warped = cv2.resize(warped, (original_shape[1], original_shape[0]), interpolation=cv2.INTER_CUBIC)

    white_image = np.zeros((640, 480, 3), np.uint8)

    white_image[:,:,:] = 255

    # warped = cv2.warpPerspective(warped, transformation_matrix, (640, 480), borderMode=cv2.BORDER_TRANSPARENT)
    warped = cv2.warpPerspective(warped, transformation_matrix, (640, 480))

    return warped 
开发者ID:guille0,项目名称:songoku,代码行数:17,代码来源:helpers.py

示例7: warp_im

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def warp_im(im, M, dshape):
    output_im = np.zeros(dshape, dtype=im.dtype)
    cv2.warpAffine(im,
                   M[:2],
                   (dshape[1], dshape[0]),
                   dst=output_im,
                   borderMode=cv2.BORDER_TRANSPARENT,
                   flags=cv2.WARP_INVERSE_MAP)
    return output_im 
开发者ID:Nicholasli1995,项目名称:VisualizingNDF,代码行数:11,代码来源:cacd_process.py

示例8: warp_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def warp_image(src, flow):
  _, h, w = flow.shape
  flow_map = np.zeros(flow.shape, dtype=np.float32)
  for y in range(h):
    flow_map[1,y,:] = float(y) + flow[1,y,:]
  for x in range(w):
    flow_map[0,:,x] = float(x) + flow[0,:,x]
  # remap pixels to optical flow
  dst = cv2.remap(
    src, flow_map[0], flow_map[1], 
    interpolation=cv2.INTER_CUBIC, borderMode=cv2.BORDER_TRANSPARENT)
  return dst 
开发者ID:cysmith,项目名称:neural-style-tf,代码行数:14,代码来源:neural_style.py

示例9: warp_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def warp_image(img, tM, shape):
    out = np.zeros(shape, dtype=img.dtype)
    # cv2.warpAffine(img,
    #                tM[:2],
    #                (shape[1], shape[0]),
    #                dst=out,
    #                borderMode=cv2.BORDER_TRANSPARENT,
    #                flags=cv2.WARP_INVERSE_MAP)
    cv2.warpPerspective(img, tM, (shape[1], shape[0]), dst=out,
                        borderMode=cv2.BORDER_TRANSPARENT,
                        flags=cv2.WARP_INVERSE_MAP)
    return out

# TODO: Modify this method to get a better face contour mask 
开发者ID:Aravind-Suresh,项目名称:FaceSwap,代码行数:16,代码来源:main.py

示例10: warp_im

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def warp_im(im, M, dshape):
    output_im = numpy.zeros(dshape, dtype=im.dtype)
    cv2.warpAffine(im,
                   M[:2],
                   (dshape[1], dshape[0]),
                   dst=output_im,
                   borderMode=cv2.BORDER_TRANSPARENT,
                   flags=cv2.WARP_INVERSE_MAP)
    return output_im 
开发者ID:matthewearl,项目名称:faceswap,代码行数:11,代码来源:faceswap.py

示例11: warp_im

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def warp_im(self,im, M, dshape):
        '''
        人脸位置仿射变换
        '''
        output_im = np.zeros(dshape, dtype=im.dtype)
        cv2.warpAffine(im,
                       M[:2],
                       (dshape[1], dshape[0]),
                       dst=output_im,
                       borderMode=cv2.BORDER_TRANSPARENT,
                       flags=cv2.WARP_INVERSE_MAP)
        return output_im 
开发者ID:QuantumLiu,项目名称:FaceSwapper,代码行数:14,代码来源:faceswapper.py

示例12: tran_matrix

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def tran_matrix(src_img, src_points, dst_img, dst_points):
    h = cv2.findHomography(dst_points, src_points)
    output = cv2.warpAffine(dst_img, h[0][:2], (src_img.shape[1], src_img.shape[0]),
                            borderMode=cv2.BORDER_TRANSPARENT,
                            flags=cv2.WARP_INVERSE_MAP)
    return output 
开发者ID:tonyiweb,项目名称:face_merge_master,代码行数:8,代码来源:morpher.py

示例13: rotoscope

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def rotoscope(self, dst, warp, properties: dict):
        if not properties["show"]:
            return dst

        corners = properties["corners"]

        wRows, wCols, wCh = warp.shape
        rows, cols, ch = dst.shape

        # Apply blur on warp
        kernel = np.ones((5, 5), np.float32) / 25
        warp = cv2.filter2D(warp, -1, kernel)

        # Prepare points to be matched on Affine Transformation
        pts1 = np.float32([[0, 0], [wCols, 0], [0, wRows]])
        pts2 = np.float32(corners) * 2

        # Enlarge image to multisample
        dst = cv2.resize(dst, (cols * 2, rows * 2))

        # Transform image with the Matrix
        M = cv2.getAffineTransform(pts1, pts2)
        cv2.warpAffine(
            warp,
            M,
            (cols * 2, rows * 2),
            dst,
            flags=cv2.INTER_AREA,
            borderMode=cv2.BORDER_TRANSPARENT,
        )

        # Sample back image size
        dst = cv2.resize(dst, (cols, rows))

        return dst 
开发者ID:TrustyJAID,项目名称:Trusty-cogs,代码行数:37,代码来源:imagemaker.py

示例14: add_substitute_quad

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import BORDER_TRANSPARENT [as 别名]
def add_substitute_quad(image, substitute_quad, dst):
 
    # dst (zeroed) and src points
    dst = _order_points(dst)
 
    (tl, tr, br, bl) = dst
    min_x = min(int(tl[0]), int(bl[0]))
    min_y = min(int(tl[1]), int(tr[1]))
 
    for point in dst:
        point[0] = point[0] - min_x
        point[1] = point[1] - min_y
 
    (max_width,max_height) = _max_width_height(dst)
    src = _topdown_points(max_width, max_height)
 
    # warp perspective (with white border)
    substitute_quad = cv2.resize(substitute_quad, (max_width,max_height))
 
    warped = np.zeros((max_height,max_width,3), np.uint8)
    warped[:,:,:] = 255
 
    matrix = cv2.getPerspectiveTransform(src, dst)
    cv2.warpPerspective(substitute_quad, matrix, (max_width,max_height), warped, borderMode=cv2.BORDER_TRANSPARENT)
 
    # add substitute quad
    image[min_y:min_y + max_height, min_x:min_x + max_width] = warped
 
    return image 
开发者ID:rdmilligan,项目名称:SaltwashAR,代码行数:31,代码来源:televisionfunctions.py


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