FrameObserver Class

class FrameObserver : ScanningSdkLibrary.Instance

Analyses live camera frames and reports how well a document is framed, so a viewfinder can guide the user and decide when to take the shot.

Feed each preview frame to observe and read the result: whether a document was found, how much of the frame it fills, and how distorted it looks. average smooths those results over recent frames so an overlay does not jitter, and reset starts a fresh session when the scene changes.

Threading. Unlike the other native-handle types, this one may be driven from more than one thread: the engine guards the state shared between frames, so a camera thread can call observe while another calls reset, duplicate or average. The calls are not queued behind one another — the analysis itself runs unguarded, and only the shared result is guarded — so a reset can land while a frame is still being analysed. That frame is then dropped rather than folded into the cleared average: observe returns a result with no flags set, which reads as “nothing seen in this frame”. close is not covered by any of this — stop frame delivery and let any in-flight call finish before closing.

Holds its analysis state in native memory. Call close — or use Kotlin’s use { } — when done to release it immediately; an unclosed instance is only reclaimed when garbage collection happens to run.

The SDK’s own camera screen uses this class; you need it directly only when building your own viewfinder.

See also

Constructors

FrameObserver

constructor()

Types

Average

data class Average(val cutout: ScanCutout, val fullness: Float)

A document outline smoothed over recent frames, with how much of the frame it fills.

Observation

data class Observation(val flags: Int, val delay: Float, val fullness: Float, val distortion: Float, val image: Bitmap?)

What the observer made of one camera frame.

Functions

average

external fun average(width: Int, height: Int, transform: Matrix): FrameObserver.Average

Returns the smoothed document outline, scaled to the size you are drawing at.

close

@Synchronized open override fun close()

Releases the native memory held by this instance immediately instead of waiting for the garbage collector.

duplicate

external fun duplicate()

Repeats the most recent result into the average, so the smoothed outline holds steady through a frame that could not be analysed.

observe

@JvmOverloads external fun observe(buffer: ByteArray, width: Int, height: Int, format: Int, rotation: Int = 0, viewfinder: Rect? = null): FrameObserver.Observation

Analyses one camera frame and returns what it found.

reset

external fun reset(pause: Boolean)

Discards the smoothed history and starts a fresh detection session.

Top