Exemplo n.º 1
0
def get_test_pipeline_manager_with_real_cam():
    config_manager = PipelineConfigManager(config_provider=MockConfigStorage())
    pipeline_instance_manager = PipelineInstanceManager(
        config_manager, MockBackgroundManager(), None,
        CamClient("http://0.0.0.0:8888"))

    return pipeline_instance_manager
Exemplo n.º 2
0
    def setUp(self):
        self.host = "0.0.0.0"
        self.cam_port = 8888
        self.pipeline_port = 8889

        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.cam_config_folder = os.path.join(test_base_dir, "camera_config/")
        self.pipeline_config_folder = os.path.join(test_base_dir,
                                                   "pipeline_config/")
        self.background_config_folder = os.path.join(test_base_dir,
                                                     "background_config/")

        cam_server_address = "http://%s:%s" % (self.host, self.cam_port)
        pipeline_server_address = "http://%s:%s" % (self.host,
                                                    self.pipeline_port)

        self.cam_process = Process(target=start_camera_server,
                                   args=(self.host, self.cam_port,
                                         self.cam_config_folder))
        self.cam_process.start()

        self.pipeline_process = Process(
            target=start_pipeline_server,
            args=(self.host, self.pipeline_port, self.pipeline_config_folder,
                  self.background_config_folder, cam_server_address))
        self.pipeline_process.start()

        # Give it some time to start.
        sleep(1)

        self.cam_client = CamClient(cam_server_address)
        self.pipeline_client = PipelineClient(pipeline_server_address)
Exemplo n.º 3
0
    def setUp(self):
        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.config_folder = os.path.join(test_base_dir, "camera_config/")
        self.user_scripts_folder = os.path.join(test_base_dir, "user_scripts/")

        self.host = "0.0.0.0"
        self.cam_server_port = 8888
        self.cam_proxy_port = 8898
        cam_server_address = "http://%s:%s" % (self.host, self.cam_server_port)

        self.process_camserver = Process(target=start_camera_server,
                                         args=(self.host, self.cam_server_port,
                                               self.config_folder,
                                               self.user_scripts_folder))
        self.process_camserver.start()

        self.cam_proxy_host = "0.0.0.0"

        self.process_camproxy = Process(target=start_camera_proxy,
                                        args=(self.host, self.cam_proxy_port,
                                              cam_server_address,
                                              self.config_folder))
        self.process_camproxy.start()

        sleep(1.0)  # Give it some time to start.
        server_address = "http://%s:%s" % (self.host, self.cam_proxy_port)
        self.client = CamClient(server_address)
Exemplo n.º 4
0
def start_record_server(host,
                        port,
                        config_directory,
                        cam_server_api_address,
                        hostname=None):
    if not os.path.isdir(config_directory):
        _logger.error("Configuration directory '%s' does not exist." %
                      config_directory)
        exit(-1)

    if hostname:
        _logger.warning("Using custom hostname '%s'." % hostname)

    # TODO: Do something with the hostname.

    app = bottle.Bottle()

    cam_client = CamClient(cam_server_api_address)
    config_manager = CamRecordConfigManager(
        config_provider=ConfigFileStorage(config_directory))

    instance_manager = CamRecordInstanceManager(cam_client=cam_client,
                                                config_manager=config_manager)
    instance_manager.start_all_cameras()

    register_rest_interface(app, instance_manager)

    try:
        bottle.run(app=app, host=host, port=port)
    finally:
        instance_manager.stop_all_cameras()
Exemplo n.º 5
0
    def test_get_simulated_camera(self):
        from cam_server import CamClient
        from cam_server.utils import get_host_port_from_stream_address
        from bsread import source, SUB

        # Change to match your camera server
        server_address = "http://0.0.0.0:8888"

        # Initialize the client.
        camera_client = CamClient(server_address)

        # Get stream address of simulation camera. Stream address in format tcp://hostname:port.
        camera_stream_address = camera_client.get_instance_stream("simulation")

        # Extract the stream hostname and port from the stream address.
        camera_host, camera_port = get_host_port_from_stream_address(
            camera_stream_address)

        # Subscribe to the stream.
        with source(host=camera_host, port=camera_port, mode=SUB) as stream:
            # Receive next message.
            data = stream.receive()

        image_width = data.data.data["width"].value
        image_height = data.data.data["height"].value
        image_bytes = data.data.data["image"].value

        print("Image size: %d x %d" % (image_width, image_height))
        print("Image data: %s" % image_bytes)

        x_size, y_size = get_simulated_camera().get_geometry()
        self.assertIsNotNone(data)
        self.assertEqual(image_width, x_size)
        self.assertIsNotNone(image_height, y_size)
Exemplo n.º 6
0
    def setUp(self):
        self.host = "0.0.0.0"
        self.cam_port = 8888
        self.pipeline_port = 8889
        self.cam_proxy_port = 8898
        self.pipeline_proxy_port = 8899

        for port in self.cam_port, self.pipeline_port, self.cam_proxy_port, self.pipeline_proxy_port:
            print("Port ", port, "avilable: ", is_port_available(port))

        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.cam_config_folder = os.path.join(test_base_dir, "camera_config/")
        self.pipeline_config_folder = os.path.join(test_base_dir,
                                                   "pipeline_config/")
        self.background_config_folder = os.path.join(test_base_dir,
                                                     "background_config/")
        self.user_scripts_folder = os.path.join(test_base_dir, "user_scripts/")

        require_folder(self.background_config_folder)
        require_folder(self.user_scripts_folder)

        cam_server_address = "http://%s:%s" % (self.host, self.cam_port)
        pipeline_server_address = "http://%s:%s" % (self.host,
                                                    self.pipeline_port)
        cam_server_proxy_address = "http://%s:%s" % (self.host,
                                                     self.cam_proxy_port)
        pipeline_server_proxy_address = "http://%s:%s" % (
            self.host, self.pipeline_proxy_port)

        self.cam_process = Process(target=start_camera_server,
                                   args=(self.host, self.cam_port,
                                         self.cam_config_folder,
                                         self.user_scripts_folder))
        self.cam_process.start()

        self.cam_proxy_process = Process(target=start_camera_proxy,
                                         args=(self.host, self.cam_proxy_port,
                                               cam_server_address,
                                               self.cam_config_folder))
        self.cam_proxy_process.start()

        self.pipeline_process = Process(
            target=start_pipeline_server,
            args=(self.host, self.pipeline_port, self.pipeline_config_folder,
                  self.background_config_folder, self.user_scripts_folder,
                  cam_server_proxy_address))
        self.pipeline_process.start()

        self.pipeline_proxy_process = Process(
            target=start_pipeline_proxy,
            args=(self.host, self.pipeline_proxy_port, pipeline_server_address,
                  self.pipeline_config_folder, self.background_config_folder,
                  self.user_scripts_folder, cam_server_proxy_address))
        self.pipeline_proxy_process.start()

        self.cam_client = CamClient(cam_server_proxy_address)
        self.pipeline_client = PipelineClient(pipeline_server_proxy_address)

        # Give it some time to start.
        sleep(1.0)  # Give it some time to start.
Exemplo n.º 7
0
def start_pipeline_server(host,
                          port,
                          config_base,
                          background_base,
                          scripts_base,
                          cam_server_api_address,
                          hostname=None,
                          port_range=None,
                          web_server=config.DEFAULT_WEB_SERVER,
                          web_server_args={}):

    # Check if config directory exists
    if not os.path.isdir(config_base):
        _logger.error("Configuration directory '%s' does not exist." %
                      config_base)
        exit(-1)

    if not os.path.isdir(background_base):
        _logger.error("Background image directory '%s' does not exist." %
                      background_base)
        exit(-1)

    if not os.path.isdir(scripts_base):
        _logger.error("Scripts directory '%s' does not exist." % scripts_base)
        exit(-1)

    if hostname:
        _logger.warning("Using custom hostname '%s'." % hostname)

    cam_server_client = CamClient(cam_server_api_address)
    config_manager = PipelineConfigManager(
        config_provider=ConfigFileStorage(config_base))
    background_manager = BackgroundImageManager(background_base)
    user_scripts_manager = UserScriptsManager(scripts_base)
    pipeline_instance_manager = PipelineInstanceManager(config_manager,
                                                        background_manager,
                                                        user_scripts_manager,
                                                        cam_server_client,
                                                        hostname=hostname,
                                                        port_range=port_range)

    app = bottle.Bottle()

    register_pipeline_rest_interface(
        app=app, instance_manager=pipeline_instance_manager)

    try:
        bottle.run(app=app,
                   server=validate_web_server(web_server),
                   host=host,
                   port=port,
                   **web_server_args)
    finally:
        # Close the external processor when terminating the web server.
        pipeline_instance_manager.stop_all_instances()
    def test_custom_hostname(self):
        config_manager = PipelineConfigManager(
            config_provider=MockConfigStorage())
        pipeline_instance_manager = PipelineInstanceManager(
            config_manager,
            MockBackgroundManager(),
            CamClient("http://0.0.0.0:8888"),
            hostname="custom_cam_hostname")

        _, stream_address = pipeline_instance_manager.create_pipeline(
            configuration={"camera_name": "simulation"})

        self.assertTrue(stream_address.startswith("tcp://custom_cam_hostname"))

        pipeline_instance_manager.stop_all_instances()
    def setUp(self):
        self.host = "0.0.0.0"
        self.port = 8888

        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.config_folder = os.path.join(test_base_dir, "camera_config/")

        self.process = Process(target=start_camera_server,
                               args=(self.host, self.port, self.config_folder))
        self.process.start()

        # Give it some time to start.
        sleep(0.5)

        server_address = "http://%s:%s" % (self.host, self.port)
        self.client = CamClient(server_address)
    def setUp(self):
        self.host = "127.0.0.1"
        self.port = 8888

        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.config_folder = os.path.join(test_base_dir, "camera_config/")
        self.user_scripts_folder = os.path.join(test_base_dir, "user_scripts/")

        self.process = Process(target=start_camera_server,
                               args=(self.host, self.port, self.config_folder,
                                     self.user_scripts_folder))
        self.process.start()

        # Give it some time to start.
        sleep(1.0)

        self.rest_api_endpoint = "http://%s:%s" % (self.host, self.port)
        self.client = CamClient(self.rest_api_endpoint)
Exemplo n.º 11
0
def start_pipeline_proxy(host,
                         port,
                         server_config,
                         config_base,
                         background_base,
                         scripts_base,
                         cam_server_api_address,
                         web_server=config.DEFAULT_WEB_SERVER,
                         web_server_args={}):

    # Check if config directory exists
    if not os.path.isdir(config_base):
        _logger.error("Configuration directory '%s' does not exist." %
                      config_base)
        exit(-1)

    if not os.path.isdir(background_base):
        _logger.error("Background image directory '%s' does not exist." %
                      background_base)
        exit(-1)

    cam_server_client = CamClient(cam_server_api_address)
    config_manager = PipelineConfigManager(
        config_provider=ConfigFileStorage(config_base))
    background_manager = BackgroundImageManager(background_base)

    app = bottle.Bottle()

    proxy = PipelineProxy(config_manager, background_manager,
                          cam_server_client, server_config)
    register_pipeline_rest_interface(app=app, instance_manager=proxy)
    proxy.register_rest_interface(app)
    proxy.register_management_page(app)

    try:
        bottle.run(app=app,
                   server=validate_web_server(web_server),
                   host=host,
                   port=port,
                   **web_server_args)
    finally:
        #clenup
        pass
Exemplo n.º 12
0
    def test_modify_camera_config(self):
        self.cam_client.set_camera_config(
            "test_camera",
            self.cam_client.get_camera_config("camera_example_2"))
        from cam_server import CamClient

        # Initialize the camera client.
        cam_client = CamClient()
        cam_client = self.cam_client

        # Print the list of available cameras.
        print(cam_client.get_cameras())

        # Put the name of the camera you want to modify.
        camera_to_modify = "test_camera"

        # Retrieve the camera config.
        camera_config = cam_client.get_camera_config(camera_to_modify)

        # Change the mirror_x setting.
        camera_config["mirror_x"] = False
        # Change the camera_calibration setting.
        camera_config["camera_calibration"] = {
            "reference_marker": [0, 0, 100, 100],
            "reference_marker_width": 100.0,
            "reference_marker_height": 100.0,
            "angle_horizontal": 0.0,
            "angle_vertical": 0.0
        }

        # Save the camera configuration.
        cam_client.set_camera_config(camera_to_modify, camera_config)

        # You can also save the same (or another) config under a different camera name.
        cam_client.set_camera_config("camera_to_delete", camera_config)

        # And also delete camera configs.
        cam_client.delete_camera_config("camera_to_delete")
Exemplo n.º 13
0
def get_axis(screen):
    camera_client = CamClient()
    camera_stream_adress = camera_client.get_instance_stream(screen)
    host, port = get_host_port_from_stream_address(camera_stream_adress)

    max_tries = 3
    for _try in range(max_tries):
        try:
            with source(host=host, port=port, mode=SUB) as stream:
                data = stream.receive()
                print('Received image')

                x_axis = np.array(data.data.data['x_axis'].value) * 1e-6
                y_axis = np.array(data.data.data['y_axis'].value) * 1e-6
        except Exception as e:
            print('Try %i' % _try, e)
            pass
        else:
            break
    else:
        raise

    return x_axis, y_axis
def start_pipeline_manager(host, port, server_config, config_base, background_base, background_files_days_to_live,
                           scripts_base, cam_server_api_address, client_timeout=None, info_update_timeout=None,
                           web_server=config.DEFAULT_WEB_SERVER, web_server_args={}):


    # Check if config directory exists
    if not os.path.isdir(config_base):
        _logger.error("Configuration directory '%s' does not exist." % config_base)
        exit(-1)

    if not os.path.isdir(background_base):
        _logger.error("Background image directory '%s' does not exist." % background_base)
        exit(-1)

    if not os.path.isdir(scripts_base):
        _logger.error("Scripts directory '%s' does not exist." % scripts_base)
        exit(-1)

    cam_server_client = CamClient(cam_server_api_address)
    config_manager = PipelineConfigManager(config_provider=ConfigFileStorage(config_base))
    background_manager = BackgroundImageManager(background_base)
    user_scripts_manager = UserScriptsManager(scripts_base)

    app = bottle.Bottle()

    proxy = PipelineManager(config_manager, background_manager,user_scripts_manager,
                            cam_server_client, server_config, int(background_files_days_to_live),
                            float(client_timeout) if client_timeout else None,
                            float(info_update_timeout) if info_update_timeout else None)
    register_pipeline_rest_interface(app=app, instance_manager=proxy)
    proxy.register_rest_interface(app)
    proxy.register_management_page(app)
    try:
        bottle.run(app=app, server=validate_web_server(web_server), host=host, port=port, **web_server_args)
    finally:
        #cleanup
        pass
    def setUp(self):
        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.config_folder = os.path.join(test_base_dir, "camera_config/")
        self.user_scripts_folder = os.path.join(test_base_dir, "user_scripts/")

        self.host = "0.0.0.0"
        self.cam_server_ports = [8880, 8881]
        self.cam_manager_port = 8888
        self.cam_server_address = []
        self.process_camserver = []
        port_range = config.CAMERA_STREAM_PORT_RANGE

        for port in self.cam_server_ports:
            print(port, is_port_available(port))

        for p in self.cam_server_ports:
            port_range = [port_range[0] + 10000, port_range[1] + 10000]
            self.cam_server_address.append("http://%s:%s" % (self.host, p))
            process = Process(target=start_camera_worker,
                              args=(self.host, p, self.user_scripts_folder,
                                    None, port_range))
            self.process_camserver.append(process)
            process.start()

        self.cam_proxy_host = "0.0.0.0"
        self.process_camproxy = Process(
            target=start_camera_manager,
            args=(self.host, self.cam_manager_port,
                  ",".join(self.cam_server_address), self.config_folder,
                  self.user_scripts_folder))
        self.process_camproxy.start()
        sleep(1.0)  # Give it some time to start.
        server_address = "http://%s:%s" % (self.host, self.cam_manager_port)
        self.client = CamClient(server_address)

        self.proxy_client = ProxyClient(server_address)
Exemplo n.º 16
0
    def setUp(self):
        test_base_dir = os.path.split(os.path.abspath(__file__))[0]
        self.cam_config_folder = os.path.join(test_base_dir, "camera_config/")
        self.pipeline_config_folder = os.path.join(test_base_dir,
                                                   "pipeline_config/")
        self.background_config_folder = os.path.join(test_base_dir,
                                                     "background_config/")
        self.user_scripts_folder = os.path.join(test_base_dir, "user_scripts/")
        self.temp_folder = os.path.join(test_base_dir, "temp/")

        require_folder(self.background_config_folder)
        require_folder(self.user_scripts_folder)
        require_folder(self.temp_folder)

        self.host = "localhost"
        self.cam_server_ports = [8880, 8881]
        self.cam_manager_port = 8888
        self.pipeline_server_ports = [8890, 8891]
        self.pipeline_manager_port = 8889

        self.cam_server_address = []
        self.process_camserver = []
        port_range = config.CAMERA_STREAM_PORT_RANGE
        for p in self.cam_server_ports:
            port_range = [port_range[0] + 10000, port_range[1] + 10000]
            self.cam_server_address.append("http://%s:%s" % (self.host, p))
            process = Process(target=start_camera_worker,
                              args=(self.host, p, self.user_scripts_folder,
                                    None, port_range))
            self.process_camserver.append(process)
            process.start()
        self.cam_proxy_host = "0.0.0.0"

        self.process_camproxy = Process(
            target=start_camera_manager,
            args=(self.host, self.cam_manager_port,
                  ",".join(self.cam_server_address), self.cam_config_folder,
                  self.user_scripts_folder))
        self.process_camproxy.start()
        cam_server_proxy_address = "http://%s:%s" % (self.host,
                                                     self.cam_manager_port)
        pipeline_server_proxy_address = "http://%s:%s" % (
            self.host, self.pipeline_manager_port)

        self.pipeline_server_address = []
        self.process_pipelineserver = []
        port_range = config.PIPELINE_STREAM_PORT_RANGE
        for p in self.pipeline_server_ports:
            port_range = [port_range[0] + 10000, port_range[1] + 10000]
            self.pipeline_server_address.append("http://%s:%s" %
                                                (self.host, p))
            process = Process(target=start_pipeline_worker,
                              args=(self.host, p, self.temp_folder,
                                    self.temp_folder, cam_server_proxy_address,
                                    None, port_range))
            self.process_pipelineserver.append(process)
            process.start()

        cfg = """{
          "http://localhost:8890": {
          "expanding": true
         }, "http://localhost:8891": {
          "cameras": [
           "simulation3"
          ],
          "expanding": false,
          "instances": [
           "simulation_sp:10123"
          ]
         }
        }"""

        self.pipeline_proxy_process = Process(
            target=start_pipeline_manager,
            args=(self.host, self.pipeline_manager_port, cfg,
                  self.pipeline_config_folder, self.background_config_folder,
                  config.DEFAULT_BACKGROUND_FILES_DAYS_TO_LIVE,
                  self.user_scripts_folder, cam_server_proxy_address))
        self.pipeline_proxy_process.start()

        sleep(1.0)  # Give it some time to start.

        cam_server_address = "http://%s:%s" % (self.host,
                                               self.cam_manager_port)
        self.cam_client = CamClient(cam_server_address)
        pipeline_server_address = "http://%s:%s" % (self.host,
                                                    self.pipeline_manager_port)
        self.pipeline_client = PipelineClient(pipeline_server_address)

        self.cam_proxy_client = ProxyClient(cam_server_address)
        self.pipeline_proxy_client = ProxyClient(pipeline_server_address)
Exemplo n.º 17
0
def get_camclient():
    global CAM_CLIENT
    if not CAM_CLIENT:
        CAM_CLIENT = CamClient()
    return CAM_CLIENT
Exemplo n.º 18
0
## Initialize the camera client.
from cam_server import CamClient
cam_client = CamClient()

# Print the list of available cameras.
print(cam_client.get_cameras())

# If modifying: Put the name of the camera you want to modify.
#camera_to_modify = "SATOP31-PSCR136"

# Retrieve the camera config.
#camera_config = cam_client.get_camera_config(camera_to_modify)
#print(camera_config)
# Specify the desired camera config.
#camera_config={
#  'name': 'SATOP31-PSCR136',
#  'source': 'SATOP31-PSCR136',
#  'source_type': 'epics',
#  'mirror_x': False,
#  'mirror_y': False,
#  'rotate': 0,
#
#  'camera_calibration': {
#    'reference_marker': [0, 0, 100, 100],
#    'reference_marker_width': 100.0,
#    'reference_marker_height': 100.0,
#    'angle_horizontal': 0.0,
#    'angle_vertical': 0.0
#  }
#}