def main(): aspect_ratio = 1 height = 256 width = int(height * aspect_ratio) # round name = "test.png" wrapper = ImageWrapper(name, width, height) red = Lambertian(Vector3(1, 0, 0)) green = Lambertian(Vector3(0.2, 1, 0.1)) camera = Camera(Vector3(0, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1), 1, 90) spheres = [ Sphere(Vector3(0, 10, 0), 5, red), Sphere(Vector3(0, 10, -100), 95, green) ] samples = 50 for y in range(height): for x in range(width): final_color = Vector3(0, 0, 0) for sample in range(samples): ray = camera.generate_ray((x + random.random()) / width, (y + random.random()) / height) color = get_intersection(ray, spheres, MAX_DEPTH) final_color += color final_color /= samples wrapper.write_pixel(x, y, final_color) wrapper.save()
def main(): ids, encodings = known_photos_loader.load_photos() process_this_frame = True with Camera.open_camera(): last_found_id = None while True: frame = Camera.get_frame() if process_this_frame: faces_locations = face_recognition.face_locations(frame) faces_encodings = face_recognition.face_encodings(frame, faces_locations) for face_encoding in faces_encodings: matches = face_recognition.compare_faces(encodings, face_encoding) if True in matches: index = matches.index(True) employee_id = ids[index] if last_found_id != employee_id: last_found_id = employee_id show_employee_welcome(employee_id) else: if last_found_id is not None: last_found_id = None LOGGER.warning("Face not recognized.") process_this_frame = not process_this_frame
def __init__(self, name): super().__init__(name) self.camera = Camera((-self.display.get_width()//2, -self.display.get_height()//2), 7) self.camera_follow = None #set this to an object with a .pos to have the camera follow it self.render_list = [] #render relitive to camera self.ui_render_list = [] #render without camera interference self.keydict = {pygame.K_ESCAPE:self.quit}
class Map(object): """ Class for storing tile layers """ def __init__(self, mapData): self.layers = [] self.offset = { 'x': 0, 'y': 0 } if mapData: self.load_map_data(mapData) self.camera = Camera( (0,0), (self.mapSize['x'], self.mapSize['y']), 10) def load_map_data(self, mapData): try: tree = ET.parse(os.path.join(MAPDATA_PATH, mapData)) except: raise 'Could not open map data file.' data = tree.getroot() self.tileSize = { 'x': int(data.attrib['tilewidth']), 'y': int(data.attrib['tileheight']) } self.mapSize = { 'x': int(data.attrib['width']) * self.tileSize['x'], 'y': int(data.attrib['height']) * self.tileSize['y'] } self.tileset = Tileset(data.find('tileset')) for prop in data.iter('property'): if prop.attrib['name'] == 'name': self.name = prop.attrib['value'] for layer in data.findall('layer'): self.layers.append(Layer(layer, self.tileset)) def update(self, events): self.camera.update(events) for layer in self.layers: layer.update(events, self.camera) def draw(self, surface): for layer in self.layers: layer.draw(surface)
def __init__(self, mapData): self.layers = [] self.offset = { 'x': 0, 'y': 0 } if mapData: self.load_map_data(mapData) self.camera = Camera( (0,0), (self.mapSize['x'], self.mapSize['y']), 10)
class main_w_aron(Window): def __init__(self, name): super().__init__(name) self.camera = Camera((-self.display.get_width()//2, -self.display.get_height()//2), 7) self.camera_follow = None #set this to an object with a .pos to have the camera follow it self.render_list = [] #render relitive to camera self.ui_render_list = [] #render without camera interference self.keydict = {pygame.K_ESCAPE:self.quit} def update(self): for item in self.render_list: item.update() if self.camera_follow is not None: self.camera.go_to(self.camera_follow.pos) def draw(self): for item in self.render_list: item.draw(self.camera.get_pos()) for item in self.ui_render_list: item.draw() def quit(self, arg): self.end = True def keydown(self, key): for k in self.keydict.keys(): if key == k: self.keydict[k](True) def keyup(self, key): for k in self.keydict.keys(): if key == k: self.keydict[k](False)
ccd_height = args.ccd_width / aspect_ratio # in this system we force fx == fy, but here fy computed separately # just for fun. fx = focal_len_mm * width / args.ccd_width fy = focal_len_mm * height / ccd_height else: print("Cannot autodetect calibrated focal length, please specify a ccd-width") quit() print('ccd: %.3f x %.3f' % (ccd_width, ccd_height)) print('fx fy = %.2f %.2f' % (fx, fy)) cu = width * 0.5 cv = height * 0.5 print('cu cv = %.2f %.2f' % (cu, cv)) cam = Camera.Camera() cam.set_defaults() cam.set_meta(make, model, lens_model) cam.set_lens_params(ccd_width, ccd_height, focal_len_mm) cam.set_K(fx, fy, cu, cv) cam.set_image_params(width, height) if os.path.exists(camera_file): print("Camera config file already exists:", camera_file) if args.force: print("Overwriting ...") else: print("Use [ --force ] to overwrite ...") quit() print("Saving:", camera_file)
def get_image(camera_name, **kwargs): """given a camera name, snap a shot""" camera = Camera(camera_name) return camera.snap(**kwargs)
#from lib.Sensor import* load = Solenoid(21) shoot = Solenoid(19) load.block() shoot.block() INPUT_PIN = 36 GPIO.setup(INPUT_PIN, GPIO.IN) #Port 8 : RX green PB0 #Port 10: TX yellow PB1 #serial0 - ttyAMA0 #serial1 - ttyS0 os.system("sudo modprobe bcm2835-v4l2") base = Base() base.step_left(197) camera = Camera(base) #sensor = Sensor() ser = serial.Serial("/dev/ttyS0", 57600) #Open port with baud rate dist_0 = 48 dist_1 = 58 dist_2 = 64 dist_3 = 72 dist_4 = 80 def launch(): # block off both solenoids load.block()