示例#1
0
	def waitAndUpdate(self, duration=0):
		'''
		Input:
			Duration (in milliseconds)
			If negative it will wait until a key is pressed
		'''
		# vv.clf()
		# time.sleep(.01)
		vv.processEvents()

		''' Reset key events '''
		for i in self.open_windows:
			i['keyEvent'] = None

		''' If negative duration then have infinite loop '''
		if duration < 0:
			duration = np.inf

		start_time = time.time()
		while(time.time()-start_time < duration/1000.):
			vv.processEvents()
			time.sleep(.0001)

			keys = [x['keyEvent'] for x in self.open_windows if x['keyEvent'] is not None]
			if len(keys) > 0:
				return keys[0]

		for i in self.open_windows:
			i['keyEvent'] = None

		return 0
示例#2
0
	def waitAndUpdate(self, duration=.00001):
		'''
		Input:
		*Duration (in milliseconds)
			If negative it will wait until a key is pressed

		Output:
		*The first key pressed
		'''

		keys = []

		''' Wait for set duration '''
		if duration >= 0:
			time.sleep(duration)
			vv.processEvents()
			keys = [x['keyEvent'] for x in self.open_windows if x['keyEvent'] is not None]
			for i in self.open_windows:
				i['keyEvent'] = None
		else:
			''' Wait until key pressed '''
			while(time.time()-start_time < np.inf):
				vv.processEvents()
				keys = [x['keyEvent'] for x in self.open_windows if x['keyEvent'] is not None]
				time.sleep(.000001)
				if len(keys) > 0:
					break

		''' Check for keys pressed '''
		if len(keys) > 0:
			return keys.pop()
		else:
			return 0
示例#3
0
def crop3d(vol, fig=None):
    """ crop3d(vol, fig=None)
    Manually crop a volume. In the given figure (or a new figure if None),
    three axes are created that display the transversal, sagittal and
    coronal MIPs (maximum intensity projection) of the volume. The user
    can then use the mouse to select a 3D range to crop the data to.
    """
    vv.use()

    # Create figure?
    if fig is None:
        fig = vv.figure()
        figCleanup = True
    else:
        fig.Clear()
        figCleanup = False

    # Create three axes and a wibject to attach text labels to
    a1 = vv.subplot(221)
    a2 = vv.subplot(222)
    a3 = vv.subplot(223)
    a4 = vv.Wibject(fig)
    a4.position = 0.5, 0.5, 0.5, 0.5

    # Set settings
    for a in [a1, a2, a3]:
        a.showAxis = False

    # Create cropper3D instance
    cropper3d = Cropper3D(vol, a1, a3, a2, a4)

    # Enter a mainloop
    while not cropper3d._finished:
        vv.processEvents()
        time.sleep(0.01)

    # Clean up figure (close if we opened it)
    fig.Clear()
    fig.DrawNow()
    if figCleanup:
        fig.Destroy()

    # Obtain ranges
    rx = cropper3d._range_transversal._rangex
    ry = cropper3d._range_transversal._rangey
    rz = cropper3d._range_coronal._rangey

    # Perform crop
    # make sure we have int not float
    rzmin, rzmax = int(rz.min), int(rz.max)
    rymin, rymax = int(ry.min), int(ry.max)
    rxmin, rxmax = int(rx.min), int(rx.max)
    vol2 = vol[rzmin:rzmax, rymin:rymax, rxmin:rxmax]
    # vol2 = vol[rz.min:rz.max, ry.min:ry.max, rx.min:rx.max]

    # Done
    return vol2
示例#4
0
def show():
    reader = imageio.read('<video0>')
    
    import visvis as vv
    im = reader.get_next_data()
    t = vv.imshow(im)
    
    while True:
        t.SetData(reader.get_next_data())
        vv.processEvents()
示例#5
0
def crop3d(vol, fig=None):
    """ crop3d(vol, fig=None)
    Manually crop a volume. In the given figure (or a new figure if None),
    three axes are created that display the transversal, sagittal and 
    coronal MIPs (maximum intensity projection) of the volume. The user
    can then use the mouse to select a 3D range to crop the data to.
    """
    app = vv.use()
    
    # Create figure?    
    if fig is None:        
        fig = vv.figure()    
        figCleanup = True
    else:
        fig.Clear()
        figCleanup = False
    
    # Create three axes and a wibject to attach text labels to    
    a1 = vv.subplot(221)
    a2 = vv.subplot(222)
    a3 = vv.subplot(223)
    a4 = vv.Wibject(fig)
    a4.position = 0.5, 0.5, 0.5, 0.5
    
    # Set settings
    for a in [a1, a2, a3]:
        a.showAxis = False
    
    # Create cropper3D instance
    cropper3d = Cropper3D(vol, a1, a3, a2, a4)
    
    # Enter a mainloop
    while not cropper3d._finished:
        vv.processEvents()
        time.sleep(0.01)
    
    # Clean up figure (close if we opened it)
    fig.Clear()
    fig.DrawNow()
    if figCleanup:    
        fig.Destroy()
    
    # Obtain ranges
    rx = cropper3d._range_transversal._rangex
    ry = cropper3d._range_transversal._rangey
    rz = cropper3d._range_coronal._rangey
    
    # Perform crop
    vol2 = vol[rz.min:rz.max, ry.min:ry.max, rx.min:rx.max]
    
    # Done
    return vol2
示例#6
0
def show_in_visvis():
    reader = imageio.read('cockatoo.mp4', 'ffmpeg')
    #reader = imageio.read('<video0>')
    
    import visvis as vv
    im = reader.get_next_data()
    f = vv.clf()
    f.title = reader.format.name
    t = vv.imshow(im, clim=(0, 255))
    
    while not f._destroyed:
        t.SetData(reader.get_next_data())
        vv.processEvents()
示例#7
0
def show_in_visvis():
    reader = imageio.read('cockatoo.mp4', 'ffmpeg')
    #reader = imageio.read('<video0>')

    import visvis as vv
    im = reader.get_next_data()
    f = vv.clf()
    f.title = reader.format.name
    t = vv.imshow(im, clim=(0, 255))

    while not f._destroyed:
        t.SetData(reader.get_next_data())
        vv.processEvents()
示例#8
0
 def run(self):
     
     # Setup detecting closing of figure
     self._closed = False
     def callback(event):
         self._closed = True
     self._fig.eventClose.Bind(callback)
     
     while not self._closed:
         time.sleep(0.02)
         vv.processEvents()
     
     self.apply_deform()
示例#9
0
def show_in_visvis():
    # reader = imageio.read("imageio:cockatoo.mp4", "ffmpeg")
    reader = imageio.read("<video0>", fps=20)

    import visvis as vv

    im = reader.get_next_data()
    f = vv.clf()
    f.title = reader.format.name
    t = vv.imshow(im, clim=(0, 255))

    while not f._destroyed:
        im = reader.get_next_data()
        if im.meta["new"]:
            t.SetData(im)
        vv.processEvents()
示例#10
0
def show_in_visvis():
    # reader = imageio.read("imageio:cockatoo.mp4", "ffmpeg")
    reader = imageio.read("<video0>", fps=20)

    import visvis as vv

    im = reader.get_next_data()
    f = vv.clf()
    f.title = reader.format.name
    t = vv.imshow(im, clim=(0, 255))

    while not f._destroyed:
        im = reader.get_next_data()
        if im.meta["new"]:
            t.SetData(im)
        vv.processEvents()
示例#11
0
	def imshow(self, name, im, axis=False):
		'''
		Inputs
			name: string with figure name
			im: numpy array
		'''

		win = self.getWindow(name)
		
		if win is None:
			win = self.createWindow(name, im, axis)
		else:	
			''' If new image is of different dimensions we must create new image'''
			if im.shape != win['shape']:
				self.destroyWindow(win['name'])
				win = self.createWindow(name, im)

		win['figure'].SetData(im)
		vv.processEvents()
示例#12
0
    def waitAndUpdate(self, duration=.00001):
        '''
		Input:
		*Duration (in milliseconds)
			If negative it will wait until a key is pressed

		Output:
		*The first key pressed
		'''

        keys = []
        ''' Wait for set duration '''
        if duration >= 0:
            time.sleep(duration)
            vv.processEvents()
            keys = [
                x['keyEvent'] for x in self.open_windows
                if x['keyEvent'] is not None
            ]
            for i in self.open_windows:
                i['keyEvent'] = None
        else:
            ''' Wait until key pressed '''
            while (time.time() - start_time < np.inf):
                vv.processEvents()
                keys = [
                    x['keyEvent'] for x in self.open_windows
                    if x['keyEvent'] is not None
                ]
                time.sleep(.000001)
                if len(keys) > 0:
                    break
        ''' Check for keys pressed '''
        if len(keys) > 0:
            return keys.pop()
        else:
            return 0
示例#13
0
 def update(self):
     ''' Does not capture key inputs '''
     vv.processEvents()
# -*- coding: utf-8 -*-
"""
Created on Thu Jan  4 21:03:33 2018

@author: Saurav
"""

import imageio
import visvis as vv

reader = imageio.get_reader('<video0>')
t = vv.imshow(reader.get_next_data(), clim=(0, 255))
for im in reader:
    vv.processEvents()
    t.SetData(im)
示例#15
0
 def Run(self):
     vv.processEvents()
     self.updatePosition()
示例#16
0
# Visvis is distributed under the terms of the (new) BSD License.
# The full license can be found in 'license.txt'.

import visvis as vv

def processEvents():
    """ processEvents()
    
    Processes all GUI events (and thereby all visvis events).
    Users can periodically call this function during running 
    an algorithm to keep the figures responsove.
    
    Note that IEP and IPython can integrate the GUI event loop to 
    periodically update the GUI events when idle.
    
    Also see Figure.DrawNow()
    
    """
    
    app = vv.backends.currentBackend.app
    if app:
        app.ProcessEvents()

if __name__ == '__main__':
    import time
    l = vv.plot([1,2,3,1,4])
    for i in range(20):
        l.SetYdata([1+i/10.0, 2,3,1,4])
        vv.processEvents() # Process gui events
        time.sleep(0.1)
示例#17
0
import visvis as vv


def processEvents():
    """ processEvents()
    
    Processes all GUI events (and thereby all visvis events).
    Users can periodically call this function during running 
    an algorithm to keep the figures responsove.
    
    Note that IEP and IPython can integrate the GUI event loop to 
    periodically update the GUI events when idle.
    
    Also see Figure.DrawNow()
    
    """

    app = vv.backends.currentBackend.app
    if app:
        app.ProcessEvents()


if __name__ == '__main__':
    import time
    l = vv.plot([1, 2, 3, 1, 4])
    for i in range(20):
        l.SetYdata([1 + i / 10.0, 2, 3, 1, 4])
        vv.processEvents()  # Process gui events
        time.sleep(0.1)
示例#18
0
        rData.buffer = self.__ai.integrate2d(data.buffer, self.outshape[0], self.outshape[1], unit="r_mm", method="lut_ocl")[0]
        return rData

extMgr = ctrl.externalOperation()
myOp = extMgr.addOp(Core.USER_LINK_TASK, "myTask", 0)
myTask = MyLink(10)
myOp.setLinkTask(myTask)
a = ctrl.acquisition()
a.setAcqNbFrames(0)
a.setAcqExpoTime(acqt)
ctrl.prepareAcq()
ctrl.startAcq()

while ctrl.getStatus().ImageCounters.LastImageReady < 1:
    print(ctrl.getStatus())
    time.sleep(0.5)
print(ctrl.getStatus())

raw_img = ctrl.ReadBaseImage().buffer
fai_img = ctrl.ReadImage().buffer
vv.figure()
rawplot = vv.subplot(121)
faiplot = vv.subplot(122)
rawtex = vv.imshow(raw_img, axes=rawplot)
faitex = vv.imshow(fai_img, axes=faiplot)
while 1:
    rawtex.SetData(ctrl.ReadBaseImage().buffer)
    faitex.SetData(ctrl.ReadImage().buffer)
    time.sleep(acqt)
    vv.processEvents()
示例#19
0
 def Run(self):
     vv.processEvents()
示例#20
0
 def Run(self):
     vv.processEvents()
     self._updateSlider()
示例#21
0
	def update(self):
		''' Does not capture key inputs '''
		vv.processEvents()