size + speed up request
This commit is contained in:
parent
d51b72d7cb
commit
de55cd3b19
|
@ -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(
|
||||
|
|
|
@ -90,7 +90,7 @@ 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
|
||||
print("converting images", len(img_array))
|
||||
|
@ -99,7 +99,7 @@ def convert_array(img_array):
|
|||
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):
|
||||
|
@ -114,7 +114,7 @@ def convert_array(img_array):
|
|||
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,7 +123,7 @@ 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]
|
||||
|
@ -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 = (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')
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
// Include GLFW
|
||||
#include <glfw3.h>
|
||||
GLFWwindow* window;
|
||||
//GLFWwindow* window;
|
||||
|
||||
// Include GLM
|
||||
#include <glm/glm.hpp>
|
||||
|
@ -42,8 +42,8 @@ using namespace std;
|
|||
|
||||
|
||||
// We would expect width and height to be 1024 and 768
|
||||
int windowWidth = 512;
|
||||
int windowHeight = 512;
|
||||
int windowWidth = 768;
|
||||
int windowHeight = 768;
|
||||
|
||||
typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*);
|
||||
typedef Bool (*glXMakeContextCurrentARBProc)(Display*, GLXDrawable, GLXDrawable, GLXContext);
|
||||
|
@ -673,13 +673,18 @@ int main( int argc, char * argv[] )
|
|||
|
||||
glGetTextureImage(renderedTexture, 0, GL_RGB, GL_UNSIGNED_SHORT, nSize*sizeof(unsigned short), dataBuffer);
|
||||
|
||||
unsigned short * dataBuffer_c = (unsigned short * ) malloc(windowWidth*windowHeight * sizeof(unsigned short));
|
||||
for (int i = 0; i < windowWidth * windowHeight; i++)
|
||||
dataBuffer_c[i] = dataBuffer[3*i];
|
||||
|
||||
|
||||
zmq::message_t reply (nByte);
|
||||
memcpy (reply.data (), (unsigned char*)dataBuffer, nByte);
|
||||
|
||||
zmq::message_t reply (windowWidth*windowHeight*sizeof(unsigned short));
|
||||
memcpy (reply.data (), (unsigned char*)dataBuffer_c, windowWidth*windowHeight*sizeof(unsigned short));
|
||||
socket.send (reply);
|
||||
|
||||
free(dataBuffer);
|
||||
free(dataBuffer_c);
|
||||
|
||||
} while (true);
|
||||
// Check if the ESC key was pressed or the window was closed
|
||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue