size + speed up request

This commit is contained in:
fxia22 2017-09-15 11:19:41 -07:00
parent d51b72d7cb
commit de55cd3b19
4 changed files with 757 additions and 744 deletions

View File

@ -130,8 +130,8 @@ bool computeMatricesFromInputs(){
//glfwSetCursorPos(window, 512/2, 512/2);
// Compute new orientation
horizontalAngle += mouseSpeed * float( 512/2 - xpos );
verticalAngle += mouseSpeed * float( 512/2 - ypos );
horizontalAngle += mouseSpeed * float( 768/2 - xpos );
verticalAngle += mouseSpeed * float( 768/2 - ypos );
// Direction : Spherical coordinates to Cartesian coordinates conversion
glm::vec3 direction(
@ -284,7 +284,7 @@ bool computeMatricesFromFile(std::string filename){
char namebuf[50];
int count = fscanf(file, "%s %f %f %f %f %f %f %f %f %f\n", namebuf, &posX, &posY, &posZ, &rotW, &rotY, &rotX, &rotZ, &junk[0], &junk[1] );
printf("Loading pose file count: %d, namebuf: %s, rot count %d\n", count, namebuf, currentPoseRotCount);
assert(count == 10);

View File

@ -25,16 +25,16 @@ blender_path = "./point_29b9558f6a244ca493d2bf52709684e2_view_equirectangular_do
def transfer(in_img, coords, h, w):
out_img = np.zeros((h,w,3)).astype(np.uint16)
for ycoord in range(0, h):
for xcoord in range(0, w):
ind, corrx, corry = coords[ycoord, xcoord, :]
ind, corrx, corry = coords[ycoord, xcoord, :]
out_img[ycoord, xcoord, :] = in_img[ind, corrx, corry, :]
return out_img
def convert_img():
inimg = InImg()
wo, ho = inimg.grid * 4, inimg.grid * 3
# Calculate height and width of output image, and size of each square face
@ -51,22 +51,22 @@ def convert_img():
np.array(Image.open("3.tiff")),
np.array(Image.open("4.tiff")),
np.array(Image.open("5.tiff"))]).astype(np.uint8)
print("Received image array", len(in_imgs))
if not os.path.isfile('coord.npy'):
coords = np.zeros((h,w,3)).astype(np.int32)
for ycoord in range(0, h):
for xcoord in range(0, w):
corrx, corry = find_corresponding_pixel(xcoord, ycoord, w, h, n)
coords[ycoord, xcoord, :] = inimg.getpixel((corrx, corry))
np.save('coord.npy', coords)
else:
coords = np.load('coord.npy')
# For each pixel in output image find colour value from input image
print(outimg.shape)
@ -81,7 +81,7 @@ def convert_img():
def convert_array(img_array):
inimg = InImg()
wo, ho = inimg.grid * 4, inimg.grid * 3
# Calculate height and width of output image, and size of each square face
@ -90,32 +90,32 @@ def convert_array(img_array):
n = ho/3
# Create new image with width w, and height h
outimg = np.zeros((h,w,3)) #.astype(np.uint8)
outimg = np.zeros((h,w,1)) #.astype(np.uint8)
in_imgs = None
in_imgs = None
print("converting images", len(img_array))
print("Passed in image array", len(img_array), np.max(img_array[0]))
in_imgs = img_array
if not os.path.isfile('coord.npy'):
coords = np.zeros((h,w,3)).astype(np.int32)
coords = np.zeros((h,w,1)).astype(np.int32)
for ycoord in range(0, h):
for xcoord in range(0, w):
corrx, corry = find_corresponding_pixel(xcoord, ycoord, w, h, n)
coords[ycoord, xcoord, :] = inimg.getpixel((corrx, corry))
np.save('coord.npy', coords)
else:
coords = np.load('coord.npy')
# For each pixel in output image find colour value from input image
print(outimg.shape)
# todo: for some reason the image is flipped 180 degrees
outimg = transfer(in_imgs, coords, h, w)[::-1, ::-1, ::]
outimg = transfer2(in_imgs, coords, h, w)[::-1, :, ::]
return outimg
@ -123,11 +123,11 @@ def convert_array(img_array):
class InImg(object):
def __init__(self):
self.grid = 512
self.grid = 768
def getpixel(self, key):
corrx, corry = key[0], key[1]
indx = int(corrx / self.grid)
indy = int(corry / self.grid)
@ -179,29 +179,37 @@ if __name__ == '__main__':
img_array = []
# Do 10 requests, waiting each time for a response
for request in range(10):
# Do 6 requests, waiting each time for a response
for request in range(6):
print("Sending request %s ..." % request)
socket.send(b"Hello")
# Get the reply.
message = socket.recv()
data = np.array(np.frombuffer(message, dtype=np.uint16)).reshape((512, 512, 3))
data = np.array(np.frombuffer(message, dtype=np.uint16)).reshape((768, 768, 1))
data = data[::-1,::-1,:]
img_array.append(data)
#data = np.log(data / 256 * (256/np.log(256))).astype(np.uint8)
#data = (data % 256).astype(np.uint8)
#data = np.log(data / 256 * (256/np.log(256))).astype(np.uint8)
#data = (data % 256).astype(np.uint8)
#data = (data / 256.0).astype(np.uint8) * 12
print(np.max(data), np.min(data))
# todo: debug
data = data[:][::-1][:]
#img = Image.fromarray(data)
#img.save(img_path + str(request) + ".tiff")
#scipy.misc.imsave(img_path + str(request) + ".png", data, 'L', bits=16)
#print("Received reply %s [ %s ]" % (request, data))
img_array2 = [img_array[0], img_array[3], img_array[2], img_array[1], img_array[4], img_array[5]]
print("max value", np.max(data[0]))
opengl_arr = convert_array(np.array(img_array))
plot_histogram(opengl_arr)
opengl_arr = convert_array(np.array(img_array2))
#plot_histogram(opengl_arr)
opengl_arr = (opengl_arr / 10).astype(np.uint8)
outimg = Image.fromarray(opengl_arr)
outimg.save('output', 'PNG')

File diff suppressed because it is too large Load Diff

View File

@ -1,8 +1,8 @@
import numpy as np
def transfer2(unsigned char [:,:,:,:] in_img, int [:,:,:]coords, int h, int w):
def transfer2(unsigned short [:,:,:,:] in_img, int [:,:,:]coords, int h, int w):
cdef unsigned char [:,:,:] out_img = np.zeros((h,w,3)).astype(np.uint8)
cdef unsigned short [:,:,:] out_img = np.zeros((h,w,3)).astype(np.uint16)
cdef int xcoord, ycoord
cdef int ind, corrx, corry
@ -14,6 +14,6 @@ def transfer2(unsigned char [:,:,:,:] in_img, int [:,:,:]coords, int h, int w):
ind = coords[ycoord, xcoord, 0]
corrx = coords[ycoord, xcoord, 1]
corry = coords[ycoord, xcoord, 2]
for c in range(3):
for c in range(1):
out_img[ycoord, xcoord, c] = in_img[ind, corry, corrx, c]
return np.array(out_img)
return np.array(out_img)