HALCON图像坐标与控件坐标相互转换

HALCON图像坐标与控件坐标相互转换

1.控件坐标转换到图像坐标

代码示例:

        public Point ControlPointToHImagePoint(this HSmartWindowControlWPF Halcon, double x, double y)
        {
            // Halcon 控件宽高
            double cHeight = Halcon.ActualHeight;
            double cWidth = Halcon.ActualWidth;
            // Halcon 图像在窗口上显示的区域
            double x0 = Halcon.HImagePart.X;
            double y0 = Halcon.HImagePart.Y;
            double imHeight = Halcon.HImagePart.Height;
            double imWidth = Halcon.HImagePart.Width;
            // 缩放系数
            double ratio_y = imHeight / cHeight;
            double ratio_x = imWidth / cWidth;
            double x1;
            double y1;
            x1 = (ratio_x * x) + x0;
            y1 = (ratio_y * y) + y0;
            return new Point(x1, y1);
        }

2.图像坐标转换到控件坐标

        public Point HImagePointToControlPoint(this HSmartWindowControlWPF Halcon, double x, double y)
        {
            // Halcon 控件宽高
            double cHeight = Halcon.ActualHeight;
            double cWidth = Halcon.ActualWidth;
            // Halcon 图像在窗口上显示的区域
            double x0 = Halcon.HImagePart.X;
            double y0 = Halcon.HImagePart.Y;
            double imHeight = Halcon.HImagePart.Height;
            double imWidth = Halcon.HImagePart.Width;
            // 缩放系数
            double ratio_y = imHeight / cHeight;
            double ratio_x = imWidth / cWidth;
            double x1;
            double y1;
            x1 = (x - x0) / ratio_x;
            y1 = (y - y0) / ratio_y;
            return new Point(x1, y1);
        }

3.HALCON灰度图像转换到byte[]数组

        public static void GetImageGrayValue(HImage ho_Image, out byte[] grayValue)
        {
            HOperatorSet.GetImagePointer1(ho_Image, out HTuple hv_Pointer, out HTuple hv_Type, out HTuple hv_Width, out HTuple hv_Height);
            int len = hv_Width * hv_Height;
            grayValue = new byte[len];
            Marshal.Copy(hv_Pointer, grayValue, 0, len);
            return;
        }

4.HALCON彩色图像转换到byte[]数组

        public static void GetImageMultiValue(HImage ho_Image, out byte[] R, out byte[] G, out byte[] B)
        {
            HOperatorSet.GetImagePointer3(ho_Image, out HTuple hv_PointerRed, out HTuple hv_PointerGreen, out HTuple hv_PointerBlue, out HTuple hv_Type, out HTuple hv_Width, out HTuple hv_Height);
            int len = hv_Width * hv_Height;
            R = new byte[len];
            G = new byte[len];
            B = new byte[len];
            Marshal.Copy(hv_PointerRed, R, 0, len);
            Marshal.Copy(hv_PointerGreen, G, 0, len);
            Marshal.Copy(hv_PointerBlue, B, 0, len);
            return;
        }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值