コード例 #1
0
    def test_disparity_map(self):
        left = cv2.imread('test_data/tsukuba/left.png')
        right = cv2.imread('test_data/tsukuba/right.png')

        # Load the ground-truth disparity map.
        disparity_expected = cv2.imread('test_data/tsukuba/disparity_left.png',
                                        cv2.CV_LOAD_IMAGE_GRAYSCALE)
        # Compute disparity using the function under test.
        disparity = stereo.disparity_map(left, right)
        # Compute the difference between the two. Useful to visualize this!
        disparity_diff = cv2.absdiff(disparity, disparity_expected)

        # The median difference between the expected and actual disparity
        # should be less than the specified threshold.
        differences = disparity_diff.flatten().tolist()
        median_diff = sorted(differences)[len(differences) / 2]
        self.assertLessEqual(median_diff, 5)
コード例 #2
0
ファイル: stereo_test.py プロジェクト: SiaJAT/cs378_p2
    def test_disparity_map(self):
        left = cv2.imread('test_data/tsukuba/left.png')
        right = cv2.imread('test_data/tsukuba/right.png')

        # Load the ground-truth disparity map.
        disparity_expected = cv2.imread('test_data/tsukuba/disparity_left.png',
                                        cv2.CV_LOAD_IMAGE_GRAYSCALE)

        # Compute disparity using the function under test.
        disparity = stereo.disparity_map(left, right)

        # Compute the difference between the two. Useful to visualize this!
        disparity_diff = cv2.absdiff(disparity, disparity_expected)

        # The median difference between the expected and actual disparity
        # should be less than the specified threshold.
        differences = disparity_diff.flatten().tolist()
        median_diff = sorted(differences)[len(differences) / 2]
        self.assertLessEqual(median_diff, 5)
コード例 #3
0
import stereo
import cv2

left = cv2.imread('set_left.jpg')
right = cv2.imread('set_right.jpg')

disparity = stereo.disparity_map(left, right)
cv2.imwrite("set_disparity.jpg", disparity)

colors = left
focal_length = 5
ply_string = stereo.point_cloud(disparity, colors, focal_length)

with open("set.ply", 'w') as f:
    f.write(ply_string)
コード例 #4
0
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)

with open("out.ply", 'w') as f:
    f.write(ply_string)
コード例 #5
0
ファイル: results.py プロジェクト: SiaJAT/cs378_p2
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

    ply_string = stereo.point_cloud(disparity, colors, focal_length)
    # View me in Meshlab!
    with open("our_results.ply", 'w') as f:
        f.write(ply_string)
コード例 #6
0
if len(sys.argv) < 3:
    print "MUST PASS IN AT LEAST 2 IMAGES TO RECTIFY"
    exit()

# Dispose of the first argument (script name)
sys.argv.remove(sys.argv[0])

# Use the last argument as the output filename
# for the PLY file, then remove it from the
# list of arguments
output_filename = sys.argv[len(sys.argv) - 1]
sys.argv.remove(sys.argv[len(sys.argv) - 1])

# Read in the two images, using the only remaining
# arguments as the filenames of the left and right images
image_left = cv2.imread(sys.argv[0])
image_right = cv2.imread(sys.argv[1])

# Calculate the disparity image
disparity_image = stereo.disparity_map(image_left, image_right)

# Construct a point cloud
pc = stereo.point_cloud(disparity_image, image_left, 10)

# Write out the point cloud
with open(output_filename, 'w') as f:
    f.write(pc)

# Write out the disparity image
cv2.imwrite('disparity_image.png', disparity_image)