public override void CreateROI()
 {
     lock (lockObj)
     {
         if (Image != null)
         {
             Window.ClearWindow();
             HTuple[] values = new HTuple[] { Row1, Col1, Row2, Col2 };
             if (drawingObj.ID > -1)
             {
                 try
                 {
                     Window.DetachBackgroundFromWindow();
                     Window.DetachDrawingObjectFromWindow(drawingObj);
                     drawingObj.Dispose();
                 }
                 catch (Exception ex)
                 {
                     WriteErrorLog(ex.ToString());
                 }
             }
             drawingObj = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.RECTANGLE1, values);
             Window.AttachDrawingObjectToWindow(drawingObj);
             Window.AttachBackgroundToWindow(Image);
             base.SetDefaultSetting();
         }
     }
 }
Exemple #2
0
        public void AttachDrawObj(HDrawingObject obj)
        {
            drawing_objects.Add(obj);
            obj.OnDrag(SobelFilter);
            obj.OnAttach(SobelFilter);
            obj.OnResize(SobelFilter);
            obj.OnSelect(OnSelectDrawingObject);
            obj.OnAttach(SobelFilter);

            //HObject region = null;

            //if (obj.GetDrawingObjectParams("type") == "line")
            //{
            //    HTuple a = obj.GetDrawingObjectParams("row1");
            //    HOperatorSet.GenRegionLine(out region, obj.GetDrawingObjectParams("row1"),
            //        obj.GetDrawingObjectParams("column1"), obj.GetDrawingObjectParams("row2"),
            //        obj.GetDrawingObjectParams("column2"));
            //}
            //else
            //{
            //    region = new HRegion(obj.GetDrawingObjectIconic());
            //}

            //AddToStack(region);
            if (selected_drawing_object == null)
            {
                selected_drawing_object = obj;
            }
            // hsmartControl.HalconWindow.AttachDrawingObjectToWindow(obj);
            HOperatorSet.AttachDrawingObjectToWindow(m_windowHandle, obj);
        }
        private void getposistion(HDrawingObject img, HWindow hwin, string type)
        {
            HRegion region = new HRegion(img.GetDrawingObjectIconic());

            HOperatorSet.RegionFeatures(region, new HTuple(new string[] { "row", "column", "rect2_len1", "rect2_len2", "phi" }), out HTuple values);
            arr1 = values.ToDArr();
        }
Exemple #4
0
 /// <summary>
 /// Triggers the image processing thread
 /// </summary>
 private void DefineShapeBasedModel(HDrawingObject drawid, HWindow window, string type)
 {
     if (buttonRun.Enabled)
     {
         createsbm.AddMessage(dummy_msg);
     }
 }
Exemple #5
0
        public void SobelFilter(HDrawingObject dobj, HWindow hwin, string type)
        {
            try
            {
                HObject region = null;

                if (dobj.GetDrawingObjectParams("type") == "line")
                {
                    HTuple a = dobj.GetDrawingObjectParams("row1");
                    HOperatorSet.GenRegionLine(out region, dobj.GetDrawingObjectParams("row1"),
                                               dobj.GetDrawingObjectParams("column1"), dobj.GetDrawingObjectParams("row2"),
                                               dobj.GetDrawingObjectParams("column2"));
                }
                else
                {
                    region = new HRegion(dobj.GetDrawingObjectIconic());
                }

                AddToStack(region);
                DisplayResults();
            }
            catch (HalconException hex)
            {
                MessageBox.Show(hex.GetErrorMessage(), "HALCON error", MessageBoxButtons.OK);
            }
        }
Exemple #6
0
        private void rectangle1ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HDrawingObject rect1 = HDrawingObject.CreateDrawingObject(
                HDrawingObject.HDrawingObjectType.RECTANGLE1, 100, 100, 210, 210);

            rect1.SetDrawingObjectParams("color", "green");
            AttachDrawObj(rect1);
        }
Exemple #7
0
 public DrawBase()
 {
     OnDrawCallBack   = new HDrawingObject.HDrawingObjectCallback(DrawingItemActioning);
     OnResizeCallBack = new HDrawingObject.HDrawingObjectCallback(DrawingItemActioning);
     OnSelectCallBack = new HDrawingObject.HDrawingObjectCallback(DrawingItemActioning);
     lockObj          = new object();
     drawingObj       = new HDrawingObject();
 }
Exemple #8
0
        private void ellipseToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HDrawingObject ellipse = HDrawingObject.CreateDrawingObject(
                HDrawingObject.HDrawingObjectType.ELLIPSE, 50, 50, 0, 100, 50);

            ellipse.SetDrawingObjectParams("color", "blue");
            AttachDrawObj(ellipse);
        }
Exemple #9
0
        private void circleToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HDrawingObject circle = HDrawingObject.CreateDrawingObject(
                HDrawingObject.HDrawingObjectType.CIRCLE, 200, 200, 70);

            circle.SetDrawingObjectParams("color", "magenta");
            AttachDrawObj(circle);
        }
Exemple #10
0
        private void rectangle2ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            HDrawingObject rect2 = HDrawingObject.CreateDrawingObject(
                HDrawingObject.HDrawingObjectType.RECTANGLE2, 100, 100, 0, 100, 50);

            rect2.SetDrawingObjectParams("color", "yellow");
            AttachDrawObj(rect2);
        }
Exemple #11
0
 private void clearAllObjectsToolStripMenuItem_Click(object sender, EventArgs e)
 {
     foreach (HDrawingObject dobj in drawing_objects)
     {
         dobj.Dispose();
     }
     drawing_objects.Clear();
     selected_drawing_object = null;
 }
Exemple #12
0
        private void BtnDrawLine_Click(object sender, EventArgs e)
        {
            HDrawingObject line = HDrawingObject.CreateDrawingObject(
                HDrawingObject.HDrawingObjectType.LINE, 100, 100, 210, 210);

            line.SetDrawingObjectParams("color", "green");
            visionControl1.AddOperations(cboOpera.Text);
            visionControl1.AttachDrawObj(line);
        }
Exemple #13
0
        private void BtnDrawRectangle2_Click(object sender, EventArgs e)
        {
            HDrawingObject rect2 = HDrawingObject.CreateDrawingObject(
                HDrawingObject.HDrawingObjectType.RECTANGLE2, 100, 100, 0, 100, 50);

            rect2.SetDrawingObjectParams("color", "green");
            visionControl1.AddOperations(cboOpera.Text);
            visionControl1.AttachDrawObj(rect2);
        }
Exemple #14
0
        private void BtnDrawCircle_Click(object sender, EventArgs e)
        {
            HDrawingObject circle = HDrawingObject.CreateDrawingObject(
                HDrawingObject.HDrawingObjectType.CIRCLE, 200, 200, 70);

            circle.SetDrawingObjectParams("color", "green");
            visionControl1.AddOperations(cboOpera.Text);
            visionControl1.AttachDrawObj(circle);
        }
Exemple #15
0
        private void BtnDrawRectangle1_Click(object sender, EventArgs e)
        {
            HDrawingObject rect1 = HDrawingObject.CreateDrawingObject(
                HDrawingObject.HDrawingObjectType.RECTANGLE1, 100, 100, 210, 210);

            //  rect1.GetDrawingObjectParams(r);
            rect1.SetDrawingObjectParams("color", "green");
            visionControl1.AddOperations(cboOpera.Text);
            visionControl1.AttachDrawObj(rect1);
        }
Exemple #16
0
 public ShapeModelDisplay(string path, HDrawingObject obj, IHActor window)
     : base(obj, window)
 {
     if (path == null)
     {
         throw new ArgumentNullException();
     }
     imggrabber = new HFramegrabber("File", 1, 1, 0, 0, 0, 0,
                                    "default", -1, "default", -1, "false", path, "", 1, 2);
 }
Exemple #17
0
 public DrawBase(HWindow window, HImage image)
 {
     OnDrawCallBack   = new HDrawingObject.HDrawingObjectCallback(DrawingItemActioning);
     OnResizeCallBack = new HDrawingObject.HDrawingObjectCallback(DrawingItemActioning);
     OnSelectCallBack = new HDrawingObject.HDrawingObjectCallback(DrawingItemActioning);
     this.Window      = window;
     this.Image       = image;
     lockObj          = new object();
     drawingObj       = new HDrawingObject();
 }
 void createRegion(double x1, double y1, double theta, double x2, double y2)
 {
     if (Drawing_Ob != null)
     {
         Drawing_Ob.Dispose();
     }
     Drawing_Ob = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.RECTANGLE2, x1, y1, theta, x2, y2);
     Drawing_Ob.SetDrawingObjectParams("color", "green");
     Drawing_Ob.OnDrag(getposistion);
     window.AttachDrawingObjectToWindow(Drawing_Ob);
 }
 public void AttachDrawObj(HDrawingObject obj)
 {
     drawing_objects.Add(obj);
     // The HALCON/C# interface offers convenience methods that
     // encapsulate the set_drawing_object_callback operator.
     obj.OnDrag(user_actions.SobelFilter);
     obj.OnAttach(user_actions.SobelFilter);
     obj.OnResize(user_actions.SobelFilter);
     obj.OnSelect(OnSelectDrawingObject);
     obj.OnAttach(user_actions.SobelFilter);
     //if (selected_drawing_object == null)
     selected_drawing_object = obj;
     halconWindow.HalconWindow.AttachDrawingObjectToWindow(obj);
 }
Exemple #20
0
        public HALCONDialog()
        {
            InitializeComponent();

            width_ratio        = halconWindow.Width / (float)Width;
            height_ratio       = halconWindow.Height / (float)Height;
            buttonRun.Location =
                new Point(buttonRun.Location.X,
                          halconWindow.Location.Y + halconWindow.Height + 10);
            buttonStop.Location =
                new Point(buttonStop.Location.X,
                          halconWindow.Location.Y + halconWindow.Height + 10);

            HOperatorSet.GenCrossContourXld(out dummy, -10, -10, 5, 0);
            halconWindow.HalconWindow.SetColor("green");
            halconWindow.HalconWindow.SetLineWidth(2);
            // Allow the shape model to be found when lying partly outside of the image
            HOperatorSet.SetSystem("border_shape_models", "true");

            //  the drawing object allows the user to dynamically select the ROI
            //  and see how it affects to the resulting shape based model
            roi_object = new HDrawingObject(350.0, 400.0, 0.0, 200.0, 100.0);
            HImage img = new HImage("metal-parts/circle_plate_01");
            HTuple width, height;

            img.GetImageSize(out width, out height);
            halconWindow.HalconWindow.SetPart(-1.0, -1.0, height - 1, width - 1);
            delayCheckBox.Checked = true;

            dummy_msg = new HMessage();
            HOperatorSet.GenEmptyObj(out dummy);
            dummy_msg.SetMessageObj(dummy, "dummy");
            // this example emulates the case where one continuously grabs images
            // in order to adapt the camera parameters so that the image processing
            // works properly. In this case, the framegrabber acquires the same image
            // continuously.
            createsbm = new ShapeModelDisplay("metal-parts/circle_plate_01", roi_object, this);
            createsbm.Start();

            roi_object.OnAttach(DefineShapeBasedModel);
            roi_object.OnDrag(DefineShapeBasedModel);
            roi_object.OnResize(DefineShapeBasedModel);
            halconWindow.HalconWindow.AttachDrawingObjectToWindow(roi_object);
            halconWindow.HalconWindow.SetColor("green");

            //  initialize the chain of responsibility pattern
            findsbm    = new ShapeModelFinder(this);
            imggrabber = new ImageGrabber("circle_plate.seq", findsbm);
        }
Exemple #21
0
 public void SobelFilter(HDrawingObject dobj, HWindow hwin, string type)
 {
     try
     {
         /*
          * HImage image = (HImage)halcon_dialog.BackgroundImage;
          * HRegion region = new HRegion(dobj.GetDrawingObjectIconic());
          * halcon_dialog.AddToStack(image.ReduceDomain(region).SobelAmp("sum_abs", 11));
          * halcon_dialog.DisplayResults();
          */
     }
     catch (HalconException hex)
     {
         MessageBox.Show(hex.GetErrorMessage(), "HALCON error", MessageBoxButtons.OK);
     }
 }
Exemple #22
0
 public void SobelFilter(HDrawingObject dobj, HWindow hwin, string type)
 {
     try
     {
         HImage  image  = halcon_dialog.BackgroundImage;
         HRegion region = new HRegion(dobj.GetDrawingObjectIconic());
         hwin.SetWindowParam("flush", "false");
         hwin.ClearWindow();
         hwin.DispObj(image.ReduceDomain(region).SobelAmp("sum_abs", 11));
         hwin.SetWindowParam("flush", "true");
         hwin.FlushBuffer();
     }
     catch (HalconException hex)
     {
         MessageBox.Show(hex.GetErrorMessage(), "HALCON error", MessageBoxButtons.OK);
     }
 }
Exemple #23
0
        private void DrawRectangle(object sender, EventArgs e)
        {
            HTuple width, height;

            background_image = new HImage(ho_Image);
            background_image.GetImageSize(out width, out height);
            VideoWindow_hWindowControl.HalconWindow.SetPart(0, 0, height.I - 1, width.I - 1);
            VideoWindow_hWindowControl.HalconWindow.AttachBackgroundToWindow(background_image);


            GraphInteractiveObect.halconWindow.Focus();
            GraphInteractiveObect.graphic_stackClear();
            VideoWindow_hWindowControl.HalconWindow.ClearWindow();

            ObjectRoi = HDrawingObject.CreateDrawingObject(HDrawingObject.HDrawingObjectType.RECTANGLE2, ImageHeight / 2, ImageWidth / 2, 0, 300, 150);
            ObjectRoi.SetDrawingObjectParams("color", "yellow");
            GraphInteractiveObect.AttachDrawObj(ObjectRoi);
        }
Exemple #24
0
        private void BtnLoadRoi_Click(object sender, EventArgs e)
        {
            OpenFileDialog f = new OpenFileDialog();

            f.Filter = "ROI文件(.roi)|*.roi;";
            HTuple[] _params;
            if (f.ShowDialog() == DialogResult.OK)
            {
                List <ROI> r = LoadRoi(f.FileName);
                foreach (ROI region in r)
                {
                    _params = new HTuple[region.data.Count];
                    for (int i = 0; i < region.data.Count; i++)
                    {
                        _params[i] = region.data[i];
                    }
                    HDrawingObject obj = HDrawingObject.CreateDrawingObject(region.type, _params);
                    obj.SetDrawingObjectParams("color", "green");
                    visionControl1.AddOperations(region.operation);
                    visionControl1.AttachDrawObj(obj);
                }
            }
        }
Exemple #25
0
 private void OnSelectDrawingObject(HDrawingObject dobj, HWindow hwin, string type)
 {
     selected_drawing_object = dobj;
     SobelFilter(dobj, hwin, type);
 }
Exemple #26
0
 public void AddDrawingObject(HDrawingObject Drawing)
 {
     drawing_objects.Add(Drawing);
 }
 public ImageProcessingTask(HDrawingObject dobj, IHActor next) : base(next, true)
 {
     drawing_obj = dobj;
 }
 public ImageProcessingTask(HDrawingObject dobj) : base(true)
 {
     drawing_obj = dobj;
 }