Exemplo n.º 1
0
    def __init__(self, hostname, username, password, width, height, frame_id,
                 camera_info_url, use_encrypted_password, camera):
        self.hostname = hostname
        self.username = username
        self.password = password
        self.width = width
        self.height = height
        self.frame_id = frame_id
        self.camera_info_url = camera_info_url
        self.use_encrypted_password = use_encrypted_password
        self.camera = camera

        # generate a valid camera name based on the hostname
        self.cname = camera_info_manager.genCameraName(self.hostname)
        self.cinfo = camera_info_manager.CameraInfoManager(
            cname=self.cname, url=self.camera_info_url)
        self.cinfo.loadCameraInfo()  # required before getCameraInfo()
        self.st = None
        self.pub = rospy.Publisher("image_raw/compressed",
                                   CompressedImage,
                                   self,
                                   queue_size=1)
        self.caminfo_pub = rospy.Publisher("camera_info",
                                           CameraInfo,
                                           self,
                                           queue_size=1)
    def __init__(self, hostname, username, password, frame_id, camera_info_url,
                 prefix):
        self.hostname = hostname
        self.username = username
        self.password = password
        self.frame_id = frame_id
        self.camera_info_url = camera_info_url

        self.msg = CompressedImage()
        self.msg.header.frame_id = self.frame_id
        self.msg.format = "jpeg"
        self.valid = False
        self.updated = False

        # generate a valid camera name based on the hostname
        self.cname = camera_info_manager.genCameraName(self.hostname)
        self.cinfo = camera_info_manager.CameraInfoManager(
            cname=self.cname, url=self.camera_info_url, namespace=prefix)
        self.cinfo.loadCameraInfo()  # required before getCameraInfo()
        self.st = StreamThread(self)
        self.st.start()
        self.pub = rospy.Publisher(prefix + "/image_raw/compressed",
                                   CompressedImage, self)
        self.caminfo_pub = rospy.Publisher(prefix + "/camera_info", CameraInfo,
                                           self)
        self.detect_dim()
Exemplo n.º 3
0
    def __init__(self, _prefix, camera_name, info_prefix, cinfo_url):
        self.name = camera_name
        self.uri = cinfo_url
        self.prefix = _prefix

        self.cname = camera_info_manager.genCameraName(self.prefix)
        rospy.loginfo("cname = " + self.cname)
        self.cinfo = camera_info_manager.CameraInfoManager(
            cname=_prefix, url=self.uri, namespace=info_prefix)
        self.caminfo_pub = rospy.Publisher(info_prefix + "/camera_info",
                                           CameraInfo, self)
        self.cinfo.loadCameraInfo()
        rospy.Subscriber(self.prefix + self.name, Image, self.image_callback)
Exemplo n.º 4
0
  def __init__(self, hostname, username, password,
               width, height, frame_id, camera_info_url):
    self.hostname = hostname
    self.username = username
    self.password = password
    self.width = width
    self.height = height
    self.frame_id = frame_id
    self.camera_info_url = camera_info_url

    # generate a valid camera name based on the hostname
    self.cname = camera_info_manager.genCameraName(self.hostname)
    self.cinfo = camera_info_manager.CameraInfoManager(cname = self.cname,
                                                       url = self.camera_info_url)
    self.cinfo.loadCameraInfo()         # required before getCameraInfo()
    self.st = None
    self.pub = rospy.Publisher("image_raw/compressed", CompressedImage, self)
    self.caminfo_pub = rospy.Publisher("camera_info", CameraInfo, self)
Exemplo n.º 5
0
  def __init__(self, hostname, username, password,
               fps, width, height, frame_id, camera_info_url,delay,compression):
    self.hostname = hostname
    self.username = username
    self.password = password
    self.fps = fps
    self.width = width
    self.height = height
    self.compression = compression
    self.frame_id = frame_id
    self.camera_info_url = camera_info_url
    self.reconnect = False

    # generate a valid camera name based on the hostname
    self.cname = camera_info_manager.genCameraName(self.hostname)
    self.cinfo = camera_info_manager.CameraInfoManager(cname = self.cname,
                                                       url = self.camera_info_url)
    self.cinfo.loadCameraInfo()         # required before getCameraInfo()
    self.st = None
    self.pub = rospy.Publisher("image_raw/compressed", CompressedImage, self)
    self.caminfo_pub = rospy.Publisher("camera_info", CameraInfo, self)
    self.fps_srv = rospy.Service('set_parameters', SetParameters, self.handle_param_req)
Exemplo n.º 6
0
    def __init__(self, filename, frame_id, camera_info_url, prefix):
        self.filename = filename
        self.frame_id = frame_id
        self.camera_info_url = camera_info_url
        
        self.msg = CompressedImage()        
        self.msg.header.frame_id = self.frame_id
        self.msg.format = "jpeg"
	im = cv2.imread(filename)
        self.width=im.shape[1]
        self.height=im.shape[0]
	f=open(filename, 'r+')
	self.msg.data = f.read()
        self.valid = True;
        self.updated = True;

        # generate a valid camera name based on the hostname
        self.cname = camera_info_manager.genCameraName(filename)
        self.cinfo = camera_info_manager.CameraInfoManager(cname = self.cname,
                                                   url = self.camera_info_url, namespace = prefix)
        self.cinfo.loadCameraInfo()         # required before getCameraInfo()
        self.st = None
        self.pub = rospy.Publisher(prefix + "/image_raw/compressed", CompressedImage, self)
        self.caminfo_pub = rospy.Publisher(prefix + "/camera_info", CameraInfo, self)
Exemplo n.º 7
0
    def __init__(self, hostname, username, password, width, height, frame_id, camera_info_url, use_encrypted_password,
                 camera_id=1, auto_wakeup_camera=True, compression=0, fps=24, use_color=True,
                 use_square_pixels=False):
        """Create the ROS-VAPIX interface.

        :param hostname: Hostname of the camera (without http://, can be an IP address).
        :type hostname: basestring
        :param username: If login is needed, provide a username here.
        :type username: :py:obj:`basestring` | None
        :param password: If login is needed, provide a password here.
        :type password: :py:obj:`basestring` | None
        :param width: Width of the requested video stream in pixels (can be changed later). Must be one of the supported
                      resolutions. If `None`, the resolution will be chosen by height only. If also `height` is `None`,
                      then the default camera resolution will be used.
        :type width: int|None
        :param height: Height of the requested video stream in pixels (can be changed later). Must be one of the
                       supported resolutions. If `None`, the resolution will be chosen by width only. If also `width` is
                       `None`, then the default camera resolution will be used.
        :type height: int|None
        :param frame_id: The ROS TF frame assigned to the camera.
        :type frame_id: basestring
        :param camera_info_url: The URL pointing to the camera calaibration, if available.
        :type camera_info_url: basestring
        :param use_encrypted_password: Whether to use Plain HTTP Auth (False) or Digest HTTP Auth (True).
        :type use_encrypted_password: bool
        :param camera_id: ID (number) of the camera. Can be 1 to 4.
        :type camera_id: int
        :param auto_wakeup_camera: If True, there will be a wakeup trial after first unsuccessful network command.
        :type auto_wakeup_camera: bool
        :param compression: Compression of the image (0 - no compression, 100 - max compression).
        :type compression: int
        :param fps: The desired frames per second.
        :type fps: int
        :param use_color: If True, send a color stream, otherwise send only grayscale image.
        :type use_color: bool
        :param use_square_pixels: If True, the resolution will be stretched to match 1:1 pixels.
                                  By default, the pixels have a ratio of 11:12.
        :type use_square_pixels: bool
        :raises: :py:exc:`ValueError` if the requested resolution (either the `resolution`, or `width`+`height`
                 is not supported.
        """
        # True every time the video parameters have changed and the URL has to be altered (set from other threads).
        self.video_params_changed = False

        self.__initializing = True

        self._hostname = hostname
        self._camera_id = camera_id

        self.diagnostic_updater = Updater()
        self.diagnostic_updater.setHardwareID(hostname)

        self._api = None
        # autodetect the VAPIX API and connect to it; try it forever
        while self._api is None and not rospy.is_shutdown():
            try:
                self._api = VAPIX.get_api_for_camera(hostname, username, password, camera_id, use_encrypted_password)
            except (IOError, ValueError):
                rospy.loginfo("Retrying connection to VAPIX on host %s, camera %d in 2 seconds." %
                              (hostname, camera_id))
                rospy.sleep(2)
        if rospy.is_shutdown():
            return

        self._allowed_resolutions = self._get_allowed_resolutions()

        rospy.loginfo("The following resolutions are available for camera %d:\n%s" %
                      (camera_id, "\n".join([str(res) for res in self._allowed_resolutions])))
        rospy.set_param("~allowed_resolutions", [res.get_vapix_representation() for res in self._allowed_resolutions])

        # Sometimes the camera falls into power saving mode and stops streaming.
        # This setting allows the script to try to wake up the camera.
        self._auto_wakeup_camera = auto_wakeup_camera

        # dynamic-reconfigurable properties - definitions
        self._width = None  # deprecated
        self._height = None  # deprecated
        self._resolution = None
        self._compression = None
        self._fps = None
        self._use_color = None
        self._use_square_pixels = None

        # treat empty strings as None in width and height params
        width = width if width != "" else None
        height = height if height != "" else None

        # dynamic-reconfigurable properties - defaults
        if width is None and height is None:
            # TODO change to perform default resolution detection from VAPIX
            self.set_resolution(self._allowed_resolutions[0])
        else:
            resolution = self.find_resolution_by_size(width, height)
            self.set_resolution(resolution.get_vapix_representation())

        self.set_compression(compression)
        self.set_fps(fps)
        self.set_use_color(use_color)
        self.set_use_square_pixels(use_square_pixels)

        # only advertise the supported resolutions on dynamic reconfigure
        change_enum_items(
            VideoStreamConfig,
            "resolution",
            [{
                'name': res.name if isinstance(res, CIFVideoResolution) else str(res),
                'value': res.get_vapix_representation(),
                'description': str(res)
            } for res in self._allowed_resolutions],
            self._resolution.get_vapix_representation()
        )

        # dynamic reconfigure server
        self._video_stream_param_change_server = dynamic_reconfigure.server.Server(VideoStreamConfig,
                                                                                   self.reconfigure_video)

        # camera info setup
        self._frame_id = frame_id
        self._camera_info_url = camera_info_url

        # generate a valid camera name based on the hostname
        self._camera_name = camera_info_manager.genCameraName(self._hostname)
        self._camera_info = camera_info_manager.CameraInfoManager(cname=self._camera_name, url=self._camera_info_url)
        self._camera_info.loadCameraInfo()  # required before getCameraInfo()

        # the thread used for streaming images (is instantiated when the first image subscriber subscribes)
        self._streaming_thread = None

        # the publishers are started/stopped lazily in peer_subscribe/peer_unsubscribe
        self._video_publisher_frequency_diagnostic = FrequencyStatusParam({'min': self._fps, 'max': self._fps})
        self._video_publisher = PausableDiagnosedPublisher(
            self,
            rospy.Publisher("image_raw/compressed", CompressedImage, self, queue_size=100),
            self.diagnostic_updater, self._video_publisher_frequency_diagnostic, TimeStampStatusParam()
        )
        self._camera_info_publisher = PausableDiagnosedPublisher(
            self,
            rospy.Publisher("camera_info", CameraInfo, self, queue_size=100),
            self.diagnostic_updater, self._video_publisher_frequency_diagnostic, TimeStampStatusParam()
        )

        self._snapshot_server = rospy.Service("take_snapshot", TakeSnapshot, self.take_snapshot)

        self.diagnostic_updater.add(FunctionDiagnosticTask("Camera parameters", self._camera_diagnostic_callback))

        # BACKWARDS COMPATIBILITY LAYER

        self.username = username  # deprecated
        self.password = password  # deprecated
        self.use_encrypted_password = use_encrypted_password  # deprecated
        self.st = None  # deprecated
        self.pub = self._video_publisher  # deprecated
        self.caminfo_pub = self._camera_info_publisher  # deprecated

        self.__initializing = False