SICK 3D相机 Ranger 图像输入转换为Halcon图像

private void SickBufferToHalconImage(Sick.Icon.IIconBuffer SickBuffer)
{
    HalconDotNet.HObject HalconImage = null;
    try
    {
        for (int i = 0; i < SickBuffer.Components.Count();  i++)
        {
            for(int j = 0; j < SickBuffer.Components[i].SubComponents.Count(); j++)
            {
                int ImageWidth  = SickBuffer.Components[i].SubComponents[j].Format.Width;
                int ImageHeight = SickBuffer.Components[i].SubComponents[j].Height;
                var RawImage    = new HalconDotNet.HImage();
                        
                switch(SickBuffer.Components[i].SubComponents[j].Format.ValueType)         
                {
                     case "WORD":
                     {
                          ushort[,] Ranger2D = SickBuffer.Components[i].SubComponents[j].GetRows(0, ImageHeight);
                          unsafe
                          {
                               fixed (ushort* pSrc = Ranger2D)
                               {
                                    RawImage.GenImage1("uint2", ImageWidth, ImageHeight, new System.IntPtr(pSrc));
                                }
                          }
                      }
                      break;
                            case "FLOAT":
                                {
                                    float[,] Ranger2D = SickBuffer.Components[i].SubComponents[j].GetRows(0, ImageHeight);
                                    unsafe
                                    {
                                        fixed (float* pSrc = Ranger2D)
                                        {
                                            RawImage.GenImage1("real", ImageWidth, ImageHeight, new System.IntPtr(pSrc));
                                        }
                                    }
                                }
                                break;
                            case "BYTE":
                                {
                                    byte[,] Ranger2D = SickBuffer.Components[i].SubComponents[j].GetRows(0, ImageHeight);
                                    unsafe
                                    {
                                        fixed (byte* pSrc = Ranger2D)
                                        {
                                            RawImage.GenImage1("byte", ImageWidth, ImageHeight, new System.IntPtr(pSrc));
                                        }
                                    }
                                }
                                break;
                            case "INT":
                                {
                                    int[,] Ranger2D = SickBuffer.Components[i].SubComponents[j].GetRows(0, ImageHeight);
                                    this.m_MarkDataDictionary.Add(SickBuffer.Components[i].Format.Name + " - " + SickBuffer.Components[i].SubComponents[j].Format.Name, Ranger2D);
                                }
                                break;
                            default:
                                continue;
                        }

                        if(!SickBuffer.Components[i].SubComponents[j].Format.Name.Contains("Mark"))
                        {
                            HalconDotNet.HOperatorSet.MirrorImage(RawImage, out HalconImage, "column");
                            RawImage.Dispose();
                            RawImage = null;
                            this.m_InputImageDictionary.Add(SickBuffer.Components[i].Format.Name + " - " + SickBuffer.Components[i].SubComponents[j].Format.Name, HalconImage);
                        }
                        this.comboBox1.Items.Add(SickBuffer.Components[i].Format.Name + " - " + SickBuffer.Components[i].SubComponents[j].Format.Name);
                    }
                }
            }
            catch
            {
                throw;
            }
        }

 

你可能感兴趣的:(HALCON,CSharp,#,SICK,Ranger)