Esempio n. 1
0
        /// <summary>
        ///   Project an affine 3D transformation matrix to a 2D projective transformation matrix.
        ///   Instance represents: 3x4 3D transformation matrix.
        /// </summary>
        /// <param name="principalPointRow">Row coordinate of the principal point. Default: 256</param>
        /// <param name="principalPointCol">Column coordinate of the principal point. Default: 256</param>
        /// <param name="focus">Focal length in pixels. Default: 256</param>
        /// <returns>Homogeneous projective transformation matrix.</returns>
        public HHomMat2D HomMat3dProject(
            HTuple principalPointRow,
            HTuple principalPointCol,
            HTuple focus)
        {
            IntPtr proc = HalconAPI.PreCall(254);

            this.Store(proc, 0);
            HalconAPI.Store(proc, 1, principalPointRow);
            HalconAPI.Store(proc, 2, principalPointCol);
            HalconAPI.Store(proc, 3, focus);
            HalconAPI.InitOCT(proc, 0);
            int err = HalconAPI.CallProcedure(proc);

            this.UnpinTuple();
            HalconAPI.UnpinTuple(principalPointRow);
            HalconAPI.UnpinTuple(principalPointCol);
            HalconAPI.UnpinTuple(focus);
            HHomMat2D hhomMat2D;
            int       procResult = HHomMat2D.LoadNew(proc, 0, err, out hhomMat2D);

            HalconAPI.PostCall(proc, procResult);
            GC.KeepAlive((object)this);
            return(hhomMat2D);
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
 private void AffineTransModelContour(HShapeModel model, HRegion modelRegion)
 {
     if (model != null && modelRegion != null)
     {
         try
         {
             //获取金字塔第一层轮廓
             HXLDCont modelContour = model.GetShapeModelContours(1);
             double   num3, num4;
             modelRegion.AreaCenter(out num3, out num4);
             HHomMat2D matd = new HHomMat2D();
             matd.VectorAngleToRigid(0.0, 0.0, 0.0, num3, num4, 0.0);
             HXLD affterAffineModelXLD = matd.AffineTransContourXld(modelContour);
             if (info.IsShowModelXLD)
             {
                 Window.SetColor("green");
                 affterAffineModelXLD.DispXld(Window.Window);
             }
         }
         catch (Exception e)
         {
             WriteErrorLog("VisionTool", e.ToString());
         }
     }
 }
Esempio n. 4
0
 private void ReadCalibData()
 {
     if (System.IO.File.Exists("./Model/Calib.dat"))
     {
         BinaryReader br;
         br = new BinaryReader(new FileStream("./Model/Calib.dat", FileMode.Open));
         HTuple Image_X = new HTuple(), Image_Y = new HTuple(), Robot_X = new HTuple(), Robot_Y = new HTuple();
         int    Num = (int)br.ReadDouble();
         for (int i = 0; i < Num; i++)
         {
             DataGridViewRow row   = new DataGridViewRow();
             int             Count = Calib_dataView.Rows.Add(row);
             double          i_x   = br.ReadDouble();
             double          i_y   = br.ReadDouble();
             double          r_x   = br.ReadDouble();
             double          r_y   = br.ReadDouble();
             Calib_dataView.Rows[Count].Cells[0].Value = i_x;
             Calib_dataView.Rows[Count].Cells[1].Value = i_y;
             Calib_dataView.Rows[Count].Cells[2].Value = r_x;
             Calib_dataView.Rows[Count].Cells[3].Value = r_y;
             Image_X = Image_X.TupleConcat(i_x);
             Image_Y = Image_Y.TupleConcat(i_y);
             Robot_X = Robot_X.TupleConcat(r_x);
             Robot_Y = Robot_Y.TupleConcat(r_y);
         }
         try
         {
             RobotHommat = new HHomMat2D();
             RobotHommat.VectorToHomMat2d(Image_X, Image_Y, Robot_X, Robot_Y);
         }
         catch {
             RobotHommat = null;
         }
     }
 }
        public bool WaitForClickPoints(double x, double y)
        {
            if (_clickedPointsPositionList.Count < _clickPoints)
            {
                _clickedPointsPositionList.Add(new PositionModel()
                {
                    ColBegin = x, RowBegin = y
                });
            }
            _initPointsDone = _clickedPointsPositionList.Count == _clickPoints;
            if (_initPointsDone)
            {
                //產生 Rectangle 資訊
                midR = _clickedPointsPositionList.Average(p => p.RowBegin);
                midC = _clickedPointsPositionList.Average(p => p.ColBegin);

                length1 = _smartWidth;
                length2 = _smartWidth;

                //決定角度
                phi = 0.0;

                rowsInit = new HTuple(new double[] { -1.0, -1.0, 1.0,
                                                     1.0, 0.0, 0.0 });
                colsInit = new HTuple(new double[] { -1.0, 1.0, 1.0,
                                                     -1.0, 0.0, 0.6 });
                //order        ul ,  ur,   lr,  ll,   mp, arrowMidpoint
                hom2D = new HHomMat2D();
                tmp   = new HHomMat2D();

                updateHandlePos();
            }
            return(_initPointsDone);
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes flags, lists, and delegates to have a valid
        /// starting point to start the assistant.
        /// </summary>
        public MatchingAssistant(MatchingParam parSet)
        {
            parameterSet        = parSet;
            NotifyIconObserver  = new MatchingDelegate(dummy);
            NotifyParamObserver = new AutoParamDelegate(dummyS);
            homSc2D             = new HHomMat2D();
            TestImages          = new Hashtable(10);
            tResult             = new MatchingResult();

            contrastLowB    = 0;
            contrastUpB     = 255;
            scaleStepLowB   = 0.0;
            scaleStepUpB    = (double)19.0 / 1000.0;
            angleStepLowB   = 0.0;
            angleStepUpB    = (double)(112.0 / 10.0) * Math.PI / 180.0;
            pyramLevLowB    = 1;
            pyramLevUpB     = 6;
            minContrastLowB = 0;
            minContrastUpB  = 30;

            findAlways        = false;
            createNewModelID  = true;
            ModelID           = new HShapeModel();
            onExternalModelID = false;
        }
        //仿射变换后的全部轮廓
        public void GenDetectionXLDResults(HXLDCont modelXldCont)
        {
            if (resultXLDCont == null)
            {
                resultXLDCont = new HXLDCont();
            }
            if (resultXLDCont != null && resultXLDCont.IsInitialized())
            {
                resultXLDCont.Dispose();
            }
            resultXLDCont.GenEmptyObj();

            HXLDCont rContours;

            for (int i = 0; i < row.Length; i++)
            {
                HHomMat2D mat1 = new HHomMat2D();
                mat1.VectorAngleToRigid(0, 0, 0, row[i].D, column[i].D, angle[i].D);
                mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D);
                //图像偏移
                rContours = mat1.AffineTransContourXld(modelXldCont);
                //获取模板集合
                resultXLDCont = resultXLDCont.ConcatObj(rContours);
                rContours.Dispose();
                rContours.GenCrossContourXld(row[i].D, column[i].D, 10, angle[i].D);
                resultXLDCont = resultXLDCont.ConcatObj(rContours);
                rContours.Dispose();
            }
        }
Esempio n. 8
0
        public override DrawROIable AffineTransROI(HHomMat2D homMat2D)
        {
            double row = homMat2D.AffineTransPoint2d(Row, Column, out double column);

            homMat2D.HomMat2dToAffinePar(out double sy, out double phi, out double theta, out double tx, out double ty);
            return(new DrawEllipse(row, column, Phi + phi, Radius1, Radius2));
        }
Esempio n. 9
0
        public override DrawROIable AffineTransROI(HHomMat2D homMat2D)
        {
            double row = homMat2D.AffineTransPoint2d(Row, Colulmn, out double column);

            homMat2D.HomMat2dToAffinePar(out double sy, out double phi, out double theta, out double tx, out double ty);
            return(new DrawRectangle2(row, column, Phi + phi, Length1, Length2));
        }
        public void GenDetectionRegionResult(HRegion modelRegion)
        {
            if (resultRegion == null)
            {
                resultRegion = new HRegion();
            }
            if (resultRegion != null && resultRegion.IsInitialized())
            {
                resultRegion.Dispose();
            }
            resultRegion.GenEmptyObj();

            HRegion temp = new HRegion();

            for (int i = 0; i < row.Length; i++)
            {
                HHomMat2D mat1 = new HHomMat2D();
                mat1.VectorAngleToRigid(
                    createShapeModel.refCoordinates[0].D,
                    createShapeModel.refCoordinates[1].D,
                    createShapeModel.refCoordinates[2].D,
                    row[i].D, column[i].D, angle[i].D);
                mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D);
                //图像偏移
                temp = mat1.AffineTransRegion(modelRegion, "nearest_neighbor");
                //获取模板集合
                resultRegion = resultRegion.ConcatObj(temp);
                temp.Dispose();
            }
        }
Esempio n. 11
0
        public HXLDCont CreateShapeModel(HImage img, ModelParameter modelParameter, out HShapeModel model)
        {
            model = new HShapeModel(
                img,
                modelParameter.numLevels,
                modelParameter.angleStart,
                modelParameter.angleExtent,
                modelParameter.angleStep,
                modelParameter.scaleMin,
                modelParameter.scaleMax,
                modelParameter.scaleStep,
                modelParameter.optimization,
                modelParameter.metric,
                modelParameter.contrast,
                modelParameter.minContrast);



            var modelContours = Model.GetShapeModelContours(1);

            var homMat2D = new HHomMat2D();


            homMat2D.VectorAngleToRigid(0, 0, 0, ModelRegion.Row, ModelRegion.Column, 0);
            var contoursAffinTrans = modelContours.AffineTransContourXld(homMat2D);

            return(contoursAffinTrans);
        }
Esempio n. 12
0
        public void AffineTransPoint()
        {
            TransLocationCross.Clear();
            ShapeMatchResult matchResult = Shape.OutputResult;

            for (int i = 0; i < matchResult.Count; i++)
            {
                HHomMat2D mat2d = new HHomMat2D();
                mat2d.VectorAngleToRigid(Shape.ModelImgRow, Shape.ModelImgCol, Shape.ModelimgAng,
                                         matchResult.Row[i].D, matchResult.Col[i].D, matchResult.Angle[i].D);
                PointF[] fs = Array.ConvertAll <Cross, PointF>(locationCross.GetAllPointFs(), e => e.Pixel);
                HTuple   tx, ty;
                HOperatorSet.AffineTransPoint2d(mat2d,
                                                Array.ConvertAll <PointF, double>(fs, e => e.Y).ToArray(),
                                                Array.ConvertAll <PointF, double>(fs, e => e.X).ToArray(),
                                                out ty,
                                                out tx);

                for (int m = 0; m < locationCross.Count; m++)
                {
                    Cross cross = new Cross();
                    cross.Pixel = new PointF(tx[m].F, ty[m].F);
                    cross.Angle = matchResult.Angle[m].D;
                    cross.Color = "green";
                    TransLocationCross.Add(cross);
                }
            }
        }
Esempio n. 13
0
        public void BuildTransferMatrix()
        {
            HTuple hv_machineY = new HTuple(), hv_machineX = new HTuple();
            HTuple hv_imageY = new HTuple(), hv_imageX = new HTuple();

            int count = Math.Min(ImgPoints.Length, MachinePoints.Length);

            if (count < 2)
            {
                return;
            }
            for (int i = 0; i < count; i++)
            {
                hv_machineX[i] = MachinePoints[i].X;
                hv_machineY[i] = MachinePoints[i].Y;

                hv_imageX[i] = ImgPoints[i].X;
                hv_imageY[i] = ImgPoints[i].Y;
            }

            try
            {
                Mat2D.VectorToSimilarity(hv_imageX, hv_imageY, hv_machineX, hv_machineY);
                var v = Scaling;
                IsBuiltted = true;
            }
            catch (Exception)
            {
                Mat2D      = new HHomMat2D();
                IsBuiltted = false;
            }
        }
        private double DistanceToClosestHandle2(double row, double col)
        {
            HTuple data = base.GetModeData();

            double[] val = new double[_numHandles];
            val[0] = HalconDotNet.HMisc.DistancePp(row, col, data[0], data[1]);

            for (int i = 1; i < _numHandles; i++)
            {
                val[i] = 99999;
            }

            HHomMat2D mat2D          = new HHomMat2D();
            HTuple    init_Arrow_Row = data[0];
            HTuple    init_Arrow_Col = data[1] + data[3] * 0.8;

            mat2D = mat2D.HomMat2dRotate(data[2].D, data[0], data[1]);
            double arrow_Row;
            double arrow_Col;

            arrow_Row            = mat2D.AffineTransPoint2d(init_Arrow_Row, init_Arrow_Col, out arrow_Col);
            val[_numHandles - 1] = HalconDotNet.HMisc.DistancePp(row, col, arrow_Row, arrow_Col);

            double minvalue = 0.0;
            int    idx      = 0;

            if (this.MinValueAndIndex(val, out minvalue, out idx))
            {
                this._activeHandleIdx = idx;
            }
            return(minvalue);
        }
Esempio n. 15
0
        public override DrawROIable AffineTransROI(HHomMat2D homMat2D)
        {
            double row1 = homMat2D.AffineTransPoint2d(Row1, Column1, out double column1);
            double row2 = homMat2D.AffineTransPoint2d(Row2, Column2, out double column2);

            return(new DrawRectangle1(row1, column1, row2, column2));
        }
Esempio n. 16
0
        public override DrawROIable AffineTransROI(HHomMat2D homMat2D)
        {
            double startRow = homMat2D.AffineTransPoint2d(StartRow, StartColumn, out double startColumn);
            double endRow   = homMat2D.AffineTransPoint2d(EndColumn, EndRow, out double endColumn);

            return(new DrawLine(startRow, startColumn, endRow, endColumn));
        }
Esempio n. 17
0
        }        //end of method

        /// <summary>
        /// Auxiliary method to recalculate the contour points of
        /// the rectangle by transforming the initial row and
        /// column coordinates (rowsInit, colsInit) by the updated
        /// homography hom2D
        /// </summary>
        private void updateHandlePos()
        {
            hom2D.HomMat2dIdentity();
            hom2D = hom2D.HomMat2dTranslate(midC, midR);
            hom2D = hom2D.HomMat2dRotateLocal(phi);
            tmp   = hom2D.HomMat2dScaleLocal(length1, length2);
            cols  = tmp.AffineTransPoint2d(colsInit, rowsInit, out rows);
        }
        public void ReverseTransPoint2d(HTuple x, HTuple y, out HTuple tx, out HTuple ty)
        {
            HHomMat2D mat2D = matrix.HomMat2dInvert();

            Debug.Assert((x != null) && (y != null));
            Debug.Assert(x.Length == y.Length, string.Format("输入参数长度错误:x={0},Y={1}", x.Length, y.Length));
            HOperatorSet.AffineTransPoint2d(mat2D, x, y, out tx, out ty);
        }
        /// <summary>
        /// 获取校正轴矩阵
        /// </summary>
        /// <returns></returns>
        public HHomMat2D getHomAxis()
        {
            HHomMat2D homA = new HHomMat2D();

            homA = homA.HomMat2dRotateLocal(PhiX);
            //homA = homA.HomMat2dSlantLocal(-PhiY, "y");
            return(homA);
        }
        /// <summary>
        /// 获取校正图片矩阵
        /// </summary>
        /// <returns></returns>
        public HHomMat2D getHomImg()
        {
            HHomMat2D hom = new HHomMat2D();

            //hom = hom.HomMat2dRotateLocal(PhiX);
            hom = hom.HomMat2dScaleLocal(ScaleX, ScaleY);
            //hom=hom.HomMat2dTranslate(Y * Math.Sin(PhiX), X * Math.Sin(PhiX));//有待验证
            return(hom);
        }
Esempio n. 21
0
        public void ClearCalibrationData()
        {
            CalibrateData.Clear();
            PixelToWorld = new HHomMat2D();
            WorldToPixel = new HHomMat2D();
            IsBuiltted   = false;

            OnChangeCalibrateData();
        }
Esempio n. 22
0
        /// <summary>
        ///更新操作点
        /// </summary>
        private void updateHandlePos()
        {
            _hom2D.HomMat2dIdentity();
            _hom2D  = _hom2D.HomMat2dTranslate(this._mid_col_x, this._mid_row_y);
            _hom2D  = _hom2D.HomMat2dRotateLocal(this._phi);
            _tmp    = _hom2D.HomMat2dScaleLocal(this._len1, this._len2);
            _cols_x = _tmp.AffineTransPoint2d(_colsInit_x, _rowsInit_y, out _rows_y);

            updateInterface();
        }
        public void RotateTrans(double x, double y, double r, out double tx, out double ty)
        {
            HHomMat2D mat2D = new HHomMat2D();

            mat2D = mat2D.HomMat2dRotate((HTuple)r, RotateCircle.Center.X, RotateCircle.Center.Y);
            HTuple qx, qy;

            HOperatorSet.AffineTransPoint2d(mat2D, x, y, out qx, out qy);
            tx = qx[0].D;
            ty = qy[0].D;
        }
Esempio n. 24
0
        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);
        }
Esempio n. 25
0
        public bool WaitForClickPoints(double x, double y)
        {
            if (_clickedPointsPositionList.Count < _clickPoints)
            {
                var isNotTheSamePoint = _clickedPointsPositionList.Count == 0;
                var prevIdx           = _clickedPointsPositionList.Count - 1;
                var prevPoint         = prevIdx > -1 ? _clickedPointsPositionList[prevIdx] : null;
                if (prevPoint != null)
                {
                    isNotTheSamePoint = Math.Abs(prevPoint.ColBegin - x) > 0 || Math.Abs(prevPoint.RowBegin - y) > 0;
                }
                if (isNotTheSamePoint)
                {
                    _clickedPointsPositionList.Add(new PositionModel()
                    {
                        ColBegin = x, RowBegin = y
                    });
                }
            }

            _initPointsDone = _clickedPointsPositionList.Count == _clickPoints;
            if (_initPointsDone)
            {
                //產生 Rectangle 資訊
                midR = _clickedPointsPositionList.Average(p => p.RowBegin);
                midC = _clickedPointsPositionList.Average(p => p.ColBegin);

                //長度
                var beginRow = _clickedPointsPositionList[0].RowBegin;
                var beginCol = _clickedPointsPositionList[0].ColBegin;
                var endRow   = _clickedPointsPositionList[1].RowBegin;
                var endCol   = _clickedPointsPositionList[1].ColBegin;

                var distance = HMisc.DistancePp(beginRow, beginCol, endRow, endCol);
                length1 = distance / 2.0;
                length2 = 10;

                //決定角度
                creakPointPhi = phi = HMisc.AngleLx(beginRow, beginCol, endRow, endCol) * -1;

                rowsInit = new HTuple(new double[] { -1.0, -1.0, 1.0,
                                                     1.0, 0.0, 0.0 });
                colsInit = new HTuple(new double[] { -1.0, 1.0, 1.0,
                                                     -1.0, 0.0, 0.6 });
                //order        ul ,  ur,   lr,  ll,   mp, arrowMidpoint
                hom2D = new HHomMat2D();
                tmp   = new HHomMat2D();

                updateHandlePos();
            }
            return(_initPointsDone);
        }
Esempio n. 26
0
        public override void construct()
        {
            NumHandles      = 6; // 4 corners +  1 midpoint + 1 rotationpoint
            activeHandleIdx = 4;

            rowsInit = new HTuple(new double[] { -1.0, -1.0, 1.0,
                                                 1.0, 0.0, 0.0 });
            colsInit = new HTuple(new double[] { -1.0, 1.0, 1.0,
                                                 -1.0, 0.0, 0.6 });
            //order        ul ,  ur,   lr,  ll,   mp, arrowMidpoint
            hom2D = new HHomMat2D();
            tmp   = new HHomMat2D();
        }
Esempio n. 27
0
        /********************************************************************/
        /*                        getter methods                            */
        /********************************************************************/

        /// <summary>
        /// Gets the model for the current image level
        /// </summary>
        public HXLD getModelContour()
        {
            if (PyramidROIs == null)
            {
                return(null);
            }

            homSc2D.HomMat2dIdentity();
            homSc2D = homSc2D.HomMat2dScaleLocal(scaleW, scaleH);

            return(((PyramidROIs.SelectObj(currentImgLevel)).
                    GenContourRegionXld("center")).
                   AffineTransContourXld(homSc2D));
        }
Esempio n. 28
0
        public ToolResult GetResult()
        {
            try
            {
                int             imageWidt, imageHeight;
                HMetrologyModel metrologyModel = new HMetrologyModel();
                HTuple          startRow, startCol, endRow, endCol;
                HHomMat2D       matd  = new HHomMat2D();
                HHomMat2D       matd3 = matd.HomMat2dRotate(info.Rectangle2Angle, 0.0, 0.0);
                HHomMat2D       matd4 = matd3.HomMat2dTranslate(info.Rectangle2Row, info.Rectangle2Col);
                HOperatorSet.AffineTransPoint2d(matd4, new HTuple(0.0), new HTuple(-info.Rectangle2Length1), out startRow, out startCol);
                HOperatorSet.AffineTransPoint2d(matd4, new HTuple(0.0), new HTuple(info.Rectangle2Length1), out endRow, out endCol);
                //创建找线工具
                Image.GetImageSize(out imageWidt, out imageHeight);
                int[]  value  = new int[] { Convert.ToInt32(startRow.D), Convert.ToInt32(startCol.D), Convert.ToInt32(endRow.D), Convert.ToInt32(endCol.D) };
                HTuple values = new HTuple(value);
                metrologyModel.CreateMetrologyModel();
                metrologyModel.SetMetrologyModelImageSize(imageWidt, imageHeight);
                int index = metrologyModel.AddMetrologyObjectGeneric("line", values, 20, 5, 1, 30, "min_score", 0.6);
                #region 设置参数
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_length1"), new HTuple(Convert.ToInt32(info.measure_length1)));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_length2"), new HTuple(Convert.ToInt32(info.measure_length2)));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_distance"), new HTuple(info.measure_distance));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("num_measures"), new HTuple(info.num_measures));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("num_instances"), new HTuple(info.num_instances));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_sigma"), new HTuple(info.measure_sigma));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_threshold"), new HTuple(info.measure_threshold));
                metrologyModel.SetMetrologyObjectParam(new HTuple(index), new HTuple("measure_transition"), new HTuple(info.measure_transition.ToString()));
                #endregion

                HTuple   Row;
                HTuple   Col;
                HXLDCont modelXLD = metrologyModel.GetMetrologyObjectMeasures(index, "all", out Row, out Col);
                if (info.IsShowLineMeasureDetail)
                {
                    Window.SetColor("red");
                    modelXLD.DispXld(Window.Window);
                }

                return(ApplyMetrology(metrologyModel, index, info.ToolName));
            }
            catch (Exception e)
            {
                return(new ToolResult()
                {
                    ResultName = info.ToolName, Errormessage = e.ToString(), GetResultTime = DateTime.Now, IsSuccess = false
                });
            }
        }
Esempio n. 29
0
        /// <summary>在鼠标位置创建一个新的ROI实例</summary>
        /// <param name="midX">
        /// x (=column) coordinate for interactive ROI
        /// </param>
        /// <param name="midY">
        /// y (=row) coordinate for interactive ROI
        /// </param>
        public override void createROI(double midX, double midY)
        {
            midR = midY;
            midC = midX;

            rowsInit = new HTuple(new double[] { -1.0, -1.0, 1.0,
                                                 1.0, 0.0, 0.0 });
            colsInit = new HTuple(new double[] { -1.0, 1.0, 1.0,
                                                 -1.0, 0.0, 1.2 });
            //order        ul ,  ur,   lr,  ll,   mp, arrowMidpoint
            hom2D = new HHomMat2D();
            tmp   = new HHomMat2D();

            updateHandlePos();
        }
Esempio n. 30
0
        /// <summary>
        /// Gets the detected contour.
        /// </summary>
        /// <returns>Detected contour</returns>
        public HXLDCont getDetectionResults()
        {
            HXLDCont rContours = new HXLDCont();

            hmat.HomMat2dIdentity();

            if (mContResults != null)
            {
                mContResults.Dispose();
            }
            mContResults.GenEmptyObj();



            for (int i = 0; i < count; i++)
            {
                if (mImageScale < 0.1 || mImageScale > 2)
                {
                    mImageScale = 1.0;
                }
                hmat.VectorAngleToRigid(0, 0, 0, mRow[i].D * mImageScale, mCol[i].D * mImageScale, mAngle[i].D);
                //2020.11.7 gengxmÐÞ¸Ä £¬ÂÖÀª·Å´óÈý±¶
                hmat = hmat.HomMat2dScale(1.0000 / mImageScale, 1.0000 / mImageScale, 0, 0);

                rContours = hmat.AffineTransContourXld(mContour);



                mContResults = mContResults.ConcatObj(rContours);
            }
            if (rContours != null)
            {
                rContours.Dispose();
            }

            if (true)
            {
                HTuple convexity;
                HTuple col1, col2, row1, row2;
                HOperatorSet.SmallestRectangle1Xld(mContResults, out row1, out col1, out row2, out col2);
                HOperatorSet.ConvexityXld(mContResults, out convexity);
                // wid = col2 - col1;
                //hei = row2 - row1;
            }

            return(mContResults);
        }
        /// <summary>Creates a new ROI instance at the mouse position</summary>
        /// <param name="midX">
        /// x (=column) coordinate for interactive ROI
        /// </param>
        /// <param name="midY">
        /// y (=row) coordinate for interactive ROI
        /// </param>
        public override void createROI(double midX, double midY)
        {
            midR = midY;
            midC = midX;

            length1 = 100;
            length2 = 50;

            phi = 0.0;

            rowsInit = new HTuple(new double[] {-1.0, -1.0, 1.0,
                                                   1.0,  0.0, 0.0 });
            colsInit = new HTuple(new double[] {-1.0, 1.0,  1.0,
                                                  -1.0, 0.0, 0.6 });
            //order        ul ,  ur,   lr,  ll,   mp, arrowMidpoint
            hom2D = new HHomMat2D();
            tmp = new HHomMat2D();

            updateHandlePos();
        }
 /// <summary>Constructor</summary>
 public MatchingResult()
 {
     hmat = new HHomMat2D();
     mContResults = new HXLDCont();
 }
Esempio n. 33
0
        /// <summary>
        /// Adds visual effects (shadows)
        /// to the measure results.
        /// </summary>
        /// <param name="edges">
        /// Add shadows along the edges provided
        /// </param>
        public void UpdateShadowContours(HObject edges)
        {
            double shift;
            HXLDCont shadow1, shadow2;
            HHomMat2D hom2D = new HHomMat2D();

            mShadow.Dispose();
            mShadow.GenEmptyObj();

            shift = Math.Min(0.5 * lineWidth, 2.0);

            hom2D.HomMat2dIdentity();
            hom2D = hom2D.HomMat2dTranslate(shift, 1);
            shadow1 = ((HXLDCont)edges).AffineTransContourXld(hom2D);

            hom2D.HomMat2dIdentity();
            hom2D = hom2D.HomMat2dTranslate(1, shift);
            shadow2 = ((HXLDCont)edges).AffineTransContourXld(hom2D);

            mShadow = mShadow.ConcatObj(shadow1);
            mShadow = mShadow.ConcatObj(shadow2);

            shadow1.Dispose();
            shadow2.Dispose();
        }
        /// <summary>
        /// Initializes flags, lists, and delegates to have a valid
        /// starting point to start the assistant.
        /// </summary>
        public MatchingAssistant(MatchingParam  parSet)
        {
            parameterSet	= parSet;
            NotifyIconObserver  = new MatchingDelegate(dummy);
            NotifyParamObserver = new AutoParamDelegate(dummyS);
            homSc2D    = new HHomMat2D();
            TestImages = new Hashtable(10);
            tResult	   = new MatchingResult();

            contrastLowB	= 0;
            contrastUpB		= 255;
            scaleStepLowB	= 0.0;
            scaleStepUpB	= (double)19.0/1000.0;
            angleStepLowB	= 0.0;
            angleStepUpB	= (double)(112.0/10.0)*Math.PI/180.0;
            pyramLevLowB	= 1;
            pyramLevUpB		= 6;
            minContrastLowB = 0;
            minContrastUpB	= 30;

            findAlways		 = false;
            createNewModelID = true;
            ModelID			  = new HShapeModel();
            onExternalModelID = false;
        }
        /// <summary>
        /// Gets the model supplied by a loaded shapebased model file (.shm)
        /// </summary>
        public HXLD getLoadedModelContour()
        {
            HTuple row1, col1, row2, col2, row, col;
            HHomMat2D homMat2D = new HHomMat2D();

            try
            {
                tResult.mContour.SmallestRectangle1Xld(out row1, out col1, out row2, out col2);
                row2 = row1.TupleMin();
                col2 = col1.TupleMin();
                row  = row2.TupleFloor()-5;
                col  = col2.TupleFloor()-5;
                homMat2D.HomMat2dIdentity();
                homMat2D = homMat2D.HomMat2dTranslate(-row,-col);

                return homMat2D.AffineTransContourXld(tResult.mContour);
            }
            catch(HOperatorException e)
            {
                exceptionText = e.Message;
                NotifyIconObserver(MatchingAssistant.ERR_READ_SHAPEMODEL);
                return null;
            }
        }
 /// <summary>
 /// Auxiliary method to recalculate the contour points of 
 /// the rectangle by transforming the initial row and 
 /// column coordinates (rowsInit, colsInit) by the updated
 /// homography hom2D
 /// </summary>
 private void updateHandlePos()
 {
     hom2D.HomMat2dIdentity();
     hom2D = hom2D.HomMat2dTranslate(midC, midR);
     hom2D = hom2D.HomMat2dRotateLocal(phi);
     tmp = hom2D.HomMat2dScaleLocal(length1, length2);
     cols = tmp.AffineTransPoint2d(colsInit, rowsInit, out rows);
 }
        /********************************************************************/
        /*                        getter methods                            */
        /********************************************************************/
        /// <summary>
        /// Gets the model for the current image level
        /// </summary>
        public HXLD getModelContour()
        {
            if(PyramidROIs==null)
                return null;

            homSc2D.HomMat2dIdentity();
            homSc2D = homSc2D.HomMat2dScaleLocal(scaleW, scaleH);

            return ((PyramidROIs.SelectObj(currentImgLevel)).
                                           GenContourRegionXld("center")).
                                           AffineTransContourXld(homSc2D);
        }
Esempio n. 38
0
        public bool WaitForClickPoints(double x, double y)
        {
            if (_clickedPointsPositionList.Count < _clickPoints)
            {
                _clickedPointsPositionList.Add(new PositionModel() { ColBegin = x, RowBegin = y });
            }
            _initPointsDone = _clickedPointsPositionList.Count == _clickPoints;
            if (_initPointsDone)
            {
                //產生 Rectangle 資訊
                midR = _clickedPointsPositionList.Average(p => p.RowBegin);
                midC = _clickedPointsPositionList.Average(p => p.ColBegin);

                length1 = _smartWidth;
                length2 = _smartWidth;

                //決定角度
                phi = 0.0;

                rowsInit = new HTuple(new double[] {-1.0, -1.0, 1.0,
                                                   1.0,  0.0, 0.0 });
                colsInit = new HTuple(new double[] {-1.0, 1.0,  1.0,
                                                  -1.0, 0.0, 0.6 });
                //order        ul ,  ur,   lr,  ll,   mp, arrowMidpoint
                hom2D = new HHomMat2D();
                tmp = new HHomMat2D();

                updateHandlePos();
            }
            return _initPointsDone;
        }
Esempio n. 39
0
        /// <summary>
        /// 重設 ROI 資訊
        /// </summary>
        /// <param name="roiRow">中心點 Row</param>
        /// <param name="roiCol">中心點 Col</param>
        /// <param name="roiPhi">角度</param>
        /// <param name="roiLength">half 長</param>
        /// <param name="roiWidth">half 寬</param>
        public void MakeROI(double roiRow, double roiCol, double roiPhi, double roiLength, double roiWidth)
        {
            midR = roiRow;
            midC = roiCol;

            length1 = roiLength;
            length2 = roiWidth;

            phi = roiPhi;

            rowsInit = new HTuple(new double[] {-1.0, -1.0, 1.0,
                                                   1.0,  0.0, 0.0 });
            colsInit = new HTuple(new double[] {-1.0, 1.0,  1.0,
                                                  -1.0, 0.0, 0.6 });
            //order        ul ,  ur,   lr,  ll,   mp, arrowMidpoint
            hom2D = new HHomMat2D();
            tmp = new HHomMat2D();

            updateHandlePos();
        }
Esempio n. 40
0
        public bool WaitForClickPoints(double x, double y)
        {
            if (_clickedPointsPositionList.Count < _clickPoints)
            {
                var isNotTheSamePoint = _clickedPointsPositionList.Count == 0;
                var prevIdx = _clickedPointsPositionList.Count - 1;
                var prevPoint = prevIdx > -1 ? _clickedPointsPositionList[prevIdx] : null;
                if (prevPoint != null)
                {
                    isNotTheSamePoint = Math.Abs(prevPoint.ColBegin - x) > 0 || Math.Abs(prevPoint.RowBegin - y) > 0;
                }
                if (isNotTheSamePoint)
                {
                    _clickedPointsPositionList.Add(new PositionModel() { ColBegin = x, RowBegin = y });
                }
            }

            _initPointsDone = _clickedPointsPositionList.Count == _clickPoints;
            if (_initPointsDone)
            {
                //產生 Rectangle 資訊
                midR = _clickedPointsPositionList.Average(p => p.RowBegin);
                midC = _clickedPointsPositionList.Average(p => p.ColBegin);

                //長度
                var beginRow = _clickedPointsPositionList[0].RowBegin;
                var beginCol = _clickedPointsPositionList[0].ColBegin;
                var endRow = _clickedPointsPositionList[1].RowBegin;
                var endCol = _clickedPointsPositionList[1].ColBegin;

                var distance = HMisc.DistancePp(beginRow, beginCol, endRow, endCol);
                length1 = distance / 2.0;
                length2 = 10;

                //決定角度
                creakPointPhi = phi = HMisc.AngleLx(beginRow, beginCol, endRow, endCol) * -1;

                rowsInit = new HTuple(new double[] {-1.0, -1.0, 1.0,
                                                   1.0,  0.0, 0.0 });
                colsInit = new HTuple(new double[] {-1.0, 1.0,  1.0,
                                                  -1.0, 0.0, 0.6 });
                //order        ul ,  ur,   lr,  ll,   mp, arrowMidpoint
                hom2D = new HHomMat2D();
                tmp = new HHomMat2D();

                updateHandlePos();
            }
            return _initPointsDone;
        }