本文整理汇总了Python中cv2.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python cv2.rotate方法的具体用法?Python cv2.rotate怎么用?Python cv2.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cv2
的用法示例。
在下文中一共展示了cv2.rotate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ff_mask_batch
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import rotate [as 别名]
def ff_mask_batch(size, b_size, maxLen, maxWid, maxAng, maxNum, maxVer, minLen = 20, minWid = 15, minVer = 5):
mask = None
temp = ff_mask(size, 1, maxLen, maxWid, maxAng, maxNum, maxVer, minLen=minLen, minWid=minWid, minVer=minVer)
temp = temp[0]
for ib in range(b_size):
if ib == 0:
mask = np.expand_dims(temp, 0)
else:
mask = np.concatenate((mask, np.expand_dims(temp, 0)), 0)
temp = cv2.rotate(temp, cv2.ROTATE_90_CLOCKWISE)
if ib == 3:
temp = cv2.flip(temp, 0)
return mask
开发者ID:Forty-lock,项目名称:PEPSI-Fast_image_inpainting_with_parallel_decoding_network,代码行数:18,代码来源:ops.py
示例2: rotate
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import rotate [as 别名]
def rotate(image, angle, center=None, scale=1.0):
(h, w) = image.shape[:2]
if center is None:
center = (w / 2, h / 2)
M = cv2.getRotationMatrix2D(center, angle, scale)
rotated = cv2.warpAffine(image, M, (w, h))
return rotated
示例3: fix_orientation
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import rotate [as 别名]
def fix_orientation(image, orientation):
# 1 = Horizontal(normal)
# 2 = Mirror horizontal
# 3 = Rotate 180
# 4 = Mirror vertical
# 5 = Mirror horizontal and rotate 270 CW
# 6 = Rotate 90 CW
# 7 = Mirror horizontal and rotate 90 CW
# 8 = Rotate 270 CW
if type(orientation) is list:
orientation = orientation[0]
if orientation == 1:
pass
elif orientation == 2:
image = cv2.flip(image, 0)
elif orientation == 3:
image = cv2.rotate(image, cv2.ROTATE_180)
elif orientation == 4:
image = cv2.flip(image, 1)
elif orientation == 5:
image = cv2.flip(image, 0)
image = cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE)
elif orientation == 6:
image = cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE)
elif orientation == 7:
image = cv2.flip(image, 0)
image = cv2.rotate(image, cv2.ROTATE_90_CLOCKWISE)
elif orientation == 8:
image = cv2.rotate(image, cv2.ROTATE_90_COUNTERCLOCKWISE)
return image
示例4: rotate_single
# 需要导入模块: import cv2 [as 别名]
# 或者: from cv2 import rotate [as 别名]
def rotate_single(image, gt_boxes, angle_range=10):
def rotate_bounding_box(image, box, M, center):
mask_image = generate_mask(image, [box])
mask_image = cv2.warpAffine(mask_image, M, center)
rotated_box = generate_bbox_from_mask(mask_image)
# print 'rotated_box shape: ', np.shape(rotated_box)
return rotated_box
'''
rotate single image with random angle
:param image: image
:param gt_boxes: bounding box in image that will rotate at same time. [N, 8]
:param angle_range:
:return:
'''
(h, w) = np.shape(image)[:2]
# if np.random.random() > 0.5:
# center = (0, 0)
# else:
# center = (w, h)
center = (w, h)
scale = 1.0
random_angle = np.random.random()
# if np.random.random() >= 0.5:
# random_angle *= angle_range
# else:
# random_angle *= (angle_range * -1)
random_angle *= angle_range
cv2.rotate(image, int(random_angle))
M = cv2.getRotationMatrix2D(center, random_angle, scale)
image_rotated = cv2.warpAffine(image, M, center)
gt_boxes_rotated = []
ignore = []
for index, gt_box in enumerate(gt_boxes):
cur_box = np.squeeze(rotate_bounding_box(image, gt_box, M, center))
if len(cur_box) == 0:
ignore.append(index)
continue
if len(np.shape(cur_box)) == 3:
gt_boxes_rotated.extend(cur_box)
if len(np.shape(cur_box)) == 2:
gt_boxes_rotated.append(cur_box)
return image_rotated, generate_mask(image, gt_boxes_rotated), gt_boxes_rotated, ignore