Class VideoSource

  • All Implemented Interfaces:
    AutoCloseable
    Direct Known Subclasses:
    CvSource, VideoCamera

    public class VideoSource
    extends Object
    implements AutoCloseable
    A source for video that provides a sequence of frames. Each frame may consist of multiple images (e.g. from a stereo or depth camera); these are called channels.
    • Field Detail

      • m_handle

        protected int m_handle
    • Constructor Detail

      • VideoSource

        protected VideoSource​(int handle)
    • Method Detail

      • getKindFromInt

        public static VideoSource.Kind getKindFromInt​(int kind)
        Convert from the numerical representation of kind to an enum type.
        Parameters:
        kind - The numerical representation of kind
        Returns:
        The kind
      • isValid

        public boolean isValid()
      • getHandle

        public int getHandle()
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getName

        public String getName()
        Get the name of the source. The name is an arbitrary identifier provided when the source is created, and should be unique.
      • getDescription

        public String getDescription()
        Get the source description. This is source-kind specific.
      • getLastFrameTime

        public long getLastFrameTime()
        Get the last time a frame was captured.
        Returns:
        Time in 1 us increments.
      • setConnectionStrategy

        public void setConnectionStrategy​(VideoSource.ConnectionStrategy strategy)
        Sets the connection strategy. By default, the source will automatically connect or disconnect based on whether any sinks are connected.

        This function is non-blocking; look for either a connection open or close event or call isConnected() to determine the connection state.

        Parameters:
        strategy - connection strategy (auto, keep open, or force close)
      • isConnected

        public boolean isConnected()
        Returns if the source currently connected to whatever is providing the images.
      • isEnabled

        public boolean isEnabled()
        Gets source enable status. This is determined with a combination of connection strategy and the number of sinks connected.
        Returns:
        True if enabled, false otherwise.
      • getProperty

        public VideoProperty getProperty​(String name)
        Get a property.
        Parameters:
        name - Property name
        Returns:
        Property contents (of kind Property::kNone if no property with the given name exists)
      • enumerateProperties

        public VideoProperty[] enumerateProperties()
        Enumerate all properties of this source.
      • getVideoMode

        public VideoMode getVideoMode()
        Get the current video mode.
      • setVideoMode

        public boolean setVideoMode​(VideoMode mode)
        Set the video mode.
        Parameters:
        mode - Video mode
      • setVideoMode

        public boolean setVideoMode​(VideoMode.PixelFormat pixelFormat,
                                    int width,
                                    int height,
                                    int fps)
        Set the video mode.
        Parameters:
        pixelFormat - desired pixel format
        width - desired width
        height - desired height
        fps - desired FPS
        Returns:
        True if set successfully
      • setPixelFormat

        public boolean setPixelFormat​(VideoMode.PixelFormat pixelFormat)
        Set the pixel format.
        Parameters:
        pixelFormat - desired pixel format
        Returns:
        True if set successfully
      • setResolution

        public boolean setResolution​(int width,
                                     int height)
        Set the resolution.
        Parameters:
        width - desired width
        height - desired height
        Returns:
        True if set successfully
      • setFPS

        public boolean setFPS​(int fps)
        Set the frames per second (FPS).
        Parameters:
        fps - desired FPS
        Returns:
        True if set successfully
      • setConfigJson

        public boolean setConfigJson​(String config)
        Set video mode and properties from a JSON configuration string.

        The format of the JSON input is:

         {
             "pixel format": "MJPEG", "YUYV", etc
             "width": video mode width
             "height": video mode height
             "fps": video mode fps
             "brightness": percentage brightness
             "white balance": "auto", "hold", or value
             "exposure": "auto", "hold", or value
             "properties": [
                 {
                     "name": property name
                     "value": property value
                 }
             ]
         }
         
        Parameters:
        config - configuration
        Returns:
        True if set successfully
      • getConfigJson

        public String getConfigJson()
        Get a JSON configuration string.
        Returns:
        JSON configuration string
      • getActualFPS

        public double getActualFPS()
        Get the actual FPS.

        CameraServerJNI#setTelemetryPeriod() must be called for this to be valid (throws VisionException if telemetry is not enabled).

        Returns:
        Actual FPS averaged over the telemetry period.
      • getActualDataRate

        public double getActualDataRate()
        Get the data rate (in bytes per second).

        CameraServerJNI#setTelemetryPeriod() must be called for this to be valid (throws VisionException if telemetry is not enabled).

        Returns:
        Data rate averaged over the telemetry period.
      • enumerateVideoModes

        public VideoMode[] enumerateVideoModes()
        Enumerate all known video modes for this source.
      • enumerateSinks

        public VideoSink[] enumerateSinks()
        Enumerate all sinks connected to this source.
        Returns:
        Vector of sinks.
      • enumerateSources

        public static VideoSource[] enumerateSources()
        Enumerate all existing sources.
        Returns:
        Vector of sources.