Exemple #1
0
 def block_setup(self):
     """Initialize blockplayer stuff"""
     glxcontext.makecurrent()
     main.initialize()
     
     config.load('data/newest_calibration')
     opennpy.align_depth_to_rgb()
     dataset.setup_opencl()
     
     self.blocks = None
     self.block_loop_quit = False
     self.block_initialized = True
     self.block_loop()
Exemple #2
0
def test_offscreen_triangle(size=(200, 200)):
    glxcontext.makecurrent()

    width, height = size

    # Set up the frame buffer
    fbo = glGenFramebuffers(1)
    glBindFramebuffer(GL_FRAMEBUFFER, fbo)

    rbc = glGenRenderbuffers(1)
    glBindRenderbuffer(GL_RENDERBUFFER, rbc)
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB8, width, height)
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_COLOR_ATTACHMENT0,
                              GL_RENDERBUFFER, rbc)
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    glOrtho(0, width, 0, height, -1, 1)

    glMatrixMode(GL_MODELVIEW)
    glLoadIdentity()

    glClearColor(0, 0, 0, 0)
    glClear(GL_COLOR_BUFFER_BIT)
    
    # Draw a triangle of area portion 0.375
    glColor3ub(11, 13, 17)
    glBegin(GL_TRIANGLES)
    glVertex2f(0.75*width, 0.25*height)
    glVertex2f(0.25*width, 0.25*height)
    glVertex2f(0.50*width, 0.75*height)
    glEnd()
    glFinish()

    # Get the pixels back and check they're right
    pixels = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, outputType='array')

    check = pixels.mean(0).mean(0)
    assert np.all(check == [11 / 8., 13 / 8., 17 / 8.])
    print 'Offscreen render produced correct results'
Exemple #3
0
def initialize():
    global initialized
    glxcontext.makecurrent()

    if initialized: return

    global fbo
    global rb, rbc, rbs

    fbo = glGenFramebuffers(1)
    glBindFramebuffer(GL_FRAMEBUFFER, fbo)

    # Create three render buffers:
    #    1) xyz/depth  2) normals 3)  4) internal depth
    rbXYZD,rbN,rbInds,rbD = glGenRenderbuffers(4)

    # 1) XYZ/D buffer
    glBindRenderbuffer(GL_RENDERBUFFER, rbXYZD)
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32F, 640, 480)
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_COLOR_ATTACHMENT0,
                              GL_RENDERBUFFER, rbXYZD)

    # 2) Normals buffer
    glBindRenderbuffer(GL_RENDERBUFFER, rbN)
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA32F, 640, 480)
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_COLOR_ATTACHMENT1,
                              GL_RENDERBUFFER, rbN)

    # 3) Index buffer
    glBindRenderbuffer(GL_RENDERBUFFER, rbInds)
    glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB8, 640, 480)
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_COLOR_ATTACHMENT2,
                              GL_RENDERBUFFER, rbInds)

    # 4) depth buffer
    glBindRenderbuffer(GL_RENDERBUFFER, rbD)
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24, 640, 480)
    glFramebufferRenderbuffer(GL_FRAMEBUFFER,
                              GL_DEPTH_ATTACHMENT,
                              GL_RENDERBUFFER, rbD)

    glBindFramebuffer(GL_FRAMEBUFFER, 0)

    global VERTEX_SHADER, FRAGMENT_SHADER, SYNTHSHADER

    # This vertex shader simulates a range image camera. It takes in 
    # camera (kinect) parameters as well as model parameters. It project
    # the model points into the camera space in order to get the right
    # correct geometry. We additionally precompute the world-coordinates
    # XYZ for each pixel, as well as the world-coordinate normal vectors.
    # (This eliminates some of the steps that would normally be computed
    # using image processing, i.e. filtering, subtraction, normals.)
    VERTEX_SHADER = shaders.compileShader("""#version 120
        varying vec4 v_xyz;
        varying vec3 n_xyz;
        varying vec4 position;
        varying vec4 color;

        mat3 mat4tomat3(mat4 m) { return mat3(m[0].xyz, m[1].xyz, m[2].xyz); }

        void main() {
            v_xyz = gl_ModelViewMatrix * gl_Vertex;
            n_xyz = normalize(gl_NormalMatrix * gl_Normal);
            position = gl_ModelViewProjectionMatrix * gl_Vertex;
            gl_Position = position;
            color = gl_Color;
        }""", GL_VERTEX_SHADER)

    
    FRAGMENT_SHADER = shaders.compileShader("""#version 120
        varying vec4 v_xyz;
        varying vec3 n_xyz;
        varying vec4 position;
        varying vec4 color;
        varying out vec4 xyzd;
        varying out vec4 nxyz;
        varying out vec4 inds;

        void main() {
            xyzd.w = 200 / (1.0 - position.z/position.w);
            xyzd.xyz = v_xyz.xyz;
            nxyz.xyz = n_xyz;
            inds = color;
        }""", GL_FRAGMENT_SHADER)

    SYNTHSHADER = shaders.compileProgram(VERTEX_SHADER, FRAGMENT_SHADER)
    initialized = True
def test_create():
    glxcontext.makecurrent()
    print 'GL_VERSION:', glGetString(GL_VERSION)
    print 'GL_RENDERER:', glGetString(GL_RENDERER)
Exemple #5
0
import time
import json
import glob
import cPickle as pickle
import glxcontext

from blockplayer import dataset
from blockplayer import grid
from blockplayer import main


out_path = os.path.join('data/experiments','output')


# Create an offscreen opengl context
glxcontext.makecurrent()
from OpenGL.GL import glGetString, GL_VERSION
print("GL Version String: ", glGetString(GL_VERSION))


def once():
    depth = dataset.depth
    rgb = dataset.rgb
    main.update_frame(depth, rgb)


def run_grid():
    datasets = glob.glob('data/sets/study_*')
    try:
        os.mkdir(out_path)
    except OSError: