Пример #1
0
        private void ExecuteBtn_Click(object sender, System.EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            HFramegrabber Framegrabber = new HFramegrabber();

            // read images and process them
            try
            {
                Framegrabber.OpenFramegrabber("File", 1, 1, 0, 0, 0, 0, "default",
                                              -1, "default", -1, "default", "fin.seq", "default", -1, -1);

                HImage  Image = new HImage();
                HRegion FinRegion;
                HTuple  FinArea;

                for (int i = 0; i <= 2; i++)
                {
                    Image.GrabImage(Framegrabber);
                    Image.DispObj(Window);

                    // execute procedure
                    ProcCall.SetInputIconicParamObject("Image", Image);
                    ProcCall.Execute();
                    // get output parameters from procedure call
                    FinRegion = ProcCall.GetOutputIconicParamRegion("FinRegion");
                    FinArea   = ProcCall.GetOutputCtrlParamTuple("FinArea");

                    // display results
                    Image.DispObj(Window);
                    Window.SetColor("red");
                    Window.DispObj(FinRegion);
                    Window.SetColor("white");
                    Window.SetTposition(150, 20);
                    Window.WriteString("FinArea: " + FinArea.D);
                    HSystem.WaitSeconds(2);

                    FinRegion.Dispose();
                    Image.Dispose();
                }
            }
            catch (HOperatorException Ex)
            {
                MessageBox.Show(Ex.Message, "HALCON Exception");
            }
            catch (HDevEngineException Ex)
            {
                MessageBox.Show(Ex.Message, "HDevEngine Exception");
            }

            Framegrabber.Dispose();

            this.Cursor = Cursors.Default;
        }
Пример #2
0
        private void WindowControl_Load(object sender, EventArgs e)
        {
            string ImgType;

            Window       = WindowControl.HalconWindow;
            Framegrabber = new HFramegrabber("File", 1, 1, 0, 0, 0, 0, "default",
                                             -1, "default", -1, "default",
                                             "board/board.seq", "default", 1, -1);
            Img = Framegrabber.GrabImage();
            Img.GetImagePointer1(out ImgType, out ImgWidth, out ImgHeight);
            Window.SetPart(0, 0, ImgHeight - 1, ImgWidth - 1);
            Img.DispObj(Window);
            Window.SetDraw("margin");
            Window.SetLineWidth(3);
            Rectangle = new HRegion(188.0, 182, 298, 412);
            Rectangle.AreaCenter(out Row, out Column);
            Rect1Row         = Row - 102;
            Rect1Col         = Column + 5;
            Rect2Row         = Row + 107;
            Rect2Col         = Column + 5;
            RectPhi          = 0;
            RectLength1      = 170;
            RectLength2      = 5;
            this.MouseWheel += my_MouseWheel;
        }
Пример #3
0
        private void InitAcqBtn_Click(object sender, System.EventArgs e)
        {
            try
            {
                // execute procedure
                InitAcqProcCall.Execute();
                // get output parameters from procedure call
                Framegrabber =
                    new HFramegrabber(InitAcqProcCall.GetOutputCtrlParamTuple("AcqHandle"));
            }
            catch (HDevEngineException Ex)
            {
                MessageBox.Show(Ex.Message, "HDevEngine Exception");
                return;
            }

            HImage Image = Framegrabber.GrabImage();

            Image.DispObj(Window);
            Image.Dispose();

            // enable ProcessImage button and disable InitAcq button
            ProcessImageBtn.Enabled = true;
            InitAcqBtn.Enabled      = false;
        }
Пример #4
0
        private void WindowControl_Load(object sender, EventArgs e)
        {
            Window = WindowControl.HalconWindow;

            Img = new HImage("coins/20cent_greek");
            Img.DispObj(Window);
        }
Пример #5
0
        private void hWindowControlWPF1_HInitWindow(object sender, EventArgs e)
        {
            // Get HALCON window from control. Due to restrictions of WPF
            // interoperating with native Windows, this is not yet available
            // in the Loaded event of the control or the parent window. The
            // best time to extract the HALCON window is in this event.
            Window = hWindowControlWPF1.HalconWindow;

            // Attention: Technically we are called by the control during its
            // initialization. Under now account should an exception be allowed
            // to propagate upwards from here (under Windows 7, not even the
            // Visual Studio debugger will function properly in this case).

            try
            {
                // Initialize enabled states
                CreateBtn.IsEnabled = true;
                StartBtn.IsEnabled  = false;
                StopBtn.IsEnabled   = false;

                // Create a timer for execution loop;
                Timer          = new DispatcherTimer();
                Timer.Interval = new TimeSpan(10);
                Timer.Tick    += new EventHandler(Timer_Tick);

                // Prepare image processing
                string ImgType;
                Framegrabber = new HFramegrabber("File", 1, 1, 0, 0, 0, 0, "default",
                                                 -1, "default", -1, "default",
                                                 "board/board.seq", "default", 1, -1);
                Img = Framegrabber.GrabImage();
                Img.GetImagePointer1(out ImgType, out ImgWidth, out ImgHeight);
                Window.SetPart(0, 0, ImgHeight - 1, ImgWidth - 1);
                Img.DispObj(Window);
                Window.SetDraw("margin");
                Window.SetLineWidth(3);
                Rectangle = new HRegion(188.0, 182, 298, 412);
                Rectangle.AreaCenter(out Row, out Column);
                Rect1Row    = Row - 102;
                Rect1Col    = Column + 5;
                Rect2Row    = Row + 107;
                Rect2Col    = Column + 5;
                RectPhi     = 0;
                RectLength1 = 170;
                RectLength2 = 5;
            }
            catch (Exception ex)
            {
                // Catch all
                MessageBox.Show("Error in HInitWindow:" + ex.ToString());
            }
        }
Пример #6
0
        private void btnLoadImg_Click(object sender, EventArgs e)
        {
            OpenFileDialog openfile = new OpenFileDialog();

            openfile.Filter = "BMP File|*.bmp| JPG File|*.jpg|PNG File|*.png| All File|*.*";
            if (openfile.ShowDialog() == DialogResult.OK)
            {
                HOperatorSet.ReadImage(out HObject Imgtrain, openfile.FileName);
                _Imgtrain = new HImage(Imgtrain);
                _Imgtrain.GetImageSize(out _width, out _height);
                WindowTrain.SetPart(0, 0, _height - 1, _width - 1);
                _Imgtrain.DispObj(WindowTrain);
            }
        }
Пример #7
0
        private void btnLoadImg_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();

            open.Filter = "BMP File|*.bmp| JPG File|*.jpg| PNG File|*.png| ALL File|*.*";
            if (open.ShowDialog() == DialogResult.OK)
            {
                HOperatorSet.ReadImage(out HObject img, open.FileName);
                Img = new HImage(img);
                Img.DispObj(window);
                Img.GetImagePointer1(out HTuple type, out HTuple width, out HTuple heigh);
                window.SetPart(new HTuple(0), new HTuple(0), heigh, width);
                //RunProgram(_img);
            }
        }
Пример #8
0
        private void ProcessImageBtn_Click(object sender, System.EventArgs e)
        {
            // image processing variables
            HTuple FinArea;

            // free memory of iconic results of previous execution
            Image.Dispose();
            FinRegion.Dispose();
            // read image and process it
            Image = Framegrabber.GrabImage();
            Image.DispObj(Window);
            try
            {
                // execute procedure
                ProcessImageProcCall.SetInputIconicParamObject("Image", Image);
                ProcessImageProcCall.Execute();
                // get output parameters from procedure call
                FinRegion = ProcessImageProcCall.GetOutputIconicParamRegion("FinRegion");
                FinArea   = ProcessImageProcCall.GetOutputCtrlParamTuple("FinArea");
            }
            catch (HDevEngineException Ex)
            {
                MessageBox.Show(Ex.Message, "HDevEngine Exception");
                return;
            }
            // display results
            Image.DispObj(Window);
            Window.SetColor("red");
            Window.DispObj(FinRegion);
            Window.SetColor("white");
            Window.SetTposition(150, 20);
            Window.WriteString("Fin Area: " + FinArea.D);

            // enable VisualizeDetails button
            VisualizeDetailsBtn.Enabled = true;
        }
Пример #9
0
        async void getDataLive()
        {
            while (true)
            {
                try
                {
                    string a;
                    HTuple b = 1000;

                    // get data from PLC
                    if (btnConnection.Text == "Connected")
                    {
                        dataWord = clsPlc.RecDataFromPLC(dataType, device_getWord, 10, _plcSocket);
                        databit  = clsPlc.GetBitFromPLC(device_getBit, 1, _plcSocket);
                        //getdataBarcode = clsPlc.RecDataFromPLC("String", 3000, 10, _plcSocket);
                        this.Invoke((MethodInvoker) delegate
                        {
                            txtRecdataBit.Text  = databit.ToString();
                            txtRecdataWord.Text = dataWord.ToString();
                        });
                        b = Lib.ToDouble(nbrDataSend.Value);
                    }

                    HTuple bb = Lib.ToDouble(nbrDataSend.Value);
                    // rec data to PLC
                    if (btnConnection.Text == "Connected")
                    {
                        clsPlc.SendDataFromPLC("Word", bb, 4000, _plcSocket);
                    }
                    if (databit == 1)
                    {
                        Img.Dispose();
                        Img = Framgraber.GrabImage();
                        Img.DispObj(window);
                    }
                    if (static_senddata == true)
                    {
                        clsPlc.SetBitFromPLC(3000, 1, 1, _plcSocket);
                        clsPlc.SetBitFromPLC(3000, 0, 1, _plcSocket);
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
Пример #10
0
 private void btnSnap_Click(object sender, EventArgs e)
 {
     if (Img != null)
     {
         Img.Dispose();
     }
     if (true)
     {
     }
     try
     {
         Img = Framgraber.GrabImage();
         Img.DispObj(window);
     }
     catch (Exception)
     {
     }
 }
Пример #11
0
 private void snap()
 {
     if (Framgraber == null)
     {
         return;
     }
     try
     {
         _Img.Dispose();
     }
     catch
     {
     }
     //_Img = _frameGrabber.GrabImage();
     HOperatorSet.GrabImage(out HObject image, Framgraber);
     //SmartSetPart(image, WindowControl);
     _Img = new HImage(image);
     _Img.DispObj(_window);
     image.Dispose();
 }
Пример #12
0
 private void snap()
 {
     if (Framgraber == null)
     {
         return;
     }
     try
     {
         Img.Dispose();
     }
     catch
     {
     }
     //_Img = _frameGrabber.GrabImage();
     HOperatorSet.GrabImage(out HObject image, Framgraber);
     //SmartSetPart(image, WindowControl);
     Img = new HImage(image);
     Img.GetImagePointer1(out HTuple type, out HTuple width, out HTuple heigh);
     WindowControl.HalconWindow.SetPart(new HTuple(0), new HTuple(0), heigh, width);
     Img.DispObj(window);
     image.Dispose();
 }
Пример #13
0
        void live()
        {
            while (true)
            {
                //HOperatorSet.SetFramegrabberParam(Framgraber, "ExposureTime", 2700);
                //HOperatorSet.SetFramegrabberParam(Framgraber, "Gain", 1);
                try
                {
                    HOperatorSet.GrabImageAsync(out HObject ImgLiv, Framgraber, 1);
                    ImgLive = new HImage(ImgLiv);
                    ImgLive.DispObj(window);
                }
                catch (Exception)
                {
                }

                if (click)
                {
                    break;
                }
            }
        }
Пример #14
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);
            }
        }
Пример #15
0
        private void StartBtn_Click(object sender, System.EventArgs e)
        {
            Framegrabber = new HFramegrabber();
            // read images and process them
            try
            {
                //Framegrabber.OpenFramegrabber("DirectShow", 1, 1, 0, 0, 0, 0, "default", 8, "rgb", -1, "false", "default", "[0] USB2.0 HD UVC WebCam", 0, -1);


                Framegrabber.OpenFramegrabber("GigEVision", 0, 0, 0, 0, 0, 0, "default", -1, "default", -1,
                                              "false", "default", "003053231ec3_basler_aca250014gm", 0, -1);
                Framegrabber.SetFramegrabberParam("AcquisitionMode", "SingleFrame");
                HImage  Image = new HImage();
                HRegion CirclesRegion;

                int shot;
                shot = Int32.Parse(shotComboBox.SelectedItem + "");

                // execute procedure
                ProcCall.SetInputCtrlParamTuple("shot", shot);
                ProcCall.Execute();
                // get output parameters from procedure call
                CirclesRegion = ProcCall.GetOutputIconicParamRegion("RegionOfInterest");
                //LightCheck = ProcCall.GetOutputIconicParamRegion("RegionOfInterest");



                StartBtn.Enabled     = false;
                shotComboBox.Enabled = false;
                Savebtn.Enabled      = true;
                StopBtn.Enabled      = true;
                while (true)
                {
                    if (!StopBtn.Enabled)
                    {
                        StartBtn.Enabled = true;
                        StopBtn.Enabled  = false;
                        Framegrabber.Dispose();
                        Image.Dispose();
                        return;
                    }
                    //Framegrabber.GrabImageStart(-1);
                    Image = Framegrabber.GrabImageAsync(-1);

                    // display results
                    Image.DispObj(Window);
                    Window.SetColor("red");
                    Window.DispObj(CirclesRegion);
                    Window.SetPart(0, 0, -2, -2);

                    HSystem.WaitSeconds(0.108);
                }
            }
            catch (HOperatorException Ex)
            {
                MessageBox.Show(Ex.Message, "HALCON Exception");
            }
            catch (HDevEngineException Ex)
            {
                MessageBox.Show(Ex.Message, "HDevEngine Exception");
            }

            Framegrabber.Dispose();
        }