opencv图像旋转后消除黑色背景

    def rotate_whole_img(self, img):
        """
           rotate noise
           rotate angle is 0 - 20
        """
        angle = np.random.randint(0,20)
        h, w = img.shape[:2]
        center = (w / 2, h / 2)
        M = cv2.getRotationMatrix2D(center, angle, 1)
        im = cv2.warpAffine(img, M, (w,h), borderValue=(255,255,255))
        return im
消除黑色区域是由于cv2.warpAffine()参数borderValue的值,默认为0

你可能感兴趣的:(图像处理,opencv)