private void bGetImage_Click(object sender, EventArgs e) { try { VisionImage img = GetImage?.Invoke(); //VisionImage img = new VisionImage(); //img.ReadFile(@"C:\Users\lichen\Desktop\黑到白\1.bmp"); if (img != null) { m_hoModedImage?.Dispose(); m_hoModedImage = HalconHelper.NI2HImage(img); HTuple htWidth = new HTuple(); HTuple htHeight = new HTuple(); HOperatorSet.GetImageSize(m_hoModedImage, out htWidth, out htHeight); HOperatorSet.SetPart(m_htWindowHandle, 0, 0, htHeight, htWidth); HOperatorSet.DispObj(m_hoModedImage, m_htWindowHandle); zoom_beginRow = 0; zoom_beginCol = 0; zoom_endCol = htWidth; zoom_endRow = htHeight; isLoadImage = true; } } catch { } }
private void DisplayPointPointDistanceGraphics(HWindow windowHandle) { windowHandle.SetColor("orange"); windowHandle.SetDraw("fill"); if (PointLineGraphics == null) { return; } HObject draw = new HObject(); draw.GenEmptyObj(); foreach (var line in PointPointGraphics) { HObject circle1, circle2, lineSeg; HOperatorSet.GenCircle(out circle1, line.YStart, line.XStart, EndPointRadius); HOperatorSet.GenCircle(out circle2, line.YEnd, line.XEnd, EndPointRadius); HOperatorSet.GenRegionLine(out lineSeg, line.YStart, line.XStart, line.YEnd, line.XEnd); draw = HalconHelper.ConcatAll(draw, circle1, circle2, lineSeg); } windowHandle.DispObj(draw); windowHandle.SetDraw("margin"); }
private void bCancel_Click(object sender, EventArgs e) { HalconHelper.ClearModel(m_htModelID); m_hoModedImage?.Dispose(); DialogResult = DialogResult.No; this.isLoadImage = false; this.Close(); }
private void ReadRegion(HWindowTool.HWindowTool hWindowTool) { string regionPath = Path.Combine(Config.Template, Config.Admin.CameraName + ".Ring.reg"); HalconHelper.ReadRegion(regionPath, hWindowTool.HalconWindow); regionPath = Path.Combine(Config.Template, Config.Admin.CameraName + ".Rect.reg"); HalconHelper.ReadRegion(regionPath, hWindowTool.HalconWindow); }
private void Save(DependencyObject obj) { Method.Invoke(obj, () => { if (Method.Find(obj, out HWindowTool.HWindowTool hWindowTool)) { foreach (var item in hWindowTool.ViewController.RoiController.ROIList) { if (item is ROICircleRing ring) { try { string regionPath = Path.Combine(Config.Template, Config.Admin.CameraName + $".Ring.reg"); HalconHelper.WriteRegion(item.GetRegion(), regionPath); } catch (Exception ex) { ex.Log(); Method.Toast(hWindowTool, ex.Message(), true); return; } } if (item is ROIRectangle2) { Config.Admin.CenterX = item.GetCenter().X; Config.Admin.CenterY = item.GetCenter().Y; DataService.Default.Update(nameof(Config.Admin.CenterX)); DataService.Default.Update(nameof(Config.Admin.CenterY)); string regionPath = Path.Combine(Config.Template, Config.Admin.CameraName + $".Rect.reg"); string modelPath = Path.Combine(Config.Template, Config.Admin.CameraName + $".Rect.shm"); try { HalconHelper.CreateShapModel(item.Image, item.GetRegion(), regionPath, modelPath); } catch (Exception ex) { ex.Log(); Method.Toast(hWindowTool, ex.Message(), true); return; } } } } }); }
private void DisplayPointMarkers(HWindow windowHandle) { if (PointMarkers == null || PointMarkers.Count == 0) { return; } HObject crosses = new HObject(); var offset = 5; foreach (var pointMarker in PointMarkers) { HObject cross; HOperatorSet.GenCrossContourXld(out cross, pointMarker.ImageY, pointMarker.ImageX, 10, 0.5); crosses = HalconHelper.ConcatAll(crosses, cross); // windowHandle.DispText($"{pointMarker.Name}{Environment.NewLine}{pointMarker.Height.ToString("f3")}", "image", pointMarker.ImageY + offset, pointMarker.ImageX + offset, "red", "border_radius", 2); } windowHandle.DispObj(crosses); }
//5-创建模板 private void buttonCreateModel_Click(object sender, EventArgs e) { try { HalconHelper.ClearModel(m_htModelID); m_htModelID = HalconVision.HalconHelper.LearnShapeModel(m_hoModelEdgesTemp); if (m_htModelID != null && m_htModelID.Length > 0) { HOperatorSet.SetColor(m_htWindowHandle, "red"); HOperatorSet.DispObj(m_hoModelEdges, m_htWindowHandle); MessageBox.Show("学习成功"); } else { throw new HalconException("轮廓学习从失败!!!"); } } catch (HalconException ex) { MessageBox.Show("创建模板异常,异常信息:" + ex.GetErrorMessage()); } }
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()); } }
public Line FindLine(HImage image, FindLineFeeding feeding, bool recordGraphics = true) { HObject lineRegion, findLineRegion; HTuple xsUsed = new HTuple(); HTuple ysUsed = new HTuple(); HTuple xsIgnored = new HTuple(); HTuple ysIgnored = new HTuple(); HTuple lineX1 = new HTuple(); HTuple lineY1 = new HTuple(); HTuple lineX2 = new HTuple(); HTuple lineY2 = new HTuple(); List <double> ys, xs; // using pair HObject edges = new HObject(); edges.GenEmptyObj(); if (feeding.UsingPair) { if (feeding.FirstAttemptOnly) { HalconScripts.FindLineGradiant_Pair(image, out findLineRegion, out lineRegion, feeding.Row, feeding.Col, feeding.Radian, feeding.Len1, feeding.Len2, feeding.NumSubRects, feeding.IgnoreFraction, feeding.Transition, feeding.Threshold, feeding.Sigma1, feeding.WhichEdge, feeding.WhichPair, feeding.MinWidth, feeding.MaxWidth, out xsUsed, out ysUsed, out xsIgnored, out ysIgnored, out lineX1, out lineY1, out lineX2, out lineY2); } else { HalconScripts.VisionProStyleFindLineOneStep_Pairs(image, out findLineRegion, out lineRegion, feeding.Row, feeding.Col, feeding.Radian, feeding.Len1, feeding.Len2, feeding.Transition, feeding.NumSubRects, feeding.Threshold, feeding.Sigma1, feeding.Sigma2, feeding.WhichEdge, feeding.IsVertical, feeding.IgnoreFraction, feeding.WhichPair, feeding.MinWidth, feeding.MaxWidth, _width, _height, feeding.CannyHigh, feeding.CannyLow, "true", feeding.NewWidth, feeding.KernelWidth, feeding.LongestOnly, out xsUsed, out ysUsed, out xsIgnored, out ysIgnored, out lineX1, out lineY1, out lineX2, out lineY2); } xs = xsUsed.DArr.ToList(); ys = ysUsed.DArr.ToList(); } // using single edge else { if (feeding.FirstAttemptOnly) { HalconScripts.FindLineGradiant(image, out findLineRegion, out lineRegion, feeding.Row, feeding.Col, feeding.Radian, feeding.Len1, feeding.Len2, feeding.NumSubRects, feeding.IgnoreFraction, feeding.Transition, feeding.Threshold, feeding.Sigma1, feeding.WhichEdge, out xsUsed, out ysUsed, out xsIgnored, out ysIgnored, out lineX1, out lineY1, out lineX2, out lineY2); ys = ysUsed.DArr.ToList(); xs = xsUsed.DArr.ToList(); } else { // HalconScripts.VisionProStyleFindLineOneStep(image, out findLineRegion, out lineRegion, // feeding.Transition, feeding.Row, feeding.Col, feeding.Radian, feeding.Len1, feeding.Len2, // feeding.NumSubRects, feeding.Threshold, feeding.WhichEdge, feeding.IgnoreFraction, // feeding.IsVertical, feeding.Sigma1, feeding.Sigma2, _width, _height, feeding.NewWidth, // feeding.CannyHigh, feeding.CannyLow, out lineX1, out lineY1, out lineX2, out lineY2, out xsUsed, // out ysUsed, out xsIgnored, out ysIgnored); var xsys = HalconHelper.FindLineSubPixel(image, feeding.Row, feeding.Col, feeding.Radian, feeding.Len1, feeding.Len2, feeding.Transition.S, feeding.NumSubRects.I, feeding.Threshold, feeding.WhichEdge.S, feeding.IgnoreFraction.D, feeding.CannyLow, feeding.CannyHigh.D, feeding.Sigma1.D, feeding.Sigma2.D, feeding.NewWidth.I, feeding.KernelWidth, feeding.LongestOnly, out edges, out findLineRegion); xs = xsys.Item1; ys = xsys.Item2; } } IEnumerable <double> xsInlier, ysInlier; var line = HalconHelper.RansacFitLine(xs.ToArray(), ys.ToArray(), feeding.ErrorThreshold, feeding.MaxTrials, feeding.IgnoreFraction, feeding.Probability, out xsInlier, out ysInlier); xs = xsInlier.ToList(); ys = ysInlier.ToList(); HalconScripts.GenLineRegion(out lineRegion, line.XStart, line.YStart, line.XEnd, line.YEnd, _width, _height); lineX1 = line.XStart; lineY1 = line.YStart; lineX2 = line.XEnd; lineY2 = line.YEnd; // Generate debugging graphics if (recordGraphics) { HObject crossesIgnored; HOperatorSet.GenCrossContourXld(out crossesIgnored, ysIgnored, xsIgnored, CrossSize, CrossAngle); // Critical section lock (this) { CrossesUsed.Add(new Tuple <List <double>, List <double> >(xs, ys)); HOperatorSet.ConcatObj(_crossesIgnored, crossesIgnored, out _crossesIgnored); HOperatorSet.ConcatObj(_findLineRects, findLineRegion, out _findLineRects); HOperatorSet.ConcatObj(_lineRegions, lineRegion, out _lineRegions); HOperatorSet.ConcatObj(Edges, edges, out _edges); } } return(new Line(lineX1.D, lineY1.D, lineX2.D, lineY2.D)); }
public async Task <ImageProcessingResult> ProcessAsync(List <HImage> images, FindLineConfigs findLineConfigs, List <FaiItem> faiItems, int indexToShow, ISnackbarMessageQueue messageQueue) { #region Initial variables HObject imageUndistorted; HTuple changeOfBase; HTuple changeOfBaseInv; HTuple rotationMat; HTuple rotationMatInv; HTuple mapToWorld; HTuple mapToImage; HTuple xLeft, yLeft, xRight, yRight, xUp, yUp, xDown, yDown; HTuple baseLeftCol, baseLeftLen1, baseLeftLen2, baseLeftRadian, baseLeftRow, baseTopCol, baseTopLen1, baseTopLen2, baseTopRadian, baseTopRow, camParams; #endregion #region Change base var image = images[0]; HalconScripts.GetI94BottomViewBaseRectsNoRectify(image, _shapeModelHandle, out baseTopRow, out baseTopCol, out baseTopRadian, out baseTopLen1, out baseTopLen2, out baseLeftRow, out baseLeftCol, out baseLeftRadian, out baseLeftLen1, out baseLeftLen2, out mapToWorld, out mapToImage, out camParams ); // images[0] = imageUndistorted.HobjectToHimage(); var findLineManager = new FindLineManager(messageQueue); // Top base var findLineParamTop = findLineConfigs.FindLineParamsDict["TopBase"]; var findLineFeedingsTop = findLineParamTop.ToFindLineFeeding(); findLineFeedingsTop.Col = baseTopCol; findLineFeedingsTop.Row = baseTopRow; findLineFeedingsTop.Radian = baseTopRadian; findLineFeedingsTop.Len1 = baseTopLen1; findLineFeedingsTop.Len2 = baseTopLen2; findLineFeedingsTop.Transition = "negative"; var lineTopBase = findLineManager.TryFindLine("X-aixs", image, findLineFeedingsTop); HalconScripts.SortLineLeftRight(lineTopBase.XStart, lineTopBase.YStart, lineTopBase.XEnd, lineTopBase.YEnd, out xLeft, out yLeft, out xRight, out yRight); // Right base var findLineParamRight = findLineConfigs.FindLineParamsDict["LeftBase"]; var findLineFeedingsRight = findLineParamRight.ToFindLineFeeding(); findLineFeedingsRight.Col = baseLeftCol; findLineFeedingsRight.Row = baseLeftRow; findLineFeedingsRight.Radian = baseLeftRadian; findLineFeedingsRight.Len1 = baseLeftLen1; findLineFeedingsRight.Len2 = baseLeftLen2; findLineFeedingsRight.Transition = "negative"; var lineLeftBase = findLineManager.TryFindLine("Y-axis", image, findLineFeedingsRight); HalconScripts.SortLineUpDown(lineLeftBase.XStart, lineLeftBase.YStart, lineLeftBase.XEnd, lineLeftBase.YEnd, out xUp, out yUp, out xDown, out yDown); HalconScripts.GetChangeOfBase(xLeft, yLeft, xRight, yRight, xUp, yUp, xDown, yDown, out changeOfBase, out changeOfBaseInv, out rotationMat, out rotationMatInv); #endregion #region Find lines var coordinateSolver = new CoordinateSolver(changeOfBase, changeOfBaseInv, rotationMat, rotationMatInv, mapToWorld, mapToImage); // Update absolute find line locations findLineConfigs.GenerateLocationsAbs(coordinateSolver); // Find lines findLineManager.FindLineFeedings = findLineConfigs.GenerateFindLineFeedings(); await findLineManager.FindLinesParallel(images); #endregion #region 21 var lineF21Top = coordinateSolver.TranslateLineInWorldUnit(21, lineTopBase, true); var lineF21Bottom = coordinateSolver.TranslateLineInWorldUnit(30, lineTopBase, true); var p1F21 = findLineManager.GetLine("21left").Intersect(lineF21Top); var p2F21 = findLineManager.GetLine("21left").Intersect(lineF21Bottom); var p3F21 = findLineManager.GetLine("21right").Intersect(lineF21Top); var p4F21 = findLineManager.GetLine("21right").Intersect(lineF21Bottom); var valueF21Top = coordinateSolver.PointPointDistanceInWorld(p1F21, p3F21, true); var valueF21Bottom = coordinateSolver.PointPointDistanceInWorld(p2F21, p4F21, true); #endregion #region 23 var lineF23Left = coordinateSolver.TranslateLineInWorldUnit(-5.5, lineLeftBase, true); var lineF23Right = coordinateSolver.TranslateLineInWorldUnit(-13.2, lineLeftBase, true); var lineF123Left = coordinateSolver.TranslateLineInWorldUnit(-5, lineLeftBase, true); var lineF123Center = coordinateSolver.TranslateLineInWorldUnit(-9.269, lineLeftBase, true); var lineF123Right = coordinateSolver.TranslateLineInWorldUnit(-14.5, lineLeftBase, true); var p1F23 = findLineManager.GetLine("23top").Intersect(lineF23Left); var p2F23 = findLineManager.GetLine("23top").Intersect(lineF23Right); var p3F23 = findLineManager.GetLine("23bottom").Intersect(lineF23Left); var p4F23 = findLineManager.GetLine("23bottom").Intersect(lineF23Right); var pLeftF23 = Point.CenterPointInImage(p1F23, p3F23); var pRightF23 = Point.CenterPointInImage(p2F23, p4F23); var valueF23Left = coordinateSolver.PointPointDistanceInWorld(p1F23, p3F23, true); var valueF23Right = coordinateSolver.PointPointDistanceInWorld(p2F23, p4F23, true); #endregion #region 24 var lineF24Top = coordinateSolver.TranslateLineInWorldUnit(7.3, lineTopBase, true); var lineF24Bottom = coordinateSolver.TranslateLineInWorldUnit(8.5, lineTopBase, true); var p1F24 = findLineManager.GetLine("24.left").Intersect(lineF24Top); var p2F24 = findLineManager.GetLine("24.left").Intersect(lineF24Bottom); var p3F24 = findLineManager.GetLine("24.right").Intersect(lineF24Top); var p4F24 = findLineManager.GetLine("24.right").Intersect(lineF24Bottom); var pLeftF24 = Point.CenterPointInImage(p1F24, p2F24); var pRightF24 = Point.CenterPointInImage(p3F24, p4F24); var valueF24 = coordinateSolver.PointPointDistanceInWorld(pLeftF24, pRightF24, true); #endregion #region 25 var rectCircleLeft = coordinateSolver.FindLineLocationRelativeToAbsolute(EdgeLocationsRelative["leftCircle"]); HTuple circleXLeft, circleYLeft, circleRadiusLeft; HObject leftCircleContour; HalconScripts.I94FindLeftCircle(image, out leftCircleContour, rectCircleLeft.Y, rectCircleLeft.X, MathUtils.ToRadian(rectCircleLeft.Angle), rectCircleLeft.Len1, rectCircleLeft.Len2, out circleXLeft, out circleYLeft, out circleRadiusLeft); var valueF25_1 = circleRadiusLeft.D * Weight * 2; var leftCenter = new Point(circleXLeft, circleYLeft); var distYCircleLeft = coordinateSolver.PointLineDistanceInWorld(leftCenter, lineTopBase); var distXCircleLeft = coordinateSolver.PointLineDistanceInWorld(leftCenter, lineLeftBase); var valueF25_2 = 2.0 * Point.Distance(new Point(distXCircleLeft, distYCircleLeft), new Point(9.299, 7.886)); #endregion #region 26 var lineF26Left = coordinateSolver.TranslateLineInWorldUnit(-0.6, findLineManager.GetLine("24.left").SortUpDown(), true); var lineF26Right = coordinateSolver.TranslateLineInWorldUnit(0.6, findLineManager.GetLine("24.right").SortUpDown(), true); var rectLeftTop = coordinateSolver.FindLineLocationRelativeToAbsolute(EdgeLocationsRelative["26-leftTop"]); var edgeLeftTop = GetContour(image, rectLeftTop); var pLeftTopF26 = LineContourIntersection(lineF26Left, edgeLeftTop); var rectLeftBottom = coordinateSolver.FindLineLocationRelativeToAbsolute(EdgeLocationsRelative["26-leftBottom"]); var edgeLeftBottom = GetContour(image, rectLeftBottom); var pLeftBottomF26 = LineContourIntersection(lineF26Left, edgeLeftBottom); var rectRightTop = coordinateSolver.FindLineLocationRelativeToAbsolute(EdgeLocationsRelative["26-rightTop"]); var edgeRightTop = GetContour(image, rectRightTop); var pRightTopF26 = LineContourIntersection(lineF26Right, edgeRightTop); var rectRightBottom = coordinateSolver.FindLineLocationRelativeToAbsolute(EdgeLocationsRelative["26-rightBottom"]); var edgeRightBottom = GetContour(image, rectRightBottom); var pRightBottomF26 = LineContourIntersection(lineF26Right, edgeRightBottom); var valueF26_1 = coordinateSolver.PointPointDistanceInWorld(pLeftTopF26, pLeftBottomF26, true); var valueF26_2 = coordinateSolver.PointPointDistanceInWorld(pRightTopF26, pRightBottomF26, true); #endregion #region 27 var rectCircleRight = coordinateSolver.FindLineLocationRelativeToAbsolute(EdgeLocationsRelative["rightCircle"]); HTuple circleXRight, circleYRight, circleRadiusRight; HObject rightCircleContour; HalconScripts.I94FindRightCircle(image, out rightCircleContour, rectCircleRight.Y, rectCircleRight.X, MathUtils.ToRadian(rectCircleRight.Angle), rectCircleRight.Len1, rectCircleRight.Len2, out circleXRight, out circleYRight, out circleRadiusRight); var rightCenter = new Point(circleXRight, circleYRight); var lineF27Left = coordinateSolver.TranslateLineInWorldUnit(-23.5, lineLeftBase, true); var lineF27Right = coordinateSolver.TranslateLineInWorldUnit(-25, lineLeftBase, true); var pTopLeftF27 = findLineManager.GetLine("27.top").Intersect(lineF27Left); var pTopRightF27 = findLineManager.GetLine("27.top").Intersect(lineF27Right); var pBottomLeftF27 = findLineManager.GetLine("27.bottom").Intersect(lineF27Left); var pBottomRightF27 = findLineManager.GetLine("27.bottom").Intersect(lineF27Right); var pF27Top = Point.CenterPointInImage(pTopLeftF27, pTopRightF27); var pF27Bottom = Point.CenterPointInImage(pBottomLeftF27, pBottomRightF27); var value27_1 = coordinateSolver.PointPointDistanceInWorld(rightCenter, pF27Top, true); var value27_2 = coordinateSolver.PointPointDistanceInWorld(rightCenter, pF27Bottom, true); #endregion #region 28 var valueF28_1 = circleRadiusRight.D * Weight * 2; var distYCircleRight = coordinateSolver.PointLineDistanceInWorld(rightCenter, lineTopBase); var distXCircleRight = coordinateSolver.PointLineDistanceInWorld(rightCenter, lineLeftBase); var valueF28_2 = 2.0 * Point.Distance(new Point(distXCircleRight, distYCircleRight), new Point(24.434, 16.624)); #endregion #region 29 var lineF29Top = coordinateSolver.TranslateLineInWorldUnit(16, lineTopBase, true); var lineF29Bottom = coordinateSolver.TranslateLineInWorldUnit(17.2, lineTopBase, true); var pLeftTopF29 = findLineManager.GetLine("29.left").Intersect(lineF29Top); var pLeftBottomF29 = findLineManager.GetLine("29.left").Intersect(lineF29Bottom); var pRightTopF29 = findLineManager.GetLine("29.right").Intersect(lineF29Top); var pRightBottomF29 = findLineManager.GetLine("29.right").Intersect(lineF29Bottom); var pF29Left = Point.CenterPointInImage(pLeftTopF29, pLeftBottomF29); var pF29Right = Point.CenterPointInImage(pRightTopF29, pRightBottomF29); var valueF29_1 = coordinateSolver.PointPointDistanceInWorld(rightCenter, pF29Left, true); var valueF29_2 = coordinateSolver.PointPointDistanceInWorld(rightCenter, pF29Right, true); #endregion #region 31 var line3F31 = findLineManager.GetLine("31.topLeft").SortUpDown(); var line1F31 = findLineManager.GetLine("31.bottomRight").SortUpDown(); var p1L5F31 = Point.CenterPointInImage(new Point(line3F31.XStart, line3F31.YStart), new Point(line1F31.XStart, line1F31.YStart)); var p2L5F31 = Point.CenterPointInImage(new Point(line3F31.XEnd, line3F31.YEnd), new Point(line1F31.XEnd, line1F31.YEnd)); var l5F31 = new Line(p1L5F31.ImageX, p1L5F31.ImageY, p2L5F31.ImageX, p2L5F31.ImageY); var line2F31 = findLineManager.GetLine("31.topRight").SortUpDown(); var line4F31 = findLineManager.GetLine("31.bottomLeft").SortUpDown(); var p1L6F31 = Point.CenterPointInImage(new Point(line2F31.XStart, line2F31.YStart), new Point(line4F31.XStart, line4F31.YStart)); var p2L6F31 = Point.CenterPointInImage(new Point(line2F31.XEnd, line2F31.YEnd), new Point(line4F31.XEnd, line4F31.YEnd)); var l6F31 = new Line(p1L6F31.ImageX, p1L6F31.ImageY, p2L6F31.ImageX, p2L6F31.ImageY); var pMeasureF31 = l5F31.Intersect(l6F31); var lineHF31 = coordinateSolver.TranslateLineInWorldUnit(25.362, lineTopBase); var lineVF31 = coordinateSolver.TranslateLineInWorldUnit(-9.299, lineLeftBase); var pIdealF31 = lineHF31.Intersect(lineVF31); var valueF31 = 2 * coordinateSolver.PointPointDistanceInWorld(pIdealF31, pMeasureF31); #endregion #region 32 var lineF32Top = lineF21Top; var lineF32Bottom = coordinateSolver.TranslateLineInWorldUnit(30.1, lineTopBase, true); var lineF32Left = lineF23Left; var lineF32Right = lineF23Right; var lineF32IdealHorizontal = coordinateSolver.TranslateLineInWorldUnit(25.392, lineTopBase, true); var lineF32IdealVertical = coordinateSolver.TranslateLineInWorldUnit(-9.299, lineLeftBase, true); var pTopLeftF32 = findLineManager.GetLine("23top").Intersect(lineF32Left); var pTopRightF32 = findLineManager.GetLine("23top").Intersect(lineF32Right); var pBottomLeftF32 = findLineManager.GetLine("23bottom").Intersect(lineF32Left); var pBottomRightF32 = findLineManager.GetLine("23bottom").Intersect(lineF32Right); var pLeftTopF32 = findLineManager.GetLine("21left").Intersect(lineF32Top); var pLeftBottomF32 = findLineManager.GetLine("21left").Intersect(lineF32Bottom); var pRightTopF32 = findLineManager.GetLine("21right").Intersect(lineF32Top); var pRightBottomF32 = findLineManager.GetLine("21right").Intersect(lineF32Bottom); var pF32Top = Point.CenterPointInImage(pLeftTopF32, pRightTopF32); var pF32Bottom = Point.CenterPointInImage(pLeftBottomF32, pRightBottomF32); var lineF32Vertical = new Line(pF32Top.ImageX, pF32Top.ImageY, pF32Bottom.ImageX, pF32Bottom.ImageY); var pF32Left = Point.CenterPointInImage(pTopLeftF32, pBottomLeftF32); var pF32Right = Point.CenterPointInImage(pTopRightF32, pBottomRightF32); var lineF32Horizontal = new Line(pF32Left.ImageX, pF32Left.ImageY, pF32Right.ImageX, pF32Right.ImageY); var pF32Ideal = lineF32IdealHorizontal.Intersect(lineF32IdealVertical); var pF32 = lineF32Horizontal.Intersect(lineF32Vertical); var valueF32 = 2 * coordinateSolver.PointPointDistanceInWorld(pF32Ideal, pF32); #endregion #region 33 var lineF33Left = lineF26Left; var lineF33Right = lineF26Right; var pM1F33 = Point.CenterPointInImage(pLeftTopF26, pLeftBottomF26); var pM2F33 = Point.CenterPointInImage(pRightTopF26, pRightBottomF26); var l4F33 = new Line(pM1F33.ImageX, pM1F33.ImageY, pM2F33.ImageX, pM2F33.ImageY); var lineLeftF33 = lineF26Left.SortUpDown(); var lineRightF33 = lineF26Right.SortUpDown(); var l3p1F33 = Point.CenterPointInImage(lineLeftF33.PointStart, lineRightF33.PointStart); var l3p2F33 = Point.CenterPointInImage(lineLeftF33.PointEnd, lineRightF33.PointEnd); var l3F33 = new Line(l3p1F33, l3p2F33); var pMeasureF33 = l4F33.Intersect(l3F33); var lineHF33 = coordinateSolver.TranslateLineInWorldUnit(7.886, lineTopBase); var lineVF33 = coordinateSolver.TranslateLineInWorldUnit(-9.299, lineLeftBase); var pIdealF33 = lineHF33.Intersect(lineVF33); var valueF33 = 2 * coordinateSolver.PointPointDistanceInWorld(pIdealF33, pMeasureF33); #endregion #region 123 var p1F123 = findLineManager.GetLine("123").Intersect(lineF123Left); var p2F123 = findLineManager.GetLine("123").Intersect(lineF123Center); var p3F123 = findLineManager.GetLine("123").Intersect(lineF123Right); var valueF123_1 = coordinateSolver.PointLineDistanceInWorld(p1F123, lineTopBase); var valueF123_2 = coordinateSolver.PointLineDistanceInWorld(p2F123, lineTopBase); var valueF123_3 = coordinateSolver.PointLineDistanceInWorld(p3F123, lineTopBase); #endregion #region Outputs Dictionary <string, double> outputs = new Dictionary <string, double>(); outputs["21_1"] = valueF21Top; outputs["21_2"] = valueF21Bottom; outputs["23_1"] = valueF23Left; outputs["23_2"] = valueF23Right; outputs["24_1"] = valueF24; outputs["25_1"] = valueF25_1; outputs["25_2"] = valueF25_2; outputs["26_1"] = valueF26_1; outputs["26_2"] = valueF26_2; outputs["27_1"] = value27_1; outputs["27_2"] = value27_2; outputs["28_1"] = valueF28_1; outputs["28_2"] = valueF28_2; outputs["29_1"] = valueF29_1; outputs["29_2"] = valueF29_2; outputs["31_1"] = valueF31; outputs["32_1"] = valueF32; outputs["33_1"] = valueF33; outputs["123_1"] = valueF123_1; outputs["123_2"] = valueF123_2; outputs["123_3"] = valueF123_3; var graphics = new HalconGraphics() { CrossesIgnored = findLineManager.CrossesIgnored, CrossesUsed = findLineManager.GenCrossesUsed(), FindLineRects = findLineManager.FindLineRects, LineRegions = findLineManager.LineRegions, Edges = HalconHelper.ConcatAll(findLineManager.Edges, edgeLeftTop, edgeLeftBottom, edgeRightTop, edgeRightBottom, leftCircleContour, rightCircleContour), PointPointGraphics = coordinateSolver.PointPointDistanceGraphics, PointLineGraphics = coordinateSolver.PointLineDistanceGraphics, // Image = image }; #endregion return(new ImageProcessingResult() { DataRecorder = new DataRecorder(changeOfBaseInv), FaiDictionary = outputs, HalconGraphics = graphics }); }
public void AddEdges(HObject edges) { Edges = HalconHelper.ConcatAll(Edges, edges); }
public void AddFindLineRects(HObject rect) { FindLineRects = HalconHelper.ConcatAll(FindLineRects, rect); }
public void AddLineRegion(HObject lineRegion) { LineRegions = HalconHelper.ConcatAll(LineRegions, lineRegion); }
private void LoadFormInfo() { try { halconHelper = new HalconHelper(hWindowControl1.HalconWindow); List <IDeviceInfo> li = Enumerator.EnumerateDevices(); //if (Convert.ToInt32(this.Tag) != -1) if (li.Count > 0) { m_dev = Enumerator.GetDeviceByIndex(0); //m_dev = Enumerator.GetDeviceByIndex(Convert.ToInt32(this.Tag)); // 注册链接时间 m_dev.CameraOpened += OnCameraOpen; m_dev.ConnectionLost += OnConnectLoss; m_dev.CameraClosed += OnCameraClose; // 打开设备 if (!m_dev.Open()) { MessageBox.Show(@"连接相机失败"); return; } // 关闭Trigger //m_dev.TriggerSet.Close(); // 打开Software Trigger m_dev.TriggerSet.Open(TriggerSourceEnum.Software); // 设置图像格式 using (IEnumParameter p = m_dev.ParameterCollection[ParametrizeNameSet.ImagePixelFormat]) { p.SetValue("Mono8"); } // 注册码流回调事件 m_dev.StreamGrabber.ImageGrabbed += OnImageGrabbed; // 开启码流 if (!m_dev.GrabUsingGrabLoopThread()) { MessageBox.Show(@"开启码流失败"); return; } else { m_dev.ExecuteSoftwareTrigger(); } } else { } //注册一维码识别完成事件 halconHelper.Complete += OnComplete; halconHelper.Error += OnError; //注册串口接收事件 serialComm.DateReceived += new Comm.EventHandle(OnDataReceived); weightComm.DateReceived += new Comm.EventHandle(OnWeightDataReceived); } catch (Exception ex) { Catcher.Show(ex); } }