Qt 如何从QVariant中提取二维单精度浮点数组?

Qt 如何从QVariant中提取二维单精度浮点数组?,qt,multidimensional-array,variant,qvariant,Qt,Multidimensional Array,Variant,Qvariant,我正在使用Qt中的ThermoVision SDK与FLIR A320红外摄像机进行通信。ThermoVision SDK基于ActiveX。使用GetImage方法从相机检索图像时遇到问题,根据手册,该方法可按以下方式使用: Image = Object.GetImage(imageType) 图像类型为VARIANT,包含带有图像像素的二维数组或错误代码(简称)。imageType确定像素的类型(16位无符号整数、单精度浮点或8位无符号整数) 我在Qt中工作,因此我通过dumpcpp.ex

我正在使用Qt中的ThermoVision SDK与FLIR A320红外摄像机进行通信。ThermoVision SDK基于ActiveX。使用GetImage方法从相机检索图像时遇到问题,根据手册,该方法可按以下方式使用:

Image = Object.GetImage(imageType)
图像类型为VARIANT,包含带有图像像素的二维数组或错误代码(简称)。imageType确定像素的类型(16位无符号整数、单精度浮点或8位无符号整数)

我在Qt中工作,因此我通过dumpcpp.exe为ActiveX组件创建了一个包装器。不幸的是,GetImage方法现在返回的是QVariant而不是VARIANT:

inline QVariant LVCam::GetImage(int imageType)
{
    QVariant qax_result;
    void *_a[] = {(void*)&qax_result, (void*)&imageType};
    qt_metacall(QMetaObject::InvokeMetaMethod, 46, _a);
    return qax_result;
}
我调用GetImage方法如下:

QVariant vaIm = m_ircam->GetImage(20 + 3);
如何访问QVariant中的像素,例如,将其转换为二维浮点数数组?我尝试使用QVariant::toFloat()、QVariant::toByteArray()、QVariant::toList()等方法,但它们似乎都没有返回图像数据


任何帮助都将不胜感激。

函数返回内存地址,您需要从内存中获取值,因此需要知道图像的确切大小

试试这个:

auto width = m_ircam->GetCameraProperty(66).toInt();
auto height = m_ircam->GetCameraProperty(67).toInt();

auto hMem = reinterpret_cast<HGLOBAL>(m_ircam->GetImage(20 + 3).toInt());
auto pSrc = reinterpret_cast<float*>(GlobalLock(hMem));

for(auto i = 0; i < width; ++i)
{
   for(auto j = 0; j < height; ++j)
   {
       arr[i][j] = pSrc[j * width + i]; //Assuming arr is a float[][]
   }
}

GlobalUnlock(hMem);
autowidth=m_ircam->GetCameraProperty(66).toInt();
自动高度=m_ircam->GetCameraProperty(67).toInt();
auto hMem=reinterpret_cast(m_ircam->GetImage(20+3).toInt());
自动pSrc=重新解释铸造(GlobalLock(hMem));
用于(自动i=0;i
Hi,你试过做一个简单的qDebug()吗