public void MPSizectorBufferToHalconIcon(MPSizectorDotNet.MP3DFrameManaged ImgBuffer,
out HalconDotNet.HObject ImgX,
out HalconDotNet.HObject ImgY,
out HalconDotNet.HObject ImgZ,
out HalconDotNet.HObject ImgMask,
out HalconDotNet.HObject ImgGray,
out HalconDotNet.HTuple Obj3DHandle)
{
// 输出初始化
ImgX = null;
ImgY = null;
ImgZ = null;
ImgMask = null;
ImgGray = null;
Obj3DHandle = null;
if (ImgBuffer == null)
return;
var ImgWidth = ImgBuffer.SensorWidth;
var ImgHeight = ImgBuffer.SensorHeight;
var DataX = new float[ImgWidth * ImgHeight];
var DataY = new float[DataX.Length];
var DataZ = new float[DataX.Length];
var DataMask = new byte[DataX.Length];
var DataGray = new byte[DataX.Length];
try
{
unsafe
{
fixed (MPSizectorDotNet.MP3DDataStruct* pData = ImgBuffer.Data)
{
fixed (float* pDataX = DataX, pDataY = DataY, pDataZ = DataZ)
{
for (int index = 0; index < DataX.Length; index++)
{
if ((pData + index)->Mask == 0)
{
*(pDataX + index) = (pData + index)->X;
*(pDataY + index) = (pData + index)->Y;
*(pDataZ + index) = (pData + index)->Z;
}
else
{
*(pDataX + index) = float.NaN;
*(pDataY + index) = float.NaN;
*(pDataZ + index) = float.NaN;
}
}
HalconDotNet.HOperatorSet.GenImage1(out this.ImgX, "real", ImgWidth, ImgHeight, new System.IntPtr(pDataX));
HalconDotNet.HOperatorSet.GenImage1(out this.ImgY, "real", ImgWidth, ImgHeight, new System.IntPtr(pDataY));
HalconDotNet.HOperatorSet.GenImage1(out this.ImgZ, "real", ImgWidth, ImgHeight, new System.IntPtr(pDataZ));
}
fixed (byte* pDataMask = DataMask, pDataGray = DataGray)
{
for (int index = 0; index < DataX.Length; index++)
{
*(pDataMask + index) = (pData + index)->Mask;
*(pDataGray + index) = (pData + index)->Gray;
}
HalconDotNet.HOperatorSet.GenImage1(out this.ImgMask, "byte", ImgWidth, ImgHeight, new System.IntPtr(pDataMask));
HalconDotNet.HOperatorSet.GenImage1(out this.ImgGray, "byte", ImgWidth, ImgHeight, new System.IntPtr(pDataGray));
}
}
}
// 创建3D模型
// Points where one of the coordinates is infinity or "Not a Number" (NaN) are ignored and not added to the 3D object model.
HalconDotNet.HOperatorSet.GenObjectModel3dFromPoints(new HalconDotNet.HTuple(DataX), new HalconDotNet.HTuple(DataY), new HalconDotNet.HTuple(DataZ), out Obj3DHandle);
}
catch
{
throw;
}
}
盛相3D相机转HALCON图像
于 2019-04-19 09:24:58 首次发布