Class ThermalStreamer
java.lang.Object
com.flir.thermalsdk.live.streaming.Streamer
com.flir.thermalsdk.live.streaming.ThermalStreamer
- All Implemented Interfaces:
Colorizer,Renderer,Closeable,AutoCloseable
Class for handling for streaming thermal images.
-
Constructor Summary
ConstructorsConstructorDescriptionThermalStreamer(Stream stream) Create a ThermalStreamer instance associated with the particularStream. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()getImage()Get "rendered result" asImageBuffer.Get the region of interest (ROI) that is used to calculate the histogram in the Agc filter.Get render result produced byRenderer.update()the last time scale rendering was enabled (seeColorizer.setRenderScale(boolean)) whenRenderer.update()was called.
The "render result" is a temperature range/span image (or bitmap if you like) colorized accordingly to the current palette and fusion mode settings.
Note: If scale rendering was disabled during last call toRenderer.update(), the result from this function may be out of sync with the result ofColorizer.getScaleRangeMin(),Colorizer.getScaleRangeMax().
Note: For getting rendered image without scale, seeRenderer.getImage().Get the max range of the scale when scale auto-adjust is set.
Note: Calling this function is only valid ifColorizer.isAutoScale()was enabled at the time of the last render.Get the min range of the scale when scale auto-adjust is set.
Note: Calling this function is only valid ifColorizer.isAutoScale()was enabled at the time of the last render.Get parameters for the VividIR filter.booleanGets if new rendered images will have scale (temperature range/span) automatically adjusted based on the min and max values in the image.
Note: auto-adjusted scale is disabled by defaultbooleanGets whether or not scale (temperature range/span image) should be rendered when rendering a new image.
This setting corresponds toColorizer.getScaleImage()in the way that when this option is disabled theColorizer.getScaleImage()will return null.
Note: Scale rendering is disabled by default for performance reasons.static booleanisTemporaryStreamError(ErrorCode errorCode) This exception may occur when live streaming from the camera when usingupdate().voidsetAutoScale(boolean autoScale) When enabled, new rendered images will have scale (temperature range/span) automatically adjusted based on the min and max values in the image.
Note: Calling this function does not trigger any render.voidSet the region of interest (ROI) that is used to calculate the histogram in the Agc filter.voidsetRenderScale(boolean renderScale) Sets whether or not scale (temperature range/span image) should be rendered when rendering a new image.
This setting corresponds toColorizer.getScaleImage()in the way that when this option is disabled theColorizer.getScaleImage()will return null.
Note: Scale rendering is disabled by default for performance reasons.voidsetVividIrParameters(VividIrParameters parameters) Set parameters for the VividIR filter.voidupdate()Executes rendering by polling image data from the source (e.g.voidwithThermalImage(Consumer<ThermalImage> functionToRun) This function allows to safely access ThermalImage during streaming.
-
Constructor Details
-
Method Details
-
withThermalImage
This function allows to safely access ThermalImage during streaming. It ensures the ThermalImage will not change during the function execution.
Typical use case would be similar to the following:Stream aStream = // a thermal stream obtained from a camera using Camera#getStreams() ThermalStreamer thermalStreamer = new ThermalStreamer(aStream); aStream.start( onReceivedResult -> { // notify UI or render thread about new frame - don't call thermalStreamer.update() directly on the stream thread updateUiOnSeparateThread(); }, error -> { // handle streaming error }); ... private void updateUiOnSeparateThread() { // you can also run most of the processing on a background thread and run only the UI-related code on the main/UI thread runOnUiThread(() -> { // update the streamer data with the new frame thermalStreamer.update(); // for rendering purposes we can read out the colorized pixels easily ImageBuffer imageBuffer = thermalStreamer.getImage(); android.graphics.Bitmap androidBmp = BitmapAndroid.createBitmap(imageBuffer).getBitMap(); // you can use androidBmp instance to render to ImageView for example mImageView.setImageBitmap(androidBmp); // UI thread required // if you want to access ThermalImage object, use the ThermalStreamer#withThermalImage() helper thermalStreamer.withThermalImage(thermalImage -> { // here you can safely read/modify different ThermalImage parameters, like palette, fusion mode, color distribution, measurements, etc. // for example you can read out the measurements data and draw them on the UI thread on top of the androidBmp as an overlay // show the current palette name on the UI mTextView.setText(thermalImage.getPalette().name); // UI thread required }); }); }- Parameters:
functionToRun- the ThermalImage instance can be safely accessed under this function, which ensures ThermalImage is not changed during the function execution
-
getVividIrParameters
Get parameters for the VividIR filter.
Note: in order to set new parameters you have to usesetVividIrParameters(VividIrParameters)- Returns:
- null if this streamer doesn't use VividIR.
- See Also:
-
setVividIrParameters
Set parameters for the VividIR filter.- Throws:
ErrorCodeException- if this streamer doesn't use VividIR- See Also:
-
update
public void update()Description copied from interface:RendererExecutes rendering by polling image data from the source (e.g. a stream or ThermalImage), then performing image processing. Result can be obtained usingRenderer.getImage(). -
getImage
Description copied from interface:RendererGet "rendered result" asImageBuffer.- Specified by:
getImagein interfaceRenderer- Returns:
- Returns a deep copy of the render output or
nullifRenderer.update()has not been called previously or no source image was available yet. - See Also:
-
getScaleImage
Description copied from interface:ColorizerGet render result produced byRenderer.update()the last time scale rendering was enabled (seeColorizer.setRenderScale(boolean)) whenRenderer.update()was called.
The "render result" is a temperature range/span image (or bitmap if you like) colorized accordingly to the current palette and fusion mode settings.
Note: If scale rendering was disabled during last call toRenderer.update(), the result from this function may be out of sync with the result ofColorizer.getScaleRangeMin(),Colorizer.getScaleRangeMax().
Note: For getting rendered image without scale, seeRenderer.getImage().- Specified by:
getScaleImagein interfaceColorizer- Returns:
- Returns a deep copy of the render output, or null if
Renderer.update()has not been called previously with scale rendering enabled (seeColorizer.setRenderScale(boolean)) or no source image was available yet. - See Also:
-
isAutoScale
public boolean isAutoScale()Description copied from interface:ColorizerGets if new rendered images will have scale (temperature range/span) automatically adjusted based on the min and max values in the image.
Note: auto-adjusted scale is disabled by default- Specified by:
isAutoScalein interfaceColorizer- Returns:
- true if auto-adjusted scale (temperature range/span) is enabled, otherwise false.
-
setAutoScale
public void setAutoScale(boolean autoScale) Description copied from interface:ColorizerWhen enabled, new rendered images will have scale (temperature range/span) automatically adjusted based on the min and max values in the image.
Note: Calling this function does not trigger any render. UseRenderer.update()if necessary.- Specified by:
setAutoScalein interfaceColorizer- Parameters:
autoScale- Use true to enable auto-adjusted scale (temperature range/span), false to disable.
-
getScaleRangeMin
Description copied from interface:ColorizerGet the min range of the scale when scale auto-adjust is set.
Note: Calling this function is only valid ifColorizer.isAutoScale()was enabled at the time of the last render.- Specified by:
getScaleRangeMinin interfaceColorizer- Returns:
- Scale min thermal value if
Renderer.update()has been called andColorizer.isAutoScale()was enabled whenRenderer.update()was called, otherwise throwsRuntimeException. - See Also:
-
getScaleRangeMax
Description copied from interface:ColorizerGet the max range of the scale when scale auto-adjust is set.
Note: Calling this function is only valid ifColorizer.isAutoScale()was enabled at the time of the last render.- Specified by:
getScaleRangeMaxin interfaceColorizer- Returns:
- Scale max thermal value if
Renderer.update()has been called andColorizer.isAutoScale()was enabled whenRenderer.update()was called, otherwise throwsRuntimeException. - See Also:
-
isRenderScale
public boolean isRenderScale()Description copied from interface:ColorizerGets whether or not scale (temperature range/span image) should be rendered when rendering a new image.
This setting corresponds toColorizer.getScaleImage()in the way that when this option is disabled theColorizer.getScaleImage()will return null.
Note: Scale rendering is disabled by default for performance reasons.- Specified by:
isRenderScalein interfaceColorizer- Returns:
- true if scale will be rendered, otherwise false.
-
setRenderScale
public void setRenderScale(boolean renderScale) Description copied from interface:ColorizerSets whether or not scale (temperature range/span image) should be rendered when rendering a new image.
This setting corresponds toColorizer.getScaleImage()in the way that when this option is disabled theColorizer.getScaleImage()will return null.
Note: Scale rendering is disabled by default for performance reasons.- Specified by:
setRenderScalein interfaceColorizer- Parameters:
renderScale- Use true to enable, false to disable.
-
getRegionOfInterest
Description copied from interface:ColorizerGet the region of interest (ROI) that is used to calculate the histogram in the Agc filter.- Specified by:
getRegionOfInterestin interfaceColorizer
-
setRegionOfInterest
Description copied from interface:ColorizerSet 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}.- Specified by:
setRegionOfInterestin interfaceColorizer
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-
isTemporaryStreamError
This exception may occur when live streaming from the camera when usingupdate().
Usually this is temporary error when the incoming frame is invalid/corrupted due to connectivity problems and cannot be parsed by the native layer. Is it suggested to use try-catch block, in example:try { thermalStreamer.update() } catch (ErrorCodeException e) { if (ThermalStreamer.isTemporaryStreamError(e.errorCode)) { // ignore this frame and await next correct frame - early return return; } } // continue processing the frame if thermalStreamer.update() was successful
-