OpenCV for Unity 3.0.4
Enox Software / Please refer to OpenCV official document ( http://docs.opencv.org/5.0/index.html ) for the details of the argument of the method.
Loading...
Searching...
No Matches
OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource Class Referencesealed

Still-image MatSourceBase that implements IImageFileMatSource and IMatUpdateFPSControllable. More...

Public Member Functions

 ImageFileMatSource (ImageFileFrameGrabber grabber, IFrameOrientationCorrector orientationCorrector=null)
 Initializes a new instance of the ImageFileMatSource class.
 
Task InitializeAsync (ImageFileOpenOptions options, CancellationToken cancellationToken=default)
 Initializes the source using one-shot open options projected onto RequestedImageFilePath and Repeat.
 
override async Task PauseAsync (CancellationToken cancellationToken=default)
 Pauses frame acquisition asynchronously. When already paused, completes immediately without error. When MatSourceState.Initializing, completes immediately without changing state.
Parameters
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when playback has been paused.
When State is MatSourceState.Initializing, completes immediately without changing state and logs a one-time warning per process.
 
override async Task PlayAsync (CancellationToken cancellationToken=default)
 Starts or resumes frame acquisition asynchronously. When already playing, completes immediately without error. When MatSourceState.Initializing, completes immediately without changing state.
Parameters
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when playback has started.
When State is MatSourceState.Initializing, completes immediately without changing state and logs a one-time warning per process.
 
override async Task StopAsync (CancellationToken cancellationToken=default)
 Stops frame acquisition asynchronously. When already in the ready (not playing) state, completes immediately without error. When MatSourceState.Initializing, completes immediately without changing state.
Parameters
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when playback has stopped.
When State is MatSourceState.Initializing, completes immediately without changing state and logs a one-time warning per process.
 
override void Tick (float deltaTime)
 Advances frame acquisition when the source is playing. Sets IMatSource.DidUpdateThisFrame only when a new frame is acquired.
Parameters
deltaTimeElapsed time since the previous tick, in seconds.
Sets DidUpdateThisFrame only when IFrameGrabber.TryGrab returns a new frame. When IFrameGrabber.TryGrab returns false, this tick is a no-op (not an error). Does not call IFrameOrientationCorrector.NotifyDisplayOrientationChanged; the host is responsible for that. Registered DerivedFrames are still evaluated when IFrameGrabber.TryGrab does not succeed so per-tick derived-frame flags such as IDerivedFrame.DidUpdateThisFrame stay in sync. Sources without a native frame rate (for example still images) may throttle Tick in a derived type that implements IMatUpdateFPSControllable.
 
- Public Member Functions inherited from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase
 MatSourceBase (IFrameGrabber grabber, IFrameOrientationCorrector orientationCorrector=null)
 Initializes a new instance of the MatSourceBase class.
 
PlaybackRestoreMode CapturePlaybackRestoreMode ()
 Captures the current playback state as a PlaybackRestoreMode for re-initialization.
Returns
PlaybackRestoreMode.Playing when playing, PlaybackRestoreMode.Paused when paused, otherwise PlaybackRestoreMode.Ready.

 
void Dispose ()
 
async ValueTask DisposeAsync ()
 Asynchronously releases resources. Required on single-threaded hosts (for example browser/WebAssembly targets); do not use Dispose on those hosts.
 
Task InitializeAsync (CancellationToken cancellationToken=default)
 Initializes the source asynchronously and leaves playback in MatSourceState.Ready.
Parameters
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when initialization finishes.

 
Task InitializeAsync (PlaybackRestoreMode playbackRestoreMode, CancellationToken cancellationToken=default)
 Initializes the source asynchronously and restores the requested playback state before IMatSourceEvents.OnInitialized is raised.
Parameters
playbackRestoreModePlayback state to apply after the grabber is ready.
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when initialization finishes.

 
Task ReinitializeAsync (PlaybackRestoreMode playbackRestoreMode, CancellationToken cancellationToken=default)
 Releases the source when initialized, then initializes again with the requested playback restore mode.
Parameters
playbackRestoreModePlayback state to apply after the grabber is ready.
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when re-initialization finishes.

 
Task ReleaseAsync (CancellationToken cancellationToken=default)
 
void SyncDerivedFrameBuffersIfStale (IList< string > pendingLayoutChanges=null)
 Re-applies derived frame outputs whose buffers are stale relative to the current source layout or derived settings.
 
bool TryGetMeta (string key, out object value)
 Attempts to get a meta property value by key.
Parameters
keyThe meta key.
valueWhen this method returns true, the retrieved value; otherwise the default value.
Returns
true when the key is supported and a value is available; otherwise false.

 
bool TrySetMeta (string key, object value)
 Attempts to set a meta property value by key.
Parameters
keyThe meta key.
valueThe value to set.
Returns
true when the key is supported and the value was applied; otherwise false.

 
- Public Member Functions inherited from OpenCVForUnity.Extensions.SourceToMat.IMatSource
- Public Member Functions inherited from OpenCVForUnity.Extensions.SourceToMat.IMatMetaProperties
- Public Member Functions inherited from OpenCVForUnity.Extensions.SourceToMat.IMatSourceTickable
- Public Member Functions inherited from OpenCVForUnity.Extensions.SourceToMat.IMatSourceReinitializable

Protected Member Functions

override void SyncGrabberBeforeOpen ()
 Copies source-specific Requested* settings onto the injected grabber immediately before IFrameGrabber.OpenAsync. Derived file-based sources override this hook; the default is a no-op.
 
- Protected Member Functions inherited from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase
void ClearDidUpdateThisFrame ()
 Clears DidUpdateThisFrame for the current tick.
 
virtual SourceToMatColorFormat InferGrabberColorFormat (Mat workingMat)
 Resolves the grabber frame color format used for output conversion. Override in derived sources when channel order is known and differs from InferColorFormat.
 
void RaiseError (SourceToMatErrorCode errorCode, string message)
 Raises OnErrorOccurred with the specified error code and message.
 
void StopPlayingCore ()
 Stops playback without async overhead. Shared by StopAsync and derived Tick handlers.
 

Properties

float MatUpdateFPS [get]
 Gets the effective frame update rate in frames per second.
 
bool Repeat [get, set]
 Gets or sets whether the image source repeats updates while MatSourceState.Playing. Repeat delivery is inactive while MatSourceState.Paused.
 
string RequestedImageFilePath = string.Empty [get, set]
 Gets or sets the requested image file path.
 
float RequestedMatUpdateFPS [get, set]
 Gets or sets the requested frame update rate in frames per second. Values of 0 or less mean update every tick.
 
- Properties inherited from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase
SourceToMatColorFormat BaseColorFormat [get]
 Gets the native color format produced by the underlying grabber before output conversion.
 
DerivedFrameCollection DerivedFrames [get]
 Gets the optional derived frame collection. When empty, tick processing matches the source layer only.
 
bool DidUpdateThisFrame [get]
 
bool FlipHorizontal [get, set]
 Gets or sets whether to flip the image horizontally.
 
bool FlipVertical [get, set]
 Gets or sets whether to flip the image vertically.
 
Mat FrameMat [get]
 
int Height [get]
 Gets the current frame height in pixels.
 
int InitTimeoutMs [get, set]
 Gets or sets the initialization wait timeout in milliseconds.
 
bool IsInitialized [get]
 Gets a value indicating whether the source has been initialized and is ready for playback control. Does not include MatSourceState.Initializing.
 
bool IsInitializing [get]
 Gets a value indicating whether initialization is in progress (MatSourceState.Initializing).
 
bool IsPaused [get]
 Gets a value indicating whether frame acquisition is paused.
 
bool IsPlaying [get]
 Gets a value indicating whether frame acquisition is active.
 
Task LifecycleTask [get]
 Gets a task that completes when the current lifecycle operation finishes. Queued operations run sequentially; this reflects the tail of that chain.
 
SourceToMatColorFormat OutputColorFormat [get, set]
 Gets or sets the output color format. When changed after initialization, the output FrameMat channel layout (Mat type) may change and implementations that raise IMatSourceEvents.OnFrameMatLayoutChanged do so after the new layout is committed.
 
bool Rotate90Degree [get, set]
 Gets or sets whether to rotate the image 90 degrees clockwise. When changed after initialization, the output IMatSource.FrameMat layout (width, height) changes and implementations that raise IMatSourceEvents.OnFrameMatLayoutChanged do so after the new layout is committed.
 
MatSourceState State [get]
 Gets the current lifecycle state.
 
int Width [get]
 Gets the current frame width in pixels.
 
- Properties inherited from OpenCVForUnity.Extensions.SourceToMat.IMatSource
- Properties inherited from OpenCVForUnity.Extensions.SourceToMat.IMatTransformable
- Properties inherited from OpenCVForUnity.Extensions.SourceToMat.IMatSourceDerivedFrames
- Properties inherited from OpenCVForUnity.Extensions.SourceToMat.IImageFileMatSource
- Properties inherited from OpenCVForUnity.Extensions.SourceToMat.IMatUpdateFPSControllable

Additional Inherited Members

- Events inherited from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase
Action< string > OnDerivedFrameLayoutChanged
 
Action OnDisposed
 
Action< SourceToMatErrorCode, string > OnErrorOccurred
 
Action OnFrameMatLayoutChanged
 
Action OnFrameMatUpdated
 
Action OnInitialized
 
Action OnReleased
 
- Events inherited from OpenCVForUnity.Extensions.SourceToMat.IMatSourceEvents
Action< string > OnDerivedFrameLayoutChanged
 Occurs after initialization when a derived frame output layout (columns, rows, type) changes without removing the derived frame, on the thread that commits the layout change. Not raised on the first derived layout establishment during IMatSource.InitializeAsync. At invocation, the derived frame's FrameMat matches the committed output layout. Layout-affecting settings updates may commit immediately without waiting for the next IMatSourceTickable.Tick.
 
Action OnDisposed
 Occurs when IDisposable.Dispose or IAsyncDisposable.DisposeAsync completes and the source enters MatSourceState.Destroyed.
 
Action< SourceToMatErrorCode, string > OnErrorOccurred
 Occurs for expected runtime failures with a SourceToMatErrorCode and message, on the thread that detected the failure.
 
Action OnFrameMatLayoutChanged
 Occurs after initialization when the output IMatSource.FrameMat layout (cols, rows, type) changes without a full release cycle, on the thread that commits the layout change. Not raised on the first layout establishment during IMatSource.InitializeAsync. When derived frames are registered, their output buffers are synced to the new primary layout before this event is raised.
 
Action OnFrameMatUpdated
 Occurs at the end of IMatSourceTickable.Tick when IMatSource.DidUpdateThisFrame is true for that tick, after any registered derived frames are evaluated.
 
Action OnInitialized
 Occurs when an initialization cycle completes and playback state (Ready / Playing / Paused) is determined, on the thread that completes the underlying async operation.
 
Action OnReleased
 Occurs when IMatSource.ReleaseAsync completes and the source returns to MatSourceState.Uninitialized, on the thread that completes the underlying async operation.
 

Detailed Description

Still-image MatSourceBase that implements IImageFileMatSource and IMatUpdateFPSControllable.

ConfigureAwait(false) is used only after MatSourceBase.PlayAsync, MatSourceBase.PauseAsync, and MatSourceBase.StopAsync complete (post-restore playback-state chain). It is not used before grabber open/close on initialization paths.

Constructor & Destructor Documentation

◆ ImageFileMatSource()

OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.ImageFileMatSource ( ImageFileFrameGrabber grabber,
IFrameOrientationCorrector orientationCorrector = null )

Initializes a new instance of the ImageFileMatSource class.

Parameters
grabberThe OpenCV image file grabber.
orientationCorrectorOptional orientation corrector.

Member Function Documentation

◆ InitializeAsync()

Task OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.InitializeAsync ( ImageFileOpenOptions options,
CancellationToken cancellationToken = default )

Initializes the source using one-shot open options projected onto RequestedImageFilePath and Repeat.

Parameters
optionsImage open options to project before initialization.
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when initialization finishes.

◆ PauseAsync()

override async Task OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.PauseAsync ( CancellationToken cancellationToken = default)
virtual

Pauses frame acquisition asynchronously. When already paused, completes immediately without error. When MatSourceState.Initializing, completes immediately without changing state.

Parameters
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when playback has been paused.
When State is MatSourceState.Initializing, completes immediately without changing state and logs a one-time warning per process.

Reimplemented from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.

◆ PlayAsync()

override async Task OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.PlayAsync ( CancellationToken cancellationToken = default)
virtual

Starts or resumes frame acquisition asynchronously. When already playing, completes immediately without error. When MatSourceState.Initializing, completes immediately without changing state.

Parameters
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when playback has started.
When State is MatSourceState.Initializing, completes immediately without changing state and logs a one-time warning per process.

Reimplemented from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.

◆ StopAsync()

override async Task OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.StopAsync ( CancellationToken cancellationToken = default)
virtual

Stops frame acquisition asynchronously. When already in the ready (not playing) state, completes immediately without error. When MatSourceState.Initializing, completes immediately without changing state.

Parameters
cancellationTokenA token used to cancel the operation.
Returns
A task that completes when playback has stopped.
When State is MatSourceState.Initializing, completes immediately without changing state and logs a one-time warning per process.

Reimplemented from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.

◆ SyncGrabberBeforeOpen()

override void OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.SyncGrabberBeforeOpen ( )
protectedvirtual

Copies source-specific Requested* settings onto the injected grabber immediately before IFrameGrabber.OpenAsync. Derived file-based sources override this hook; the default is a no-op.

Reimplemented from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.

◆ Tick()

override void OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.Tick ( float deltaTime)
virtual

Advances frame acquisition when the source is playing. Sets IMatSource.DidUpdateThisFrame only when a new frame is acquired.

Parameters
deltaTimeElapsed time since the previous tick, in seconds.
Sets DidUpdateThisFrame only when IFrameGrabber.TryGrab returns a new frame. When IFrameGrabber.TryGrab returns false, this tick is a no-op (not an error). Does not call IFrameOrientationCorrector.NotifyDisplayOrientationChanged; the host is responsible for that. Registered DerivedFrames are still evaluated when IFrameGrabber.TryGrab does not succeed so per-tick derived-frame flags such as IDerivedFrame.DidUpdateThisFrame stay in sync. Sources without a native frame rate (for example still images) may throttle Tick in a derived type that implements IMatUpdateFPSControllable.

Reimplemented from OpenCVForUnity.Extensions.SourceToMat.MatSourceBase.

Property Documentation

◆ MatUpdateFPS

float OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.MatUpdateFPS
get

Gets the effective frame update rate in frames per second.

Implements OpenCVForUnity.Extensions.SourceToMat.IMatUpdateFPSControllable.

◆ Repeat

bool OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.Repeat
getset

Gets or sets whether the image source repeats updates while MatSourceState.Playing. Repeat delivery is inactive while MatSourceState.Paused.

Implements OpenCVForUnity.Extensions.SourceToMat.IImageFileMatSource.

◆ RequestedImageFilePath

string OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.RequestedImageFilePath = string.Empty
getset

Gets or sets the requested image file path.

Implements OpenCVForUnity.Extensions.SourceToMat.IImageFileMatSource.

◆ RequestedMatUpdateFPS

float OpenCVForUnity.Extensions.SourceToMat.ImageFileMatSource.RequestedMatUpdateFPS
getset

Gets or sets the requested frame update rate in frames per second. Values of 0 or less mean update every tick.

Implements OpenCVForUnity.Extensions.SourceToMat.IMatUpdateFPSControllable.


The documentation for this class was generated from the following file: