Halcon C# 数据类型转换

HObject ==> HImage

  // 灰度图片
  public static void HObjectToHImage(HObject hObject, ref HImage image)
  {
      HTuple pointer, type, width, height;
      HOperatorSet.GetImagePointer1(hObject, out pointer, out type, out width, out height);
      image.GenImage1(type, width, height, pointer);
  }


  // 彩色图片
  public static void HObjectToRGBHImage(HObject hobject, ref HImage image)
  {
      HTuple pointerRed, pointerGreen, pointerBlue, type, width, height;
      HOperatorSet.GetImagePointer3(hobject, out pointerRed, out pointerGreen, out pointerBlue, out type, out width, out height);
      image.GenImage3(type, width, height, pointerRed, pointerGreen, pointerBlue);
  }

HObject ==> HRegion

HRegion hRegion = new HRegion(ho_ResultAllRegion);

HImage/ HRegion ==> HObject

因为HObject是父类,所以一般不需要类型转换,可以直接替换

HTuple ==> int、double 等

int ErrorCode = hv_ErroCode.I;   // HTuple ==> int
string message = hv_Message.S; // HTuple ==> string
        //
        // 摘要:
        //     Convenience accessor for tuple[0].S
        public string S { get; set; }
        //
        // 摘要:
        //     Convenience accessor for tuple[0].D
        public double D { get; set; }
        //
        // 摘要:
        //     Convenience accessor for tuple[0].L
        public long L { get; set; }
        //
        // 摘要:
        //     Convenience accessor for tuple[0].I
        public int I { get; set; }
        //
        // 摘要:
        //     Exposes the internal array representation to allow most efficient (but not safest)
        //     access. Tuple type must be HTupleType.MIXED. It is not recommended to modify
        //     the array. If you do make sure to only store supported element types int, long,
        //     double, string and HHandle. The array length may be greater than the used tuple
        //     length.
        [EditorBrowsable(EditorBrowsableState.Never)]
        public object[] OArr { get; }
        //
        // 摘要:
        //     Exposes the internal array representation to allow most efficient (but not safest)
        //     access. Tuple type must be HTupleType.STRING. The array length may be greater
        //     than the used tuple length.
        public string[] SArr { get; set; }
        //
        // 摘要:
        //     Convenience accessor for tuple[0].H
        public object O { get; set; }
        //
        // 摘要:
        //     Exposes the internal array representation to allow most efficient (but not safest)
        //     access. Tuple type must be HTupleType.DOUBLE. The array length may be greater
        //     than the used tuple length.
        public double[] DArr { get; set; }
        //
        // 摘要:
        //     Exposes the internal array representation to allow most efficient (but not safest)
        //     access. Tuple type must be HTupleType.LONG. The array length may be greater than
        //     the used tuple length.
        public long[] LArr { get; set; }
        //
        // 摘要:
        //     Exposes the internal array representation to allow most efficient (but not safest)
        //     access. Tuple type must be HTupleType.INTEGER. The array length may be greater
        //     than the used tuple length.
        public int[] IArr { get; set; }

版权声明:本文为weixin_45875105原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。