read_dictT_read_dictReadDictReadDictread_dict (算子)
名称
read_dictT_read_dictReadDictReadDictread_dict — 从文件中读字典。
签名
void ReadDict(const HTuple& FileName, const HTuple& GenParamName, const HTuple& GenParamValue, HTuple* DictHandle)
void HDict::HDict(const HString& FileName, const HTuple& GenParamName, const HTuple& GenParamValue)
void HDict::HDict(const HString& FileName, const HString& GenParamName, const HString& GenParamValue)
void HDict::HDict(const char* FileName, const char* GenParamName, const char* GenParamValue)
void HDict::HDict(const wchar_t* FileName, const wchar_t* GenParamName, const wchar_t* GenParamValue)
(
Windows only)
void HDict::ReadDict(const HString& FileName, const HTuple& GenParamName, const HTuple& GenParamValue)
void HDict::ReadDict(const HString& FileName, const HString& GenParamName, const HString& GenParamValue)
void HDict::ReadDict(const char* FileName, const char* GenParamName, const char* GenParamValue)
void HDict::ReadDict(const wchar_t* FileName, const wchar_t* GenParamName, const wchar_t* GenParamValue)
(
Windows only)
static void HOperatorSet.ReadDict(HTuple fileName, HTuple genParamName, HTuple genParamValue, out HTuple dictHandle)
public HDict(string fileName, HTuple genParamName, HTuple genParamValue)
public HDict(string fileName, string genParamName, string genParamValue)
void HDict.ReadDict(string fileName, HTuple genParamName, HTuple genParamValue)
void HDict.ReadDict(string fileName, string genParamName, string genParamValue)
描述
read_dictread_dictReadDictReadDictReadDictread_dict reads a dictionary from the file FileNameFileNameFileNameFileNamefileNamefile_name
and returns the handle of the dictionary in DictHandleDictHandleDictHandleDictHandledictHandledict_handle。
The operator supports the following file formats:
- 'hdict'"hdict""hdict""hdict""hdict""hdict":
Binary HALCON format for dictionaries. Files with this format can be
written by write_dictwrite_dictWriteDictWriteDictWriteDictwrite_dict。The default file extension for this format is 'hdict'.
- 'json'"json""json""json""json""json":
JSON (JavaScript Object Notation) file format.
The default file extension for this format is 'json'.
If the given file does not exist, the operator attempts to find
the file by appending the default file extensions to the filename.
The file type is automatically recognized based on the file content
and the file ending (which have to be consistent).
A set of additional optional parameters can be set. The names and values
of the parameters are passed in GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name and
GenParamValueGenParamValueGenParamValueGenParamValuegenParamValuegen_param_value, respectively. Some of the optional parameters
can only be set for a certain file type.GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name 的可能取值如下:
- 'json_value_true'"json_value_true""json_value_true""json_value_true""json_value_true""json_value_true",
'json_value_false'"json_value_false""json_value_false""json_value_false""json_value_false""json_value_false",
'json_value_null'"json_value_null""json_value_null""json_value_null""json_value_null""json_value_null":
-
Set the values that are used for JSON primitives.
Valid JSON primitives are 'true'"true""true""true""true""true", 'false'"false""false""false""false""false", and
'null'"null""null""null""null""null".
When encountering such a primitive in a JSON file, the corresponding
value in the read dictionary is set to the value defined with these
parameters.
The value passed in GenParamValueGenParamValueGenParamValueGenParamValuegenParamValuegen_param_value must be a tuple of length 1.
The default values for primitives are
1 for 'true'"true""true""true""true""true",
0 for 'false'"false""false""false""false""false", and
'HNULL'"HNULL""HNULL""HNULL""HNULL""HNULL" for 'null'"null""null""null""null""null".
These parameters only have an effect when reading a JSON file.
- 'convert_json_arrays_to'"convert_json_arrays_to""convert_json_arrays_to""convert_json_arrays_to""convert_json_arrays_to""convert_json_arrays_to":
-
This parameter controls which HALCON-internal data type is used
to represent JSON arrays.
Possible values for GenParamValueGenParamValueGenParamValueGenParamValuegenParamValuegen_param_value are:
- 'dict'"dict""dict""dict""dict""dict" (default):
-
JSON arrays are converted into HALCON-Dictionaries with consecutive
integer keys starting at 0.
This is always possible, even if the JSON array contains further
JSON arrays.
However, using dictionaries might require more memory than storing
the same data in HALCON tuples.
- 'tuple'"tuple""tuple""tuple""tuple""tuple":
-
JSON arrays are converted into HALCON tuples.
If this is not possible, for example if an array contains an array,
an exception is raised.
- 'tuple_if_possible'"tuple_if_possible""tuple_if_possible""tuple_if_possible""tuple_if_possible""tuple_if_possible":
-
JSON arrays are converted into HALCON tuples if possible, and into
HALCON dictionaries otherwise.
Note that when using this option, the structure of the returned
dictionary can change even if the JSON data follows the same schema.
For example, an array of 2D point coordinates of the form
'{"pt": [[1,2], [3,4]]}'"{"pt": [[1,2], [3,4]]}""{"pt": [[1,2], [3,4]]}""{"pt": [[1,2], [3,4]]}""{"pt": [[1,2], [3,4]]}""{"pt": [[1,2], [3,4]]}"
would be converted into an outer dictionary which contains two
tuples.
However, if under the same schema no points are contained in the
array, the corresponding entry in the JSON of the form
'{"pt": []}'"{"pt": []}""{"pt": []}""{"pt": []}""{"pt": []}""{"pt": []}"
would be converted into a tuple instead of a dictionary.
Code using the read dictionary must be prepared to deal with this
kind of change in types.
执行信息
- 多线程类型:独立(即使使用独占算子也能并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
此算子返回一个句柄。请注意,即使该句柄被用作特定算子的输入参数,这些算子仍可能改变此句柄类型的实例状态。
参数
FileNameFileNameFileNameFileNamefileNamefile_name (输入控制) filename.read → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
File name.
File extension:
.hdict, .json
GenParamNameGenParamNameGenParamNameGenParamNamegenParamNamegen_param_name (输入控制) attribute.name(-array) → HTupleMaybeSequence[str]HTupleHtuple (string) (string) (HString) (char*)
Name of the generic parameter.
默认值:
[]
值列表:
'convert_json_arrays_to'"convert_json_arrays_to""convert_json_arrays_to""convert_json_arrays_to""convert_json_arrays_to""convert_json_arrays_to", 'json_value_false'"json_value_false""json_value_false""json_value_false""json_value_false""json_value_false", 'json_value_null'"json_value_null""json_value_null""json_value_null""json_value_null""json_value_null", 'json_value_true'"json_value_true""json_value_true""json_value_true""json_value_true""json_value_true"
GenParamValueGenParamValueGenParamValueGenParamValuegenParamValuegen_param_value (输入控制) attribute.name(-array) → HTupleMaybeSequence[Union[int, float, str]]HTupleHtuple (string / integer / real) (string / int / long / double) (HString / Hlong / double) (char* / Hlong / double)
Value of the generic parameter.
默认值:
[]
建议值:
0, 1, 'HNULL'"HNULL""HNULL""HNULL""HNULL""HNULL", 'true'"true""true""true""true""true", 'false'"false""false""false""false""false", 'dict'"dict""dict""dict""dict""dict", 'tuple'"tuple""tuple""tuple""tuple""tuple", 'tuple_if_possible'"tuple_if_possible""tuple_if_possible""tuple_if_possible""tuple_if_possible""tuple_if_possible"
DictHandleDictHandleDictHandleDictHandledictHandledict_handle (输出控制) dict → HDict, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
Dictionary handle.
元素数量:
DictHandle == 1
结果
如果参数有效,算子 read_dictread_dictReadDictReadDictReadDictread_dict 返回值 2 ( H_MSG_TRUE )。如有必要,则抛出异常。
可能的前趋
write_dictwrite_dictWriteDictWriteDictWriteDictwrite_dict
替代
json_to_dictjson_to_dictJsonToDictJsonToDictJsonToDictjson_to_dict,
create_dictcreate_dictCreateDictCreateDictCreateDictcreate_dict
另见
write_dictwrite_dictWriteDictWriteDictWriteDictwrite_dict,
serialize_handleserialize_handleSerializeHandleSerializeHandleSerializeHandleserialize_handle,
deserialize_handledeserialize_handleDeserializeHandleDeserializeHandleDeserializeHandledeserialize_handle
模块
基础