Пример #1
0
        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
            });
        }
Пример #2
0
        public async Task <ImageProcessingResult> ProcessAsync(List <HImage> images, FindLineConfigs findLineConfigs,
                                                               List <FaiItem> faiItems, int indexToShow, ISnackbarMessageQueue messageQueue)
        {
            int backLightIndex  = 1;
            int frontLightIndex = 0;

            HObject imageUndistorted;
            HTuple  changeOfBase;
            HTuple  changeOfBaseInv;
            HTuple  rotationMat;
            HTuple  rotationMatInv;
            HTuple  mapToWorld;
            HTuple  mapToImage;
            HTuple  xLeft, yLeft, xRight, yRight, xUp, yUp, xDown, yDown;
            HTuple  baseRightCol,
                    baseRightLen1,
                    baseRightLen2,
                    baseRightRadian,
                    baseRightRow,
                    baseTopCol,
                    baseTopLen1,
                    baseTopLen2,
                    baseTopRadian,
                    baseTopRow,
                    camParams;


            // Calculate matrices

            HalconScripts.GetI94TopViewBaseRectsNoRectify(images[backLightIndex], _shapeModelHandle, out baseTopRow,
                                                          out baseTopCol, out baseTopRadian, out baseTopLen1, out baseTopLen2, out baseRightRow,
                                                          out baseRightCol, out baseRightRadian, out baseRightLen1, out baseRightLen2, out mapToWorld, out mapToImage, out camParams
                                                          );

            // Undistort images
//            images[backLightIndex] = imageUndistorted.HobjectToHimage();
//            HTuple _;
//            HalconScripts.UndistortImage(images[frontLightIndex], out imageUndistorted, camParams, out _);
//            images[frontLightIndex] = 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", images[backLightIndex], 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["RightBase"];
            var findLineFeedingsRight = findLineParamRight.ToFindLineFeeding();

            findLineFeedingsRight.Col        = baseRightCol;
            findLineFeedingsRight.Row        = baseRightRow;
            findLineFeedingsRight.Radian     = baseRightRadian;
            findLineFeedingsRight.Len1       = baseRightLen1;
            findLineFeedingsRight.Len2       = baseRightLen2;
            findLineFeedingsRight.Transition = "negative";
            var lineRightBase = findLineManager.TryFindLine("Y-axis", images[backLightIndex], findLineFeedingsRight);

            HalconScripts.SortLineUpDown(lineRightBase.XStart, lineRightBase.YStart, lineRightBase.XEnd, lineRightBase.YEnd, out xUp, out yUp, out xDown, out yDown);


            HalconScripts.GetChangeOfBase(xRight, yRight, xLeft, yLeft, xUp, yUp, xDown, yDown, out changeOfBase, out changeOfBaseInv, out rotationMat, out rotationMatInv);
            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);

            // Make parallel lines
            var lineFai2and3P2 = coordinateSolver.TranslateLineInWorldUnit(9, lineRightBase, true);

            var lineFai4P1 = coordinateSolver.TranslateLineInWorldUnit(3, lineRightBase, true);
            var lineFai4P2 = coordinateSolver.TranslateLineInWorldUnit(9.269, lineRightBase, true);
            var lineFai4P3 = coordinateSolver.TranslateLineInWorldUnit(15.5, lineRightBase, true);

            var lineFai5P1 = coordinateSolver.TranslateLineInWorldUnit(5.299, lineRightBase, true);
            var lineFai5P2 = coordinateSolver.TranslateLineInWorldUnit(9.299, lineRightBase, true);
            var lineFai5P3 = coordinateSolver.TranslateLineInWorldUnit(13.299, lineRightBase, true);

            var lineFai6P1 = coordinateSolver.TranslateLineInWorldUnit(22.024, lineRightBase, true);
            var lineFai6P2 = coordinateSolver.TranslateLineInWorldUnit(24.024, lineRightBase, true);
            var lineFai6P3 = coordinateSolver.TranslateLineInWorldUnit(26.024, lineRightBase, true);

            var lineFai9P1 = coordinateSolver.TranslateLineInWorldUnit(21.753, lineRightBase, true);
            var lineFai9P2 = coordinateSolver.TranslateLineInWorldUnit(23.753, lineRightBase, true);
            var lineFai9P3 = coordinateSolver.TranslateLineInWorldUnit(25.753, lineRightBase, true);

            var lineFai12P1 = coordinateSolver.TranslateLineInWorldUnit(-23.213, lineTopBase, true);
            var lineFai12P2 = coordinateSolver.TranslateLineInWorldUnit(-34.97, lineTopBase, true);

            var lineFai16P1 = coordinateSolver.TranslateLineInWorldUnit(-13.071, lineTopBase, true);
            var lineFai16P2 = coordinateSolver.TranslateLineInWorldUnit(-20.213, lineTopBase, true);

            var lineFai17P1 = coordinateSolver.TranslateLineInWorldUnit(-1.53, lineTopBase, true);
            var lineFai17P2 = coordinateSolver.TranslateLineInWorldUnit(-9.827, lineTopBase, true);

            var lineFai19P1 = coordinateSolver.TranslateLineInWorldUnit(-2.157, lineTopBase, true);
            var lineFai19P2 = coordinateSolver.TranslateLineInWorldUnit(-13.791, lineTopBase, true);

            var lineFai20CenterX = coordinateSolver.TranslateLineInWorldUnit(9.299, lineRightBase, true);
            var lineFai20CenterY = coordinateSolver.TranslateLineInWorldUnit(-7.886, lineTopBase, true);

            // Intersections
            var p2F2 = lineFai2and3P2.Intersect(findLineManager.GetLine("02"));

            var p2F3 = lineFai2and3P2.Intersect(findLineManager.GetLine("03"));

            var p1F4 = lineFai4P1.Intersect((findLineManager.GetLine("04")));
            var p2F4 = lineFai4P2.Intersect((findLineManager.GetLine("04")));
            var p3F4 = lineFai4P3.Intersect((findLineManager.GetLine("04")));

            var p1F5 = lineFai5P1.Intersect((findLineManager.GetLine("05")));
            var p2F5 = lineFai5P2.Intersect((findLineManager.GetLine("05")));
            var p3F5 = lineFai5P3.Intersect((findLineManager.GetLine("05")));

            var p1F6 = lineFai6P1.Intersect((findLineManager.GetLine("06")));
            var p2F6 = lineFai6P2.Intersect((findLineManager.GetLine("06")));
            var p3F6 = lineFai6P3.Intersect((findLineManager.GetLine("06")));

            var p1F9 = lineFai9P1.Intersect((findLineManager.GetLine("09")));
            var p2F9 = lineFai9P2.Intersect((findLineManager.GetLine("09")));
            var p3F9 = lineFai9P3.Intersect((findLineManager.GetLine("09")));

            var p1F12 = lineFai12P1.Intersect((findLineManager.GetLine("12")));
            var p2F12 = lineFai12P2.Intersect((findLineManager.GetLine("12")));

            var p1F16 = lineFai16P1.Intersect((findLineManager.GetLine("16")));
            var p2F16 = lineFai16P2.Intersect((findLineManager.GetLine("16")));

            var p1F17 = lineFai17P1.Intersect((findLineManager.GetLine("17")));
            var p2F17 = lineFai17P2.Intersect((findLineManager.GetLine("17")));

            var p1F19 = lineFai19P1.Intersect((findLineManager.GetLine("19")));
            var p2F19 = lineFai19P2.Intersect((findLineManager.GetLine("19")));

            var p20Center = lineFai20CenterX.Intersect(lineFai20CenterY);

            // Measure point-line distances
            var valueF2P2 = coordinateSolver.PointLineDistanceInWorld(p2F2, lineTopBase);

            var valueF3P2 = coordinateSolver.PointLineDistanceInWorld(p2F3, lineTopBase);

            var valueF4P1 = coordinateSolver.PointLineDistanceInWorld(p1F4, lineTopBase);
            var valueF4P2 = coordinateSolver.PointLineDistanceInWorld(p2F4, lineTopBase);
            var valueF4P3 = coordinateSolver.PointLineDistanceInWorld(p3F4, lineTopBase);

            var valueF5P1 = coordinateSolver.PointLineDistanceInWorld(p1F5, lineTopBase);
            var valueF5P2 = coordinateSolver.PointLineDistanceInWorld(p2F5, lineTopBase);
            var valueF5P3 = coordinateSolver.PointLineDistanceInWorld(p3F5, lineTopBase);

            var valueF6P1 = coordinateSolver.PointLineDistanceInWorld(p1F6, lineTopBase);
            var valueF6P2 = coordinateSolver.PointLineDistanceInWorld(p2F6, lineTopBase);
            var valueF6P3 = coordinateSolver.PointLineDistanceInWorld(p3F6, lineTopBase);

            var valueF9P1 = coordinateSolver.PointLineDistanceInWorld(p1F9, lineTopBase);
            var valueF9P2 = coordinateSolver.PointLineDistanceInWorld(p2F9, lineTopBase);
            var valueF9P3 = coordinateSolver.PointLineDistanceInWorld(p3F9, lineTopBase);

            var valueF12P1 = coordinateSolver.PointLineDistanceInWorld(p1F12, lineRightBase);
            var valueF12P2 = coordinateSolver.PointLineDistanceInWorld(p2F12, lineRightBase);

            var valueF16P1 = coordinateSolver.PointLineDistanceInWorld(p1F16, lineRightBase);
            var valueF16P2 = coordinateSolver.PointLineDistanceInWorld(p2F16, lineRightBase);

            var valueF17P1 = coordinateSolver.PointLineDistanceInWorld(p1F17, lineRightBase);
            var valueF17P2 = coordinateSolver.PointLineDistanceInWorld(p2F17, lineRightBase);

            var valueF19P1 = coordinateSolver.PointLineDistanceInWorld(p1F19, lineRightBase);
            var valueF19P2 = coordinateSolver.PointLineDistanceInWorld(p2F19, lineRightBase);


            // Record points
            var recorder = new DataRecorder(changeOfBaseInv);

            recorder.RecordPoint(findLineManager.GetLine("02"), lineRightBase, "XAxis-02");
            recorder.RecordPoint(findLineManager.GetLine("03"), lineRightBase, "YAxis-03");
            recorder.RecordPoint(findLineManager.GetLine("04"), lineRightBase, "YAxis-04");
            recorder.RecordPoint(findLineManager.GetLine("05"), lineRightBase, "YAxis-05");
            recorder.RecordPoint(findLineManager.GetLine("06"), lineRightBase, "YAxis-06");
            // Record angles
            recorder.RecordLine(lineTopBase, "X-axis");
            recorder.RecordLine(lineRightBase, "Y-axis");
            recorder.RecordLine(findLineManager.GetLine("02"), "02");
            recorder.RecordLine(findLineManager.GetLine("03"), "03");
            recorder.RecordLine(findLineManager.GetLine("04"), "04");
            recorder.RecordLine(findLineManager.GetLine("05"), "05");
            recorder.RecordLine(findLineManager.GetLine("06"), "06");
            recorder.RecordLine(findLineManager.GetLine("20.topRight"), "20.topRight");
            recorder.RecordLine(findLineManager.GetLine("20.bottomLeft"), "20.bottomLeft");



            //Fai 20.1
            var     ptOrigin = lineTopBase.Intersect(lineRightBase);
            HTuple  rotatedX1, rotatedX2, rotatedY1, rotatedY2;
            HObject lineRegion;

            HalconScripts.PivotLineAroundPoint(out lineRegion, xLeft, yLeft, xRight, yRight, ptOrigin.ImageX, ptOrigin.ImageY,
                                               MathUtils.ToRadian(45), "right", 5120, 5120, out rotatedX1, out rotatedY1, out rotatedX2,
                                               out rotatedY2);
            var lineRotated = new Line(rotatedX1.D, rotatedY1.D, rotatedX2.D, rotatedY2.D);

            lineRotated.IsVisible = true;

            HalconScripts.PivotLineAroundPoint(out lineRegion, xLeft, yLeft, xRight, yRight, ptOrigin.ImageX, ptOrigin.ImageY,
                                               MathUtils.ToRadian(-45), "right", 5120, 5120, out rotatedX1, out rotatedY1, out rotatedX2,
                                               out rotatedY2);
            var lineProject = new Line(rotatedX1.D, rotatedY1.D, rotatedX2.D, rotatedY2.D)
            {
                IsVisible = true
            };
            var lineFai20TopRight             = findLineManager.GetLine("20.topRight");
            var pointOnTopRight               = new Point((lineFai20TopRight.XStart + lineFai20TopRight.XEnd) / 2.0, (lineFai20TopRight.YStart + lineFai20TopRight.YEnd) / 2.0);
            var lineFai20BottomLeft           = findLineManager.GetLine("20.bottomLeft");
            var valueF20P1                    = coordinateSolver.PointLineDistanceInWorld(pointOnTopRight, lineFai20BottomLeft);
            var linePerpendiculerToBottomLeft =
                lineFai20BottomLeft.PerpendicularLineThatPasses(pointOnTopRight);

            linePerpendiculerToBottomLeft.IsVisible = true;
            var angle    = linePerpendiculerToBottomLeft.AngleWithLine(lineProject);
            var cosValue = Math.Cos(angle);

            valueF20P1 = valueF20P1 * cosValue;

            // Fai 20.2
            var pointOnBottomLeft = linePerpendiculerToBottomLeft.Intersect(lineFai20BottomLeft);
            var midPoint          = new Point((pointOnBottomLeft.ImageX + pointOnTopRight.ImageX) / 2.0,
                                              (pointOnBottomLeft.ImageY + pointOnTopRight.ImageY) / 2.0);
            var pointMidProjected = lineProject.ProjectPoint(midPoint);
            var distanceToOrigin  = coordinateSolver.PointPointDistanceInWorld(pointMidProjected, ptOrigin, true);
            var valueF20P2        = Math.Abs(12.202 - distanceToOrigin) * 2;



            // outputs
            var outputs = new Dictionary <string, double>();

            outputs["02_2"] = valueF2P2;

            outputs["03_2"] = valueF3P2;

            outputs["04_1"] = valueF4P1;
            outputs["04_2"] = valueF4P2;
            outputs["04_3"] = valueF4P3;

            outputs["05_1"] = valueF5P1;
            outputs["05_2"] = valueF5P2;
            outputs["05_3"] = valueF5P3;

            outputs["06_1"] = valueF6P1;
            outputs["06_2"] = valueF6P2;
            outputs["06_3"] = valueF6P3;

            outputs["09_1"] = valueF9P1;
            outputs["09_2"] = valueF9P2;
            outputs["09_3"] = valueF9P3;

            outputs["12_1"] = valueF12P1;
            outputs["12_2"] = valueF12P2;

            outputs["16_1"] = valueF16P1;
            outputs["16_2"] = valueF16P2;

            outputs["17_1"] = valueF17P1;
            outputs["17_2"] = valueF17P2;

            outputs["19_1"] = valueF19P1;
            outputs["19_2"] = valueF19P2;

            outputs["20_1"] = valueF20P1;

            outputs["20_2"] = valueF20P2;

            var graphics = new HalconGraphics()
            {
                CrossesIgnored     = findLineManager.CrossesIgnored,
                CrossesUsed        = findLineManager.GenCrossesUsed(),
                FindLineRects      = findLineManager.FindLineRects,
                LineRegions        = findLineManager.LineRegions,
                Edges              = findLineManager.Edges,
                PointPointGraphics = coordinateSolver.PointPointDistanceGraphics,
                PointLineGraphics  = coordinateSolver.PointLineDistanceGraphics,
//                 Image = images[indexToShow]
            };

            return(new ImageProcessingResult()
            {
                DataRecorder = recorder,
                FaiDictionary = outputs,
                HalconGraphics = graphics
            });
        }