def acquire(self, size: Size, manual_fetch: bool = False) -> SphericalImage: """Acquire a Spherical image from the current position/configuration of the camera""" ver_fov = 2 * math.degrees( math.atan(size.height * math.tan( (math.radians(self.h_fov.value)) / 2) / size.width)) if not self.h_fov.min < ver_fov < self.h_fov.max: raise Exception( 'Vertical fov {ver_fov:2f} is out of range [{min:1f}, [{max:1f}]]' .format(ver_fov=ver_fov, min=self.h_fov.min, max=self.h_fov.max)) if self.network_client != None: request_builder = ImageRequestBuilder(self.frame.recordingid, self.frame.uuid) request = request_builder.build_spherical( size, Direction(self.yaw, self.pitch), self.h_fov.value) image = SphericalImage() image.set_network_configuration(self.network_client, ImageProvider(), ComputationProvider(), request, self.height, self.frame, self.recording) if not manual_fetch: image.fetch() return image return None
def __init__(self, *args, **kwargs): super(TestClient, self).__init__(*args, **kwargs) recording_id = 871 frame_uuid = "44d25183-cc3e-4c8b-8661-8c286e71b2dc" host_url = "http://webplayer.horus.nu/" self.grid = Grid() self.request_builder = ImageRequestBuilder(recording_id, frame_uuid) self.stitcher = ImageProvider() self.client = Client(host_url)
"dbname=HorusWebMoviePlayer user=postgres password=horusweb") connection = get_connection() frames = Frames(connection) client = Client() image_provider = ImageProvider() # Get a frame frame = Frame(frames.query()) if frame is None: print("No recordings!") exit() # Set parameters size = Size(1024, 1024) direction = Direction(yaw=45, pitch=-20) # Get the image request_builder = ImageRequestBuilder(frame.recordingid, frame.uuid) request = client.fetch(request_builder.build_spherical(size, direction)) result = image_provider.fetch(request) # Save the file filename = ".\\spherical_{}.jpg".format(frame.id) with open(filename, 'wb') as f: f.write(result.image.getvalue()) result.image.close()
cursor = frames.query(within=(location, distance), recordingid=recording_id, limit=1) frame = Frame(cursor) if not frame: logging.warning( f"Location {location} not found within {distance} meters") continue if recording_id: assert frame.recordingid in recording_id angle = compute_angle(frame, location) attempts = args.attempts while True: if (clipping_interval[0] <= angle <= clipping_interval[1]): requestBuilder = ImageRequestBuilder(frame.recordingid, frame.uuid) filename = None if mode == Mode.panoramic.name: fov = Box.create(center=(angle, 0), width=horizontal_fov, height=vertical_fov) sections = grid.filter(fov=fov) requests = client.fetch_all( requestBuilder.build(mode, Scales.Px_1024, section) for section in sections) result = image_provider.combine(requests, Scales.Px_1024.size, Scales.Px_1024.size) if temp_path: filename = temp_path + \
cursor = frames.query(within=(location, distance), recordingid=recording_id, limit=1) frame = Frame(cursor) if not frame: logging.warning( f"Location {location} not found within {distance} meters") continue if recording_id: assert frame.recordingid in recording_id angle = compute_angle(frame, location) attempts = args.attempts while True: if (clipping_interval[0] <= angle <= clipping_interval[1]): requestBuilder = ImageRequestBuilder(frame.recordingid, frame.uuid) filename = None if mode == Mode.panoramic.name: fov = Box.create(center=(angle, 0), width=horizontal_fov, height=vertical_fov) sections = grid.filter(fov=fov) requests = client.fetch_all( requestBuilder.build(mode, Scales.Px_1024, section) for section in sections) result = image_provider.combine(requests, Scales.Px_1024.size, Scales.Px_1024.size) if temp_path: filename = temp_path + "stitched_{}.jpg".format(
def get_image_request(frame, size, direction, hor_fov): request_builder = ImageRequestBuilder(frame.recordingid, frame.uuid) return client.fetch( request_builder.build_spherical(size, direction, hor_fov))
if next_frame is not None: alti_next = next_frame.altitude else: alti_next = None # Set parameters # Size of render buffer, should at least be the size of the original camera resolution of the roi size = Size(4096, 2048) # The geometry values relative to the frame center, same as used in the Horus MoviePlayer ortho projection geom_scale = 400 # output scale (px/m) geom_width = 6 # geometry width (m) geom_height = 2 # geometry height (m) geom_dist = 4 # geometry distance (m) geom_shift = 0 # geometry shift (m) geometry = Geometry(geom_scale, geom_width, geom_height, geom_dist, geom_shift, alti_next) # Get the image request_builder = ImageRequestBuilder(frame.recordingid, frame.uuid) request = client.fetch(request_builder.build_orthographic(size, geometry)) result = image_provider.fetch(request) # Save the file filename = ".\\orthographic_{}.tif".format(frame.index) with open(filename, 'wb') as f: f.write(result.image.getvalue()) result.image.close()
"dbname=HorusWebMoviePlayer user=postgres password=horusweb") connection = get_connection() frames = Frames(connection) client = Client() image_provider = ImageProvider() # Get a frame frame = Frame(frames.query()) if frame is None: print("No recordings!") exit() # Set parameters mode = Mode.panoramic scale = Scales.Px_2048 # Get the image request_builder = ImageRequestBuilder(frame.recordingid, frame.uuid) request = client.fetch(request_builder.build(mode, scale)) result = image_provider.fetch(request) # Save the file filename = ".\\panoramic_{}.jpg".format(frame.index) with open(filename, 'wb') as f: f.write(result.image.getvalue()) result.image.close()
class TestClient(unittest.TestCase): def __init__(self, *args, **kwargs): super(TestClient, self).__init__(*args, **kwargs) recording_id = 871 frame_uuid = "44d25183-cc3e-4c8b-8661-8c286e71b2dc" host_url = "http://webplayer.horus.nu/" self.grid = Grid() self.request_builder = ImageRequestBuilder(recording_id, frame_uuid) self.stitcher = ImageProvider() self.client = Client(host_url) def request_stitched_sections(self, sections, scale, path=None): requests = self.client.fetch_all( self.request_builder.build(Mode.panoramic, scale, section) for section in sections) result = self.stitcher.combine(requests, scale.size, scale.size) if path: with open(path, 'wb') as f: f.write(result.image.getvalue()) result.image.close() return result def test_client_request_pano(self): request = self.client.fetch(self.request_builder.build(Mode.panoramic, Scales.Px_1024)) with open('./tests/data/pano.jpg', "wb") as file: file.write(request.result()) def test_client_request(self): sections = self.grid.filter(h_min=-44, h_max=44, w_min=-170, w_max=-1) self.request_stitched_sections( sections, Scales.Px_1024, './tests/data/stitched.jpg') def test_client_request_pano_stitched(self): result = self.request_stitched_sections( self.grid, Scales.Px_1024, './tests/data/pano_stitched.jpg') self.assertEqual(result.to_pixel_coordinates((0, 0)).x, 0) self.assertEqual(result.fov, Rect( x=-180.0, y=-90.0, width=360.0, height=180.0)) def test_client_request_single_section_stitched(self): result = self.request_stitched_sections( (self.grid[3],), Scales.Px_1024, './tests/data/single_section_stitched.jpg') self.assertEqual(result.to_pixel_coordinates((170.0, 0)).x, 796) self.assertEqual(result.fov, Rect( x=-45.0, y=45.0, width=45.0, height=45.0)) def test_client_request_left_wrapped(self): sections = self.grid.filter(h_min=-46, h_max=1, w_min=-270, w_max=-46) result = self.request_stitched_sections( sections, Scales.Px_1024, './tests/data/stitched_lw.jpg') self.assertEqual(result.to_pixel_coordinates((0, 0)).x, 0) def test_client_request_right_wrapped(self): sections = self.grid.filter(h_min=0, w_min=70, w_max=246) result = self.request_stitched_sections( sections, Scales.Px_1024, './tests/data/stitched_rw.jpg') self.assertEqual(result.to_pixel_coordinates((70.0, 0)).x, 1592) self.assertEqual(result.fov, Rect( x=-180.0, y=0.0, width=225.0, height=90.0)) def test_client_request_left_right_wrapped(self): sections = self.grid.filter(w_min=-240, w_max=246) result = self.request_stitched_sections( sections, Scales.Px_1024, './tests/data/stitched_lrw.jpg') self.assertEqual(result.to_pixel_coordinates((-240.0, 0)).x, 2730) self.assertEqual(result.fov, Rect( x=-180.0, y=-90.0, width=180.0, height=180.0))
image_provider = ImageProvider() # Get a frame frame = Frame(frames.query()) if frame is None: print("No recordings!") exit() # Set parameters mode = Mode.panoramic scale = Scales.Px_2048 # Get the image request_builder = ImageRequestBuilder(frame.recordingid, frame.uuid) #(min, max) yaw in deg directions = { "front": (-45, 45), "back": (135, 225), "left": (-135, -45), "right": (45, 135), } grid = Grid() for direction in directions: min_yaw = directions[direction][0] max_yaw = directions[direction][1] sections = grid.filter(h_min=-44, h_max=44, w_min=min_yaw, w_max=max_yaw) requests = client.fetch_all(