def ShowMesh2D(hmesh, nim, cmap, mode): cm = gp.colormap.Grey if cmap == 'Hot': cm = gp.colormap.Hot elif cmap == 'Fire': cm = gp.colormap.Fire elif cmap == 'Ice': cm = gp.colormap.Ice elif cmap == 'IceAndFire': cm = gp.colormap.IceAndFire wire = True fill = True if mode == 'Wire': fill = False elif mode == 'Fill': wire = False mesh = Mesh2D(hmesh, nim, cm) fig = figure(size=(800, 800)) trackball = Trackball(0, 0, 2) fig.push(mesh) fig.show()
def ShowMesh2D(hmesh,nim,cmap,mode): cm = gp.colormap.Grey if cmap=='Hot': cm = gp.colormap.Hot elif cmap=='Fire': cm = gp.colormap.Fire elif cmap=='Ice': cm = gp.colormap.Ice elif cmap=='IceAndFire': cm = gp.colormap.IceAndFire wire = True fill = True if mode=='Wire': fill = False elif mode=='Fill': wire = False mesh = Mesh2D(hmesh,nim,cm) fig = figure(size=(800,800)) trackball = Trackball(0,0,2) fig.push (mesh) fig.show()
def plotter3D(data_q,plots,scale): fig = figure(size=(400,400)) trackball = Trackball(65,135,1.,2.) tri_c = [(1,0,0,1),(0,1,0,1),(0,0,1,1)] tri_o = array([0,0,0]) tri = 0.1*array([[1,0,0],[0,1,0],[0,0,1]]) @fig.event def on_mouse_drag(x,y,dx,dy,button): trackball.drag_to(x,y,dx,dy) fig.redraw() @fig.event def on_scroll(x,y,dx,dy): trackball.scroll_to(x,y,dx,dy) fig.redraw() @fig.timer(10.0) def timer(dt): fig.redraw() @fig.event def on_draw(): d = data_q.get() fig.clear(0,0,0,1) trackball.push() gl.glBegin(gl.GL_LINES) for i in range(3): gl.glColor(*tri_c[i]) gl.glVertex(*tri_o) gl.glVertex(*(tri[i]+tri_o)) gl.glEnd() gl.glEnable(gl.GL_POINT_SMOOTH) for name,x in d.iteritems(): style = plots[name] gl.glColor(*style['color']) if 'size' in style: gl.glPointSize(style['size']) if 'line' in style: gl.glBegin(gl.GL_LINES) else: gl.glBegin(gl.GL_POINTS) for i in xrange(len(x)): gl.glVertex(*(x[i]/scale)) gl.glEnd() trackball.pop() fig.show()
def play(z, T=5.): """ T: duration in second of a period TODO: currently failing on MacOsX - use numpyGL? """ global t, t0, frames N_X, N_Y, N_frame = z.shape import glumpy fig = glumpy.figure((N_X, N_Y)) Z = z[:, :, 0].T.astype(np.float32) image = glumpy.image.Image(Z) #, interpolation='nearest', colormap=glumpy.colormap.Grey, vmin=0, vmax=1) t0, frames, t = 0, 0, 0 @fig.event def on_draw(): fig.clear() image.draw(x=0, y=0, z=0, width=fig.width, height=fig.height ) @fig.event def on_key_press(symbol, modifiers): if symbol == glumpy.window.key.TAB: if fig.window.get_fullscreen(): fig.window.set_fullscreen(0) else: fig.window.set_fullscreen(1) if symbol == glumpy.window.key.ESCAPE: import sys sys.exit() @fig.event def on_idle(dt): global t, t0, frames t += dt frames = frames + 1 if t-t0 > 5.0: fps = float(frames)/(t-t0) print('FPS: %.2f (%d frames in %.2f seconds)' % (fps, frames, t-t0)) frames, t0 = 0, t # computing the frame more closely to the actual time Z[...] = z[:, :, np.int(np.mod(t, T)/T * N_frame)].T.astype(np.float32) #Z[...] = z[:, :, frames % N_frame].T.astype(np.float32) image.update() fig.redraw() glumpy.show()
def __init__(self, title="SfM Browser"): self.title = title self.point_manager = None self.camera_manager = None self.verts = None self.bar = None self.space_key = False self.fig_size = (1280,960) self.fig_pos = (0,10) self.fig = glumpy.figure(self.fig_size, self.fig_pos) self.trackball = trackball.Trackball(0.0,0.0,1.0,10.0) self.eye = eye.Eye(center=[0.0, 0.0, -10.0], focus=[0.0,0.0,0.0], up=[0.0,1.0,0.0]) self.tb_show = c_bool(1) self.eye_show = c_bool(0) self.points_show = c_bool(1) self.full = c_bool(0) self.color = (c_float * 4)(0.,0.,0.,1.0)
def dantien(feed_func, layout, update_rate=5): ts = TimeSeries(feed_func) cols = len(layout[0]) rows = len(layout) fig = glumpy.figure() for x, y in product(range(cols), range(rows)): cons = layout[y][x] subfig = fig.add_figure(cols=cols, rows=rows, position=[x,rows-y-1]) cons(subfig, ts) @fig.timer(update_rate) def update(_): ts.eat() @fig.event('on_idle') def idle(_): fig.redraw() glumpy.show()
def __init__(self, title="SfM Browser"): self.title = title self.point_manager = None self.camera_manager = None self.verts = None self.bar = None self.space_key = False self.fig_size = (1280, 960) self.fig_pos = (0, 10) self.fig = glumpy.figure(self.fig_size, self.fig_pos) self.trackball = trackball.Trackball(0.0, 0.0, 1.0, 10.0) self.eye = eye.Eye(center=[0.0, 0.0, -10.0], focus=[0.0, 0.0, 0.0], up=[0.0, 1.0, 0.0]) self.tb_show = c_bool(1) self.eye_show = c_bool(0) self.points_show = c_bool(1) self.full = c_bool(0) self.color = (c_float * 4)(0., 0., 0., 1.0)
def imagedraw(data_q,num): fig = glumpy.figure(size=(400,400)) data = np.zeros((num,num)).astype(np.float32) cmap = glumpy.colormap.Hot cmap.set_under(cmap.get_color(-1)) cmap.set_over(cmap.get_color(1)) img = glumpy.image.Image(data, colormap=cmap,vmin=-10,vmax=50) @fig.timer(10.0) def timer(dt): fig.redraw() @fig.event def on_draw(): data[...] = data_q.get() img.update() fig.clear() img.draw(0,0,0,fig.width,fig.height) fig.show()
def browser(data_path, video_path, pts_path, cam_intrinsics_path): record = Temp() record.path = None record.writer = None c = Temp() c.captures = [cv2.VideoCapture(path) for path in video_path] total_frames = min([cap.get(7) for cap in c.captures]) record.fps = min([cap.get(5) for cap in c.captures]) r, img_arr = c.captures[0].read() if len(c.captures)==2: r, img_arr2 =c.captures[1].read() img_arr = cv2.cvtColor(img_arr, cv2.COLOR_BGR2RGB) fig = glumpy.figure((img_arr.shape[1], img_arr.shape[0])) image = glumpy.Image(img_arr) image.x, image.y = 0,0 # gaze object gaze = Temp() gaze.list = np.load(pts_path) # gaze.x_pos = gaze.list[:,0] # gaze.y_pos = gaze.list[:,1] # gaze.dt = gaze.list[:,2] gaze_list = list(gaze.list) gaze_point = Point(color=(255,0,0,0.3), scale=40.0) positions_by_frame = [[] for frame in range(int(gaze_list[-1][-1]) + 1)] while gaze_list: s = gaze_list.pop(0) frame = int(s[-1]) positions_by_frame[frame].append({'x': s[0], 'y': s[1], 'dt': s[2]}) gaze.map = positions_by_frame # keyframe list object framelist = Temp() framelist.keyframes = [] framelist.otherframes = [] cam_intrinsics = Temp() cam_intrinsics.H_map = [] g_pool = Temp() if cam_intrinsics_path is not None: cam_intrinsics.K = np.load(cam_intrinsics_path[0]) cam_intrinsics.dist_coefs = np.load(cam_intrinsics_path[1]) atb.init() bar = Bar("Browser", data_path, total_frames, framelist, dict(label="Controls", help="Scene controls", color=(50,50,50), alpha=50, text='light', position=(10, 10), size=(200, 440))) def draw(): gaze_point.draw() def on_draw(): fig.clear(0.0, 0.0, 0.0, 1.0) image.draw(x=image.x, y=image.y, z=0.0, width=fig.width, height=fig.height) draw() def on_close(): pass print "Close event !" def on_idle(dt): bar.update_fps(dt) sleep(0.03) if bar.play or bar.get_single: # load new images r, img1 = c.captures[0].read() if len(c.captures)==2: r, img2 =c.captures[1].read() if r and img1.shape != img2.shape: img2 = cv2.resize(img2,(img1.shape[1],img1.shape[0])) if not r: bar.play.value = 0 return bar.frame_num.value +=1 #stop playback when at the end of file. if bar.frame_num.value == 0: bar.play.value = 0 # Extract corresponing Pupil posistions. # Here we are taking only the first values of the frame for positions hence 0 index try: x_screen, y_screen = denormalize((gaze.map[bar.frame_num.value][0]['x'], gaze.map[bar.frame_num.value][0]['y']), fig.width, fig.height, flip_y=True) img1[int(y_screen), int(x_screen)] = [255,255,255] # update gaze.x_screen, gaze.y_screen /OPENGL COORIDANTE SYSTEM gaze.x_screen,gaze.y_screen = flip_horizontal((x_screen,y_screen), fig.height) gaze_point.update(( gaze.x_screen, gaze.y_screen)) print x_screen, y_screen except: pass if cam_intrinsics_path is not None and bar.display.value is not 0: # undistor world image img1 = cv2.undistort(img1, cam_intrinsics.K, cam_intrinsics.dist_coefs) # Undistort the gaze point based on the distortion coefs x_screen, y_screen = undistort_point((x_screen, y_screen), cam_intrinsics.K, cam_intrinsics.dist_coefs) if bar.display.value in (2,3): # homography mapping overlay, H = homography_map(img2, img1) # map img1 onto img2 (the world onto the source video) # cam_intrinsics.H_map.append([bar.frame_num.value, H]) if overlay is not None: pt_homog = np.array([x_screen, y_screen, 1]) pt_homog = np.dot(H, pt_homog) pt_homog /= pt_homog[-1] # normalize the gaze.pts x_screen, y_screen, z = pt_homog img1=overlay #overwrite img with the overlay if bar.display.value == 3: # cv2.circle(img2, (int(x_screen), int(y_screen)), 10, (0,255,0,100), 1) img1=img2 #overwrite img1 with the source video # update the img array img_arr[...] = cv2.cvtColor(img1, cv2.COLOR_BGR2RGB) #recorder logic if bar.record_video.value and not bar.record_running.value: record.path = os.path.join(bar.data_path, "out.avi") record.writer = cv2.VideoWriter(record.path,cv2.cv.CV_FOURCC(*'DIVX'),record.fps, (img1.shape[1],img1.shape[0]) ) bar.record_running.value = 1 if bar.record_video.value and bar.record_running.value: # Save image frames to video writer try: cv2.circle(img1, (int(x_screen), int(y_screen)), 20, (0,255,0,100), 1) except: pass record.writer.write(img1) # Finish all recordings, clean up. if not bar.record_video.value and bar.record_running.value: record.writer = None bar.record_running.value = 0 #just grab one image. bar.get_single = 0 image.update() fig.redraw() if bar.exit: on_close() fig.window.stop() fig.window.push_handlers(on_idle) fig.window.push_handlers(atb.glumpy.Handlers(fig.window)) fig.window.push_handlers(on_draw) fig.window.push_handlers(on_close) fig.window.set_title("Browser") fig.window.set_position(0,0) glumpy.show()
print "Visco-EFIT2D" else: FD = EFIT2D(image, materials, source, transducer, signal, simModel,"ELASTIC", Local_Size) print "Elastic-EFIT2D" #setup receiver line (100 receivers) y = np.linspace(1,100,100) x = np.zeros((np.size(y))) FD.ReceiverVectorSetup(x,y) start = time.time() if Plotting: Z = FD.SV fig = glumpy.figure((int(FD.MRI/4.0),int(FD.NRI/4.0)) ) I = glumpy.Image(Z, interpolation='bilinear', colormap= glumpy.colormap.IceAndFire, vmin=-40, vmax=0) @fig.event def on_key_press(key, modifiers): if key == glumpy.window.key.ESCAPE: sys.exit(); else: pass @fig.event def on_draw(): fig.clear() I.draw(x=0, y=0, z=0, width=fig.window.width, height=fig.window.height)
# Create instaces of the RGB and IR interface RGB = RGB_Interface.RGB_Camera() IR = IR_Interface.IR_Camera() # OpenCV Face Detection stuff haar_face = FaceRec.HaarDetectFace() face_rec = FaceRec.FaceRec() # Initilize glumpy stuff fig = glumpy.figure((1280, 1760)) haar_frame = haar_face.getFrame(RGB, IR)[0] haar_img = glumpy.image.Image(haar_frame) depth_frame = IR.getNumpyArray().astype(np.float32) depth_img = glumpy.image.Image(depth_frame) depth_frame_8 = IR.getNumpyArray_8() depth_img_8 = glumpy.image.Image(depth_frame_8) #depth_frame_color = IR.getColorArray() #depth_img_color = glumpy.image.Image(depth_frame_color) #crop_face = np.zeros([23, 23])
def glumpy_viewer(img_array, arrays_to_print = [], commands=None, cmap=None, window_shape=(512, 512), contrast_norm=None ): """ Setup and start glumpy main loop to visualize Image array `img_array`. img_array - an array-like object whose elements are float32 or uint8 ndarrays that glumpy can show. larray objects work here. arrays_to_print - arrays whose elements will be printed to stdout after a keypress changes the current position. """ if contrast_norm not in (None, 'each', 'all'): raise ValueError('contrast_norm', contrast_norm) if contrast_norm == 'all': np.array(img_array, 'float32') img_array -= img_array.min() img_array /= max(img_array.max(), 1e-12) try: n_imgs = len(img_array) except TypeError: n_imgs = None state = dict( pos=0, fig=glumpy.figure((window_shape[1], window_shape[0])), I=glumpy.Image(img_array[0], colormap=cmap), len=n_imgs ) fig = state['fig'] if commands is None: commands = _commands @fig.event def on_draw(): fig.clear() state['I'].draw(x=0, y=0, z=0, width=fig.width, height=fig.height) @fig.event def on_key_press(symbol, modifiers): if chr(symbol) not in commands: print 'unused key', chr(symbol), modifiers return pos = state['pos'] commands[chr(symbol)](state) if pos == state['pos']: return else: img_i = img_array[state['pos']] if contrast_norm == 'each': # -- force copy img_i = np.array(img_i, 'float32') img_i -= img_i.min() img_i /= max(img_i.max(), 1e-12) #print img_i.shape #print img_i.dtype #print img_i.max() #print img_i.min() state['I'] = glumpy.Image(img_i, colormap=cmap, vmin=0.0, vmax=1.0 ) print state['pos'], [o[state['pos']] for o in arrays_to_print] fig.redraw() glumpy.show()
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Nicolas P. Rougier. # ----------------------------------------------------------------------------- ''' This example shows figure splitting. ''' import OpenGL.GL as gl from glumpy import figure, show top_left = figure() top_right = top_left.split('right') bottom_left = top_left.split('bottom', size=.75) bottom_right= top_right.split('bottom', size=.25) @top_left.event def on_draw(): top_left.clear(1,0,0,1) @top_right.event def on_draw(): top_right.clear(0,0,1,1) @bottom_right.event def on_draw(): bottom_right.clear(0,1,0,1) @bottom_left.event def on_draw(): bottom_left.clear(1,1,1,1)
format='%(levelname).1s %(asctime)s [%(module)s:%(lineno)d] %(message)s') numpy.seterr(all='raise') opts, args = FLAGS.parse_args() if not args: FLAGS.error('No images specified!') def add(r, c, size=(1, 1), spacing=0.025): f = fig.add_figure(cols=N, rows=N, position=(r, c), size=size) return f.add_frame(spacing=spacing) n = opts.filters N = 2 * n fig = glumpy.figure(size=(800, 800)) sim = Simulator( add(0, n, size=(n, n), spacing=0.025 / n), add(n, n, size=(n, n), spacing=0.025 / n), [[add(r, c) for c in xrange(n)] for r in xrange(n)], [[add(n + r, c) for c in xrange(n)] for r in xrange(n)], opts, args) @fig.event def on_draw(): fig.clear() sim.draw() @fig.event def on_idle(dt): if sim.frames_until_pause != 0:
def main(simulator): fig = glumpy.figure() world = fig.add_figure() @fig.event def on_init(): gl.glEnable(gl.GL_BLEND) gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_BLEND) gl.glEnable(gl.GL_COLOR_MATERIAL) gl.glColorMaterial(gl.GL_FRONT_AND_BACK, gl.GL_AMBIENT_AND_DIFFUSE) gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) @fig.event def on_draw(): fig.clear() # draw the opengl driving world. w = world.width h = world.height x = world.x y = world.y gl.glBegin(gl.GL_QUADS) gl.glColor(0.2, 0.2, 0.2) gl.glNormal(0, 0, 1) gl.glVertex(x, y, 0) gl.glVertex(x + w, y, 0) gl.glVertex(x + w, y + h, 0) gl.glVertex(x, y + h, 0) gl.glEnd() z = min(w, h) / 300. gl.glPushMatrix() gl.glLoadIdentity() gl.glTranslate(x + w / 2., y + h / 2., 10) gl.glScale(z, z, 1) a, b = simulator.agent.position gl.glTranslate(-a, -b, 0) gl.glLight(gl.GL_LIGHT0, gl.GL_POSITION, (0, 0, 100, 1)) # draw lanes. gl.glLineWidth(2) gl.glColor(0, 0, 0) for lane in simulator.lanes: gl.glBegin(gl.GL_LINE_STRIP) for a, b in lane: gl.glVertex(a, b, 1) gl.glEnd() # draw cars. simulator.leader.draw(sys.modules[__name__], 1, 0, 0) simulator.agent.draw(sys.modules[__name__], 1, 1, 0) gl.glPopMatrix() @fig.event def on_idle(dt): global elapsed elapsed += dt while elapsed > simulator.dt: elapsed -= simulator.dt try: simulator.step() except StopIteration: sys.exit() fig.redraw() @fig.event def on_key_press(key, modifiers): if key == glumpy.window.key.ESCAPE: sys.exit() elif key == glumpy.window.key.SPACE: global ESTIMATE ESTIMATE ^= ESTIMATE else: simulator.reset() fig.redraw() glumpy.show()
FD.InitCL("GPU") # change for "CPU" when running on a CPU FD.Setup(Tap) ####if not interested the Layer intercepting just FD.MediumSetup() FD.MediumSetup(LayerInterProps=[2200, 1800, 967], LayerInterDim=[3.9, 4.2], LayerIntercepting=True) FD.absSetup() FD.receivers_setup(pr, pz, TimeIter) FD.Init_Fields_CL() start = time.time() if Plotting: Z = FD.SV.transpose() fig = glumpy.figure((int(FD.NRI * 0.5), int(FD.NZI * 0.5))) I = glumpy.Image(Z, interpolation='bilinear', colormap=glumpy.colormap.IceAndFire, vmin=-50, vmax=0) @fig.event def on_key_press(key, modifiers): if key == glumpy.window.key.ESCAPE: sys.exit() else: pass @fig.event def on_draw():
help='process N images in one minibatch') if __name__ == '__main__': logging.basicConfig( stream=sys.stdout, level=logging.INFO, format='%(levelname).1s %(asctime)s [%(module)s:%(lineno)d] %(message)s') args = FLAGS.parse_args() _visibles = np.zeros((args.n, 28, 28), dtype=np.float32) _hiddens = np.zeros((args.n, args.n), dtype=np.float32) _weights = np.zeros((args.n * args.n, 28, 28), dtype=np.float32) fig = glumpy.figure() visibles = [glumpy.image.Image(v) for v in _visibles] hiddens = glumpy.image.Image(_hiddens) weights = [glumpy.image.Image(w) for w in _weights] visible_frames = [ fig.add_figure(args.n + 1, args.n, position=(args.n, r)).add_frame(aspect=1) for r in range(args.n)] weight_frames = [ fig.add_figure(args.n + 1, args.n, position=(c, r)).add_frame(aspect=1) for r in range(args.n) for c in range(args.n)] loaded = False recent = collections.deque(maxlen=20)
gl.glEnable(gl.GL_DEPTH_TEST) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) gl.glPolygonOffset(1, 1) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) self.buffer.draw(gl.GL_QUADS, 'pnc') gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_LINE) gl.glDepthMask(gl.GL_FALSE) gl.glEnable(gl.GL_BLEND) gl.glEnable(gl.GL_LINE_SMOOTH) gl.glColor(0.0, 0.0, 0.0, 0.5) self.buffer.draw(gl.GL_QUADS, 'p') gl.glDepthMask(gl.GL_TRUE) self.trackball.pop() gl.glPolygonMode(gl.GL_FRONT_AND_BACK, gl.GL_FILL) fig = figure(size=(800, 400)) fig1 = fig.add_figure(cols=2, rows=1, position=[0, 0]) fig2 = fig.add_figure(cols=2, rows=1, position=[1, 0]) Cube(frame=fig1.add_frame(aspect=1)) Cube(frame=fig2.add_frame(aspect=1)) @fig.event def on_draw(): fig.clear(.85, .85, .85, 1) show()
help='process N images in one minibatch') if __name__ == '__main__': logging.basicConfig( stream=sys.stdout, level=logging.INFO, format='%(levelname).1s %(asctime)s [%(module)s:%(lineno)d] %(message)s' ) opts, args = FLAGS.parse_args() _visibles = numpy.zeros((opts.n, 28, 28), dtype=numpy.float32) _hiddens = numpy.zeros((opts.n, opts.n), dtype=numpy.float32) _weights = numpy.zeros((opts.n * opts.n, 28, 28), dtype=numpy.float32) fig = glumpy.figure() m = opts.gaussian and 0.5 or 1.5 visibles = [glumpy.image.Image(v) for v in _visibles] hiddens = glumpy.image.Image(_hiddens) weights = [glumpy.image.Image(w, vmin=-m, vmax=m) for w in _weights] visible_frames = [ fig.add_figure(opts.n + 1, opts.n, position=(opts.n, r)).add_frame(aspect=1) for r in range(opts.n) ] weight_frames = [ fig.add_figure(opts.n + 1, opts.n, position=(c, r)).add_frame(aspect=1) for r in range(opts.n) for c in range(opts.n)
FD = FD25D(scenario, source, rx, vpx, vsx, rho) FD.InitCL("GPU") # change for "CPU" when running on a CPU FD.Setup(Tap) ####if not interested the Layer intercepting just FD.MediumSetup() FD.MediumSetup(LayerInterProps=[2200, 1800, 967],LayerInterDim=[3.9, 4.2],LayerIntercepting=True) FD.absSetup() FD.receivers_setup(pr, pz, TimeIter) FD.Init_Fields_CL() start = time.time() if Plotting: Z = FD.SV.transpose() fig = glumpy.figure((int(FD.NRI*0.5),int(FD.NZI*0.5)) ) I = glumpy.Image(Z, interpolation='bilinear', colormap= glumpy.colormap.IceAndFire, vmin=-50, vmax=0) @fig.event def on_key_press(key, modifiers): if key == glumpy.window.key.ESCAPE: sys.exit(); else: pass @fig.event def on_draw(): fig.clear() I.draw(x=0, y=0, z=0, width=fig.window.width, height=fig.window.height)
from io import BytesIO import socket import sys import struct import numpy import glumpy server = socket.socket() server.connect(('192.168.1.125', 2224)) size = (640, 480) conn = server.makefile('rb') buf = numpy.zeros(size, dtype=np.float32) im = glumpy.image.Image(buf) while True: img_len = struct.unpack('<L', conn.read(struct.calcsize('<L')))[0] print(img_len) fig = glumpy.figure(size) buf = numpy.frombuffer(conn.read(img_len)) fig.clear() im.update() im.draw(x=0, y=0, width=fig.width, height=fig.height)
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Nicolas P. Rougier. # ----------------------------------------------------------------------------- """ This example demonstrates subfigure usage. """ from glumpy import figure, show fig = figure(size=(600, 600)) fig1 = fig.add_figure(cols=2, rows=2, position=[0, 0], size=[2, 1]) fig2 = fig.add_figure(cols=2, rows=2, position=[0, 1], size=[1, 1]) fig3 = fig.add_figure(cols=2, rows=2, position=[1, 1], size=[1, 1]) fig31 = fig3.add_figure(cols=2, rows=2, position=[0, 0], size=[1, 1]) fig32 = fig3.add_figure(cols=2, rows=2, position=[0, 1], size=[1, 1]) fig33 = fig3.add_figure(cols=2, rows=2, position=[1, 0], size=[1, 2]) @fig1.event def on_draw(): fig1.clear(1, 0, 0, 1) @fig2.event def on_draw():
a = cam.rainbowSurf()#.astype(numpy.float32) print a #a.shape = (480, 640) return a def getFrame2(): a = numpy.fromstring(cam.depth.get_raw_depth_map(), dtype="uint16").astype(numpy.float32) # a = cam.rainbowSurf()#.astype(numpy.float32) print a a.shape = (480, 640) return a #fig = glumpy.figure( (640,480) ) fig2 = glumpy.figure( (640,480) ) #Z = getFrame() Z2 = getFrame2() #image = glumpy.image.Image(Z) image2 = glumpy.image.Image(Z2) # Main loop x = True while x: @fig2.event def on_draw():
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Nicolas P. Rougier. # ----------------------------------------------------------------------------- ''' This example shows figure available events. ''' import OpenGL.GL as gl from glumpy import figure fig = figure(size=(400,400)) @fig.event def on_init(): print 'Inititalization' @fig.event def on_draw(): print 'Drawing requested' @fig.event def on_resize(width,height): print 'Figure resized (width=%.1f, height=%.1f)'% (width,height) @fig.timer(1.0) def timer(elapsed):
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Nicolas P. Rougier. # ----------------------------------------------------------------------------- ''' This example demonstrates subfigure usage. ''' from glumpy import figure, show fig = figure(size=(600,600)) fig1 = fig.add_figure(cols=2,rows=2, position=[0,0], size=[2,1]) fig2 = fig.add_figure(cols=2,rows=2, position=[0,1], size=[1,1]) fig3 = fig.add_figure(cols=2,rows=2, position=[1,1], size=[1,1]) fig31 = fig3.add_figure(cols=2,rows=2, position=[0,0], size=[1,1]) fig32 = fig3.add_figure(cols=2,rows=2, position=[0,1], size=[1,1]) fig33 = fig3.add_figure(cols=2,rows=2, position=[1,0], size=[1,2]) @fig1.event def on_draw(): fig1.clear(1,0,0,1) @fig2.event def on_draw(): fig2.clear(0,1,0,1) @fig31.event def on_draw(): fig31.clear(0,0,1,1)
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The views and conclusions contained in the software and documentation are # those of the authors and should not be interpreted as representing official # policies, either expressed or implied, of Nicolas P. Rougier. # ----------------------------------------------------------------------------- ''' This example shows figure splitting. ''' import OpenGL.GL as gl from glumpy import figure, show top_left = figure() top_right = top_left.split('right') bottom_left = top_left.split('bottom', size=.75) bottom_right = top_right.split('bottom', size=.25) @top_left.event def on_draw(): top_left.clear(1, 0, 0, 1) @top_right.event def on_draw(): top_right.clear(0, 0, 1, 1)
# Create instaces of the RGB and IR interface RGB = RGB_Interface.RGB_Camera() IR = IR_Interface.IR_Camera() # OpenCV Face Detection stuff haar_face = FaceRec.HaarDetectFace() # Initilize glumpy stuff haar_fig = glumpy.figure((1280, 480)) #fig1 = haar_fig.add_figure(cols=2,rows=1, position=[0,0]) haar_frame = haar_face.getFrame(RGB)[0] #haar_frame = fig1.add_frame(aspect=1) #haar_frame.push(haar_face.getFrame(RGB)[0]) haar_img = glumpy.image.Image(haar_frame) #haar_croped_frame = haar_face.getCropedFaceImg(RGB) #haar_croped_img = glumpy.image.Image(haar_croped_frame) ## Main loop #run = True