本文整理汇总了Python中imutils.rotate方法的典型用法代码示例。如果您正苦于以下问题:Python imutils.rotate方法的具体用法?Python imutils.rotate怎么用?Python imutils.rotate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类imutils
的用法示例。
在下文中一共展示了imutils.rotate方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: exitProg
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def exitProg(self):
config = open('satconfig.txt','w')
config.write(str(trackSettings.telescopetype)+'\n')
config.write(str(self.entryCom.get()) + '\n')
config.write(str(self.entryCam.get()) + '\n')
config.write(str(trackSettings.mainviewX) + '\n')
config.write(str(trackSettings.mainviewY) + '\n')
config.write(str(trackSettings.imagescale) + '\n')
config.write(str(self.entryLat.get())+'\n')
config.write(str(self.entryLon.get())+'\n')
config.write(str(trackSettings.trackingtype) + '\n')
config.write(str(trackSettings.minbright)+'\n')
config.write(str(trackSettings.flip)+'\n')
config.write(str(trackSettings.mounttype)+'\n')
config.write(str(trackSettings.rotate)+'\n')
config.close()
sys.exit()
示例2: generate_rotated_image
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def generate_rotated_image(image, lower_angle=-90, upper_angle=90):
"""Generate a rotated image with a random rotation angle"""
import imutils
percent = np.random.random()
percent_to_angle = lambda x: x * (upper_angle-lower_angle) + lower_angle
#percent_to_scale = lambda x: x * 0.5 + 0.5
angle = percent_to_angle(percent)
rotated = imutils.rotate(image, angle, scale=1)
return rotated, percent
示例3: test_layer_overlay_rotated
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def test_layer_overlay_rotated():
black_frame_image = np.zeros((100, 200, 3), dtype='uint8')
rand_frame_1_image = black_frame_image.copy()
rand_frame_2_image = black_frame_image.copy()
add_random_circles(rand_frame_1_image, seed=42)
add_random_circles(rand_frame_2_image, seed=8675309)
rand_frame_1 = Frame(rand_frame_1_image)
rand_frame_2 = Frame(rand_frame_2_image)
rand_frame_1, _ = border_frame(rand_frame_1, border_size=0, border_type='black')
rand_frame_2, _ = border_frame(rand_frame_2, border_size=0, border_type='black')
rand_frame_2 = imutils.rotate(rand_frame_2, 90)
overlay_1 = layer_overlay(rand_frame_1, rand_frame_2)
overlay_2 = layer_overlay(rand_frame_2, rand_frame_1)
overlay_2_expected = cv2.imread(overlay_2_test_file)
overlay_1 = overlay_1[:, :, :3]
overlay_2 = overlay_2[:, :, :3]
# write/read as jpg to match expected
cv2.imwrite(overlay_2_test_file, overlay_2)
overlay_2 = cv2.imread(overlay_2_test_file)
assert np.allclose(overlay_1, overlay_1)
assert np.allclose(overlay_2, overlay_2_expected)
示例4: get_transform
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def get_transform(center, scale, res, rot=0):
"""
General image processing functions
"""
# Generate transformation matrix
h = 200 * scale
t = np.zeros((3, 3))
t[0, 0] = float(res[1]) / h
t[1, 1] = float(res[0]) / h
t[0, 2] = res[1] * (-float(center[0]) / h + .5)
t[1, 2] = res[0] * (-float(center[1]) / h + .5)
t[2, 2] = 1
if not rot == 0:
rot = -rot # To match direction of rotation from cropping
rot_mat = np.zeros((3,3))
rot_rad = rot * np.pi / 180
sn,cs = np.sin(rot_rad), np.cos(rot_rad)
rot_mat[0,:2] = [cs, -sn]
rot_mat[1,:2] = [sn, cs]
rot_mat[2,2] = 1
# Need to rotate around center
t_mat = np.eye(3)
t_mat[0,2] = -res[1]/2
t_mat[1,2] = -res[0]/2
t_inv = t_mat.copy()
t_inv[:2,2] *= -1
t = np.dot(t_inv,np.dot(rot_mat,np.dot(t_mat,t)))
return t
示例5: set0Rotate
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def set0Rotate(self):
trackSettings.rotate = 0
示例6: setPos90Rotate
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def setPos90Rotate(self):
trackSettings.rotate = 90
示例7: setNeg90Rotate
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def setNeg90Rotate(self):
trackSettings.rotate = -90
示例8: set180Rotate
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def set180Rotate(self):
trackSettings.rotate = 180
示例9: get_sight
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def get_sight(self, orientation, veh_id):
"""Return the local observation of a vehicle.
Parameters
----------
orientation : list
An orientation is a list contains [x, y, angle]
veh_id : str
The vehicle to observe for
"""
x, y, ang = orientation
x = (x-self.x_shift)*self.x_scale*self.pxpm
y = (y-self.y_shift)*self.y_scale*self.pxpm
x_med = x
y_med = self.height - y
sight_radius = self.sight_radius * self.pxpm
x_min = int(x_med - sight_radius)
y_min = int(y_med - sight_radius)
x_max = int(x_med + sight_radius)
y_max = int(y_med + sight_radius)
fixed_sight = self.frame[y_min:y_max, x_min:x_max]
height, width = fixed_sight.shape[0:2]
mask = np.zeros((height, width), np.uint8)
cv2.circle(mask, (int(sight_radius), int(sight_radius)),
int(sight_radius), (255, 255, 255), thickness=-1)
rotated_sight = cv2.bitwise_and(fixed_sight, fixed_sight, mask=mask)
rotated_sight = imutils.rotate(rotated_sight, ang)
if self.save_render:
cv2.imwrite("%s/sight_%s_%06d.png" %
(self.path, veh_id, self.time),
rotated_sight)
if "gray" in self.mode:
return rotated_sight[:, :, 0]
else:
return rotated_sight
示例10: resize
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def resize(self, to_resize_batch, targets=None, fixed='fixed', height=32):
all_images = []
all_targets = []
for i, sample in enumerate(to_resize_batch):
# if sample.shape[0] < self.config['min_h'] and targets!=None:
# # print("Skipping")
# continue
if fixed == 'fixed':
size = (320, 32)
else:
new_width = int(max(int(height/sample.shape[0]*sample.shape[1]), 2*height)*1.5)
size=(new_width, height)
# print("New size:",size)
if self.num_channels == 1:
image = Image.fromarray(sample).convert('L')
else:
image = Image.fromarray(sample).convert('RGB')
if self.config['augmentation']['flag'] and self.Type == 'train' and not self.only_OWN:
#Random rotate to account for flipped words
# if np.random.random() < self.vertical_flip_prob:
# image = image.rotate(180)
# if np.random.random() < self.horizontal_flip_prob:
# image = image.transpose(Image.FLIP_LEFT_RIGHT)
#Distortion
if np.random.random() < self.distort_prob:
hori_tile_final = self.hori_tile + np.random.randint(5) - 2
verti_tile_final = self.verti_tile + np.random.randint(3) - 1
mag_final = self.distort_mag + np.random.randint(3) - 1
image = self.elastic_deformation(image, hori_tile_final, verti_tile_final, mag_final)
# print('elastic')
#Shearing
# if np.random.random() < self.shear_prob:
# image = tf.warp(np.array(image), inverse_map=self.afine_tf)
# print(image.size)
# print('shear')
# print('There')
if self.num_channels == 1:
image = torch.FloatTensor(np.array(image.resize(size)).astype(np.uint8)[:,:,None].transpose(2, 0, 1)[None])/255
else:
image = torch.FloatTensor(np.array(image.resize(size)).astype(np.uint8).transpose(2, 0, 1)[None])/255
all_images.append(image)
all_targets.append(targets[i])
return all_images, all_targets
# else:
# return all_images
示例11: rotate
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def rotate(self, cnt, image):
#Consider some outer region for accurate text
boundary = self.config['around_bound']
#Find rotated rect's centre, rotation, heigh, width
rect = list(cv2.minAreaRect(cnt))
rect[1] = list(rect[1])
#Add brder pixels
rect[1][0] += boundary
rect[1][1] += boundary
rect[1] = tuple(rect[1])
cnt = cv2.boxPoints(tuple(rect)).astype(np.int32).reshape([4, 1, 2])
#Calculate minimum and maximum of contour coordinates for cropping
min_x, min_y = np.min(cnt[:, 0, :], axis=0)
min_x = max(0, min_x)
min_y = max(0, min_y)
max_x, max_y = np.max(cnt[:, 0, :], axis=0)
max_x = min(image.shape[1], max_x)
max_y = min(image.shape[0], max_y)
if max_y - min_y <= 0 or max_x - min_x <= 0:
return None
mask = np.zeros([max_y - min_y, max_x - min_x, 3]).astype(np.uint8)
#Shift origin
cnt = cnt-np.array([min_x, min_y])
cnt = cnt.astype(np.int32)
#Draw just the rectangle on the mask
cv2.drawContours(mask, [cnt], -1, (1, 1, 1), cv2.FILLED)
#Crop part of the image with the contour only
cropped_image = image[min_y:max_y, min_x:max_x, :].copy()
cropped_image *= mask
if rect[1][0]>rect[1][1]:
rotated = imutils.rotate(cropped_image, rect[2])
width, height = np.array(rect[1][0]).astype(np.int32), np.array(rect[1][1]).astype(np.int32)
else:
rotated = imutils.rotate(cropped_image, 90 + rect[2])
width, height = np.array(rect[1][1]).astype(np.int32), np.array(rect[1][0]).astype(np.int32)
center_x, center_y = np.array(rect[0]).astype(np.int32)-np.array([min_x, min_y])
if self.num_channels == 1:
return cv2.cvtColor(rotated, cv2.COLOR_BGR2GRAY)
return rotated
示例12: make_own_cache
# 需要导入模块: import imutils [as 别名]
# 或者: from imutils import rotate [as 别名]
def make_own_cache(self):
d_name, d, image_root = 'OWN', self.datasets_attr['OWN'], self.datasets_attr['OWN']['image_root']
self.own_cache = {'l_to_img_name':{}}
images, target = [], []
for i in range(len(self.images)):
if not (i < d['range'][1] and i >= d['range'][0]):
continue
try:
image = np.array(self.loader(image_root+'/'+self.images[i]))
not_blank = [j for j in range(len(self.texts[i])) if len(self.texts[i][j])!=0]
except:
continue
for (cnt, text) in zip(self.annots[i][not_blank], np.array(self.texts[i])[not_blank]):
# print(cv2.contourArea(cnt), len(text))
# if len(text)<3:#cv2.contourArea(cnt) < 400*len(text) or
# continue
rotated = self.rotate(cnt, image)
if rotated is None:
continue
images.append(rotated)
l = [self.encoding_to_char[e] for e in text]
self.own_cache['l_to_img_name'][''.join(l)] = self.images[i]
target.append(torch.IntTensor(text))
if self.list_or_tensor == 'list':
images, targets = self.resize(images, target, 'not_fixed')
else:
images, targets = self.resize(images, target, 'fixed')
self.own_cache['images'] = images
self.own_cache['labels'] = targets
# print(len(targets))
dump_name = self.config['cache_path']+'/OWN_'+self.Type+'_cache.pkl'
with open(dump_name, 'wb') as f:
pickle.dump(self.own_cache, f)
print("Successfully dumped",self.Type,"cache for OWN exclusive")