mirror of
https://github.com/opencv/opencv.git
synced 2026-07-30 07:43:03 +04:00
Modify Base64 functions and add test and documentation
Major changes: - modify the Base64 functions to compatible with `cvWriteRawData` and so on. - add a Base64 flag for FileStorage and outputs raw data in Base64 automatically. - complete all testing and documentation.
This commit is contained in:
@@ -1976,8 +1976,19 @@ CVAPI(void) cvSetIPLAllocators( Cv_iplCreateImageHeader create_header,
|
||||
|
||||
The function opens file storage for reading or writing data. In the latter case, a new file is
|
||||
created or an existing file is rewritten. The type of the read or written file is determined by the
|
||||
filename extension: .xml for XML and .yml or .yaml for YAML. The function returns a pointer to the
|
||||
CvFileStorage structure. If the file cannot be opened then the function returns NULL.
|
||||
filename extension: .xml for XML and .yml or .yaml for YAML.
|
||||
|
||||
At the same time, it also supports adding parameters like "example.xml?base64".
|
||||
@code
|
||||
CvFileStorage* fs = cvOpenFileStorage( "example.yml?base64", 0, CV_STORAGE_WRITE );
|
||||
@endcode
|
||||
it's exactly the same as
|
||||
@code
|
||||
CvFileStorage* fs = cvOpenFileStorage( "example.yml", 0, CV_STORAGE_WRITE_BASE64 );
|
||||
@endcode
|
||||
|
||||
The function returns a pointer to the CvFileStorage structure.
|
||||
If the file cannot be opened then the function returns NULL.
|
||||
@param filename Name of the file associated with the storage
|
||||
@param memstorage Memory storage used for temporary data and for
|
||||
: storing dynamic structures, such as CvSeq or CvGraph . If it is NULL, a temporary memory
|
||||
@@ -1985,6 +1996,7 @@ CvFileStorage structure. If the file cannot be opened then the function returns
|
||||
@param flags Can be one of the following:
|
||||
> - **CV_STORAGE_READ** the storage is open for reading
|
||||
> - **CV_STORAGE_WRITE** the storage is open for writing
|
||||
(use **CV_STORAGE_WRITE | CV_STORAGE_WRITE_BASE64** to write rawdata in Base64)
|
||||
@param encoding
|
||||
*/
|
||||
CVAPI(CvFileStorage*) cvOpenFileStorage( const char* filename, CvMemStorage* memstorage,
|
||||
@@ -2162,7 +2174,7 @@ the file with multiple streams looks like this:
|
||||
@endcode
|
||||
The YAML file will look like this:
|
||||
@code{.yaml}
|
||||
%YAML:1.0
|
||||
%YAML 1.0
|
||||
# stream #1 data
|
||||
...
|
||||
---
|
||||
@@ -2187,6 +2199,46 @@ to a sequence rather than a map.
|
||||
CVAPI(void) cvWriteRawData( CvFileStorage* fs, const void* src,
|
||||
int len, const char* dt );
|
||||
|
||||
/** @brief Writes multiple numbers in Base64.
|
||||
|
||||
If either CV_STORAGE_WRITE_BASE64 or cv::FileStorage::WRITE_BASE64 is used,
|
||||
this function will be the same as cvWriteRawData. If neither, the main
|
||||
difference is that it outputs a sequence in Base64 encoding rather than
|
||||
in plain text.
|
||||
|
||||
This function can only be used to write a sequence with a type "binary".
|
||||
|
||||
Consider the following two examples where their output is the same:
|
||||
@code
|
||||
std::vector<int> rawdata(10, 0x00010203);
|
||||
// without the flag CV_STORAGE_WRITE_BASE64.
|
||||
CvFileStorage* fs = cvOpenFileStorage( "example.yml", 0, CV_STORAGE_WRITE );
|
||||
// both CV_NODE_SEQ and "binary" are necessary.
|
||||
cvStartWriteStruct(fs, "rawdata", CV_NODE_SEQ | CV_NODE_FLOW, "binary");
|
||||
cvWriteRawDataBase64(fs, rawdata.data(), rawdata.size(), "i");
|
||||
cvEndWriteStruct(fs);
|
||||
cvReleaseFileStorage( &fs );
|
||||
@endcode
|
||||
and
|
||||
@code
|
||||
std::vector<int> rawdata(10, 0x00010203);
|
||||
// with the flag CV_STORAGE_WRITE_BASE64.
|
||||
CvFileStorage* fs = cvOpenFileStorage( "example.yml", 0, CV_STORAGE_WRITE_BASE64);
|
||||
// parameter, typename "binary" could be omitted.
|
||||
cvStartWriteStruct(fs, "rawdata", CV_NODE_SEQ | CV_NODE_FLOW);
|
||||
cvWriteRawData(fs, rawdata.data(), rawdata.size(), "i");
|
||||
cvEndWriteStruct(fs);
|
||||
cvReleaseFileStorage( &fs );
|
||||
@endcode
|
||||
|
||||
@param fs File storage
|
||||
@param src Pointer to the written array
|
||||
@param len Number of the array elements to write
|
||||
@param dt Specification of each array element, see @ref format_spec "format specification"
|
||||
*/
|
||||
CVAPI(void) cvWriteRawDataBase64( CvFileStorage* fs, const void* _data,
|
||||
int len, const char* dt );
|
||||
|
||||
/** @brief Returns a unique pointer for a given name.
|
||||
|
||||
The function returns a unique pointer for each particular file node name. This pointer can be then
|
||||
|
||||
@@ -311,7 +311,10 @@ public:
|
||||
FORMAT_MASK = (7<<3), //!< mask for format flags
|
||||
FORMAT_AUTO = 0, //!< flag, auto format
|
||||
FORMAT_XML = (1<<3), //!< flag, XML format
|
||||
FORMAT_YAML = (2<<3) //!< flag, YAML format
|
||||
FORMAT_YAML = (2<<3), //!< flag, YAML format
|
||||
|
||||
BASE64 = 64, //!< flag, write rawdata in Base64 by default. (consider using WRITE_BASE64)
|
||||
WRITE_BASE64 = BASE64 | WRITE, //!< flag, enable both WRITE and BASE64
|
||||
};
|
||||
enum
|
||||
{
|
||||
@@ -354,7 +357,9 @@ public:
|
||||
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.).
|
||||
the output file format (e.g. mydata.xml, .yml etc.). A file name can also contain parameters.
|
||||
You can use this format, "*?base64" (e.g. "file.xml?base64"), as an alternative to
|
||||
FileStorage::BASE64 flag. Note: it is case sensitive.
|
||||
@param flags Mode of operation. One of FileStorage::Mode
|
||||
@param encoding Encoding of the file. Note that UTF-16 XML encoding is not supported currently and
|
||||
you should use 8-bit encoding instead of it.
|
||||
|
||||
@@ -1669,6 +1669,8 @@ typedef struct CvFileStorage CvFileStorage;
|
||||
#define CV_STORAGE_FORMAT_AUTO 0
|
||||
#define CV_STORAGE_FORMAT_XML 8
|
||||
#define CV_STORAGE_FORMAT_YAML 16
|
||||
#define CV_STORAGE_BASE64 64
|
||||
#define CV_STORAGE_WRITE_BASE64 (CV_STORAGE_BASE64 | CV_STORAGE_WRITE)
|
||||
|
||||
/** @brief List of attributes. :
|
||||
|
||||
|
||||
Reference in New Issue
Block a user