Class Camera

java.lang.Object
com.flir.thermalsdk.live.Camera
All Implemented Interfaces:
AutoCloseable

public final class Camera extends Object implements AutoCloseable
Manages any FLIR camera.

Note: This class is not guaranteed to be thread-safe, so calls must be synchronized if a Camera object is accessed from multiple threads.

  • Constructor Details

  • Method Details

    • authenticate

      @BackgroundThread public AuthenticationResponse authenticate(@NotNull @NotNull Identity identity, @NotNull @NotNull String commonName, long timeoutMs) throws IOException
       Authenticates with a network camera,
      
       You are only required to call this when connecting to a network camera,
       you do not have to call it when connecting to a FLIR ONE
      
       Note: this method is blocking and it is highly recommended to call this function
       from a background thread in order to keep the UI/main thread non-blocking.
      
       Important
       During development do NOT call `Camera::authenticate(..,commonName,..)` with the same "commonName" between two application installs.
       During the call to `Camera::authenticate(..)` authentication files are create and uploaded with the "commonName" as a "key"
       to the camera, new authentication files can't be used with the same "commonName" to connect to the camera.
       We recommended generate a commonName and store it a `SharedPreferences` (see network sample code) this will also work for release applications
       
      Parameters:
      identity - an Identity to connect to
      commonName - the name shown in the camera when authorizing access and the key for the authorization information (see the information above),
      timeoutMs - timeout for the connection in milliseconds, if 0 a default timeout is used.
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
      IOException - if the camera could not be connected to
    • authenticate

      @BackgroundThread public AuthenticationResponse authenticate(@NotNull @NotNull InetAddress ipaddress, String commonName, long timeoutMs) throws IOException
      Throws:
      IOException
      See Also:
    • connect

      @BackgroundThread public void connect(@NotNull @NotNull InetAddress inetAddress, @NotNull @NotNull ConnectionStatusListener listener, @Nullable @Nullable ConnectParameters connectParameters) throws IOException
      Connects to the given ip address. Note: this method is blocking and it is highly recommended to call this function from a background thread in order to keep the UI/main thread non-blocking.
      Parameters:
      inetAddress - an InetAddress to connect to
      listener - listener for connection status changes
      connectParameters - parameters eg timeout, if null default values will be used
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
      IllegalArgumentException - if an invalid ip address has been provided
      IOException - if the camera could not be connected to
    • connect

      @BackgroundThread public void connect(@NotNull @NotNull Identity identity, @NotNull @NotNull ConnectionStatusListener listener, @Nullable @Nullable ConnectParameters connectParameters) throws IOException
      Connects to the given Identity. Note: this method is blocking and it is highly recommended to call this function from a background thread in order to keep the UI/main thread non-blocking.
      Parameters:
      identity - an Identity to connect to
      listener - listener for connection status changes
      connectParameters - parameters eg timeout, if null default values will be used
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
      IOException - if the camera could not be connected to
    • disconnect

      @BackgroundThread public void disconnect()
      Disconnect from the camera. Note: this method is blocking and it is highly recommended to call this function from a background thread in order to keep the UI/main thread non-blocking.
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
    • isConnected

      public boolean isConnected()
      Get the connection status.
      Returns:
      Returns the connection status.
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
    • getIdentity

      @Nullable public @Nullable Identity getIdentity()
      Get the camera identity.
      Returns:
      Returns an Identity object or null if connect() hasn't been called yet.
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
    • getRemoteControl

      @Nullable public @Nullable RemoteControl getRemoteControl()
      Get camera remote controller.
      Returns:
      Returns a camera remote controller, or null if the camera isn't in connected state.
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
    • getImporter

      @Nullable public @Nullable Importer getImporter()
      Get a camera's Importer service used to import images.
      Returns:
      Returns a camera's Importer service used to import images or null if camera does not support importing feature (i.e. network cameras, FLIR ONE camera).
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
    • subscribeStream

      @Deprecated public void subscribeStream(ThermalImageStreamListener listener)
      Deprecated.
      Use getStreams() and Stream API instead, supported with Renderer API and ThermalStreamer.
      Subscribe a callback for frame grabbing.
      Starts the frame grabbing.
      Note: The implementation for thermal streaming for network cameras is still in experimental stage.
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
    • unsubscribeStream

      @Deprecated public void unsubscribeStream(ThermalImageStreamListener listener)
      Deprecated.
      Use getStreams() and Stream API instead, supported with Renderer API and ThermalStreamer.
      Unsubscribe a callback from frame grabbing.

      Stops the frame grabbing if there are no remaining subscribers.

      Parameters:
      listener - A reference to an already subscribed listener.
      Throws:
      IllegalStateException - if the state of the Camera object is invalid
    • unsubscribeAllStreams

      @Deprecated public void unsubscribeAllStreams()
      Deprecated.
      Use getStreams() and Stream API instead, supported with Renderer API and ThermalStreamer.
      Unsubscribe all frame grabbing callbacks.

      Stops the frame grabbing.

      Throws:
      IllegalStateException - if the state of the Camera object is invalid
    • withImage

      @Deprecated public void withImage(ThermalImageStreamListener listener, Consumer<ThermalImage> functionToRun)
      Deprecated.
      Use getStreams() and Stream API instead, supported with Renderer API and ThermalStreamer.
      This method ensures a thread-safe access to the received ThermalImage. Use a previously(!) activated ThermalImageStreamListener via subscribeStream(ThermalImageStreamListener). Consumer allows to pass a lambda expression to be executed on the given ThermalImage. The ThermalImage available for the Consumer represents a frame received from the camera. Note that each frame is independent, you have to set all your custom parameters for every new frame, i.e.:
      - fusion mode, see: ThermalImage.getFusion(), Fusion, Fusion.setFusionMode(FusionMode)
      - palette, see: ThermalImage.setPalette(Palette), Palette, PaletteManager
      - measurements, see: ThermalImage.getMeasurements(), MeasurementShapeCollection
            Camera camera = new Camera();
            Camera.connect(...);
            // create stream listener
            ThermalImageStreamListener listener = new ThermalImageStreamListener() {
                @Override
                public void onImageReceived() {
                    camera.withImage(this, thermalImage -> {
                        // this callback is called for every new frame
                        // now we set a custom palette
                        thermalImage.setPalette(...);
                        // MSX fusion mode
                        thermalImage.getFusion().setFusionMode(FusionMode.MSX);
                        // finally we can get colorized pixels to render on the UI
                        JavaImageBuffer buffer = thermalImage.getImage();
                        // in Java desktop - use Atlas Android SDK BitmapAwt API to create Java-compatible BufferedImage object
                        java.awt.image.BufferedImage img = BitmapAwt.createBitmap(javaBuffer).getBitMap();
                        // in Android - use Atlas Android SDK BitmapAndroid API to create Android-compatible Bitmap object
                        android.graphics.Bitmap bmp = BitmapAndroid.createBitmap(javeBuffer).getBitMap();
                        // now, on the UI thread, we can refresh UI with the new BufferedImage (Java desktop) or Bitmap (Android)
                    });
                }
            };
            // subscribe for a stream
            camera.subscribeStream(listener);
       
      Parameters:
      listener - a previously(!) activated ThermalImageStreamListener via subscribeStream(ThermalImageStreamListener)
      functionToRun - a code to run on the given ThermalImage, i.e. a lambda expression
      See Also:
    • withImage

      @Deprecated public void withImage(Consumer<ThermalImage> functionToRun)
      Deprecated.
      Use getStreams() and Stream API instead, supported with Renderer API and ThermalStreamer.
      This method ensures a thread-safe access to the received ThermalImage. Consumer allows to pass a lambda expression to be executed on the given ThermalImage. The ThermalImage available for the Consumer represents a frame received from the camera. Note that each frame is independent, you have to set all your custom parameters for every new frame, i.e.:
      - fusion mode, see: ThermalImage.getFusion(), Fusion, Fusion.setFusionMode(FusionMode)
      - palette, see: ThermalImage.setPalette(Palette), Palette, PaletteManager
      - measurements, see: ThermalImage.getMeasurements(), MeasurementShapeCollection
            Camera camera = new Camera();
            Camera.connect(...);
            // create stream listener
            ThermalImageStreamListener listener = new ThermalImageStreamListener() {
                @Override
                public void onImageReceived() {
                    // Given the Consumer functional interface use lambda:
                    // camera.withImage(thermalImage -> {
                    //      // my code here ...
                    // });
                    // or use anonymous class:
                    // camera.withImage(new Consumer() {
                    //     @Override
                    //     public void accept(ThermalImage thermalImage) {
                    //          // my code here ...
                    //      }
                    // });
                    camera.withImage(thermalImage -> {
                        // this callback is called for every new frame
                        // now we set a custom palette
                        thermalImage.setPalette(...);
                        // MSX fusion mode
                        thermalImage.getFusion().setFusionMode(FusionMode.MSX);
                        // finally we can get colorized pixels to render on the UI
                        JavaImageBuffer buffer = thermalImage.getImage();
                        // in Java desktop - use Atlas Android SDK BitmapAwt API to create Java-compatible BufferedImage object
                        java.awt.image.BufferedImage img = BitmapAwt.createBitmap(javaBuffer).getBitMap();
                        // in Android - use Atlas Android SDK BitmapAndroid API to create Android-compatible Bitmap object
                        android.graphics.Bitmap bmp = BitmapAndroid.createBitmap(javeBuffer).getBitMap();
                        // now, on the UI thread, we can refresh UI with the new BufferedImage (Java desktop) or Bitmap (Android)
                    });
                }
            };
            // subscribe for a stream
            camera.subscribeStream(listener);
       
      Parameters:
      functionToRun - a code to run on the given ThermalImage, i.e. a lambda expression
      See Also:
    • isGrabbing

      @Deprecated public boolean isGrabbing()
      Deprecated.
      Check if we're in frame grabbing state.
      Returns:
      Returns true if we're in frame grabbing state, otherwise returns false.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • getStreams

      public List<Stream> getStreams()
      Get a list of available camera streams. List can be empty if camera doesn't support streaming.
      Note: The implementation for thermal streaming for network cameras is still in experimental stage.
      Returns:
      a list of available camera streams or empty list if camera doesn't support streaming
    • getLicenseData

      @Nullable public @org.jetbrains.annotations.Nullable byte[] getLicenseData()
      Get license data (from F1 Wireless only).
      Returns:
      byte array with license data as read from a F1 wireless, null if not a F1 wireless
    • glSetupPipeline

      public void glSetupPipeline(Stream stream, boolean enableMsx)
      Setup a GL pipeline with a specified Stream.
      Note: supported on Android platform only.
      Parameters:
      stream - stream to use with the GL pipeline
      enableMsx - flag determining we the stream should start with the MSX mode enabled - note that it can be later changed using glEnableMsx(boolean)
      See Also:
    • glTeardownPipeline

      public void glTeardownPipeline()
      Close the pipeline and release all used resources.
      Note: supported on Android platform only.
    • glOnDrawFrame

      public boolean glOnDrawFrame()
      Renders the frame to GL surface.
      Note: supported on Android platform only.
      Returns:
      Returns true on success.
    • glWithThermalImage

      public void glWithThermalImage(Consumer<ThermalImage> functionToRun)
      This method ensures a thread-safe access to the received ThermalImage.
      Note: supported on Android platform only.
      Parameters:
      functionToRun - a code to run on the given ThermalImage, i.e. a lambda expression
    • glSetPalette

      public void glSetPalette(Palette palette)
      Helper function to set a palette for the stream running with GL pipeline.
      Note: supported on Android platform only.
      Parameters:
      palette - a Palette object to set
    • glOnSurfaceChanged

      public void glOnSurfaceChanged(int width, int height)
      When a GL surface for rendering changes size this should be called to ensure proper viewport.
      Note: supported on Android platform only.
      Parameters:
      width - new width of the GLSurfaceView
      height - new height of the GLSurfaceView
    • glEnableMsx

      public void glEnableMsx(boolean enableMsx)
      Enable or disable MSX mode while rendering to GL surface.
      Note: supported on Android platform only.
      Important: since this function requires GLSurfaceView to be ready (including EGLContext) it mustn't be called before the glOnSurfaceChanged(int, int) function, which is usually triggered by GLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)).
      Parameters:
      enableMsx - flag determining if MSX mode should be enabled or disabled
    • glScaleAutoAdjust

      public void glScaleAutoAdjust(boolean enableAutoAdjust)
      Enable or disable Scale auto adjust while rendering to GL surface.
      Note: supported on Android platform only.
      Important: since this function requires GLSurfaceView to be ready (including EGLContext) it mustn't be called before the glOnSurfaceChanged(int, int) function, which is usually triggered by GLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)).
      Parameters:
      enableAutoAdjust - flag determining if Scale auto adjust should be enabled or disabled
    • glSetRegionOfInterest

      public void glSetRegionOfInterest(Rectangle roi)
      Set the region of interest (ROI) that is used to calculate the histogram in the Agc filter.
      Note: To disable the ROI and use the entire image contents, set an empty ROI Rectangle{0,0,0,0}.
      Note: supported on Android platform only.
      Important: since this function requires GLSurfaceView to be ready (including EGLContext) it mustn't be called before the glOnSurfaceChanged(int, int) function, which is usually triggered by GLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)).
    • glGetRegionOfInterest

      public Rectangle glGetRegionOfInterest()
      Get the region of interest (ROI) that is used to calculate the histogram in the Agc filter.
      Note: supported on Android platform only.
      Important: since this function requires GLSurfaceView to be ready (including EGLContext) it mustn't be called before the glOnSurfaceChanged(int, int) function, which is usually triggered by GLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)).
    • glRenderScale

      public JavaImageBuffer glRenderScale()
      Allows to render Scale image.
      Note: supported on Android platform only.
      Important: since this function requires GLSurfaceView to be ready (including EGLContext) it mustn't be called before the glOnSurfaceChanged(int, int) function, which is usually triggered by GLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)).
    • glGetScaleRange

      public Pair<ThermalValue,ThermalValue> glGetScaleRange()
      Allows to read current auto Scale range.
      Note: supported on Android platform only.
      Important: since this function requires GLSurfaceView to be ready (including EGLContext) it mustn't be called before the glOnSurfaceChanged(int, int) function, which is usually triggered by GLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)).
    • glSetViewport

      public void glSetViewport(int viewportX, int viewportY, int viewportWidth, int viewportHeight)
      Set the viewport where the resulting image should end up on the screen.
      This can be a subset of the screen coordinates or can even be outside of the screen to discard parts of the image.
      Also be aware that if fusion is enabled the visual image will be scaled up/down to the size of the viewport and will keep aspect ratio when doing so.
      See glViewport.
      Important: since this function requires GLSurfaceView to be ready (including EGLContext) it mustn't be called before the glOnSurfaceChanged(int, int) function, which is usually triggered by GLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)).
      Parameters:
      viewportX - Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0).
      viewportY - Specify the lower left corner of the viewport rectangle, in pixels. The initial value is (0,0).
      viewportWidth - Specify the width of the viewport. When a GL context is first attached to a window, width and height are set to the dimensions of that window.
      viewportHeight - Specify the height of the viewport. When a GL context is first attached to a window, width and height are set to the dimensions of that window.