Exemple #1
0
    def test_rectify_pair(self):
        left = cv2.imread('test_data/kitchen_left.jpg')
        right = cv2.imread('test_data/kitchen_right.jpg')

        F, H_left, H_right = stereo.rectify_pair(left, right)

        # Check accuracy against known fundamental matrix and homographies.
        max_difference_magnitude = 0.5

        F_expected = numpy.array(
            [[2.38958660e-07, -2.30078185e-05, -3.82577705e-03],
             [-4.57131715e-05, -2.03219010e-06, 1.42189842e-01],
             [-5.01095221e-03, -1.09146504e-01, 1.00000000e+00]])
        F_diff = self._matrix_diff(F_expected, F, "fundamental matrix")
        self.assertLessEqual(F_diff, max_difference_magnitude)

        H_left_expected = numpy.array(
            [[-9.78273713e-02, 6.04430191e-02, -1.69179548e+01],
             [-4.78698812e-03, -1.09671985e-01, 2.31661658e-01],
             [4.25159162e-05, -8.17208264e-07, -1.32607389e-01]])
        H_left_diff = self._matrix_diff(H_left_expected, H_left,
                                        "left rectifying homography")

        H_right_expected = numpy.array(
            [[1.04725916e+00, 1.32521331e-01, -7.95404897e+01],
             [-2.73716541e-02, 1.00451089e+00, 5.43598999e+00],
             [1.96336656e-04, 2.48446573e-05, 9.32407071e-01]])
        H_right_diff = self._matrix_diff(H_right_expected, H_right,
                                         "right rectifying homography")
Exemple #2
0
    def test_rectify_pair(self):
        left = cv2.imread('test_data/kitchen_left.jpg')
        right = cv2.imread('test_data/kitchen_right.jpg')

        F, H_left, H_right = stereo.rectify_pair(left, right)

        # Check accuracy against known fundamental matrix and homographies.
        max_difference_magnitude = 0.5

        F_expected = numpy.array(
            [[2.38958660e-07, -2.30078185e-05, -3.82577705e-03],
             [-4.57131715e-05, -2.03219010e-06, 1.42189842e-01],
             [-5.01095221e-03, -1.09146504e-01, 1.00000000e+00]])
        F_diff = self._matrix_diff(F_expected, F, "fundamental matrix")
        self.assertLessEqual(F_diff, max_difference_magnitude)

        H_left_expected = numpy.array(
            [[-9.78273713e-02, 6.04430191e-02, -1.69179548e+01],
             [-4.78698812e-03, -1.09671985e-01, 2.31661658e-01],
             [4.25159162e-05, -8.17208264e-07, -1.32607389e-01]])
        H_left_diff = self._matrix_diff(H_left_expected, H_left,
                                        "left rectifying homography")

        H_right_expected = numpy.array(
            [[1.04725916e+00, 1.32521331e-01, -7.95404897e+01],
             [-2.73716541e-02, 1.00451089e+00, 5.43598999e+00],
             [1.96336656e-04, 2.48446573e-05, 9.32407071e-01]])
        H_right_diff = self._matrix_diff(H_right_expected, H_right,
                                         "right rectifying homography")
import argparse

parser = argparse.ArgumentParser(description='TEST DESCRIPTION')
parser.add_argument('-l', '--left', help='Input left image', required=True)
parser.add_argument('-r', '--right', help='Input right image', required=True)
args = parser.parse_args()

print ("Left image: %s" % args.left)
print ("Right image: %s" % args.right)

image_left = cv2.imread(args.left)
image_right = cv2.imread(args.right)

focal_length = 10

F, h_left, h_right = stereo.rectify_pair(image_left, image_right)

r_image_left = cv2.warpPerspective(image_left, h_left,
                                   image_left.shape[:2])

r_image_right = cv2.warpPerspective(image_right, h_right,
                                    image_right.shape[:2])

disp = stereo.disparity_map(image_left, image_right)

ply_string = stereo.point_cloud(disp, image_left, focal_length)

cv2.imwrite("image_left.jpg", r_image_left)
cv2.imwrite("image_right.jpg", r_image_right)
cv2.imwrite("disparity.jpg", disp)
Exemple #4
0
"""Project 2: results script
We used a picture we took of kitchen objects, they can be found under test_data
The script uses right_4.jpn and left_4.jpg
"""

import cv2
import stereo
import numpy


if __name__ == '__main__':
    # Read initial images
    img_right = cv2.imread("test_data/right_4.jpg")
    img_left = cv2.imread("test_data/left_4.jpg")

    F, H_left, H_right = stereo.rectify_pair(img_left, img_right)

    rectified_left = stereo.warp_image(img_left, H_left)
    cv2.imwrite("test_data/rect_left.jpg", rectified_left)

    rectified_right = stereo.warp_image(img_right, H_right)
    cv2.imwrite("test_data/rect_right.jpg", rectified_right)

    disparity = stereo.disparity_map(rectified_left, rectified_right)
    cv2.imwrite("test_data/disparity.jpg", disparity)
    disparity_image = cv2.imread('test_data/disparity.png',
                                 cv2.CV_LOAD_IMAGE_GRAYSCALE)

    colors = cv2.imread('test_data/left_4.jpg')
    focal_length = 10
Exemple #5
0
import cv2
import numpy as np
import stereo

left = cv2.imread("my_stereo/mouseleft.JPG")
right = cv2.imread("my_stereo/mouseright.JPG")

f, hleft, hright = stereo.rectify_pair(left, right)
wl, p = stereo.warp_image(left, hleft)
wr, p = stereo.warp_image(right, hright)
#  cv2.imwrite("left.png",left)
#  cv2.imwrite("right.png",wr)

disparity = stereo.disparity_map(left, right)

cv2.imwrite('disparity.png', disparity)

s = stereo.point_cloud(disparity, left, 3)
with open("my_stereo/mouse.ply", 'w') as f:
    f.write(s)