浅谈Halcon中的HTuple类型
halcon中的HTuple类型类非常强大;1、既可以表示的类型有int,double、float、string,既可以表示单个值;2、可以是容器;3、可以是数组,数组遍历时需要有下标,如:变量名称[下标]相互转换//HTuple 转 int double stringint _i;HTuple tuple;_i = tuple[0].I();double _d;_d = tuple[0].D()
·
halcon中的HTuple类型类非常强大;
1、既可以表示的类型有int,double、float、string,既可以表示单个值;
2、可以是容器;
3、可以是数组,数组遍历时需要有下标,如:变量名称[下标]
相互转换
//HTuple 转 int double string
int _i;
HTuple tuple;
_i = tuple[0].I();
double _d;
_d = tuple[0].D();
const char* _str;
_str = tuple[0].S();
//int double string 转 HTuple
tuple = (HTuple)_i;
tuple = (HTuple)_d;
tuple = (HTuple)_str;
//HTuple 转换 vector<int/ double/ string>
vector<int> *_vInt = new vector<int>();
for (size_t i = 0; i < (size_t)tuple.Length(); i++)
{
_vInt->push_back((int)tuple[0].I());
}
vector<double> *_vDouble = new vector<double>();
for (size_t i = 0; i < (size_t)tuple.Length(); i++)
{
_vDouble->push_back((double)tuple[0].D());
}
vector<const char*> *_vString = new vector<const char*>();
for (size_t i = 0; i < (size_t)tuple.Length(); i++)
{
_vString->push_back((const char*)tuple[0].S());
}
//vector<int/ double/ string> 转换 HTuple
for (size_t i = 0; i < _vInt->size(); i++)
{
tuple.Append((HTuple)_vInt->at(i));
}
for (size_t i = 0; i < _vDouble->size(); i++)
{
tuple.Append((HTuple)_vDouble->at(i));
}
for (size_t i = 0; i < _vString->size(); i++)
{
tuple.Append((HTuple)_vString->at(i));
}
delete[]_vInt;
_vInt = nullptr;
delete[] _vDouble;
_vDouble = nullptr;
delete[] _vString;
_vString = nullptr;
//HTuple 与 数组转换
int _iArray[10];
for (size_t i = 0; i < 10; i++)
{
tuple[i] = (HTuple)_iArray[i];
}
double _dArray[10];
for (size_t i = 0; i < 10; i++)
{
tuple[i] = (HTuple)_dArray[i];
}
const char* _strArray[10];
for (size_t i = 0; i < 10; i++)
{
tuple[i] = (HTuple)_strArray[i];
}
更多推荐
已为社区贡献1条内容
所有评论(0)