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


Python cv2.getRotationMatrix2D方法代码示例

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


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

示例1: cv_rotate

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def cv_rotate(image, landmarks, heatmap, rot, scale, resolution=256):
    img_mat = cv2.getRotationMatrix2D((resolution//2, resolution//2), rot, scale)
    ones = np.ones(shape=(landmarks.shape[0], 1))
    stacked_landmarks = np.hstack([landmarks, ones])
    new_landmarks = img_mat.dot(stacked_landmarks.T).T
    if np.max(new_landmarks) > 255 or np.min(new_landmarks) < 0:
        return image, landmarks, heatmap
    else:
        new_image = cv2.warpAffine(image, img_mat, (resolution, resolution))
        if heatmap is not None:
            new_heatmap = np.zeros((heatmap.shape[0], 64, 64))
            for i in range(heatmap.shape[0]):
                if new_landmarks[i][0] > 0:
                    new_heatmap[i] = draw_gaussian(new_heatmap[i],
                                                   new_landmarks[i]/4.0+1, 1)
        return new_image, new_landmarks, new_heatmap 
开发者ID:protossw512,项目名称:AdaptiveWingLoss,代码行数:18,代码来源:utils.py

示例2: get_transform

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def get_transform(self, img):
        center = img.shape[1::-1] * self._rand_range(
            self.center_range[0], self.center_range[1], (2,))
        deg = self._rand_range(-self.max_deg, self.max_deg)
        if self.step_deg:
            deg = deg // self.step_deg * self.step_deg
        """
        The correct center is shape*0.5-0.5. This can be verified by:

        SHAPE = 7
        arr = np.random.rand(SHAPE, SHAPE)
        orig = arr
        c = SHAPE * 0.5 - 0.5
        c = (c, c)
        for k in range(4):
            mat = cv2.getRotationMatrix2D(c, 90, 1)
            arr = cv2.warpAffine(arr, mat, arr.shape)
        assert np.all(arr == orig)
        """
        mat = cv2.getRotationMatrix2D(tuple(center - 0.5), deg, 1)
        return WarpAffineTransform(
            mat, img.shape[1::-1], interp=self.interp,
            borderMode=self.border, borderValue=self.border_value) 
开发者ID:tensorpack,项目名称:dataflow,代码行数:25,代码来源:geometry.py

示例3: merge_img

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def merge_img(src_img, dst_img, dst_matrix, dst_points, blur_detail_x=None, blur_detail_y=None, mat_multiple=None):
    face_mask = np.zeros(src_img.shape, dtype=src_img.dtype)

    for group in core.OVERLAY_POINTS:
        cv2.fillConvexPoly(face_mask, cv2.convexHull(dst_matrix[group]), (255, 255, 255))

    r = cv2.boundingRect(np.float32([dst_points[:core.FACE_END]]))

    center = (r[0] + int(r[2] / 2), r[1] + int(r[3] / 2))

    if mat_multiple:
        mat = cv2.getRotationMatrix2D(center, 0, mat_multiple)
        face_mask = cv2.warpAffine(face_mask, mat, (face_mask.shape[1], face_mask.shape[0]))

    if blur_detail_x and blur_detail_y:
        face_mask = cv2.blur(face_mask, (blur_detail_x, blur_detail_y), center)

    return cv2.seamlessClone(np.uint8(dst_img), src_img, face_mask, center, cv2.NORMAL_CLONE) 
开发者ID:gyp03,项目名称:yry,代码行数:20,代码来源:morpher.py

示例4: __init__

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def __init__(self, y, x, height, width, angle):
        """
        A efficient tool to rotate multiple images in the same size.
        :author 申瑞珉 (Ruimin Shen)
        :param y: The y coordinate of rotation point.
        :param x: The x coordinate of rotation point.
        :param height: Image height.
        :param width: Image width.
        :param angle: Rotate angle.
        """
        self._mat = cv2.getRotationMatrix2D((x, y), angle, 1.0)
        r = np.abs(self._mat[0, :2])
        _height, _width = np.inner(r, [height, width]), np.inner(r, [width, height])
        fix_y, fix_x = _height / 2 - y, _width / 2 - x
        self._mat[:, 2] += [fix_x, fix_y]
        self._size = int(_width), int(_height) 
开发者ID:ruiminshen,项目名称:yolo2-pytorch,代码行数:18,代码来源:augmentation.py

示例5: __rotate_image_size_corrected

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def __rotate_image_size_corrected(image, angle):
    # Calculate max size for the rotated template and image offset
    image_size_height, image_size_width = image.shape
    image_center_x = image_size_width // 2
    image_center_y = image_size_height // 2

    # Create rotation matrix
    rotation_matrix = cv2.getRotationMatrix2D((image_center_x, image_center_y), -angle, 1)

    # Apply offset
    new_image_size = int(math.ceil(cv2.norm((image_size_height, image_size_width), normType=cv2.NORM_L2)))
    rotation_matrix[0, 2] += (new_image_size - image_size_width) / 2
    rotation_matrix[1, 2] += (new_image_size - image_size_height) / 2

    # Apply rotation to the template
    image_rotated = cv2.warpAffine(image, rotation_matrix, (new_image_size, new_image_size))
    return image_rotated 
开发者ID:microsoft,项目名称:AI-Robot-Challenge-Lab,代码行数:19,代码来源:cv_detection_right_hand.py

示例6: rotate_oriented_bbox_to_horizontal

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def rotate_oriented_bbox_to_horizontal(center, bbox):
    """
    Step 2 of Figure 5 in seglink paper
    
    Rotate bbox horizontally along a `center` point
    Args:
        center: the center of rotation
        bbox: [cx, cy, w, h, theta]
    """
    assert np.shape(center) == (2, ), "center must be a vector of length 2"
    assert np.shape(bbox) == (5, ) or np.shape(bbox) == (4, ), "bbox must be a vector of length 4 or 5"
    bbox = np.asarray(bbox.copy(), dtype = np.float32)
    
    cx, cy, w, h, theta = bbox;
    M = cv2.getRotationMatrix2D(center, theta, scale = 1) # 2x3
    
    cx, cy = np.dot(M, np.transpose([cx, cy, 1]))
    
    bbox[0:2] = [cx, cy] 
    return bbox 
开发者ID:dengdan,项目名称:seglink,代码行数:22,代码来源:seglink.py

示例7: rotate_horizontal_bbox_to_oriented

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def rotate_horizontal_bbox_to_oriented(center, bbox):
    """
    Step 4 of Figure 5 in seglink paper: 
        Rotate the cropped horizontal bbox back to its original direction
    Args:
        center: the center of rotation
        bbox: [cx, cy, w, h, theta]
    Return: the oriented bbox
    """
    assert np.shape(center) == (2, ), "center must be a vector of length 2"
    assert np.shape(bbox) == (5, ) , "bbox must be a vector of length 4 or 5"
    bbox = np.asarray(bbox.copy(), dtype = np.float32)
    
    cx, cy, w, h, theta = bbox;
    M = cv2.getRotationMatrix2D(center, -theta, scale = 1) # 2x3
    cx, cy = np.dot(M, np.transpose([cx, cy, 1]))
    bbox[0:2] = [cx, cy]
    return bbox 
开发者ID:dengdan,项目名称:seglink,代码行数:20,代码来源:seglink.py

示例8: rotate_bound

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def rotate_bound(image, angle):
    # grab the dimensions of the image and then determine the
    # centre
    (h, w) = image.shape[:2]
    (cX, cY) = (w // 2, h // 2)

    # grab the rotation matrix (applying the negative of the
    # angle to rotate clockwise), then grab the sine and cosine
    # (i.e., the rotation components of the matrix)
    M = cv2.getRotationMatrix2D((cX, cY), angle, 1.0)
    cos = np.abs(M[0, 0])
    sin = np.abs(M[0, 1])

    # compute the new bounding dimensions of the image
    nW = int((h * sin) + (w * cos))
    nH = int((h * cos) + (w * sin))

    # adjust the rotation matrix to take into account translation
    M[0, 2] += (nW / 2) - cX
    M[1, 2] += (nH / 2) - cY

    # perform the actual rotation and return the image
    return cv2.warpAffine(image, M, (nW, nH)) 
开发者ID:tensorboy,项目名称:centerpose,代码行数:25,代码来源:data_inspect_utils.py

示例9: __rotate

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def __rotate(self, image, landmarks, max_angle):
        """
        Do image rotate
        Args:
            image: a numpy type
            landmarks: face landmarks with format [(x1, y1), ...]. range is 0-w or h in int
            max_angle: random to rotate in [-max_angle, max_angle]. range is 0-180.
        Return:
            an image and landmarks will be returned
        Raises:
            No
        """
        c_x = (min(landmarks[:, 0]) + max(landmarks[:, 0])) / 2
        c_y = (min(landmarks[:, 1]) + max(landmarks[:, 1])) / 2
        h, w = image.shape[:2]
        angle = np.random.randint(-max_angle, max_angle)
        M = cv2.getRotationMatrix2D((c_x, c_y), angle, 1)
        image = cv2.warpAffine(image, M, (w, h))
        b = np.ones((landmarks.shape[0], 1))
        d = np.concatenate((landmarks, b), axis=1)
        landmarks = np.dot(d, np.transpose(M))
        return image, landmarks 
开发者ID:junhwanjang,项目名称:face_landmark_dnn,代码行数:24,代码来源:landmark_augment.py

示例10: rotation

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def rotation(img, degrees, interpolation=cv2.INTER_LINEAR, value=0):
    if isinstance(degrees, list):
        if len(degrees) == 2:
            degree = random.uniform(degrees[0], degrees[1])
        else:
            degree = random.choice(degrees)
    else:
        degree = degrees

    h, w = img.shape[0:2]
    center = (w / 2, h / 2)
    map_matrix = cv2.getRotationMatrix2D(center, degree, 1.0)

    img = cv2.warpAffine(
        img,
        map_matrix, (w, h),
        flags=interpolation,
        borderMode=cv2.BORDER_CONSTANT,
        borderValue=value)

    return img 
开发者ID:lxx1991,项目名称:VS-ReID,代码行数:23,代码来源:transforms.py

示例11: rotate_img_np

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def rotate_img_np(img, gtboxes_and_label, r_theta):
    h, w, c = img.shape
    center = (w // 2, h // 2)

    M = cv2.getRotationMatrix2D(center, r_theta, 1.0)
    cos, sin = np.abs(M[0, 0]), np.abs(M[0, 1])
    nW, nH = int(h*sin + w*cos), int(h*cos + w*sin)  # new W and new H
    M[0, 2] += (nW/2) - center[0]
    M[1, 2] += (nH/2) - center[1]
    rotated_img = cv2.warpAffine(img, M, (nW, nH))
    # -------

    new_points_list = []
    obj_num = len(gtboxes_and_label)
    for st in range(0, 7, 2):
        points = gtboxes_and_label[:, st:st+2]
        expand_points = np.concatenate((points, np.ones(shape=(obj_num, 1))), axis=1)
        new_points = np.dot(M, expand_points.T)
        new_points = new_points.T
        new_points_list.append(new_points)
    gtboxes = np.concatenate(new_points_list, axis=1)
    gtboxes_and_label = np.concatenate((gtboxes, gtboxes_and_label[:, -1].reshape(-1, 1)), axis=1)
    gtboxes_and_label = np.asarray(gtboxes_and_label, dtype=np.int32)

    return rotated_img, gtboxes_and_label 
开发者ID:Thinklab-SJTU,项目名称:R3Det_Tensorflow,代码行数:27,代码来源:image_preprocess_multi_gpu.py

示例12: rotate_bound

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def rotate_bound(image, angle):
    # grab the dimensions of the image and then determine the
    # center
    h, w = image.shape[:2]

    (cX, cY) = (w // 2, h // 2)

    M = cv2.getRotationMatrix2D((cX, cY), angle, 1.0)
    cos = np.abs(M[0, 0])
    sin = np.abs(M[0, 1])

    # compute the new bounding dimensions of the image
    nW = int((h * sin) + (w * cos))
    nH = int((h * cos) + (w * sin))

    # adjust the rotation matrix to take into account translation
    M[0, 2] += (nW / 2) - cX
    M[1, 2] += (nH / 2) - cY

    rotated = cv2.warpAffine(image, M, (nW, nH))

    return rotated 
开发者ID:KaiJin1995,项目名称:ZSL2018_Zero_Shot_Learning,代码行数:24,代码来源:transforms_self.py

示例13: dumpRotateImage

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def dumpRotateImage(img, degree, pt1, pt2, pt3, pt4):
    height, width = img.shape[:2]
    heightNew = int(width * fabs(sin(radians(degree))) + height * fabs(cos(radians(degree))))
    widthNew = int(height * fabs(sin(radians(degree))) + width * fabs(cos(radians(degree))))
    matRotation = cv2.getRotationMatrix2D((width // 2, height // 2), degree, 1)
    matRotation[0, 2] += (widthNew - width) // 2
    matRotation[1, 2] += (heightNew - height) // 2
    imgRotation = cv2.warpAffine(img, matRotation, (widthNew, heightNew), borderValue=(255, 255, 255))
    pt1 = list(pt1)
    pt3 = list(pt3)

    [[pt1[0]], [pt1[1]]] = np.dot(matRotation, np.array([[pt1[0]], [pt1[1]], [1]]))
    [[pt3[0]], [pt3[1]]] = np.dot(matRotation, np.array([[pt3[0]], [pt3[1]], [1]]))
    ydim, xdim = imgRotation.shape[:2]
    imgOut = imgRotation[max(1, int(pt1[1])): min(ydim - 1, int(pt3[1])),
             max(1, int(pt1[0])): min(xdim - 1, int(pt3[0]))]

    return imgOut 
开发者ID:GlassyWing,项目名称:text-detection-ocr,代码行数:20,代码来源:text_detection_app.py

示例14: random_rotate

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def random_rotate(self, img):
        """Random rotations by 0, 90, 180, 360 degrees"""
        theta = np.random.choice([0, 90, 180, 360])
        if theta == 0:
            return img
        h, w, _ = img.shape
        mat = cv2.getRotationMatrix2D((w / 2, h / 2), theta, 1)
        return cv2.warpAffine(img, mat, (w, h)) 
开发者ID:preritj,项目名称:progressive_growing_of_GANs,代码行数:10,代码来源:utils.py

示例15: apply_transform_image

# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import getRotationMatrix2D [as 别名]
def apply_transform_image(image, rot,sc, horz_flip, inputRes=None):

    meanval = (104.00699, 116.66877, 122.67892)

    if inputRes is not None:
        image = sm.imresize(image, inputRes)

    #print(image.shape)
    h, w = image.shape[:2]

    center = (w / 2, h / 2)
    assert (center != 0)  # Strange behaviour warpAffine
    M = cv2.getRotationMatrix2D(center, rot, sc)

    image = np.array(image, dtype=np.float32)
    image = np.subtract(image, np.array(meanval, dtype=np.float32))

    flagval = cv2.INTER_CUBIC
    image = cv2.warpAffine(image, M, (w,h),flags=flagval)

    if horz_flip:
        image = cv2.flip(image,flipCode=1)

    if image.ndim == 2:
        image=image[:,:,np.newaxis]

    # swap color axis because
    # numpy image: H x W x C
    # torch image: C X H X W

    image = image.transpose((2,0,1))
    image = torch.from_numpy(image)

    return image 
开发者ID:omkar13,项目名称:MaskTrack,代码行数:36,代码来源:utility_functions.py


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