data_augmentation.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:CVtools 作者: Tyler-D 项目源码 文件源码
def augmentate(self):
        angles = [45, 90, 135, 180, 225, 270, 315]
        scale = 1.0
        for img in self.images:
            print "image shape : ", img.shape
            w = img.shape[1]
            h = img.shape[0]
            img_vmirror = cv2.flip(img,1)
            skimage.io.imsave("testv"+".jpg", img_vmirror )
            for angle in angles:
            #rangle = np.deg2rad(angle)
            # nw = (abs(np.sin(rangle)*h) + abs(np.cos(rangle)*w))*scale
            # nh = (abs(np.cos(rangle)*h) + abs(np.sin(rangle)*w))*scale
                rot_mat = cv2.getRotationMatrix2D((w*0.5, h*0.5), angle, scale)
            # rot_move = np.dot(rot_mat, np.array([(nw-w)*0.5, (nh-h)*0.5,0]))
            # rot_mat[0,2] += rot_move[0]
            # rot_mat[1,2] += rot_move[1]
                new_img = cv2.warpAffine(img, rot_mat, (int(math.ceil(w)), int(math.ceil(h))), flags=cv2.INTER_LANCZOS4)
                skimage.io.imsave("test"+str(angle)+".jpg", new_img)
                new_img_vmirror = cv2.flip(new_img, 1)
                skimage.io.imsave("testv"+str(angle)+".jpg", new_img_vmirror)
                # img_rmirror = cv2.flip(new_img, 0)
                # skimage.io.imsave("testh"+str(angle)+".jpg", img_rmirror)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号