Exemplo n.º 1
0
def create_prepared_image_dict(img, angle, config):
    img_alpha = helpers.add_alpha_channel(img['img'])
    rectificator = prep.Rectificator(config)
    rect_img = rectificator.rectify_image(img_alpha)
    rect_detections = rectificator.rectify_points(img['detections'],
                                                  img['size'])
    rect_img_w_detections = rectificator.rectify_image(img['img_w_detections'])

    rot_img, rot_mat = prep.rotate_image(rect_img, angle)
    rot_detections = prep.rotate_points(rect_detections, angle, img['size'])
    rot_img_w_detections, rot_mat = prep.rotate_image(rect_img_w_detections,
                                                      angle)

    d = dict()
    d['img'] = rot_img
    d['detections'] = rot_detections
    d['img_w_detections'] = rot_img_w_detections
    return d
Exemplo n.º 2
0
def test_rotate_image():
    img = np.zeros((30, 40), np.uint8)
    border = 1
    img[-border:, :] = 100  # bottom
    img[:, -border:] = 150  # right
    img[:border, :] = 200  # top
    img[:, :border] = 250  # left

    rot_img, mat = prep.rotate_image(img, 90)

    assert img.shape[0] == rot_img.shape[1] and img.shape[1] == rot_img.shape[0]

    assert rot_img[-1][15] == 250
    assert rot_img[20][-1] == 100
    assert rot_img[0][15] == 150
    assert rot_img[20][0] == 200

    rot_img, mat = prep.rotate_image(img, -90)
    assert img.shape[0] == rot_img.shape[1] and img.shape[1] == rot_img.shape[0]
    assert rot_img[-1][15] == 150
    assert rot_img[20][-1] == 200
    assert rot_img[0][15] == 250
    assert rot_img[20][0] == 100
Exemplo n.º 3
0
def test_rectify_and_rotate_image(left_img, config, outdir):
    rectificator = prep.Rectificator(config)
    rect_img = rectificator.rectify_image(left_img['img_w_detections'])
    rect_detections = rectificator.rectify_points(left_img['detections'],
                                                  left_img['size'])

    angle = 90
    rot_img, rot_mat = prep.rotate_image(rect_img, angle)
    rot_detections = prep.rotate_points(rect_detections, angle,
                                        left_img['size'])

    marked_img = draw_marks(rot_img, rot_detections)
    name_out = ''.join([left_img['name'], '_detections_rectified_rot.jpg'])
    out = os.path.join(outdir, name_out)
    cv2.imwrite(out, marked_img)
Exemplo n.º 4
0
    def _prepare_image(self, image, angle=0):
        """Prepare image for stitching.

        It rotates and rectifies the image. Ff the Stitcher is initialized with ``rectify=False``
        the image will not be rectified.

        Args:
            image (ndarray): Image to prepare.
            angle (int): angle in degree to rotate image.

        Returns:
            - **image** (ndarray) -- rotated (and rectified) image.
            - **affine** (ndarray) -- An affine *(3,3)*--matrix for rotation of image or points.
        """
        image = helpers.add_alpha_channel(image)
        if self.rectify:
            image = self.rectificator.rectify_image(image)
        image_rot, affine = prep.rotate_image(image, angle)
        return image_rot, affine
Exemplo n.º 5
0
def test_rotate_image_specifc(left_img, outdir):
    img, mat = prep.rotate_image(left_img['img'], 90)
    name_img_rot = ''.join([left_img['name'], '_rotated.jpg'])
    out = os.path.join(outdir, name_img_rot)
    cv2.imwrite(out, img)