Created
February 26, 2014 21:44
-
-
Save Orpheon/9239268 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from __future__ import division, print_function | |
| from PIL import Image | |
| import sys | |
| import math | |
| IMAGE_WIDTH = int(sys.argv[3]) | |
| IMAGE_HEIGHT = int(sys.argv[4]) | |
| # sys.argv[5] is a string marking the shift parameter, we don't need that | |
| CAMERA_DISTANCE = 20 | |
| # This controls the skew of the projection | |
| DISTANCE_TO_SCREEN = 205 | |
| left_image = Image.open(sys.argv[1]) | |
| depthmap_file = Image.open(sys.argv[2]) | |
| output = "" | |
| for x in range(IMAGE_WIDTH - CAMERA_DISTANCE): | |
| for y in range(IMAGE_HEIGHT): | |
| d = depthmap_file.getpixel((x, y)) | |
| xpos = (x - IMAGE_WIDTH/2) * d / (DISTANCE_TO_SCREEN * IMAGE_WIDTH) | |
| ypos = (y - IMAGE_HEIGHT/2) * d / (DISTANCE_TO_SCREEN * IMAGE_HEIGHT) | |
| zpos = d / (DISTANCE_TO_SCREEN) | |
| colors = " ".join([str(i) for i in left_image.getpixel((x, y))]) | |
| output += "{0} {1} {2} {3}\n".format(xpos, ypos, -zpos, colors) | |
| text = open((sys.argv[2])[:-4]+".asc", "w") | |
| text.write(output) | |
| text.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment