Beispiel #1
0
        public void funcMeasureLineDistance()
        {
            viewPort.Focus();

            HWindow window = viewPort.hvppleWindow;

            HWndMessage message = new HWndMessage(clsWellsLanguage.getString(126), 20, 20, 20, "green", "window");

            message.DispMessage(window, message.coordSystem, 1);

            isStaticWnd = true;

            viewPort.ContextMenuStrip = null;

            double r1, c1, r2, c2;
            HTuple dd;

            //获取当前显示信息
            HTuple hv_Red = null, hv_Green = null, hv_Blue = null;
            int    hv_lineWidth;

            window.GetRgb(out hv_Red, out hv_Green, out hv_Blue);

            hv_lineWidth = (int)window.GetLineWidth();
            string hv_Draw = window.GetDraw();

            window.SetLineWidth(1);   //设置线宽
            window.SetLineStyle(new HTuple());
            window.SetColor("green"); //画点的颜色

            window.DrawLine(out r1, out c1, out r2, out c2);
            window.DispLine(r1, c1, r2, c2);

            //恢复窗口显示信息
            window.SetRgb(hv_Red, hv_Green, hv_Blue);
            window.SetLineWidth(hv_lineWidth);
            window.SetDraw(hv_Draw);


            HOperatorSet.DistancePp(r1, c1, r2, c2, out dd);
            double dr = Math.Abs(r2 - r1);
            double dc = Math.Abs(c2 - c1);

            Wells.class_Public.Show(null, string.Format(clsWellsLanguage.getString(127), dd.D, dc, dr), clsWellsLanguage.getString(128), MessageBoxButtons.OK, MessageBoxIcon.Information);


            viewPort.ContextMenuStrip = hv_MenuStrip;

            isStaticWnd = false;

            repaint(window);
        }
Beispiel #2
0
        /// <summary>
        /// here do selecShape both for imageThresholded and imageCropped
        /// for imageCropped is only for display on the screen, bigger and clear to check for user
        /// </summary>
        /// <param name="WindowControl"></param>
        /// <param name="image_C"></param>
        /// <param name="Region_T"></param>
        /// <param name="Region_C"></param>
        /// <param name="hWindowHandle"></param>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="SRegion_T"></param>
        /// <param name="SRegion_C"></param>
        public void selectShape(HWindowControl WindowControl, ref HObject image_C, ref HObject Region_T, ref HObject Region_C, HTuple hWindowHandle, HTuple min,
                                HTuple max, out HObject SRegion_T, out HObject SRegion_C)
        {
            WindowControl.Focus();

            if (!m_tools.ObjectValided(Region_T))
            {
                SRegion_T = null;
                SRegion_C = null;
                return;
            }
            try
            {
                HOperatorSet.GenEmptyObj(out connectRegion_T);  //initialize variable connectRegion_T (imageThresholded)
                HOperatorSet.GenEmptyObj(out connectRegion_C);  //initialize variable connectRegion_C (imageCropped)
                HOperatorSet.Connection(Region_T, out connectRegion_T);
                HOperatorSet.Connection(Region_C, out connectRegion_C);

                //Graphics set for display
                HOperatorSet.SetDraw(hWindowHandle, "fill");
                HOperatorSet.SetColor(hWindowHandle, "green");

                //ReduceImage
                HOperatorSet.GenEmptyObj(out SRegion_T);       //initialize variable SRegion_T
                HOperatorSet.GenEmptyObj(out SRegion_C);       //initialize variable SRegion_C
                SRegion_T.Dispose();
                SRegion_C.Dispose();
                HOperatorSet.SelectShape(connectRegion_T, out SRegion_T, "area", "and", min, max);
                HOperatorSet.SelectShape(connectRegion_C, out SRegion_C, "area", "and", min, max);

                //Union segmented regions
                HOperatorSet.Union1(SRegion_T, out SRegion_T);
                HOperatorSet.Union1(SRegion_C, out SRegion_C);

                //Refresh window; Select_shape region for imageCropped
                m_tools.Imgshow(image_C, hWindowHandle, image_C);
                HOperatorSet.DispObj(SRegion_C, hWindowHandle);

                //Release;
                connectRegion_T.Dispose();
                connectRegion_C.Dispose();
            }
            catch
            {
                SRegion_T = null;
                SRegion_C = null;
                return;
            }
        }
Beispiel #3
0
        public void DrawRectangel(HWindowControl WindowControl, HObject Image, HTuple hWindowHandle, ref HObject Region, ref HObject ImageReduced, ref HObject ImageCroped)
        {
            WindowControl.Focus();
            if (!ObjectValided(Image))
            {
                MessageBox.Show("Image Invalid");
                return;
            }

            try
            {
                HOperatorSet.GenEmptyObj(out ImageCroped);
                HOperatorSet.GenEmptyObj(out ImageReduced);     //初始化图像变量ImageReduced
                HOperatorSet.GenEmptyObj(out Region);           //初始化图像变量Region

                HTuple Row1, Col1, Row2, Col2;                  //初始化参数变量

                //提示信息
                disp_message(hWindowHandle, "Draw ROI,click right mouse to confirm", "window", 20, 20, "red", "true");

                //draw_rectangle1
                HOperatorSet.DrawRectangle1(hWindowHandle, out Row1, out Col1, out Row2, out Col2);

                //gen_rectangle1
                Region.Dispose();
                HOperatorSet.GenRectangle1(out Region, Row1, Col1, Row2, Col2);

                //reduce_domain
                ImageReduced.Dispose();
                ImageCroped.Dispose();
                HOperatorSet.ReduceDomain(Image, Region, out ImageReduced);
                HOperatorSet.CropDomain(ImageReduced, out ImageCroped);   //裁剪图片

                //显示
                HOperatorSet.DispObj(Image, hWindowHandle);
                HOperatorSet.DispObj(Region, hWindowHandle);

                disp_message(hWindowHandle, "Draw ROI complete", "window", 20, 20, "blue", "true");

                //生命周期释放
                //Region.Dispose();
                //ImageReduced.Dispose();
                //ImageCroped.Dispose();
            }
            catch
            {
            }
        }
Beispiel #4
0
        public void CrossDisp(HWindowControl WindowControl, HObject Image, HTuple hWindowHandle)
        {
            WindowControl.Focus();
            try
            {
                HOperatorSet.GenEmptyObj(out CrossCenter_R);      //初始化图像变量CrossCenter
                CrossCenter_R.Dispose();
                HOperatorSet.GenCrossContourXld(out CrossCenter_R, RowCenter_R, ColCenter_R, 35, 0);

                //刷新图形
                HOperatorSet.DispObj(Image, hWindowHandle);
                HOperatorSet.SetColor(hWindowHandle, "red");    //单独设置CrossCenter的颜色     //修改颜色5
                HOperatorSet.DispObj(CrossCenter_R, hWindowHandle);

                //生命周期释放
                CrossCenter_R.Dispose();
            }
            catch
            {
            }
        }
Beispiel #5
0
        //HObject C_Region
        #endregion

        #region Threshold 函数
        public void HThreshold(HWindowControl WindowControl, ref HObject image_R, ref HObject image_C, HTuple hWindowHandle, HTuple minGray,
                               HTuple maxGray, ref HObject R_Region, ref HObject C_Region)
        {
            WindowControl.Focus();

            if (!m_tools.ObjectValided(image_R))
            {
                return;
            }
            try
            {
                //图像设置‘线宽与填充模式’
                HOperatorSet.SetDraw(hWindowHandle, "fill");
                HOperatorSet.SetColor(hWindowHandle, "green");  //添加代码4

                //ReduceImage
                HOperatorSet.GenEmptyObj(out R_Region);       //初始化图像变量C_Region
                HOperatorSet.GenEmptyObj(out C_Region);       //初始化图像变量C_Region
                R_Region.Dispose();
                C_Region.Dispose();
                HOperatorSet.Threshold(image_R, out R_Region, minGray, maxGray);
                HOperatorSet.Threshold(image_C, out C_Region, minGray, maxGray);

                HOperatorSet.FillUp(R_Region, out R_Region);
                HOperatorSet.FillUp(C_Region, out C_Region);

                //刷新图形
                m_tools.Imgshow(image_C, hWindowHandle, image_C);
                HOperatorSet.DispObj(C_Region, hWindowHandle);

                //生命周期释放
                //image_R.Dispose();
                //R_Region.Dispose();
            }
            catch
            {
            }
        }
Beispiel #6
0
        private void ShowHistogram_strip_Click(object sender, EventArgs e)
        {
            viewPort.Focus();
#if NativeCode
            ShowUnit.ShowText(viewPort.HalconWindow, "鼠标左键点击并拉取矩形区域,鼠标右键完成", 20, 20, 20, "green", "window");
#else
            HWndMessage message = new HWndMessage("鼠标左键点击并拉取矩形区域,鼠标右键完成", 20, 20, 20, "green");
            message.DispMessage(viewPort.HalconWindow, "window", 1);
#endif
            inMeasureLine             = true;
            viewPort.ContextMenuStrip = null;
            double r1, c1, r2, c2;
            //HTuple dd;

            //获取当前显示信息
            HTuple  hv_Red = null, hv_Green = null, hv_Blue = null;
            int     hv_lineWidth;
            HWindow window = viewPort.HalconWindow;
            window.GetRgb(out hv_Red, out hv_Green, out hv_Blue);
            hv_lineWidth = (int)window.GetLineWidth();
            string hv_Draw = window.GetDraw();

            window.SetLineWidth(1);   //设置线宽
            window.SetLineStyle(new HTuple());
            window.SetColor("green"); //画点的颜色


            window.DrawRectangle1(out r1, out c1, out r2, out c2);
            window.DispRectangle1(r1, c1, r2, c2);
            Form frm = new Form();

            FunctionPlotUnit pointUnit = new FunctionPlotUnit();
            Size             size      = pointUnit.Size;
            size.Height = (int)(size.Height + 50);
            size.Width  = (int)(size.Width + 50);
            frm.Size    = size;
            frm.Controls.Add(pointUnit);
            pointUnit.Dock = DockStyle.Fill;
            HTuple grayVals;
#if NativeCode
            grayVals = Wrapper.ShowUnit.GetGrayHisto(viewPort.HalconWindow, new HTuple(r1, c1, r2, c2));
#else
            grayVals = GetGrayHisto(new HTuple(r1, c1, r2, c2));
#endif
            pointUnit.SetAxisAdaption(FunctionPlot.AXIS_RANGE_INCREASING);
            pointUnit.SetLabel("灰度值", "频率");
            pointUnit.SetFunctionPlotValue(grayVals);

            pointUnit.ComputeStatistics(grayVals);

            frm.ShowDialog();


            //window.DrawLine(out r1, out c1, out r2, out c2);
            //window.DispLine(r1, c1, r2, c2);


            //恢复窗口显示信息
            window.SetRgb(hv_Red, hv_Green, hv_Blue);
            window.SetLineWidth(hv_lineWidth);
            window.SetDraw(hv_Draw);


            //HOperatorSet.DistancePp(r1, c1, r2, c2, out dd);
            //double dr = Math.Abs(r2 - r1);
            //double dc = Math.Abs(c2 - c1);
            //MessageBox.Show(string.Format("直线距离{0:f2}px\rx轴距离{1:f2}px\ry轴距离{2:f2}px", dd.D, dc, dr), "结果", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //hv_MenuStrip.Visible = true;
            viewPort.ContextMenuStrip = hv_MenuStrip;
            inMeasureLine             = false;
            Repaint();
        }
Beispiel #7
0
 public static void mouseenter(HWindowControl HW)
 {
     HW.Focus();
     //OperateClass.resetPic(HW);
 }