def main(): global calib, cyl src_dir = os.path.split(os.path.abspath(__file__))[0] data_dir = os.path.join(src_dir, '..', 'data') pmat = np.loadtxt(os.path.join(data_dir, 'cameramatrix.txt')) calib = decompose(pmat) width = 752 height = 480 glut.glutInit() glut.glutInitWindowSize(width, height) glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DEPTH | glut.GLUT_ACCUM | glut.GLUT_DOUBLE) glut.glutCreateWindow("calib_test_pyopengl") cyl = PointCylinder() if 1: # compose view matrix r = get_gluLookAt(pmat) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() glu.gluLookAt(*r['all_args']) gl.glDisable(gl.GL_DEPTH_TEST) glut.glutDisplayFunc(on_draw) on_resize(width, height) glut.glutMainLoop()
def main(): global calib, cyl src_dir = os.path.split(os.path.abspath(__file__))[0] data_dir = os.path.join(src_dir,'..','data') pmat = np.loadtxt( os.path.join(data_dir, 'cameramatrix.txt') ) calib = decompose(pmat) width = 752 height = 480 glut.glutInit() glut.glutInitWindowSize(width,height) glut.glutInitDisplayMode(glut.GLUT_RGBA | glut.GLUT_DEPTH | glut.GLUT_ACCUM | glut.GLUT_DOUBLE) glut.glutCreateWindow("calib_test_pyopengl"); cyl = PointCylinder() if 1: # compose view matrix r = get_gluLookAt(pmat) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() glu.gluLookAt( *r['all_args'] ) gl.glDisable(gl.GL_DEPTH_TEST) glut.glutDisplayFunc(on_draw) on_resize(width,height) glut.glutMainLoop()
def __init__(self,image_fname=None,pmat=None,window_coords=None,**kwargs): if window_coords is None: # set default value window_coords = 'y down' super(MyAppWindow, self).__init__(**kwargs) self.calib = decompose(pmat) self.window_coords = window_coords self.img = pyglet.image.load(image_fname).get_texture(rectangle=True) if self.window_coords=='y up': self.img = self.img.get_transform(flip_y=True) self.img.anchor_x = self.img.anchor_y = 0 self.width = self.img.width self.height = self.img.height checks = pyglet.image.create(32, 32, pyglet.image.CheckerImagePattern()) self.background = pyglet.image.TileableTexture.create_for_image(checks) # Enable alpha blending, required for image.blit. gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) self.cyl = PointCylinder() # set modelview matrix to camera extrinsic parameters if 0: # do it directly e = np.vstack((self.calib['extrinsic'],[[0,0,0,1]])) # These HZ eye coords have +Z in front of camera. coord_xform = np.eye(4) coord_xform[1,1]=-1 # flip Y coordinate in eye space (OpenGL has +Y as up, HZ has -Y) coord_xform[2,2]=-1 # flip Z coordinate in eye space (OpenGL has -Z in front of camera, HZ has +Z) e2 = np.dot( coord_xform, e) extrinsic = map(float,e2.T.flat) extrinsic = (gl.GLfloat * 16)(*extrinsic) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadMatrixf(extrinsic) else: # compose view matrix r = get_gluLookAt(pmat) gl.glMatrixMode(gl.GL_MODELVIEW) gl.glLoadIdentity() gl.gluLookAt( *r['all_args'] ) gl.glDisable(gl.GL_DEPTH_TEST)
#!/usr/bin/env python import os import numpy as np from calib_test_utils import get_gluLookAt data_dir = os.path.split(os.path.abspath(__file__))[0] pmat = np.loadtxt( os.path.join(data_dir, 'cameramatrix.txt') ) r = get_gluLookAt(pmat) for n in ['eye','center','up']: print 'osg::Vec3 %s = osg::Vec3(%s,%s,%s);'%tuple([n]+r[n])
#!/usr/bin/env python import os import numpy as np from calib_test_utils import get_gluLookAt data_dir = os.path.split(os.path.abspath(__file__))[0] pmat = np.loadtxt(os.path.join(data_dir, 'cameramatrix.txt')) r = get_gluLookAt(pmat) for n in ['eye', 'center', 'up']: print 'osg::Vec3 %s = osg::Vec3(%s,%s,%s);' % tuple([n] + r[n])