上位机模块之halcon绘制ROI与获取ROI,在hsmartwindow实现

在上位机中通常需要使用到绘制ROI模块或者获取已经绘制好的ROI区域的参数,在这里通过使用hsmartwindow窗体控件进行对ROI的绘制和获取。

先上代码:

csharp 复制代码
/// <summary>
        /// 创建ROI
        /// </summary>
        /// <param name="Win">传入HSmartWindowControl</param>
        /// <param name="ROItype">需要绘制的ROI类型</param>
        /// <param name="drawingObject">绘制好的ROI参数,传出</param>
        public void Set_DrawHalconROI(HSmartWindowControl Win, HDrawingObject.HDrawingObjectType ROItype, out HDrawingObject drawingObject
                                        )
        {
            switch (ROItype)
            {
                case HDrawingObject.HDrawingObjectType.CIRCLE:
                    drawingObject = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.CIRCLE, 500, 500, 300);
                    Win.HalconWindow.AttachDrawingObjectToWindow(drawingObject);
                    break;

                case HDrawingObject.HDrawingObjectType.RECTANGLE2:
                    drawingObject = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.RECTANGLE2, 500, 500, 0, 500, 500);
                    Win.HalconWindow.AttachDrawingObjectToWindow(drawingObject);
                    break;

                case HDrawingObject.HDrawingObjectType.LINE:
                    drawingObject = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.LINE, 200, 200, 500, 500);
                    Win.HalconWindow.AttachDrawingObjectToWindow(drawingObject);
                    break;
                default:
                    drawingObject = null;
                    break;
            }
        }
csharp 复制代码
/// <summary>
        /// 获取ROI参数
        /// </summary>
        /// <param name="ROItype">需要输入的ROI类型</param>
        /// <param name="drawingObject">传入的ROI对象参数</param>
        /// <param name="Result">输出结果double数组</param>
        /// <param name="HROI">输出ROI形状,Hobject类型</param>
        public void Get_DrawHalconROI(HDrawingObject.HDrawingObjectType ROItype, HDrawingObject drawingObject
                                        , out double[] Result, out HObject HROI)
        {
            HTuple paramName = new HTuple(), param = new HTuple();
            string[] paramlist = new string[10];
            switch (ROItype)
            {
                case HDrawingObject.HDrawingObjectType.RECTANGLE2:
                    paramlist = new string[] { "row", "column", "phi", "length1", "length2" };
                    paramName = paramlist;
                    param = drawingObject.GetDrawingObjectParams(paramName);
                    HOperatorSet.GenRectangle2(out HROI, param.DArr[0], param.DArr[1], param.DArr[2], param.DArr[3], param.DArr[4]);
                    Result = param.DArr;
                    break;

                case HDrawingObject.HDrawingObjectType.CIRCLE:

                    paramlist = new string[] { "row", "column", "radius" };
                    paramName = paramlist;
                    param = drawingObject.GetDrawingObjectParams(paramName);
                    HOperatorSet.GenCircle(out HROI, param.DArr[0], param.DArr[1], param.DArr[2]);
                    Result = param.DArr;
                    break;
                case HDrawingObject.HDrawingObjectType.LINE:
                    paramlist = new string[] { "row1", "column1", "row2", "column2" };
                    paramName = paramlist;
                    param = drawingObject.GetDrawingObjectParams(paramName);
                    HOperatorSet.GenRegionLine(out HROI, param.DArr[0], param.DArr[1], param.DArr[2], param.DArr[3]);
                    Result = param.DArr;
                    break;
                default:
                    Result = new double[] { 0 };
                    HROI = null;
                    break;
            }
        }

实际效果:


延申说明:

1.Halcon自带的.netROI是通过调用HDrawingObject中的算子实现的,获取ROI同样也是,如何去得到延申的其他ROI。在Halcon的帮助文档中,搜索SetDrawingObjectParams并在.net格式中我们可以找到halcon所支持的全部ROI区域的参数,我们根据区域参数去获取即可。

注意事项:

1.我们在编写的时候一定要主语获取的ROI的变量名称是否输入错误。我们在传入获取的参数名称需要与文档中的参数名称一一对应,并且大小写不能错误。

相关推荐
bluefox197940 分钟前
使用 Oracle.DataAccess.Client 驱动 和 OleDB 调用Oracle 函数的区别
开发语言·c#
鲤籽鲲2 小时前
C# MethodTimer.Fody 使用详解
开发语言·c#·mfc
工业3D_大熊3 小时前
3D可视化引擎HOOPS Luminate场景图详解:形状的创建、销毁与管理
java·c++·3d·docker·c#·制造·数据可视化
yngsqq3 小时前
c#使用高版本8.0步骤
java·前端·c#
hccee6 小时前
C# IO文件操作
开发语言·c#
广煜永不挂科8 小时前
Devexpress.Dashboard的调用二义性
c#·express
初九之潜龙勿用10 小时前
C#校验画布签名图片是否为空白
开发语言·ui·c#·.net
GOTXX10 小时前
基于Opencv的图像处理软件
图像处理·人工智能·深度学习·opencv·卷积神经网络
xrgs_shz11 小时前
MATLAB读入不同类型图像并显示图像和相关信息
图像处理·计算机视觉·matlab
吾与谁归in11 小时前
【C#设计模式(13)——代理模式(Proxy Pattern)】
设计模式·c#·代理模式