public override HMessage ActorTask(HMessage imsg) { HTuple row, column, angle, score; HImage img = new HImage(imsg.GetMessageObj("image")); if (sbm == null) { return(GenFinishMessage()); } HMessage msg = new HMessage(); msg.SetMessageObj(img, "image"); Monitor.Enter(lockobj); try { sbm.FindShapeModel(img, -Math.PI, 2 * Math.PI, 0.5, 1, 0.5, "least_squares", 0, 0.9, out row, out column, out angle, out score); if (row.Length > 0) { HXLDCont contours = sbm.GetShapeModelContours(1); HHomMat2D homMat2D = new HHomMat2D(); homMat2D.VectorAngleToRigid(0.0, 0.0, 0.0, row.D, column.D, angle.D); HXLDCont projcont = homMat2D.AffineTransContourXld(contours); msg.SetMessageObj(projcont, "contour"); } } finally { Monitor.Exit(lockobj); } imsg.Dispose(); return(msg); }
public override HMessage ActorTask(HMessage obj) { HTuple isempty = msg_queue.GetMessageQueueParam("is_empty"); if (isempty.I == 0) { msg_queue.SetMessageQueueParam("flush_queue", 1); } if (obj != null) { obj.Dispose(); } HTuple row, column, angle, score; HImage img; img = imggrabber.GrabImageAsync(-1); HRegion roi = new HRegion(ActiveObject); HMessage msg = new HMessage(); msg.SetMessageObj(img, "image"); Monitor.Enter(lockobj); try { if (sbm != null) { sbm.Dispose(); } sbm = new HShapeModel(img.ReduceDomain(roi), "auto", -Math.PI, 2 * Math.PI, "auto", "auto", "use_polarity", "auto", "auto"); sbm.FindShapeModel(img, 0.0, 0.0, 0.5, 1, 0.5, "least_squares", 0, 0.9, out row, out column, out angle, out score); if (row.Length > 0) { HXLDCont contours = sbm.GetShapeModelContours(1); HHomMat2D homMat2D = new HHomMat2D(); homMat2D.VectorAngleToRigid(0.0, 0.0, 0.0, row.D, column.D, angle.D); HXLDCont projcont = homMat2D.AffineTransContourXld(contours); msg.SetMessageObj(projcont, "contour"); } else { sbm.Dispose(); sbm = null; } } finally { Monitor.Exit(lockobj); } return(msg); }
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); }
public override HMessage ActorTask(HMessage obj) { if (obj != null) { obj.Dispose(); } HMessage msg = new HMessage(); HImage img = grabber.GrabImageAsync(-1); msg.SetMessageObj(img, "image"); if (SlowMotion == true) { HOperatorSet.WaitSeconds(0.2); } return(msg); }
public override HMessage ActorTask(HMessage imsg) { HImage img = new HImage(imsg.GetMessageObj("image")); HRegion roi = new HRegion(ActiveObject); HObject obj = new HObject(); if (roi != null) { obj.ConcatObj(img); obj.ConcatObj(img.ReduceDomain(roi).SobelAmp("sum_abs", 3)); } else { obj.ConcatObj(img.SobelAmp("sum_abs", 3)); } HMessage msg = new HMessage(); msg.SetMessageObj(obj, "filter_image"); return(msg); }