Package com.flir.thermalsdk.live
Class Camera
java.lang.Object
com.flir.thermalsdk.live.Camera
- All Implemented Interfaces:
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.
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticate
(@NotNull Identity identity, @NotNull String commonName, long timeoutMs) 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.authenticate
(@NotNull InetAddress ipaddress, String commonName, long timeoutMs) void
close()
void
connect
(@NotNull Identity identity, @NotNull ConnectionStatusListener listener, @Nullable ConnectParameters connectParameters) Connects to the givenIdentity
.void
connect
(@NotNull InetAddress inetAddress, @NotNull ConnectionStatusListener listener, @Nullable ConnectParameters connectParameters) Connects to the given ip address.void
Disconnect from the camera.@Nullable Identity
Get the camera identity.@Nullable Importer
Get a camera'sImporter
service used to import images.@org.jetbrains.annotations.Nullable byte[]
Get license data (from F1 Wireless only).@Nullable RemoteControl
Get camera remote controller.Get a list of available camera streams.void
glEnableMsx
(boolean enableMsx) Enable or disable MSX mode while rendering to GL surface.Get the region of interest (ROI) that is used to calculate the histogram in the Agc filter.Allows to read current auto Scale range.boolean
Renders the frame to GL surface.void
glOnSurfaceChanged
(int width, int height) When a GL surface for rendering changes size this should be called to ensure proper viewport.Allows to render Scale image.void
glScaleAutoAdjust
(boolean enableAutoAdjust) Enable or disable Scale auto adjust while rendering to GL surface.void
glSetPalette
(Palette palette) Helper function to set a palette for the stream running with GL pipeline.void
Set the region of interest (ROI) that is used to calculate the histogram in the Agc filter.void
glSetupPipeline
(Stream stream, boolean enableMsx) Setup a GL pipeline with a specified Stream.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.void
Close the pipeline and release all used resources.void
glWithThermalImage
(Consumer<ThermalImage> functionToRun) This method ensures a thread-safe access to the receivedThermalImage
.boolean
Get the connection status.boolean
Deprecated.UsegetStreams()
andStream.isStreaming()
instead.void
subscribeStream
(ThermalImageStreamListener listener) Deprecated.void
Deprecated.void
unsubscribeStream
(ThermalImageStreamListener listener) Deprecated.void
withImage
(ThermalImageStreamListener listener, Consumer<ThermalImage> functionToRun) Deprecated.void
withImage
(Consumer<ThermalImage> functionToRun) Deprecated.
-
Constructor Details
-
Camera
public Camera()Creates a new Camera instance. Note that you have to callconnect(Identity, ConnectionStatusListener, ConnectParameters)
in order to establish connection and interact with the camera.
-
-
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
- anIdentity
to connect tocommonName
- 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 invalidIOException
- 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
- anInetAddress
to connect tolistener
- listener for connection status changesconnectParameters
- parameters eg timeout, if null default values will be used- Throws:
IllegalStateException
- if the state of the Camera object is invalidIllegalArgumentException
- if an invalid ip address has been providedIOException
- 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 givenIdentity
. 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
- anIdentity
to connect tolistener
- listener for connection status changesconnectParameters
- parameters eg timeout, if null default values will be used- Throws:
IllegalStateException
- if the state of the Camera object is invalidIOException
- if the camera could not be connected to
-
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
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
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
Get a camera'sImporter
service used to import images.- Returns:
- Returns a camera's
Importer
service used to import images ornull
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.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.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.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.This method ensures a thread-safe access to the receivedThermalImage
. Use a previously(!) activatedThermalImageStreamListener
viasubscribeStream(ThermalImageStreamListener)
.Consumer
allows to pass a lambda expression to be executed on the givenThermalImage
. TheThermalImage
available for theConsumer
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(!) activatedThermalImageStreamListener
viasubscribeStream(ThermalImageStreamListener)
functionToRun
- a code to run on the givenThermalImage
, i.e. a lambda expression- See Also:
-
withImage
Deprecated.This method ensures a thread-safe access to the receivedThermalImage
.Consumer
allows to pass a lambda expression to be executed on the givenThermalImage
. TheThermalImage
available for theConsumer
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 givenThermalImage
, i.e. a lambda expression- See Also:
-
isGrabbing
Deprecated.UsegetStreams()
andStream.isStreaming()
instead.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 interfaceAutoCloseable
-
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
Setup a GL pipeline with a specified Stream.
Note: supported on Android platform only.- Parameters:
stream
- stream to use with the GL pipelineenableMsx
- flag determining we the stream should start with the MSX mode enabled - note that it can be later changed usingglEnableMsx(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
This method ensures a thread-safe access to the receivedThermalImage
.
Note: supported on Android platform only.- Parameters:
functionToRun
- a code to run on the givenThermalImage
, i.e. a lambda expression
-
glSetPalette
Helper function to set a palette for the stream running with GL pipeline.
Note: supported on Android platform only.- Parameters:
palette
- aPalette
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 GLSurfaceViewheight
- 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 requiresGLSurfaceView
to be ready (includingEGLContext
) it mustn't be called before theglOnSurfaceChanged(int, int)
function, which is usually triggered byGLSurfaceView.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 requiresGLSurfaceView
to be ready (includingEGLContext
) it mustn't be called before theglOnSurfaceChanged(int, int)
function, which is usually triggered byGLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)
).- Parameters:
enableAutoAdjust
- flag determining if Scale auto adjust should be enabled or disabled
-
glSetRegionOfInterest
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 requiresGLSurfaceView
to be ready (includingEGLContext
) it mustn't be called before theglOnSurfaceChanged(int, int)
function, which is usually triggered byGLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)
). -
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 requiresGLSurfaceView
to be ready (includingEGLContext
) it mustn't be called before theglOnSurfaceChanged(int, int)
function, which is usually triggered byGLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)
). -
glRenderScale
Allows to render Scale image.
Note: supported on Android platform only.
Important: since this function requiresGLSurfaceView
to be ready (includingEGLContext
) it mustn't be called before theglOnSurfaceChanged(int, int)
function, which is usually triggered byGLSurfaceView.Renderer.onSurfaceChanged(javax.microedition.khronos.opengles.GL10, int, int)
). -
glGetScaleRange
Allows to read current auto Scale range.
Note: supported on Android platform only.
Important: since this function requiresGLSurfaceView
to be ready (includingEGLContext
) it mustn't be called before theglOnSurfaceChanged(int, int)
function, which is usually triggered byGLSurfaceView.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 requiresGLSurfaceView
to be ready (includingEGLContext
) it mustn't be called before theglOnSurfaceChanged(int, int)
function, which is usually triggered byGLSurfaceView.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.
-
Consumer
instead.