def _batch_random_roate(self, images, labels, degree):
if(images.shape[0] != labels.shape[0]):
raise Exception("Batch size Error.")
degree = degree * math.pi / 180
rand_degree = np.random.uniform(-degree, degree)
o_images = np.zeros_like(images)
o_labels = np.zeros_like(labels)
for idx in xrange(images.shape[0]):
theta = rand_degree
# labels
for ii in xrange(self.points_num):
o_labels[idx, 2*ii: 2*ii+2] = self._rotate(labels[idx, ii*2: 2*ii+2], theta)
# image
M = cv2.getRotationMatrix2D((self.img_width/2,self.img_height/2),-theta*180/math.pi,1)
o_images[idx] = np.expand_dims(cv2.warpAffine(images[idx],M,(self.img_width,self.img_height)), axis=2)
return o_images, o_labels
评论列表
文章目录