def __init__(self, fname=None): '''Straightforward init fname : I think this needs to be *.avi ''' # Set camera up first, as this is more likley to fail (I guess) self.cv_cam = CVCam() im = self.cv_cam.get_image() arr = self.cv_cam.conv2array(im) self.size = self.cv_cam.width, self.cv_cam.height if fname: self.writer = CVWriter(fname, self.size) # Then, we set up our graphical environment # SimpleVisionEgg is a custom set-up class I wrote to avoid boilerplate # code duplication. It's a little clunky, sadly. self.vision_egg = SimpleVisionEgg() screen_center = [x/2.0 for x in self.vision_egg.screen.size] tex_stim = TextureStimulus(mipmaps_enabled=False, texture=Texture(arr), size=self.size, # We shouldn't invoke OpenGL texture # filtering, as we take our texture size # directly from the camera. # the other option would be # GL_NEAREST texture_min_filter=GL.GL_LINEAR, position=screen_center, anchor='center') # This gives us programmatic access to the actual video memory (if # possible), so it should make things nice and fast. We still seem to be # down around 14 fps, though, on the Mac. We're not going to get much # faster on this front. self.tex_object = tex_stim.parameters.texture.get_texture_object() self.vision_egg.set_stimuli([tex_stim])
limit -- if you give it key values (e.g. ("l","m") accepts only those) buttonbox -- a parallel.respbox.RespBox instance this gives back the integer 2^x, x indexes the finger dont give it a limit if you do this """ # Here's an easy way to imput the subject designation and other starting info subject = raw_input('Subject designation: ') exp_version = None while exp_version not in (1, 2): exp_version = input("Experiment Version (1 or 2): ") ############## # Initialize # ############## vision_egg = SimpleVisionEgg() screen = vision_egg.screen screen.parameters.bgcolor = [0,0,0] xlim, ylim = vision_egg.screen.size # screen size in pixels #box = respbox.RespBox() ########### # Stimuli # ########### std_params = {'anchor': 'center', # for text display objects 'position': (xlim/2,ylim/2), 'on': False} rest = Text(text="Press space to begin.", **std_params) fixation = Text(text="+", font_size=55, **std_params) blank = Text(text="", **std_params)
class CameraWindow: '''A simple class to set up a pygame window A general design principle is that ALL openCV code should be encapsulated in classes such as the above.`''' writer = None def __init__(self, fname=None): '''Straightforward init fname : I think this needs to be *.avi ''' # Set camera up first, as this is more likley to fail (I guess) self.cv_cam = CVCam() im = self.cv_cam.get_image() arr = self.cv_cam.conv2array(im) self.size = self.cv_cam.width, self.cv_cam.height if fname: self.writer = CVWriter(fname, self.size) # Then, we set up our graphical environment # SimpleVisionEgg is a custom set-up class I wrote to avoid boilerplate # code duplication. It's a little clunky, sadly. self.vision_egg = SimpleVisionEgg() screen_center = [x/2.0 for x in self.vision_egg.screen.size] tex_stim = TextureStimulus(mipmaps_enabled=False, texture=Texture(arr), size=self.size, # We shouldn't invoke OpenGL texture # filtering, as we take our texture size # directly from the camera. # the other option would be # GL_NEAREST texture_min_filter=GL.GL_LINEAR, position=screen_center, anchor='center') # This gives us programmatic access to the actual video memory (if # possible), so it should make things nice and fast. We still seem to be # down around 14 fps, though, on the Mac. We're not going to get much # faster on this front. self.tex_object = tex_stim.parameters.texture.get_texture_object() self.vision_egg.set_stimuli([tex_stim]) def update_image(self, t): '''Grab an image from the camera and convert to a pygame.image I'm using my SimpleVisionEgg system, so I need to discard the time parameter `t` that gets passed in''' im = self.cv_cam.get_image() if self.writer: self.writer.write_im(im) arr = self.cv_cam.conv2array(im) # Note - we use .put_sub_image because we aren't using dimensions that # are a power of 2. There's a little more OpenGL magic going on somwhere # that I don't know about... self.tex_object.put_sub_image(arr) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: # For some reason, using VisionEgg we don't exit cleanly and # finalize our writer (thus, the movie is corrupted) del self.writer del self.cv_cam self.vision_egg.quit() def run(self): '''Run forever (until we get a QUIT event)''' self.vision_egg.set_functions(update=self.update_image) self.vision_egg.go()
i = 3 final = x[-i:] while i < len(x): final = x[-(i+3):-i] + ',' + final i += 3 return final ### Presentation Classes # This seems "wrong," instantiating classes before declaring others but it gets # the job done! vision_egg = SimpleVisionEgg() xlim, ylim = vision_egg.screen.size std_params = {'anchor': 'center', 'color': (0,0,0), 'font_size': 55, 'on': False} instruction = Text(text='ESTIMATE', position=(xlim/2, 7 * ylim/8), **std_params) description = [] for i in range(4): description.append(Text(text='Total U.S. population', position=(xlim/2, (11-i) * ylim/16), **std_params))