public void SetWindowHandle(PictureBox pictureBox)
        {
            HTuple FatherWindow = pictureBox.Handle;

            HOperatorSet.OpenWindow(0, 0, pictureBox.Width, pictureBox.Height, FatherWindow, "visible", "", out m_hvWindowHandle);
            HSystem.SetSystem("clip_region", "false");
        }
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        private void Repaint(HWindow window)
        {
            if (window.Handle == (IntPtr)0)
            {
                return;
            }
            //线程锁定
            lock (LockDisplay)
            {
                HObject obj;

                HSystem.SetSystem("flush_graphic", "false");
                window.ClearWindow();

                for (int i = 0; i < HObjList.Count; i++)
                {
                    obj = HObjList[i];
                    window.DispObj(obj);
                }

                //显示十字线
                if (IsDisplayCross)
                {
                    DisplayCross(window);
                }

                //显示Region和XLD
                ShowHObjectList(window);

                //显示所有ROI的合并区域
                if (IsGatherRegionShow)
                {
                    DisplayGatherRegion(window);
                }

                if (RoiController != null && (dispROI == MODE_INCLUDE_ROI))
                {
                    RoiController.PaintData(window);
                }

                //显示文本
                ShowTextList(window);

                //显示消息
                ShowMessageList(window);

                //显示待生成ROI的预览
                if (RoiController.ROI != null && RoiController.RoiDrawConfig.IsDrawPrepare)
                {
                    window.SetColor(RoiController.ActiveCol);            //设置颜色
                    window.SetLineStyle(new HTuple(new int[] { 2, 2 })); //设置显示为虚线
                    RoiController.ROI.Draw(window);                      //显示待生成的ROI
                }

                HSystem.SetSystem("flush_graphic", "true");

                window.SetColor("black");
                window.DispLine(-100.0, -100.0, -101.0, -101.0);
            }
        }
        /*********************************************************************
        * Construction and Deconstruction
        *********************************************************************/
        public HDisplayControl()
        {
            InitializeComponent();

            //DoubleBuffer:
            //UserPaint:
            //AllPaintingInWmPaint:
            //ResizeRedraw:
            this.SetStyle(ControlStyles.DoubleBuffer |
                          ControlStyles.OptimizedDoubleBuffer |
                          ControlStyles.AllPaintingInWmPaint |
                          ControlStyles.ResizeRedraw, true);

            HSystem.SetSystem("clip_region", "false");

            locker = new object();
            this.ImageViewState = ImageViewStates.fitToWindow;

            // Intialize ScrollBars and display modus of image
            hScrollBar1.Enabled = false;
            hScrollBar1.Value   = 0;
            vScrollBar1.Enabled = false;
            vScrollBar1.Value   = 0;


            // Initialize ToolBar
            toolStrip1.Width = viewPort.Location.X + viewPort.Width;

            // Region interaction
            this.EnabledROISetup = true;
        }
Example #4
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaint(hvppleDotNet.HWindow window)
        {
            try
            {
                int          count = HObjImageList.Count;
                HObjectEntry entry;

                HSystem.SetSystem("flush_graphic", "false");
                window.ClearWindow();
                mGC.stateOfSettings.Clear();

                //显示图片及文字
                showHObjectList();

                //显示region
                showHRegionList();

                //显示ROI
                showROIList();

                showHat(window);

                showBorder(window);

                HSystem.SetSystem("flush_graphic", "true");

                //注释了下面语句,会导致窗口无法实现缩放和拖动
                window.SetColor("dim gray");
                window.DispLine(-100.0, -100.0, -101.0, -101.0);
            }
            catch (Exception exc)
            {
            }
        }
        private bool StartupLicenseTest()
        {
            bool status = false;

            HImage  testImage  = new HImage();
            HRegion testRegion = new HRegion();

            try
            {
                // This will fail if we don't have a proper license
                testImage  = new HImage("byte", 16, 16);
                testRegion = testImage.Threshold(0.0, 255.0);

                HSystem.SetSystem("temporary_mem_cache", "false");  // This saves RAM significantly!
                HSystem.SetSystem("global_mem_cache", "idle");      // Likewise

                status = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " " + DateTime.Now);    // Display errors if any in a listbox
            }
            finally
            {
                testImage.Dispose();
                testRegion.Dispose();
            }

            return(status);
        }
Example #6
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaint(HalconDotNet.HWindow window)
        {
            int          count = HObjList.Count;
            HObjectEntry entry;

            HSystem.SetSystem("flush_graphic", "false");
            window.ClearWindow();
            mGC.stateOfSettings.Clear();

            for (int i = 0; i < count; i++)
            {
                entry = ((HObjectEntry)HObjList[i]);
                mGC.applyContext(window, entry.gContext);
                window.DispObj(entry.HObj);
            }

            addInfoDelegate();

            if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
            {
                roiManager.paintData(window);
            }

            HSystem.SetSystem("flush_graphic", "true");

            window.SetColor("black");
            window.DispLine(-100.0, -100.0, -101.0, -101.0);
        }
Example #7
0
        public void repaint()
        {
            HSystem.SetSystem("flush_graphic", "false");
            HWindow.ClearWindow();

            try
            {
                if (image != null)
                {
                    HWindow.DispObj(image);
                }

                HWindow.SetDraw("margin");
                HWindow.SetColor("red");

                if (region != null)
                {
                    HWindow.DispObj(region);
                }
            }
            catch (System.Exception ex)
            {
            }
            finally
            {
                HSystem.SetSystem("flush_graphic", "true");

                //注释了下面语句,会导致窗口无法实现缩放和拖动
                HWindow.SetColor("dim gray");
                HWindow.DispLine(-100.0, -100.0, -101.0, -101.0);
            }
        }
Example #8
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaint(HalconDotNet.HWindow window)

        {
            HSystem.SetSystem("flush_graphic", "false");
            window.ClearWindow();


            window.DispObj(ho_Image_Changed);

            if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
            {
                roiManager.paintData(window);
            }

            HSystem.SetSystem("flush_graphic", "true");

            window.SetColor("black");
            window.DispLine(-100.0, -100.0, -101.0, -101.0);

            if (ReDrawEvent != null)
            {
                ReDrawEvent();
            }
            mGC.stateOfSettings.Clear();
        }
Example #9
0
 /// <summary>
 /// 显示图像
 /// </summary>
 private void DisplayImage(HWindowControl hCtrl, IHalImage image)
 {
     if (hCtrl.InvokeRequired)
     {
         DisplayImageCallBack a = new DisplayImageCallBack(DisplayImage);
         hCtrl.Invoke(a, hCtrl, image);
         return;
     }
     else
     {
         if (System.Environment.TickCount - ticketNum > 33)
         {
             ticketNum = System.Environment.TickCount;
             try
             {
                 HSystem.SetSystem("flush_graphic", "false");
                 //hCtrl.HalconWindow.ClearWindow();
                 //if (image.Width != hCtrl.ImagePart.Width)
                 //    SetImagePart(hCtrl,0, 0, image.Height, image.Width);
                 hCtrl.HalconWindow.DispObj(image.SourceImage);
                 HSystem.SetSystem("flush_graphic", "true");
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.ToString());
             }
         }
     }
 }
 public void Repaint()
 {
     HSystem.SetSystem("flush_graphic", "false");
     RepaintWithoutGraphics();
     HSystem.SetSystem("flush_graphic", "true");
     HalconWindow.SetColor("black");
     HalconWindow.DispLine(-100.0, -100.0, -101.0, -101.0);
 }
Example #11
0
        /*******************************************************************/
        private void mouseMoved(object sender, hvppleDotNet.HMouseEventArgs e)
        {
            //关闭缩放事件
            if (isStaticWnd)
            {
                return;
            }

            double motionX = 0, motionY = 0;
            double posX, posY;
            double zoomZone;


            if (!mousePressed)
            {
                return;
            }

            if (roiManager != null && (roiManager.activeROIidx != -1) && (dispROI == MODE_INCLUDE_ROI))
            {
                roiManager.mouseMoveAction(e.X, e.Y);
            }
            else if (stateView == MODE_VIEW_MOVE)
            {
                if (imageShowWidth > viewPort.Width || imageShowHeight > viewPort.Height)
                {
                    motionX = ((e.X - startX));
                    motionY = ((e.Y - startY));
                    if (((int)motionX != 0) || ((int)motionY != 0))
                    {
                        moveImage(motionX, motionY);
                        startX = e.X - motionX;
                        startY = e.Y - motionY;
                    }
                }
            }
            else if (stateView == MODE_VIEW_ZOOMWINDOW)
            {
                HSystem.SetSystem("flush_graphic", "false");
                ZoomWindow.ClearWindow();


                posX     = ((e.X - ImgCol1) / (ImgCol2 - ImgCol1)) * viewPort.Width;
                posY     = ((e.Y - ImgRow1) / (ImgRow2 - ImgRow1)) * viewPort.Height;
                zoomZone = (zoomWndSize / 2) * xScale * zoomAddOn;

                ZoomWindow.SetWindowExtents((int)posY - (zoomWndSize / 2),
                                            (int)posX - (zoomWndSize / 2),
                                            zoomWndSize, zoomWndSize);
                ZoomWindow.SetPart((int)(e.Y - zoomZone), (int)(e.X - zoomZone),
                                   (int)(e.Y + zoomZone), (int)(e.X + zoomZone));
                repaint(ZoomWindow);

                HSystem.SetSystem("flush_graphic", "true");
                ZoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0);
            }
        }
 //刷新窗口
 public void RefreshWindow()
 {
     if (ho_image != null)
     {
         HSystem.SetSystem("flush_graphic", "false");
         HOperatorSet.ClearWindow(hWindowHandle);
         HSystem.SetSystem("flush_graphic", "true");
         HOperatorSet.DispObj(ho_image, hWindowHandle);
     }
 }
Example #13
0
        /*******************************************************************/
        private void mouseMoved(object sender, HalconDotNet.HMouseEventArgs e)
        {
            double motionX, motionY;
            double posX, posY;
            double zoomZone;

            PointF point = new PointF((float)e.X, (float)e.Y);

            if (m_event_disCurrentPoint != null)
            {
                m_event_disCurrentPoint(point);
            }

            if (!mousePressed)
            {
                return;
            }

            if (roiManager != null && (roiManager.activeROIidx != -1) && (dispROI == MODE_INCLUDE_ROI))
            {
                roiManager.mouseMoveAction(e.X, e.Y);
            }
            else if (stateView == MODE_VIEW_MOVE)
            {
                motionX = ((e.X - startX));
                motionY = ((e.Y - startY));

                if (((int)motionX != 0) || ((int)motionY != 0))
                {
                    moveImage(motionX, motionY);
                    startX = e.X - motionX;
                    startY = e.Y - motionY;
                }
            }
            else if (stateView == MODE_VIEW_ZOOMWINDOW)
            {
                HSystem.SetSystem("flush_graphic", "false");
                ZoomWindow.ClearWindow();


                posX     = ((e.X - ImgCol1) / (ImgCol2 - ImgCol1)) * viewPort.Width;
                posY     = ((e.Y - ImgRow1) / (ImgRow2 - ImgRow1)) * viewPort.Height;
                zoomZone = (zoomWndSize / 2) * zoomWndFactor * zoomAddOn;

                ZoomWindow.SetWindowExtents((int)posY - (zoomWndSize / 2),
                                            (int)posX - (zoomWndSize / 2),
                                            zoomWndSize, zoomWndSize);
                ZoomWindow.SetPart((int)(e.Y - zoomZone), (int)(e.X - zoomZone),
                                   (int)(e.Y + zoomZone), (int)(e.X + zoomZone));
                repaint(ZoomWindow);

                HSystem.SetSystem("flush_graphic", "true");
                ZoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0);
            }
        }
        private void MouseMove(object sender, HMouseEventArgsWPF e)
        {
            double motionX, motionY;
            double posX, posY;
            double zoomZone;

            //判断是否有待生成的ROI
            if (RoiController.ROI != null)
            {
                RoiController.ROI.CreateROI(e.Column, e.Row); //设置ROI位置
                Repaint();                                    //刷新显示
            }

            if (!mousePressed)
            {
                return;
            }

            if (RoiController != null && (RoiController.ActiveROIidx != -1) && (dispROI == MODE_INCLUDE_ROI))
            {
                RoiController.MouseMoveAction(e.Column, e.Row);
            }
            else if (stateView == MODE_VIEW_MOVE)
            {
                motionX = ((e.Column - startX));
                motionY = ((e.Row - startY));

                if (((int)motionX != 0) || ((int)motionY != 0))
                {
                    MoveImage(motionX, motionY);
                    startX = e.Column - motionX;
                    startY = e.Row - motionY;
                }
            }
            else if (stateView == MODE_VIEW_ZOOMWINDOW)
            {
                HSystem.SetSystem("flush_graphic", "false");
                ZoomWindow.ClearWindow();


                posX     = ((e.Column - ImgX) / (ImgWidth - ImgX)) * viewPort.ActualWidth;
                posY     = ((e.Row - ImgY) / (ImgHeight - ImgY)) * viewPort.ActualHeight;
                zoomZone = (zoomWndSize / 2) * zoomWndFactor * zoomAddOn;

                ZoomWindow.SetWindowExtents((int)posY - (zoomWndSize / 2),
                                            (int)posX - (zoomWndSize / 2),
                                            zoomWndSize, zoomWndSize);
                ZoomWindow.SetPart((int)(e.Row - zoomZone), (int)(e.Column - zoomZone),
                                   (int)(e.Row + zoomZone), (int)(e.Column + zoomZone));
                Repaint(ZoomWindow);

                HSystem.SetSystem("flush_graphic", "true");
                ZoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0);
            }
        }
Example #15
0
        private void ViewPort_HMouseMove(object sender, HMouseEventArgsWPF e)
        {
            if (stateView == MODE_ROI_Create)
            {
                return;
            }

            double motionX, motionY;
            double posX, posY;
            double zoomZone;
            int    a = roiManager.mouseMoveROI(e.Column, e.Row);//鼠标经过的index

            if (!mousePressed)
            {
                return;
            }

            if (roiManager != null && (roiManager.activeROIidx != -1) && (dispROI == MODE_INCLUDE_ROI))
            {
                roiManager.mouseMoveAction(e.Column, e.Row);
            }
            else if (stateView == MODE_VIEW_MOVE)
            {
                motionX = ((e.Column - startX));
                motionY = ((e.Row - startY));

                if (((int)motionX != 0) || ((int)motionY != 0))
                {
                    moveImage(motionX, motionY);
                    startX = e.Column - motionX;
                    startY = e.Row - motionY;
                }
            }
            else if (stateView == MODE_VIEW_ZOOMWINDOW)
            {
                HSystem.SetSystem("flush_graphic", "false");
                ZoomWindow.ClearWindow();


                posX     = ((e.Column - ImgCol1) / (ImgCol2 - ImgCol1)) * viewPort.ActualWidth;
                posY     = ((e.Row - ImgRow1) / (ImgRow2 - ImgRow1)) * viewPort.ActualHeight;
                zoomZone = (zoomWndSize / 2) * zoomWndFactor * zoomAddOn;

                ZoomWindow.SetWindowExtents((int)posY - (zoomWndSize / 2),
                                            (int)posX - (zoomWndSize / 2),
                                            zoomWndSize, zoomWndSize);
                ZoomWindow.SetPart((int)(e.Row - zoomZone), (int)(e.Column - zoomZone),
                                   (int)(e.Row + zoomZone), (int)(e.Column + zoomZone));
                repaint(ZoomWindow);

                HSystem.SetSystem("flush_graphic", "true");
                ZoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0);
            }
        }
Example #16
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaint(HalconDotNet.HWindow window, HObject obj)
        {
            HSystem.SetSystem("flush_graphic", "false");
            window.ClearWindow();

            window.DispObj(obj);

            HSystem.SetSystem("flush_graphic", "true");

            window.SetColor("black");
            window.DispLine(-100.0, -100.0, -101.0, -101.0);
        }
Example #17
0
        void ShowHat(HWindow window)
        {
            HSystem.SetSystem("flush_graphic", "true");
            if (isShowCross)
            {
                //获取当前显示信息
                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"); //十字架显示颜色
                double CrossCol = (double)imageWidth / 2.0, CrossRow = (double)imageHeight / 2.0;
                double borderWidth = (double)imageWidth / 50.0;
                CrossCol = (double)imageWidth / 2.0;
                CrossRow = (double)imageHeight / 2.0;
                //竖线1
                //window.DispLine(0, CrossCol, CrossRow - 50, CrossCol);

                //window.DispLine(CrossRow + 50, CrossCol, imageHeight, CrossCol);

                window.DispPolygon(new HTuple(0, CrossRow - 50), new HTuple(CrossCol, CrossCol));
                window.DispPolygon(new HTuple(CrossRow + 50, ImageHeight), new HTuple(CrossCol, CrossCol));


                //中心点
                window.DispPolygon(new HTuple(CrossRow - 2, CrossRow + 2), new HTuple(CrossCol, CrossCol));
                window.DispPolygon(new HTuple(CrossRow, CrossRow), new HTuple(CrossCol - 2, CrossCol + 2));

                //横线

                window.DispPolygon(new HTuple(CrossRow, CrossRow), new HTuple(0, CrossCol - 50));
                window.DispPolygon(new HTuple(CrossRow, CrossRow), new HTuple(CrossCol + 50, ImageWidth));


                //window.DispLine(CrossRow, 0, CrossRow, CrossCol - 50);
                //window.DispLine(CrossRow, CrossCol + 50, CrossRow, imageWidth);

                //恢复窗口显示信息
                window.SetRgb(hv_Red, hv_Green, hv_Blue);
                window.SetLineWidth(hv_lineWidth);
                window.SetDraw(hv_Draw);
            }
            else
            {
                window.SetColor(backguoundColor);
                window.DispLine(-100.0, -100.0, -101.0, -101.0);
            }
        }
Example #18
0
        /// <summary>
        /// 需要在相机回调函数中传入图像HObject对象
        /// </summary>
        /// <param name="ho_Image">图像HObject对象</param>
        public void DisplayContinuous(HImage ho_Image)
        {
            ho_Image.GetImageSize(out this.width, out this.height);
            HSystem.SetSystem("width", this.width);
            HSystem.SetSystem("height", this.height);
            this.hWinContinuous.HalconWindow.SetPart(0, 0, this.height - 1, this.width - 1);
            this.hWinContinuous.HalconWindow.DispObj(ho_Image);
            if (this.cTextBoxDesc.Text == "")
            {
                return;
            }

            HRegion ho_Calib = ho_Image.FindCaltab(this.cTextBoxDesc.Text, 3, 112, 5);

            this.hWinContinuous.HalconWindow.DispObj(ho_Calib);
            ho_Calib.Dispose();
        }
Example #19
0
        void ShowObject(HWindow window)
        {
            if (window.IsInitialized() == false)
            {
                return;
            }
            //关闭显示刷新
            HSystem.SetSystem("flush_graphic", "false");
            //窗体图像清空
            window.ClearWindow();
            mGC.stateOfSettings.Clear();
            try
            {
                //HTuple showStart;
                //HOperatorSet.CountSeconds(out showStart);

                int count1 = 0;
                foreach (var item in HObjList)
                {
                    if (ResultShow == ResultShow.原图 && count1 > 0)
                    {
                        break;
                    }
                    if (item.HObj != null && item.HObj.IsInitialized())
                    {
                        mGC.ApplyContext(window, item.gContext);
                        window.DispObj(item.HObj);
                    }
                    else if (item.Message != null && isShowMessage)
                    {
                        //item.Message.DispMessage(window, "image", ((double)imageWidth / (double)(viewPort.Width)) / ZoomWndFactor);
                        double sizeTmp = item.Message.CahangeDisplayFontSize(window, (1.0) / ZoomWndFactor, currentTextSize);
                        currentTextSize = sizeTmp;
                        item.Message.DispMessage(window, "image");
                    }
                    count1++;
                }
                //HTuple showEnd;
                //HOperatorSet.CountSeconds(out showEnd);
                //double timeShow = (showEnd - showStart) * 1000.0;
                //Util.Notify(string.Format("内部显示图像用时{0:f2}ms", timeShow));
            }
            catch (Exception)
            {; }
        }
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaintUsingFlushGraphic(HalconDotNet.HWindow window)
        {
            int          count = HObjList.Count;
            HObjectEntry entry;

            if (window != null)
            {
                HSystem.SetSystem("flush_graphic", "false");
                window.ClearWindow();
                // check the boundatries of the image part
                if ((ImgRow2 > ImgRow1) && (ImgCol2 > ImgCol1))
                {
                    window.SetPart((int)ImgRow1, (int)ImgCol1, (int)ImgRow2, (int)ImgCol2);
                }
                // set the image part to window size
                else
                {
                    window.SetPart(0, 0, windowHeight - 1, windowWidth - 1);
                }
                mGC.stateOfSettings.Clear();

                for (int i = 0; i < count; i++)
                {
                    entry = ((HObjectEntry)HObjList[i]);
                    if (entry != null)
                    {
                        mGC.applyContext(window, entry.gContext);
                        window.DispObj(entry.HObj);
                    }
                }

                addInfoDelegate();

                if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
                {
                    roiManager.paintData(window);
                }

                HSystem.SetSystem("flush_graphic", "true");

                window.DispLine(-1000.0, -1000.0, -1001.0, -1001.0);
            }
        }
        /// <summary>
        /// 重置放大鏡視窗
        /// </summary>
        /// <param name="e"></param>
        private void resetZoomWindow(HalconDotNet.HMouseEventArgs e)
        {
            HSystem.SetSystem("flush_graphic", "false");
            ZoomWindow.ClearWindow();
            double posX     = ((e.X - ImgCol1) / (ImgCol2 - ImgCol1)) * _viewPort.Width;
            double posY     = ((e.Y - ImgRow1) / (ImgRow2 - ImgRow1)) * _viewPort.Height;
            double zoomZone = (zoomWndSize / 2) * zoomWndFactor * zoomAddOn;

            ZoomWindow.SetWindowExtents((int)posY - (zoomWndSize / 2),
                                        (int)posX - (zoomWndSize / 2),
                                        zoomWndSize, zoomWndSize);
            ZoomWindow.SetPart((int)(e.Y - zoomZone), (int)(e.X - zoomZone),
                               (int)(e.Y + zoomZone), (int)(e.X + zoomZone));

            repaint(ZoomWindow);

            HSystem.SetSystem("flush_graphic", "true");
            ZoomWindow.DispLine(-100.0, -100.0, -100.0, -100.0);
        }
Example #22
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaint(HalconDotNet.HWindow window)
        {
            int h = imageHeight;

            if (window.IsInitialized() == false || viewPort.HalconID.ToInt32() == -1 || viewPort.ImagePart.Width <= 1 || viewPort.ImagePart.Height <= 1)
            {
                return;
            }
            int          count = HObjList.Count;
            HObjectEntry entry;

            HSystem.SetSystem("flush_graphic", "false");
            window.ClearWindow();
            mGC.stateOfSettings.Clear();

            for (int i = 0; i < count; i++)
            {
                entry = ((HObjectEntry)HObjList[i]);
                mGC.applyContext(window, entry.gContext);
                window.DispObj(entry.HObj);
            }

            addInfoDelegate();

            if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
            {
                roiManager.paintData(window);
            }

            HSystem.SetSystem("flush_graphic", "true");

            window.SetColor("black");
            window.DispLine(-100.0, -100.0, -101.0, -101.0);

            for (int i = 0; i < HMsgList.Count; i++)
            {
                if (HMsgList[i].Size != 0)
                {
                    set_display_font(viewPort.HalconID, HMsgList[i].Size, HMsgList[i].Font, HMsgList[i].Bold, HMsgList[i].Slant);
                }
                window.DispText(HMsgList[i].HMsg, HMsgList[i].coordSystem, HMsgList[i].row, HMsgList[i].column, HMsgList[i].color, HMsgList[i].genParamName, HMsgList[i].genParamValue);
            }
        }
Example #23
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaint(HalconDotNet.HWindow window)
        {
            try
            {
                int          count = HObjImageList.Count;
                HObjectEntry entry;

                HSystem.SetSystem("flush_graphic", "false");
                window.ClearWindow();
                mGC.stateOfSettings.Clear();

                //显示图片
                for (int i = 0; i < count; i++)
                {
                    entry = ((HObjectEntry)HObjImageList[i]);
                    mGC.applyContext(window, entry.gContext);
                    window.DispObj(entry.HObj);
                }

                //显示region
                showHObjectList();


                addInfoDelegate();

                if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
                {
                    roiManager.paintData(window);
                }


                HSystem.SetSystem("flush_graphic", "true");

                //注释了下面语句,会导致窗口无法实现缩放和拖动
                window.SetColor("black");
                window.DispLine(-100.0, -100.0, -101.0, -101.0);
            }
            catch (Exception)
            {
            }
        }
Example #24
0
        //3-手绘
        private void buttonModelByHand_Click(object sender, EventArgs e)
        {
            try
            {
                HTuple htNumber;
                try
                {
                    m_hoModelEdgesTemp.Dispose();
                }
                catch
                {
                }

                isDraw = true;
                HOperatorSet.GenEmptyObj(out m_hoModelEdgesTemp);
                HOperatorSet.CountObj(m_hoModedImage, out htNumber);
                HSystem.SetSystem("flush_graphic", "false");
                HOperatorSet.ClearWindow(m_htWindowHandle);
                HSystem.SetSystem("flush_graphic", "true");
                HOperatorSet.DispObj(m_hoModedImage, m_htWindowHandle);
                HOperatorSet.DispObj(m_hoModelEdges, m_htWindowHandle);
                if (0 != htNumber.I)
                {
                    m_hoModelEdgesTemp.Dispose();
                    HOperatorSet.SetColor(m_htWindowHandle, "red");
                    HOperatorSet.SetLineWidth(m_htWindowHandle, 3);
                    HObject region = null;
                    HOperatorSet.DrawRegion(out region, m_htWindowHandle);
                    HObject reduceImage = null;
                    HOperatorSet.ReduceDomain(m_hoModedImage, region, out reduceImage);
                    HOperatorSet.EdgesSubPix(reduceImage, out m_hoModelEdgesTemp, "canny", 1, 20, 70);
                    HOperatorSet.DispObj(m_hoModelEdgesTemp, m_htWindowHandle);
                }
                isDraw = false;
            }
            catch (HalconException ex)
            {
                MessageBox.Show("手绘出现异常,异常信息:" + ex.GetErrorMessage());
            }
        }
Example #25
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        private void repaint(HalconDotNet.HWindow window)
        {
            int count = HObjList.Count;

            if (count > 0)
            {
                HObjectEntry entry;
                HSystem.SetSystem("flush_graphic", "false");
                window.ClearWindow();
                mGC.stateOfSettings.Clear();
                for (int i = 0; i < count; i++)
                {
                    entry = ((HObjectEntry)HObjList[i]);
                    if (entry.colorShow.Length > 0)
                    {
                        window.SetColor(entry.colorShow);
                    }
                    mGC.applyContext(window, entry.gContext);
                    window.DispObj(entry.HObj);
                }
                if (roiManager != null)
                {
                    roiManager.paintData(window);
                }
                HSystem.SetSystem("flush_graphic", "true");
                window.DispLine(-100.0, -100.0, -101.0, -101.0);
            }
            count = StrList.Count;
            if (count > 0)
            {
                foreach (StringX strX in StrList)
                {
                    window.SetFont("-Consolas-" + strX.size.ToString() + "-*-" + (strX.bold ? "1" : "0") + "-*-*-" + (strX.slant ? "1" : "0") + "-");
                    window.SetColor(strX.color.Name.ToLower());
                    window.SetTposition(strX.row, strX.column);
                    window.WriteString(strX.str);
                }
            }
        }
Example #26
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaint(HalconDotNet.HWindow window)
        {
            int h = imageHeight;

            if (window.IsInitialized() == false || viewPort.HalconID.ToInt32() == -1 || viewPort.ImagePart.Width <= 1 || viewPort.ImagePart.Height <= 1)
            {
                return;
            }
            int          count = HObjList.Count;
            HObjectEntry entry;

            HSystem.SetSystem("flush_graphic", "false");
            window.ClearWindow();
            mGC.stateOfSettings.Clear();

            for (int i = 0; i < count; i++)
            {
                entry = ((HObjectEntry)HObjList[i]);
                mGC.applyContext(window, entry.gContext);
                window.DispObj(entry.HObj);
            }

            addInfoDelegate();

            if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
            {
                roiManager.paintData(window);
            }

            HSystem.SetSystem("flush_graphic", "true");

            //window.SetColor("black");
            //window.DispLine(-100.0, -100.0, -101.0, -101.0);

            window.SetDraw("fill");
            //window.SetColored(12);
            window.SetColor("green");
        }
Example #27
0
        private void buttonFindModel_Click(object sender, EventArgs e)
        {
            HSystem.SetSystem("flush_graphic", "false");
            HOperatorSet.ClearWindow(m_htWindowHandle);
            HSystem.SetSystem("flush_graphic", "true");
            HOperatorSet.DispObj(m_hoModedImage, m_htWindowHandle);
            try
            {
                if (m_htModelID == null || m_htModelID.Length == 0)
                {
                    return;
                }
                HObject            image     = m_hoModedImage.Clone();
                Variable.CamReturn camreturn = new Variable.CamReturn();
                HalconHelper.FindShapeModel(image, null, m_htModelID, ref camreturn, m_htWindowHandle, 0.6, 1);
                tRX.Text          = camreturn.X.ToString();
                tRY.Text          = camreturn.Y.ToString();
                this.tRAngle.Text = camreturn.Angle.ToString();


                double offsetX = (double)this.nOffsetX.Value * camreturn.XScale;
                double offsetY = (double)this.nOffsetY.Value * camreturn.YScale;

                double       deg   = -camreturn.Angle / 180.0 * Math.PI;
                PointContour outPt = new PointContour();
                outPt.X = camreturn.X + offsetX;
                outPt.Y = camreturn.Y + offsetY;

                var PTRotated = this.PtRotateDown(outPt, new PointContour(camreturn.X, camreturn.Y), -camreturn.Angle);
                HOperatorSet.SetColor(this.m_htWindowHandle, "green");
                HOperatorSet.DispCross(this.m_htWindowHandle, PTRotated.Y, PTRotated.X, 24, deg);
            }
            catch (HalconException ex)
            {
                MessageBox.Show("查找模板失败,失败信息:" + ex.GetErrorMessage());
            }
        }
Example #28
0
        private void Action()
        {
            double    S1, S2;
            HTuple    RowCheck, ColumnCheck, AngleCheck, Score;
            HHomMat2D Matrix = new HHomMat2D();
            HRegion   ModelRegionTrans;
            HTuple    Rect1RowCheck, Rect1ColCheck;
            HTuple    Rect2RowCheck, Rect2ColCheck;
            HRegion   Rectangle1 = new HRegion();
            HRegion   Rectangle2 = new HRegion();
            HMeasure  Measure1, Measure2;
            HTuple    RowEdgeFirst1, ColumnEdgeFirst1;
            HTuple    AmplitudeFirst1, RowEdgeSecond1;
            HTuple    ColumnEdgeSecond1, AmplitudeSecond1;
            HTuple    IntraDistance1, InterDistance1;
            HTuple    RowEdgeFirst2, ColumnEdgeFirst2;
            HTuple    AmplitudeFirst2, RowEdgeSecond2;
            HTuple    ColumnEdgeSecond2, AmplitudeSecond2;
            HTuple    IntraDistance2, InterDistance2;
            HTuple    MinDistance;
            int       NumLeads;

            HSystem.SetSystem("flush_graphic", "false");
            Img.GrabImage(Framegrabber);
            Img.DispObj(Window);

            // Find the IC in the current image.
            S1 = HSystem.CountSeconds();
            ShapeModel.FindShapeModel(Img, 0,
                                      new HTuple(360).TupleRad().D,
                                      0.7, 1, 0.5, "least_squares",
                                      4, 0.9, out RowCheck, out ColumnCheck,
                                      out AngleCheck, out Score);
            S2 = HSystem.CountSeconds();
            MatchingTimeLabel.Text = "Time: " +
                                     String.Format("{0,4:F1}", (S2 - S1) * 1000) + "ms";
            MatchingScoreLabel.Text = "Score: ";

            if (RowCheck.Length == 1)
            {
                MatchingScoreLabel.Text = "Score: " +
                                          String.Format("{0:F5}", Score.D);
                // Rotate the model for visualization purposes.
                Matrix.VectorAngleToRigid(new HTuple(Row), new HTuple(Column), new HTuple(0.0),
                                          RowCheck, ColumnCheck, AngleCheck);

                ModelRegionTrans = ModelRegion.AffineTransRegion(Matrix, "false");
                Window.SetColor("green");
                Window.SetDraw("fill");
                ModelRegionTrans.DispObj(Window);
                // Compute the parameters of the measurement rectangles.
                Matrix.AffineTransPixel(Rect1Row, Rect1Col,
                                        out Rect1RowCheck, out Rect1ColCheck);
                Matrix.AffineTransPixel(Rect2Row, Rect2Col,
                                        out Rect2RowCheck, out Rect2ColCheck);

                // For visualization purposes, generate the two rectangles as
                // regions and display them.
                Rectangle1.GenRectangle2(Rect1RowCheck.D, Rect1ColCheck.D,
                                         RectPhi + AngleCheck.D,
                                         RectLength1, RectLength2);
                Rectangle2.GenRectangle2(Rect2RowCheck.D, Rect2ColCheck.D,
                                         RectPhi + AngleCheck.D,
                                         RectLength1, RectLength2);
                Window.SetColor("blue");
                Window.SetDraw("margin");
                Rectangle1.DispObj(Window);
                Rectangle2.DispObj(Window);
                // Do the actual measurements.
                S1       = HSystem.CountSeconds();
                Measure1 = new HMeasure(Rect1RowCheck.D, Rect1ColCheck.D,
                                        RectPhi + AngleCheck.D,
                                        RectLength1, RectLength2,
                                        ImgWidth, ImgHeight, "bilinear");
                Measure2 = new HMeasure(Rect2RowCheck.D, Rect2ColCheck.D,
                                        RectPhi + AngleCheck.D,
                                        RectLength1, RectLength2,
                                        ImgWidth, ImgHeight, "bilinear");
                Measure1.MeasurePairs(Img, 2, 90,
                                      "positive", "all",
                                      out RowEdgeFirst1,
                                      out ColumnEdgeFirst1,
                                      out AmplitudeFirst1,
                                      out RowEdgeSecond1,
                                      out ColumnEdgeSecond1,
                                      out AmplitudeSecond1,
                                      out IntraDistance1,
                                      out InterDistance1);
                Measure2.MeasurePairs(Img, 2, 90,
                                      "positive", "all",
                                      out RowEdgeFirst2,
                                      out ColumnEdgeFirst2,
                                      out AmplitudeFirst2,
                                      out RowEdgeSecond2,
                                      out ColumnEdgeSecond2,
                                      out AmplitudeSecond2,
                                      out IntraDistance2,
                                      out InterDistance2);
                S2 = HSystem.CountSeconds();
                MeasureTimeLabel.Text = "Time: " +
                                        String.Format("{0,5:F1}", (S2 - S1) * 1000) + "ms";
                Window.SetColor("red");
                Window.DispLine(RowEdgeFirst1 - RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeFirst1 - RectLength2 * Math.Sin(AngleCheck),
                                RowEdgeFirst1 + RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeFirst1 + RectLength2 * Math.Sin(AngleCheck));
                Window.DispLine(RowEdgeSecond1 - RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeSecond1 - RectLength2 * Math.Sin(AngleCheck),
                                RowEdgeSecond1 + RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeSecond1 + RectLength2 * Math.Sin(AngleCheck));
                Window.DispLine(RowEdgeFirst2 - RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeFirst2 - RectLength2 * Math.Sin(AngleCheck),
                                RowEdgeFirst2 + RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeFirst2 + RectLength2 * Math.Sin(AngleCheck));
                Window.DispLine(RowEdgeSecond2 - RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeSecond2 - RectLength2 * Math.Sin(AngleCheck),
                                RowEdgeSecond2 + RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeSecond2 + RectLength2 * Math.Sin(AngleCheck));
                NumLeads             = IntraDistance1.Length + IntraDistance2.Length;
                MeasureNumLabel.Text = "Number of leads: " +
                                       String.Format("{0:D2}", NumLeads);
                MinDistance           = InterDistance1.TupleConcat(InterDistance2).TupleMin();
                MeasureDistLabel.Text = "Minimum lead distance: " +
                                        String.Format("{0:F3}", MinDistance.D);
                HSystem.SetSystem("flush_graphic", "true");
                // Force the graphics window update by displaying an offscreen pixel
                Window.DispLine(-1.0, -1.0, -1.0, -1.0);
            }
        }
Example #29
0
        /// <summary>
        /// Repaints the HALCON window 'window'
        /// </summary>
        public void repaint(HalconDotNet.HWindow window)
        {
            lock (lockershow)
            {
                int count = HObjList.Count;
                //HObjectEntry entry;

                HSystem.SetSystem("flush_graphic", "false");
                window.ClearWindow();
                mGC.stateOfSettings.Clear();

                //for (int i = 0; i < count; i++)
                //{
                //    entry = ((HObjectEntry)HObjList[i]);
                //    mGC.applyContext(window, entry.gContext);
                //    window.DispObj(entry.HObj);
                //}
                if (entry != null)
                {
                    try
                    {
                        mGC.applyContext(window, entry.gContext);
                        window.DispObj(entry.HObj);
                    }
                    catch (Exception ex)
                    { }
                }
                addInfoDelegate();

                if (roiManager != null && (dispROI == MODE_INCLUDE_ROI))
                {
                    roiManager.paintData(window);
                }

                HSystem.SetSystem("flush_graphic", "true");

                if (myRect.Count != 0)
                {
                    window.SetColor("green");
                    window.SetLineWidth(2);
                    HObject ho_Rect = new HObject();

                    for (int i = 0; i < myRect.Count; i++)
                    {
                        if (myRect[i].isCircle)
                        {
                            window.SetColor("green");
                            window.SetLineWidth(2);
                            if (myRect[i].Found)
                            {
                                HOperatorSet.GenCircleContourXld(out ho_Rect, myRect[i].Y, myRect[i].X, myRect[i].Radius, 0, 6.28318, "positive", 1.0);
                                window.DispObj(ho_Rect);
                            }
                            //window.DispCircle(myRect[i].Y, myRect[i].X, myRect[i].Radius);
                            window.DispCross(myRect[i].Y, myRect[i].X, 50, 0);

                            disp_message(window, "X:" + myRect[i].X.ToString("F1") + ", Y:" + myRect[i].Y.ToString("F1") + ", Means:" + myRect[i].Means.ToString("F1"), "image", 100, 50, "green", "false");
                            disp_message(window, "Radius:" + myRect[i].Radius.ToString("F1") + ",Angle:" + Helper.GetDegreeFromRadian((float)myRect[i].Angle).ToString("F1"), "image", 300, 50, "green", "false");
                        }
                        else
                        {
                            window.SetColor("green");
                            window.SetLineWidth(2);
                            if (myRect[i].Found)
                            {
                                HOperatorSet.GenRectangle2ContourXld(out ho_Rect, myRect[i].Y, myRect[i].X, myRect[i].Angle, myRect[i].Width / 2, myRect[i].Height / 2);
                                window.DispObj(ho_Rect);
                            }
                            //if (myRect[i].Found)
                            //{
                            //window.SetColor("cyan");
                            //window.DispObj(myRect[i].rect_border);
                            //}
                            window.DispCross(myRect[i].Y, myRect[i].X, 50, 0);

                            disp_message(window, "X:" + myRect[i].X.ToString("F1") + ", Y:" + myRect[i].Y.ToString("F1") + ", Means:" + myRect[i].Means.ToString("F1"), "image", 100, 50, "green", "false");
                            disp_message(window, "Width:" + myRect[i].Width.ToString("F1") + ", Height:" + myRect[i].Height.ToString("F1"), "image", 300, 50, "green", "false");
                            //disp_message(window, "Means:" + myRect[i].Means.ToString("F1"), "image", 500, 50, "green", "false");
                        }
                    }

                    //for (int i = 0; i < myRect.Count; i++)
                    //    window.DispRectangle2(myRect[i].Y, myRect[i].X, myRect[i].Angle, myRect[i].Width / 2, myRect[i].Length / 2);
                }

                if (bShowCrossHair)
                {
                    window.SetColor("red");
                    window.SetLineWidth(2);
                    int winrow, winclom, winwidth, winHeight;
                    window.GetPart(out winrow, out winclom, out winwidth, out winHeight);
                    window.DispLine(winrow + (winwidth - winrow) / 2, (double)winclom, winrow + (winwidth - winrow) / 2, winHeight);
                    window.DispLine((double)winrow, winclom + (winHeight - winclom) / 2, winwidth, winclom + (winHeight - winclom) / 2);
                }

                if (IsDrawCross1)
                {
                    window.DispCross(200.0, 200.0, 40, 0);
                    //window.WriteString("标定1");
                }
                if (IsDrawCross2)
                {
                    //window.DispCross(200.0, 200.0, 2, 0);
                    window.DispCross(600.0, 600.0, 40, 0);
                    // window.WriteString("标定2");
                }
            }
        }
Example #30
0
        private void hWindowControl2_HMouseMove(object sender, HMouseEventArgs e)
        {
            HTuple x = 0, y = 0, z = 0;

            x = e.X;
            y = e.Y;

            if (mainForm.ho_MainImagePositiveB != null && mainForm.ImageHeightPositiveB != null)
            {
                try
                {
                    HOperatorSet.GetGrayval(mainForm.ho_MainImagePositiveB, y, x, out z);
                }
                catch
                {
                    if (x > 4096)
                    {
                        x = 4096;
                    }
                    if (y > mainForm.ImageHeightPositiveB)
                    {
                        y = mainForm.ImageHeightPositiveB;
                    }
                }

                lblPointInfoRowB.Text       = y.TupleInt().ToString();
                lblPointInfoColumnB.Text    = x.TupleInt().ToString();
                lblPointInfoGrayValueB.Text = z.ToString();
            }


            if (!bl_IsMoveB)
            {
                return;
            }
            try
            {
                HTuple row, col;
                GetPosB(out row, out col);

                dbl_PositionB[2] = col;
                dbl_PositionB[3] = row;

                double[] vecB = { dbl_PositionB[2] - dbl_PositionB[0], dbl_PositionB[3] - dbl_PositionB[1] };
                hv_c1B = hv_c1B - vecB[0];
                hv_c2B = hv_c2B - vecB[0];
                hv_r1B = hv_r1B - vecB[1];
                hv_r2B = hv_r2B - vecB[1];
                HOperatorSet.SetPart(hWindowIDTwo, hv_r1B, hv_c1B, hv_r2B, hv_c2B);

                //清除halconWindow窗口 ,避免闪屏
                HSystem.SetSystem("flush_graphic", "false");
                HOperatorSet.ClearWindow(hWindowIDTwo);
                HSystem.SetSystem("flush_graphic", "true");

#if CPlusPlus
                ShowImage(DE.htup_WindowHandle, DE.bl_showdefect);
#else
                HOperatorSet.DispObj(mainForm.ho_MainImagePositiveB, hWindowIDTwo);
#endif
            }
            catch { }
        }