def run_entity(upstream_conn, entity_cls, *args, **kwargs): '''perpetually loops the vision class entity_cls, and outputs data through the upstream_conn pipe ''' try: svr.connect() entity = entity_cls(upstream_conn, *args, **kwargs) print "running", entity entity.run() except Exception as e: upstream_conn.send(KillSignal()) traceback.print_exc() sys.exit()
def svrConnect(): """ connecting to svr """ svr.connect() """setting up svr streams """ forward = svr.Stream("forward") forward.unpause() down = svr.Stream("down") down.unpause() global cameras cameras = { "forward" : forward, "down" : down }
def svrConnect(): """ Connecting to svr """ svr.connect() """ Setting up svr streams """ forward = svr.Stream("forward") #Forward? are these names of cameras? forward.unpause() down = svr.Stream("down") #Down? where are the names defined? down.unpause() global cameras cameras = { "forward" : forward, "down" : down }
def __init__(self, entities = None): self.entities = entities #setting the scale factor, this means each pixel is one cm when obj is 1m away sf = .0017 svr.connect() #making the down camera downTransform = np.float32([[1, 0, 0], [0, 1, 0], [0, 0, -1 * sf]]) downCam = Camera(name = "down", transform = downTransform) #making the forward camera forTransform = np.float32([[1, 0, 0], [ 0, 0, 1], [ 0, sf * 1, 0]]) forCam = Camera(name = "forward", transform = forTransform) self.cams = [downCam, forCam] return
from __future__ import division from sys import argv from time import time import os.path import cv import svr svr.connect() open_streams = {} # Map stream names to stream objects stream_directories = {} # Map stream names to recording directories stream_framecounts = {} # Map stream names to number of frames recorded SOURCES_UPDATE_FREQUENCY = 5 # How many times per second to update sources last_sources_update = 0 # Last time that the open_streams was updated def get_next_dir(base_dir, prefix=""): '''Find the next directory base_dir+prefix+i that isn't taken.''' i=0 while True: candidate = os.path.join(base_dir, prefix+str(i)) if not os.path.exists(candidate): break i += 1 os.mkdir(candidate) return candidate if __name__ == "__main__": base_dir = argv[1]
'''Show all SVR streams, and show any new streams that appear.''' from __future__ import division from time import time import cv import svr svr.connect() open_streams = {} # Map stream names to stream objects last_sources_update = 0 # Last time that the open_streams was updated SOURCES_UPDATE_FREQUENCY = 5 # How many times per second to update sources if __name__ == "__main__": while True: # Rate limit stream listing t = time() if t > last_sources_update + 1/SOURCES_UPDATE_FREQUENCY: last_sources_update = t # Add new streams to open_streams all_streams = svr.get_sources_list() for stream in all_streams: stream_name = stream.split(":")[1] if stream_name not in open_streams: try:
def __init__(self, cam_pos=(0, 0, 0), cam_pitch=0, cam_yaw=0, parameter_sets={}, svr_source=False): self.cam_pos = numpy.array(cam_pos, numpy.float) self.cam_pitch = cam_pitch # Degrees self.cam_yaw = cam_yaw # Degrees self.last_parameter_set = None self.parameter_sets = parameter_sets self.svr_source = svr_source self.frame_number = 0 self.camera_modes = [ "Free Cam", "Forward Cam", "Down Cam", ] self.camera_mode = self.camera_modes[0] self.simulator = None self.left_mouse_down = False self.view_width = 800 self.view_height = 800 self.fov = 70 # Degrees # Window Init glutInit(sys.argv) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH) glutInitWindowSize(self.view_width, self.view_height) glutCreateWindow("Simulator") # OpenGL Settings glClearColor(0, 0, 0, 0) glShadeModel(GL_FLAT) glEnable(GL_NORMALIZE) glEnable(GL_DEPTH_TEST) glEnable(GL_COLOR_MATERIAL) glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE) glDisable(GL_CULL_FACE) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) # Lighting glLightModelfv(GL_LIGHT_MODEL_AMBIENT, (0.2, 0.2, 0.2, 0.1)) glLightfv(GL_LIGHT0, GL_POSITION, (0, 1, -1, 0)) glLightfv(GL_LIGHT0, GL_AMBIENT, (0, 0, 0, 1)) glLightfv(GL_LIGHT0, GL_DIFFUSE, (0.5, 0.5, 0.5, 1)) glLightfv(GL_LIGHT0, GL_SPECULAR, (0, 0, 0, 0)) glLightfv(GL_LIGHT1, GL_POSITION, (0.5, -1, -1, 0)) glLightfv(GL_LIGHT1, GL_AMBIENT, (0, 0, 0, 1)) glLightfv(GL_LIGHT1, GL_DIFFUSE, (0.5, 0.5, 0.5, 1)) glLightfv(GL_LIGHT1, GL_SPECULAR, (0, 0, 0, 0)) # glShadeModel(GL_SMOOTH) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glEnable(GL_LIGHT1) # Callbacks glutDisplayFunc(self.draw) glutKeyboardFunc(self.keyboard_callback) glutSpecialFunc(self.special_keyboard_callback) glutMouseFunc(self.mouse_callback) # Parameter Set Menu parameter_set_menu = glutCreateMenu(self.parameter_set_menu_callback) for i, set_name in enumerate(self.parameter_sets.iterkeys()): glutAddMenuEntry(set_name, i) # Camera Mode Menu camera_mode_menu = glutCreateMenu(self.camera_mode_callback) for i, mode_name in enumerate(self.camera_modes): glutAddMenuEntry(mode_name, i) # Main menu glutCreateMenu(self.main_menu_callback) glutAddSubMenu("Reset", parameter_set_menu) glutAddSubMenu("Cam Mode", camera_mode_menu) glutAddMenuEntry("Zero Thrusters", 2) glutAddMenuEntry("Quit", 1) glutAttachMenu(GLUT_RIGHT_BUTTON) self.init_viewport() # Init SVR Sources if self.svr_source: svr.connect() self.svr_sources = {} # Map camera names to svr sources for camera in ["forward", "down"]: source = svr.Source(camera) source.set_encoding("raw") self.svr_sources[camera] = source