VisionPro与C# 图像显示十字光标

程序通过 CogRecordDisplay 显示控件显示视觉运行结果图像,当我们对调试时,可能需要用到图像中心十字对位光标。

本文通过VisionPro两个拟合线工具,一个拟合圆工具在图像中画出光标,具体代码如下:

using System.Windows.Forms;
using Cognex.VisionPro;
using Cognex.VisionPro.ToolBlock;

        /// <summary>
        /// 界面显示十字光标
        /// </summary>
        /// <param name="cogDisplay"></param>
        /// <param name="camPixX"></param>
        /// <param name="camPixY"></param>
        private void DrawCross(CogRecordDisplay cogDisplay, double camPixX, double camPixY)
        {
            try
            {
                CogLine vLine = new CogLine();//竖线
                CogLine hLine = new CogLine();//横线
                CogCircle CenterCircle = new CogCircle();
                double centerPixX = camPixX / 2;
                double centerPixY = camPixY / 2;
                vLine.Color = CogColorConstants.Red;
                hLine.Color = CogColorConstants.Red;
                CenterCircle.Color = CogColorConstants.Red;
                CenterCircle.CenterX = centerPixX;
                CenterCircle.CenterY = centerPixY;
                CenterCircle.Radius = 100;
                vLine.SetFromStartXYEndXY(centerPixX, 0, centerPixX, camPixY);
                hLine.SetFromStartXYEndXY(0, centerPixY, camPixX, centerPixY);
                cogDisplay.InteractiveGraphics.Clear();
                cogDisplay.InteractiveGraphics.Add(vLine, "vline", true);
                cogDisplay.InteractiveGraphics.Add(hLine, "hline", true);
            }
            catch (Exception ex)
            {

            }
        }

相互学习,共同富裕。

猜你喜欢

转载自blog.csdn.net/m0_62778855/article/details/125999332
今日推荐