Exemplo n.º 1
0
    def test_point_cloud(self):
        disparity = cv2.imread('test_data/tsukuba/disparity_left.png',
                               cv2.CV_LOAD_IMAGE_GRAYSCALE)
        colors = cv2.imread('test_data/tsukuba/left.png')
        focal_length = 10

        ply_string = stereo.point_cloud(disparity, colors, focal_length)
        # View me in Meshlab!
        with open("tsukuba.ply", 'w') as f:
            f.write(ply_string)
        # Trivial test. We'll also inspect the cloud visually.
        self.assertGreater(len(ply_string), 0)
Exemplo n.º 2
0
    def test_point_cloud(self):
        disparity = cv2.imread('test_data/tsukuba/disparity_left.png',
                               cv2.CV_LOAD_IMAGE_GRAYSCALE)
        colors = cv2.imread('test_data/tsukuba/left.png')
        focal_length = 10

        ply_string = stereo.point_cloud(disparity, colors, focal_length)
        # View me in Meshlab!
        with open("tsukuba.ply", 'w') as f:
            f.write(ply_string)
        # Trivial test. We'll also inspect the cloud visually.
        self.assertGreater(len(ply_string), 0)
Exemplo n.º 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)
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)
Exemplo n.º 5
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)
Exemplo n.º 6
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)