Table of Contents

Class FileStorage

Namespace
Emgu.CV
Assembly
Emgu.CV.dll

XML/YAML file storage class that encapsulates all the information necessary for writing or reading data to/from a file.

public class FileStorage : UnmanagedObject, IDisposable
Inheritance
FileStorage
Implements
Inherited Members

Constructors

FileStorage(string, Mode, string)

Initializes a new instance of the FileStorage class.

public FileStorage(string source, FileStorage.Mode flags, string encoding = null)

Parameters

source string

Name of the file to open or the text string to read the data from. Extension of the file (.xml or .yml/.yaml) determines its format (XML or YAML respectively). Also you can append .gz to work with compressed files, for example myHugeMatrix.xml.gz. If both FileStorage::WRITE and FileStorage::MEMORY flags are specified, source is used just to specify the output file format (e.g. mydata.xml, .yml etc.).

flags FileStorage.Mode

Mode of operation.

encoding string

Encoding of the file. Note that UTF-16 XML encoding is not supported currently and you should use 8-bit encoding instead of it.

Properties

IsOpened

Gets a value indicating whether this instance is opened.

public bool IsOpened { get; }

Property Value

bool

true if the object is associated with the current file; otherwise, false.

this[string]

Gets the FileNode with the specified node name.

public FileNode this[string nodeName] { get; }

Parameters

nodeName string

Name of the node.

Property Value

FileNode

The FileNode.

Methods

DisposeObject()

Release the unmanaged resources

protected override void DisposeObject()

GetFirstTopLevelNode()

Gets the first element of the top-level mapping.

public FileNode GetFirstTopLevelNode()

Returns

FileNode

The first element of the top-level mapping.

GetNode(string)

Gets the specified element of the top-level mapping.

public FileNode GetNode(string nodeName)

Parameters

nodeName string

Name of the node.

Returns

FileNode

The specified element of the top-level mapping.

GetRoot(int)

Gets the top-level mapping.

public FileNode GetRoot(int streamIdx = 0)

Parameters

streamIdx int

Zero-based index of the stream. In most cases there is only one stream in the file. However, YAML supports multiple streams and so there can be several.

Returns

FileNode

The top-level mapping

Insert(string)

Similar to the << operator in C++, we cannot have the operator overload to << in C# where the second parameter is not an int. Therefore we use this function instead.

public void Insert(string value)

Parameters

value string

The string value to insert.

ReleaseAndGetString()

Closes the file and releases all the memory buffers Call this method after all I/O operations with the storage are finished. If the storage was opened for writing data and FileStorage.Mode.Write was specified

public string ReleaseAndGetString()

Returns

string

The string that represent the text in the FileStorage

Write(Mat, string)

Writes the specified Mat to the node with the specific name.

public void Write(Mat m, string nodeName = null)

Parameters

m Mat

The Mat to be written to the file storage

nodeName string

The name of the node.

Write(double, string)

Writes the specified Mat to the node with the specific name

public void Write(double value, string nodeName = null)

Parameters

value double

The value to be written to the file storage

nodeName string

The name of the node.

Write(int, string)

Writes the specified Mat to the node with the specific name

public void Write(int value, string nodeName = null)

Parameters

value int

The value to be written to the file storage

nodeName string

The name of the node.

Write(float, string)

Writes the specified Mat to the node with the specific name

public void Write(float value, string nodeName = null)

Parameters

value float

The value to be written to the file storage

nodeName string

The name of the node.

Write(string, string)

Writes the specified Mat to the node with the specific name

public void Write(string value, string nodeName = null)

Parameters

value string

The value to be written to the file storage

nodeName string

The name of the node.