예제 #1
0
        public void get_features(HObject ho_Region, out HTuple hv_Features)
        {
            // Local iconic variables
            HObject ho_SingleRegion, ho_Contours;
            // Local control variables
            HTuple hv_Circularity_xld = null, hv_ContLength = null;
            HTuple hv_Circularity = null, hv_Anisometry = null, hv_Bulkiness = null;
            HTuple hv_StructureFactor = null, hv_Distance = null, hv_Sigma = null;
            HTuple hv_Roundness = null, hv_Sides = null, hv_PSI1 = null;
            HTuple hv_PSI2 = null, hv_PSI3 = null, hv_PSI4 = null;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_SingleRegion);
            HOperatorSet.GenEmptyObj(out ho_Contours);
            ho_SingleRegion.Dispose();
            HOperatorSet.SelectObj(ho_Region, out ho_SingleRegion, 1);
            ho_Contours.Dispose();
            HOperatorSet.GenContourRegionXld(ho_SingleRegion, out ho_Contours, "border");
            HOperatorSet.CircularityXld(ho_Contours, out hv_Circularity_xld);
            HOperatorSet.Contlength(ho_SingleRegion, out hv_ContLength);
            HOperatorSet.Circularity(ho_SingleRegion, out hv_Circularity);
            HOperatorSet.Eccentricity(ho_SingleRegion, out hv_Anisometry, out hv_Bulkiness, out hv_StructureFactor);
            HOperatorSet.Roundness(ho_SingleRegion, out hv_Distance, out hv_Sigma, out hv_Roundness, out hv_Sides);
            HOperatorSet.MomentsRegionCentralInvar(ho_SingleRegion, out hv_PSI1, out hv_PSI2, out hv_PSI3, out hv_PSI4);
            hv_Features = new HTuple();
            hv_Features = hv_Features.TupleConcat(hv_Circularity);
            hv_Features = hv_Features.TupleConcat(hv_Circularity_xld);
            //, PSI1, PSI2, PSI3, PSI4]
            ho_SingleRegion.Dispose();
            ho_Contours.Dispose();
            return;
        }
예제 #2
0
        private void Act_Source(HImage image, HTuple angle, int i)
        {
            HObject temp = new HObject();

            temp.GenEmptyObj();
            HTuple dist_PZT_temp, pZTOkNg_temp;
            HTuple hv_Rows1, hv_Cols1, hv_Rows2, hv_Cols2;

            PZT_Detection_ext(Pzt_Region_Affine, image, out temp,
                              new HTuple(mesureNumber), angle[i], new HTuple(mes_width),
                              new HTuple(sigma), new HTuple(threshold), new HTuple(dist_STD),
                              out dist_PZT_temp, out pZTOkNg_temp, out hv_Rows1,
                              out hv_Cols1, out hv_Rows2, out hv_Cols2);

            if (pZTOkNg.Length == 0)
            {
                dist_PZT = dist_PZT_temp;
                pZTOkNg  = pZTOkNg_temp;
            }
            else
            {
                dist_PZT = dist_PZT.TupleConcat(dist_PZT_temp);
                pZTOkNg  = pZTOkNg.TupleConcat(pZTOkNg_temp);
            }
            if (temp != null && temp.IsInitialized())
            {
                HXLD temp2 = new HXLD(temp);
                Arrow = Arrow.ConcatObj(temp2);
                temp.Dispose();
                temp2.Dispose();
            }
        }
예제 #3
0
        private void action()
        {
            HObject ho_Rectangle1, ho_ImageReduced1, ho_Border, ho_ContoursSplit, ho_RegionLines;

            HOperatorSet.GenEmptyObj(out ho_Rectangle1);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced1);
            HOperatorSet.GenEmptyObj(out ho_Border);
            HOperatorSet.GenEmptyObj(out ho_ContoursSplit);
            HOperatorSet.GenEmptyObj(out ho_RegionLines);
            HTuple hv_RowBeginOut = null, hv_ColBeginOut = null, hv_RowEndOut = null, hv_ColEndOut = null;

            if (hv_ModelID == null)
            {
                HOperatorSet.ReadNccModel(PathHelper.currentProductPath + @"\jdmx.ncm", out hv_ModelID);
            }
            HTuple hv_ColBegin = null, hv_RowEnd = null, hv_ColEnd = null, hv_Angle1 = null, hv_jiaodu = null;
            HTuple hv_Nr = null, hv_Nc = null, hv_Dist = null, hv_RowBegin = null;
            HTuple hv_Angle = null, hv_Score = null, hv_Row1 = null, hv_Column1 = null;

            HOperatorSet.FindNccModel(Image, hv_ModelID, -0.2, 0.39, 0.8, 1, 0.5, "true",
                                      0, out hv_Row1, out hv_Column1, out hv_Angle, out hv_Score);
            ho_Rectangle1.Dispose();
            HOperatorSet.GenRectangle2(out ho_Rectangle1, hv_Row1, hv_Column1, hv_Phi + hv_Angle,
                                       hv_Length1, hv_Length2);
            ho_ImageReduced1.Dispose();
            HOperatorSet.ReduceDomain(Image, ho_Rectangle1, out ho_ImageReduced1);
            ho_Border.Dispose();
            HOperatorSet.ThresholdSubPix(ho_ImageReduced1, out ho_Border, thv);
            ho_ContoursSplit.Dispose();
            HOperatorSet.SegmentContoursXld(ho_Border, out ho_ContoursSplit, "lines_circles",
                                            5, 10, 10);
            HOperatorSet.FitLineContourXld(ho_ContoursSplit, "tukey", -1, 0, 5, 2, out hv_RowBegin,
                                           out hv_ColBegin, out hv_RowEnd, out hv_ColEnd, out hv_Nr, out hv_Nc, out hv_Dist);
            HOperatorSet.SelectLinesLongest(hv_RowBegin, hv_ColBegin, hv_RowEnd, hv_ColEnd,
                                            2, out hv_RowBeginOut, out hv_ColBeginOut, out hv_RowEndOut, out hv_ColEndOut);
            HOperatorSet.AngleLl(hv_RowBeginOut.TupleSelect(0), hv_ColBeginOut.TupleSelect(0),
                                 hv_RowEndOut.TupleSelect(0), hv_ColEndOut.TupleSelect(0), hv_RowBeginOut.TupleSelect(
                                     1), hv_ColBeginOut.TupleSelect(1), hv_RowEndOut.TupleSelect(1), hv_ColEndOut.TupleSelect(
                                     1), out hv_Angle1);
            ho_RegionLines.Dispose();
            HOperatorSet.GenRegionLine(out ho_RegionLines, hv_RowBeginOut, hv_ColBeginOut,
                                       hv_RowEndOut, hv_ColEndOut);
            HOperatorSet.Union2(ho_RegionLines, ho_RegionLines, out RegionToDisp);
            hv_jiaodu = ((hv_Angle1.TupleDeg())).TupleAbs();
            HTuple hv_result = GetHv_result();

            hv_result = hv_result.TupleConcat("夹角");
            hv_result = hv_result.TupleConcat(hv_jiaodu.D);
            result    = hv_result.Clone();
            ho_Rectangle1.Dispose();
            ho_ImageReduced1.Dispose();
            ho_Border.Dispose();
            ho_ContoursSplit.Dispose();
            ho_RegionLines.Dispose();
        }
예제 #4
0
    // Procedures
    public void PaintGrayOffset(HObject ho_ImageSource, HObject ho_ImageDestination,
                                out HObject ho_MixedImage, HTuple hv_OffsetRow, HTuple hv_OffsetColumn)
    {
        // Local iconic variables

        HObject ho_Images;

        // Local control variables

        HTuple hv_SourceWidth = null, hv_SourceHeight = null;
        HTuple hv_DestinationWidth = null, hv_DestinationHeight = null;
        HTuple hv_OffsetCol = null, hv_Row1 = null, hv_Col1 = null;
        HTuple hv_Row2 = null, hv_Col2 = null;
        HTuple hv_OffsetRow_COPY_INP_TMP = hv_OffsetRow.Clone();

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_MixedImage);
        HOperatorSet.GenEmptyObj(out ho_Images);
        HOperatorSet.GetImageSize(ho_ImageSource, out hv_SourceWidth, out hv_SourceHeight);
        HOperatorSet.GetImageSize(ho_ImageDestination, out hv_DestinationWidth, out hv_DestinationHeight);

        ho_Images.Dispose();
        HOperatorSet.ConcatObj(ho_ImageDestination, ho_ImageSource, out ho_Images);

        hv_OffsetRow_COPY_INP_TMP = (new HTuple(0)).TupleConcat(hv_OffsetRow_COPY_INP_TMP);
        hv_OffsetCol    = new HTuple();
        hv_OffsetCol[0] = 0;
        hv_OffsetCol    = hv_OffsetCol.TupleConcat(hv_OffsetColumn);
        hv_Row1         = new HTuple();
        hv_Row1[0]      = 0;
        hv_Row1[1]      = 0;
        hv_Col1         = new HTuple();
        hv_Col1[0]      = 0;
        hv_Col1[1]      = 0;
        hv_Row2         = new HTuple();
        hv_Row2         = hv_Row2.TupleConcat(hv_DestinationHeight);
        hv_Row2         = hv_Row2.TupleConcat(hv_SourceHeight);
        hv_Col2         = new HTuple();
        hv_Col2         = hv_Col2.TupleConcat(hv_DestinationWidth);
        hv_Col2         = hv_Col2.TupleConcat(hv_SourceWidth);

        ho_MixedImage.Dispose();
        HOperatorSet.TileImagesOffset(ho_Images, out ho_MixedImage, hv_OffsetRow_COPY_INP_TMP,
                                      hv_OffsetCol, hv_Row1, hv_Col1, hv_Row2, hv_Col2, hv_DestinationWidth, hv_DestinationHeight);

        ho_Images.Dispose();

        return;
    }
예제 #5
0
        private void Act_Engine(HImage image)
        {
            Grab_Intervene_ProcedureCall.SetInputIconicParamObject("G", image);
            Grab_Intervene_ProcedureCall.SetInputIconicParamObject("ROI_Grab_T", Grab_Intervene_Region_Affine);
            Grab_Intervene_ProcedureCall.SetInputCtrlParamTuple("minThreshold", new HTuple(minThreshold));
            Grab_Intervene_ProcedureCall.SetInputCtrlParamTuple("filterRadiu", new HTuple(filterRadiu));
            Grab_Intervene_ProcedureCall.SetInputCtrlParamTuple("minAreaThread", new HTuple(minAreaThread));
            Grab_Intervene_ProcedureCall.Execute();
            if (grabInterveneOkNg.Length == 0)
            {
                grabInterveneOkNg = (Grab_Intervene_ProcedureCall.GetOutputCtrlParamTuple("grabInterveneOkNg"));
            }
            else
            {
                grabInterveneOkNg = grabInterveneOkNg.TupleConcat(Grab_Intervene_ProcedureCall.GetOutputCtrlParamTuple("grabInterveneOkNg"));
            }
            HRegion temp = new HRegion();

            temp = Grab_Intervene_ProcedureCall.GetOutputIconicParamRegion("ResultRegion");
            if (temp != null && temp.IsInitialized())
            {
                ResultRegion = ResultRegion.ConcatObj(temp);
                temp.Dispose();
            }
        }
예제 #6
0
        public bool FitCircle(double[] X, double[] Y, out double RcX, out double RcY, out double R)
        {
            try
            {
                HTuple hTuple  = new HTuple();
                HTuple hTuple2 = new HTuple();
                int    num     = 0;
                for (num = 0; num < X.Length; num++)
                {
                    if ((X[num] > 0.0) & (Y[num] > 0.0))//获得寻找到的模板中心装入hTuple2与hTuple
                    {
                        hTuple2.TupleConcat(X[num]);
                        hTuple.TupleConcat(Y[num]);
                    }
                }
                HObject contour;
                HOperatorSet.GenContourPolygonXld(out contour, hTuple, hTuple2);                                                                                   //使用模板中心生成多边形XLD轮廓
                HTuple row, column, radius, StartPhi, EndPhi, pointOrder;
                HOperatorSet.FitCircleContourXld(contour, "algebraic", -1, 0, 0, 3, 2, out row, out column, out radius, out StartPhi, out EndPhi, out pointOrder); //拟合圆形
                                                                                                                                                                   //得出结果
                RcY = row;
                RcX = column;
                R   = radius;

                contour.Dispose();
                return(true);
            }
            catch
            {
                RcY = -1.0;
                RcX = -1.0;
                R   = -1.0;
                return(false);
            }
        }
        public bool setTarget(List <HHomMat2D> mat2DsList)
        {
            if (mat2DsList == null || mat2DsList.Count < 1)
            {
                return(false);
            }

            if (GrabXld != null && GrabXld.IsInitialized())
            {
                GrabXld.Dispose();
            }
            else
            {
                GrabXld = new HXLDCont();
                GrabXld.GenEmptyObj();
            }

            GrabRowTarget = new HTuple();
            GrabColTarget = new HTuple();
            HTuple rowTemp, colTemp;

            for (int i = 0; i < mat2DsList.Count; i++)
            {
                HOperatorSet.AffineTransPixel(mat2DsList[i], new HTuple(GrabRowOrg), new HTuple(GrabColOrg), out rowTemp, out colTemp);
                GrabRowTarget = GrabRowTarget.TupleConcat(rowTemp);
                GrabColTarget = GrabColTarget.TupleConcat(colTemp);
            }
            return(true);
        }
예제 #8
0
파일: Class1.cs 프로젝트: Isaac320/X_RAY3
        public bool Init(string path)
        {
            try
            {
                //throw new NotImplementedException();
                // Local iconic variables

                // Local control variables
                HObject Line = null;
                HTuple  hv_ModelID1 = null, hv_ModelID2 = null;
                HTuple  hv_ModelID3 = null, hv_ModelID4 = null, hv_ModelID = null;
                // Initialize local and output iconic variables
                //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID1", out hv_ModelID1);
                //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID2", out hv_ModelID2);
                //HOperatorSet.ReadShapeModel("D:/scindtec/STS/simulation/halcon/ModelID3", out hv_ModelID3);
                HOperatorSet.ReadShapeModel(path + "/model/ModelID4", out hv_ModelID4);
                hv_ModelIDOut = hv_ModelID4.Clone();
                HOperatorSet.ReadNccModel(path + "/model/model1test", out hv_ModelID);
                HOperatorSet.ReadNccModel(path + "/model/model1test1", out hv_ModelID1);
                HOperatorSet.ReadNccModel(path + "/model/model1test2", out hv_ModelID2);
                HOperatorSet.ReadNccModel(path + "/model/model1test3", out hv_ModelID3);
                hv_model = new HTuple();
                hv_model = hv_model.TupleConcat(hv_ModelID);
                hv_model = hv_model.TupleConcat(hv_ModelID1);
                hv_model = hv_model.TupleConcat(hv_ModelID2);
                hv_model = hv_model.TupleConcat(hv_ModelID3);
                return(true);
            }
            catch (Exception ee)
            {
                return(false);
            }
        }
예제 #9
0
        private bool Refresh_parm(UnitFindModel FM_data)
        {
            FM_data.HangleStart  = HangleStart;
            FM_data.HangleExtent = HangleExtent;
            FM_data.HscaleMin    = HscaleMin;
            FM_data.HscaleMax    = HscaleMax;
            FM_data.ContrastMin  = ContrastMin;
            FM_data.ContrastMax  = ContrastMax;
            FM_data.MinSize      = MinSize;
            Hcontrast            = new HTuple();
            Hcontrast            = Hcontrast.TupleConcat(ContrastMin);
            Hcontrast            = Hcontrast.TupleConcat(ContrastMax);
            Hcontrast            = Hcontrast.TupleConcat(MinSize);
            FM_data.HminContrast = HminContrast;

            FM_data.HminScore   = HminScore;
            FM_data.HmaxOverlap = HmaxOverlap;
            FM_data.Hgreediness = Hgreediness;

            FM_data.HShapeModelID = HShapeModelID;
            FM_data.modelpath     = modelpath;
            if (HShapeModelID == null)
            {
                return(false);
            }
            return(true);
        }
예제 #10
0
        private void Act_Engine(HImage image)
        {
            FangDai_ProcedureCall.SetInputIconicParamObject("G", image);
            FangDai_ProcedureCall.SetInputIconicParamObject("RegionFD_T", FangDai_Region_Affine);
            FangDai_ProcedureCall.SetInputCtrlParamTuple("minThreshold", new HTuple(minThreshold));
            FangDai_ProcedureCall.SetInputCtrlParamTuple("minArea", new HTuple(minArea));
            FangDai_ProcedureCall.SetInputCtrlParamTuple("maxArea", new HTuple(maxArea));
            FangDai_ProcedureCall.Execute();
            if (FangDai_OkNg.Length == 0)
            {
                FangDai_OkNg = (FangDai_ProcedureCall.GetOutputCtrlParamTuple("fD_OkNg"));
                Area         = FangDai_ProcedureCall.GetOutputCtrlParamTuple("Area");
            }
            else
            {
                FangDai_OkNg = FangDai_OkNg.TupleConcat(FangDai_ProcedureCall.GetOutputCtrlParamTuple("fD_OkNg"));
                Area         = Area.TupleConcat(FangDai_ProcedureCall.GetOutputCtrlParamTuple("Area"));
            }
            HRegion temp = new HRegion();

            temp = FangDai_ProcedureCall.GetOutputIconicParamRegion("ResultRegion");
            if (temp != null && temp.IsInitialized())
            {
                ResultRegion = ResultRegion.ConcatObj(temp);
                temp.Dispose();
            }
        }
예제 #11
0
        private void Act_Engine(HImage image)
        {
            LM_DP_ProcedureCall.SetInputIconicParamObject("R", image);
            LM_DP_ProcedureCall.SetInputIconicParamObject("ROI_LuoMuDiePian_T", LM_DP_Region_Affine);
            LM_DP_ProcedureCall.SetInputCtrlParamTuple("minThreshold", new HTuple(minThreshold));
            LM_DP_ProcedureCall.SetInputCtrlParamTuple("filterRadiu", new HTuple(filterRadiu));
            LM_DP_ProcedureCall.SetInputCtrlParamTuple("minAreaThreshold", new HTuple(minAreaThread));
            LM_DP_ProcedureCall.SetInputCtrlParamTuple("luoMuMaxArea", new HTuple(luoMuMaxArea));
            LM_DP_ProcedureCall.SetInputCtrlParamTuple("luoMuWidth", new HTuple(luoMuWidth));
            LM_DP_ProcedureCall.Execute();
            if (lM_DP_OkNg.Length == 0)
            {
                lM_DP_OkNg = (LM_DP_ProcedureCall.GetOutputCtrlParamTuple("luoMuDiePian_OKNG"));
                lM_DP_Num  = (LM_DP_ProcedureCall.GetOutputCtrlParamTuple("lM_DP_Num"));
                lM_DP_Area = (LM_DP_ProcedureCall.GetOutputCtrlParamTuple("lM_DP_Area"));
            }
            else
            {
                lM_DP_OkNg = lM_DP_OkNg.TupleConcat(LM_DP_ProcedureCall.GetOutputCtrlParamTuple("luoMuDiePian_OKNG"));
                lM_DP_Num  = lM_DP_Num.TupleConcat(LM_DP_ProcedureCall.GetOutputCtrlParamTuple("lM_DP_Num"));
                lM_DP_Area = lM_DP_Area.TupleConcat(LM_DP_ProcedureCall.GetOutputCtrlParamTuple("lM_DP_Area"));
            }
            HRegion temp = new HRegion();

            temp = LM_DP_ProcedureCall.GetOutputIconicParamRegion("Result_Region");
            if (temp != null && temp.IsInitialized())
            {
                ResultRegion = ResultRegion.ConcatObj(temp);
                temp.Dispose();
            }
        }
예제 #12
0
        public static void AddRegionsIsEnable(IEnumerable <UserRegion> userRegions, string name, string IdentifyString = "", int RefineUserRegionsIdx = 0)//
        {
            if (userRegions.Count() == 0)
            {
                return;
            }
            HTuple DieRegionsTemp         = new HTuple();
            HTuple ICRegionsTemp          = new HTuple();
            HTuple RefineUserRegionsTempt = new HTuple();

            foreach (var userRegion in userRegions)
            {
                if (IdentifyString == "ICRECIPEXML")
                {
                    ICRegionsTemp = ICRegionsTemp.TupleConcat(userRegion.IsEnable ? 1 : 0);
                }
                else if (IdentifyString == "BONRECIPEXML")
                {
                    RefineUserRegionsTempt = RefineUserRegionsTempt.TupleConcat(userRegion.IsEnable ? 1 : 0);
                }
            }
            if (IdentifyString == "ICRECIPEXML")
            {
                //HOperatorSet.WriteTuple(ICRegionsTemp, FilePath.PathMainIC + name + "_" + "IsEnable.tup");
            }
            else if (IdentifyString == "BONRECIPEXML")
            {
                //HOperatorSet.WriteTuple(RefineUserRegionsTempt, FilePath.PathBondWire + "第" + RefineUserRegionsIdx + "套精炼区" + "_" + "IsEnable.tup");
            }
        }
예제 #13
0
        /// <summary>
        /// 计算出每个Pin针的偏移量
        /// </summary>
        /// <param name="InspectPinParamIn"></param>
        /// <param name="PinRows"></param>
        /// <param name="PinCols"></param>
        /// <param name="OffSetRows"></param>
        /// <param name="OffSetCols"></param>
        /// <param name="OffSetDist"></param>
        /// <returns></returns>
        public static bool CalculatePinOffset(St_InspectPinParam InspectPinParamIn, HTuple PinRows, HTuple PinCols, out HTuple OffSetRows, out HTuple OffSetCols, out HTuple OffSetDist)
        {
            OffSetRows = new HTuple();
            OffSetCols = new HTuple();
            OffSetDist = new HTuple();
            HTuple TeachPinRows = new HTuple(), TeachPinCols = new HTuple();

            for (int i = 0; i < InspectPinParamIn.Elements.Count(); i++)
            {
                HTuple row0 = new HTuple(), col0 = new HTuple();
                MyVisionBase.ListToHTuple(InspectPinParamIn.ListRows[i], out row0);
                MyVisionBase.ListToHTuple(InspectPinParamIn.ListCols[i], out col0);
                TeachPinRows = TeachPinRows.TupleConcat(row0);
                TeachPinCols = TeachPinCols.TupleConcat(col0);
            }
            HTuple HomMat = new HTuple();

            HOperatorSet.VectorToHomMat2d(TeachPinCols, TeachPinRows, PinCols, PinRows, out HomMat); //计算平移矩阵
            HTuple TargetRows = new HTuple(), TargetCols = new HTuple();

            HOperatorSet.AffineTransPixel(HomMat, TeachPinCols, TeachPinRows, out TargetCols, out TargetRows); //平移示教点的坐标
            if (TargetRows.Length != TeachPinRows.Length)
            {
                return(false);
            }
            HTuple OffSetRows0 = new HTuple(), OffSetCols0 = new HTuple(), OffSetDist0 = new HTuple();

            OffSetCols0 = PinCols - TargetCols;
            OffSetRows0 = PinRows - TargetRows;
            HOperatorSet.DistancePp(TargetRows, TargetCols, PinRows, PinCols, out OffSetDist0); //计算出偏移量
            OffSetRows = OffSetRows0;
            OffSetCols = OffSetCols0;
            OffSetDist = OffSetDist0;
            return(true);
        }
        /// <summary>
        /// Generate a contour in form of an arrow.
        /// </summary>
        private void gen_arrow_cont(out HObject ho_Arrow,
                                    HTuple hv_Row1,
                                    HTuple hv_Column1,
                                    HTuple hv_Row2,
                                    HTuple hv_Column2)
        {
            // Local iconic variables

            HObject ho_Cross1, ho_Cross2, ho_CrossP1, ho_CrossP2;


            // Local control variables

            HTuple hv_Length, hv_Angle, hv_MinArrowLength;
            HTuple hv_DRow, hv_DCol, hv_ArrowLength, hv_Phi, hv_P1R;
            HTuple hv_P1C, hv_P2R, hv_P2C;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Arrow);
            HOperatorSet.GenEmptyObj(out ho_Cross1);
            HOperatorSet.GenEmptyObj(out ho_Cross2);
            HOperatorSet.GenEmptyObj(out ho_CrossP1);
            HOperatorSet.GenEmptyObj(out ho_CrossP2);

            //Generate a contour in form of a arrow
            hv_Length         = 7;
            hv_Angle          = 40;
            hv_MinArrowLength = 2;
            hv_DRow           = hv_Row2 - hv_Row1;
            hv_DCol           = hv_Column2 - hv_Column1;
            hv_ArrowLength    = (((hv_DRow * hv_DRow) + (hv_DCol * hv_DCol))).TupleSqrt();
            if ((int)(new HTuple(hv_ArrowLength.TupleLess(hv_MinArrowLength))) != 0)
            {
                hv_Length = 0;
            }
            HOperatorSet.TupleAtan2(hv_DRow, -hv_DCol, out hv_Phi);
            hv_P1R = hv_Row2 - (hv_Length * (((hv_Phi - (hv_Angle.TupleRad()))).TupleSin()));
            hv_P1C = hv_Column2 + (hv_Length * (((hv_Phi - (hv_Angle.TupleRad()))).TupleCos()));
            hv_P2R = hv_Row2 - (hv_Length * (((hv_Phi + (hv_Angle.TupleRad()))).TupleSin()));
            hv_P2C = hv_Column2 + (hv_Length * (((hv_Phi + (hv_Angle.TupleRad()))).TupleCos()));
            ho_Cross1.Dispose();
            HOperatorSet.GenCrossContourXld(out ho_Cross1, hv_Row1, hv_Column1, 6, 0.785398);
            ho_Cross2.Dispose();
            HOperatorSet.GenCrossContourXld(out ho_Cross2, hv_Row2, hv_Column2, 6, 0.785398);
            ho_CrossP1.Dispose();
            HOperatorSet.GenCrossContourXld(out ho_CrossP1, hv_P1R, hv_P1C, 6, 0.785398);
            ho_CrossP2.Dispose();
            HOperatorSet.GenCrossContourXld(out ho_CrossP2, hv_P2R, hv_P2C, 6, 0.785398);
            ho_Arrow.Dispose();
            HOperatorSet.GenContourPolygonXld(out ho_Arrow, ((((((hv_Row1.TupleConcat(hv_Row2))).TupleConcat(
                                                                    hv_P1R))).TupleConcat(hv_Row2))).TupleConcat(hv_P2R), ((((((hv_Column1.TupleConcat(
                                                                                                                                    hv_Column2))).TupleConcat(hv_P1C))).TupleConcat(hv_Column2))).TupleConcat(
                                                  hv_P2C));
            ho_Cross1.Dispose();
            ho_Cross2.Dispose();
            ho_CrossP1.Dispose();
            ho_CrossP2.Dispose();

            return;
        }
        private void Act_Engine(HImage R, HImage B)
        {
            LanQuan_ProcedureCall.SetInputIconicParamObject("R", R);
            LanQuan_ProcedureCall.SetInputIconicParamObject("B", B);
            LanQuan_ProcedureCall.SetInputIconicParamObject("ROI_LanQuan_T", LanQuan_Region_Affine);
            LanQuan_ProcedureCall.SetInputCtrlParamTuple("minThreshold", new HTuple(minThreshold));
            LanQuan_ProcedureCall.SetInputCtrlParamTuple("filterRadiu", new HTuple(filterRadiu));
            LanQuan_ProcedureCall.SetInputCtrlParamTuple("minArea", new HTuple(minArea));
            LanQuan_ProcedureCall.Execute();
            if (LanQuan_OkNg.Length == 0)
            {
                LanQuan_OkNg = (LanQuan_ProcedureCall.GetOutputCtrlParamTuple("lanQuan_OKNG"));
                Area         = LanQuan_ProcedureCall.GetOutputCtrlParamTuple("Area");
            }
            else
            {
                LanQuan_OkNg = LanQuan_OkNg.TupleConcat(LanQuan_ProcedureCall.GetOutputCtrlParamTuple("lanQuan_OKNG"));
                Area         = Area.TupleConcat(LanQuan_ProcedureCall.GetOutputCtrlParamTuple("Area"));
            }
            HRegion temp = new HRegion();

            temp = LanQuan_ProcedureCall.GetOutputIconicParamRegion("Result_Region");
            if (temp != null && temp.IsInitialized())
            {
                ResultRegion = ResultRegion.ConcatObj(temp);
                temp.Dispose();
            }
        }
예제 #16
0
        public static HTuple MetrologyType(IEnumerable <UserRegion> regions)
        {
            HTuple _MetrologyType = new HTuple();
            HTuple MetrologyType  = new HTuple();

            foreach (var region in regions)
            {
                switch (region.RegionType)
                {
                case RegionType.Line:
                    _MetrologyType = 1;
                    break;

                case RegionType.Rectangle2:
                    _MetrologyType = 2;
                    break;

                case RegionType.Circle:
                    _MetrologyType = 3;
                    break;

                case RegionType.Ellipse:
                    _MetrologyType = 4;
                    break;

                default:
                    MessageBox.Show("请重新选择画区域工具!");
                    return(null);
                }
                MetrologyType = MetrologyType.TupleConcat(_MetrologyType);
            }
            return(MetrologyType);
        }
예제 #17
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;
         }
     }
 }
예제 #18
0
        /// <summary>
        /// 获取大芯片中心的扫描点位(IC的中心为相机视野中心)
        /// </summary>
        /// <param name="hv_width"></param>
        /// <param name="hv_height"></param>
        /// <param name="hv_uvHxy"></param>
        /// <param name="hv_widthFactor"></param>
        /// <param name="hv_heightFactor"></param>
        /// <param name="hv_zoomFactor"></param>
        /// <param name="hv_mapRowCnt"></param>
        /// <param name="hv_mapColCnt"></param>
        /// <param name="hv_clipmapX"></param>
        /// <param name="hv_clipmapY"></param>
        /// <param name="hv_clipmapRow"></param>
        /// <param name="hv_clipmapCol"></param>
        /// <param name="hv_snapX"></param>
        /// <param name="hv_snapY"></param>
        /// <param name="hv_snapRow"></param>
        /// <param name="hv_snapCol"></param>
        /// <param name="hv_iFlag"></param>
        public void get_scan_points(HTuple hv_width, HTuple hv_height, HTuple hv_uvHxy, HTuple hv_zoomFactor, HTuple hv_mapRowCnt, HTuple hv_mapColCnt, HTuple hv_clipmapX,
                                    HTuple hv_clipmapY, HTuple hv_clipmapRow, HTuple hv_clipmapCol, out HTuple hv_snapX, out HTuple hv_snapY, out HTuple hv_snapRow, out HTuple hv_snapCol, out HTuple hv_iFlag)
        {
            hv_iFlag   = "";
            hv_snapX   = new HTuple();
            hv_snapY   = new HTuple();
            hv_snapRow = new HTuple();
            hv_snapCol = new HTuple();

            HTuple hv_uvHxyScaled = new HTuple();

            try
            {
                //HOperatorSet.HomMat2dScale(hv_uvHxy, 1 /*/ hv_zoomFactor*/, 1 /*/ hv_zoomFactor*/, 0, 0, out hv_uvHxyScaled);

                //hv_snapX = hv_clipmapX + ((hv_uvHxyScaled.TupleSelect(0) * (-1) * (hv_height - 1)) / 2.0)
                //    + ((hv_uvHxyScaled.TupleSelect(1) * (-1) * (hv_width - 1)) / 2.0);

                //hv_snapY = hv_clipmapY + ((hv_uvHxyScaled.TupleSelect(3) * (-1) * (hv_height - 1)) / 2.0)
                //    + ((hv_uvHxyScaled.TupleSelect(4) * (-1) * (hv_width - 1)) / 2.0);

                //*****将扫描点位按弓字形排序
                HTuple hv_seqInd      = new HTuple();
                HTuple hv_rowIndConst = new HTuple();
                HTuple hv_colIndSeq   = new HTuple();
                HTuple hv__x          = new HTuple();
                HTuple hv__y          = new HTuple();
                HTuple hv_i           = 0;
                for (hv_i = 0; hv_i < hv_mapRowCnt; hv_i++)
                {
                    HOperatorSet.TupleGenSequence(hv_i * hv_mapColCnt, ((hv_i + 1) * hv_mapColCnt) - 1,
                                                  1, out hv_seqInd);
                    HOperatorSet.TupleGenConst(hv_mapColCnt, hv_i, out hv_rowIndConst);
                    HOperatorSet.TupleGenSequence(0, hv_mapColCnt - 1, 1, out hv_colIndSeq);
                    if ((int)(new HTuple(((hv_i % 2)).TupleEqual(0))) != 0)
                    {
                        hv__x = hv_clipmapX.TupleSelect(hv_seqInd);
                        hv__y = hv_clipmapY.TupleSelect(hv_seqInd);
                    }
                    else
                    {
                        hv__x        = ((hv_clipmapX.TupleSelect(hv_seqInd))).TupleInverse();
                        hv__y        = ((hv_clipmapY.TupleSelect(hv_seqInd))).TupleInverse();
                        hv_colIndSeq = hv_colIndSeq.TupleInverse();
                    }
                    hv_snapX   = hv_snapX.TupleConcat(hv__x);
                    hv_snapY   = hv_snapY.TupleConcat(hv__y);
                    hv_snapRow = hv_snapRow.TupleConcat(hv_rowIndConst);
                    hv_snapCol = hv_snapCol.TupleConcat(hv_colIndSeq);
                }
            }
            catch (HalconException HDevExpDefaultException)
            {
                HTuple hv_Exception = new HTuple();
                HDevExpDefaultException.ToHTuple(out hv_Exception);
                VisionMethonDll.VisionMethon.GetErrInfo(hv_Exception, out hv_iFlag);
            }
        }
예제 #19
0
        public void GetRegionPoints(HObject ho_Regions, HTuple hv_Tolerance, out HTuple hv_Rows,
                                    out HTuple hv_Cols, out HTuple hv_BreakPoints)
        {
            // Local iconic variables

            HObject ho_RegionUnion, ho_ConnectedRegions;
            HObject ho_ObjectSelected = null;

            // Local control variables

            HTuple hv_Num = null, hv_Index = null, hv_Rows0 = new HTuple();
            HTuple hv_Columns0 = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_RegionUnion);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            try
            {
                ho_RegionUnion.Dispose();
                HOperatorSet.Union1(ho_Regions, out ho_RegionUnion);
                ho_ConnectedRegions.Dispose();
                HOperatorSet.Connection(ho_RegionUnion, out ho_ConnectedRegions);
                HOperatorSet.CountObj(ho_ConnectedRegions, out hv_Num);

                hv_Rows        = new HTuple();
                hv_Cols        = new HTuple();
                hv_BreakPoints = new HTuple();

                HTuple end_val8  = hv_Num;
                HTuple step_val8 = 1;
                for (hv_Index = 1; hv_Index.Continue(end_val8, step_val8); hv_Index = hv_Index.TupleAdd(step_val8))
                {
                    ho_ObjectSelected.Dispose();
                    HOperatorSet.SelectObj(ho_ConnectedRegions, out ho_ObjectSelected, hv_Index);
                    HOperatorSet.GetRegionPolygon(ho_ObjectSelected, hv_Tolerance, out hv_Rows0,
                                                  out hv_Columns0);
                    hv_Rows        = hv_Rows.TupleConcat(hv_Rows0);
                    hv_Cols        = hv_Cols.TupleConcat(hv_Columns0);
                    hv_BreakPoints = hv_BreakPoints.TupleConcat(new HTuple(hv_Rows0.TupleLength()
                                                                           ));
                }
                ho_RegionUnion.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_ObjectSelected.Dispose();

                return;
            }
            catch (HalconException HDevExpDefaultException)
            {
                ho_RegionUnion.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_ObjectSelected.Dispose();

                throw HDevExpDefaultException;
            }
        }
        /// <summary>
        /// Evaluates the gray value contrast between the marks and the calibration
        /// plate and the homogeneity of the used illumination.
        /// </summary>
        public void eval_caltab_contrast_homogeneity(HObject ho_Image,
                                                     HObject ho_Marks,
                                                     out HTuple hv_Contrast,
                                                     out HTuple hv_ContrastScore,
                                                     out HTuple hv_HomogeneityScore)
        {
            // Local iconic variables

            HObject ho_Region, ho_RegionDilation;


            // Local control variables

            HTuple hv_Number, hv_Min, hv_Max, hv_Range;
            HTuple hv_MinContrast, hv_MaxContrast, hv_DeviationMax;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation);

            hv_ContrastScore    = 0.0;
            hv_Contrast         = 0.0;
            hv_HomogeneityScore = 0.0;
            HOperatorSet.CountObj(ho_Marks, out hv_Number);
            if ((int)(new HTuple(hv_Number.TupleLess(4))) != 0)
            {
                ho_Region.Dispose();
                ho_RegionDilation.Dispose();

                return;
            }
            ho_Region.Dispose();
            HOperatorSet.GenRegionContourXld(ho_Marks, out ho_Region, "margin");
            ho_RegionDilation.Dispose();
            HOperatorSet.DilationCircle(ho_Region, out ho_RegionDilation, 5.5);
            HOperatorSet.MinMaxGray(ho_RegionDilation, ho_Image, 3, out hv_Min, out hv_Max,
                                    out hv_Range);
            //Calculate contrast score
            hv_Contrast    = hv_Range.TupleMean();
            hv_MinContrast = 70;
            hv_MaxContrast = 160;
            if ((int)(new HTuple(hv_Contrast.TupleGreater(hv_MinContrast))) != 0)
            {
                hv_ContrastScore = (hv_Contrast - hv_MinContrast) / (hv_MaxContrast - hv_MinContrast);
                hv_ContrastScore = ((hv_ContrastScore.TupleConcat(1.0))).TupleMin();
            }
            //Now for the homogeneity score
            HOperatorSet.TupleDeviation(hv_Max, out hv_DeviationMax);
            hv_HomogeneityScore = 1.1 - (hv_DeviationMax / 40.0);
            hv_HomogeneityScore = ((((((hv_HomogeneityScore.TupleConcat(1.0))).TupleMin()
                                      )).TupleConcat(0.0))).TupleMax();
            ho_Region.Dispose();
            ho_RegionDilation.Dispose();

            return;
        }
예제 #21
0
        internal static HTuple ConcatArray(HData[] data)
        {
            HTuple htuple = new HTuple();

            for (int index = 0; index < data.Length; ++index)
            {
                htuple = htuple.TupleConcat(data[index].tuple);
            }
            return(htuple);
        }
예제 #22
0
        /// <summary>
        /// 测试小球OKNG的方法
        /// </summary>
        /// <param name="hv_liudao">小球所在位置</param>
        /// <param name="hv_channels">流道信息</param>
        /// <param name="hv_liudaoR">小球直径(像素值)</param>
        /// <param name="hv_myLength">小球标准直径(像素值)</param>
        /// <param name="hv_myThreashod">小球阈值范围</param>
        /// <param name="hv_myResult">是否都是好的</param>
        /// <param name="hv_NGLengths">NG小球直径</param>
        /// <param name="hv_NGChls">NG小球所在流道</param>
        public void testOKNG2(HTuple hv_liudao, HTuple hv_channels, HTuple hv_liudaoR,
                              HTuple hv_myLength, HTuple hv_myThreashod, out HTuple hv_myResult, out HTuple hv_NGLengths,
                              out HTuple hv_NGChls)
        {
            // Local iconic variables

            // Local control variables

            HTuple hv_num = null, hv_num2 = null, hv_Index1 = null;
            HTuple hv_Index2 = new HTuple(), hv_lll = new HTuple();
            HTuple hv_ff1 = new HTuple(), hv_ff2 = new HTuple(), hv_ff = new HTuple();

            // Initialize local and output iconic variables
            hv_myResult = 1;
            hv_num      = new HTuple(hv_liudao.TupleLength());
            hv_num2     = new HTuple(hv_channels.TupleLength());

            hv_NGChls    = new HTuple();
            hv_NGLengths = new HTuple();


            HTuple end_val8  = hv_num - 1;
            HTuple step_val8 = 1;

            for (hv_Index1 = 0; hv_Index1.Continue(end_val8, step_val8); hv_Index1 = hv_Index1.TupleAdd(step_val8))
            {
                HTuple end_val9  = hv_num2;
                HTuple step_val9 = 1;
                for (hv_Index2 = 1; hv_Index2.Continue(end_val9, step_val9); hv_Index2 = hv_Index2.TupleAdd(step_val9))
                {
                    if ((int)(new HTuple(((hv_liudao.TupleSelect(hv_Index1))).TupleLess(hv_channels.TupleSelect(
                                                                                            hv_Index2)))) != 0)
                    {
                        break;
                    }
                }
                hv_lll = hv_Index2 - 1;
                hv_ff1 = new HTuple(((hv_liudaoR.TupleSelect(hv_Index1))).TupleGreater((hv_myLength.TupleSelect(
                                                                                            hv_lll)) - (hv_myThreashod.TupleSelect(hv_lll))));
                hv_ff2 = new HTuple(((hv_liudaoR.TupleSelect(hv_Index1))).TupleLess((hv_myLength.TupleSelect(
                                                                                         hv_lll)) + (hv_myThreashod.TupleSelect(hv_lll))));
                hv_ff = hv_ff1.TupleAnd(hv_ff2);
                if ((int)(hv_ff) != 0)
                {
                }
                else
                {
                    hv_NGChls    = hv_NGChls.TupleConcat(hv_Index2);
                    hv_NGLengths = hv_NGLengths.TupleConcat(hv_liudaoR.TupleSelect(hv_Index1));
                }
                hv_myResult = hv_myResult.TupleAnd(hv_ff);
            }

            return;
        }
    /// <summary>
    /// Evaluates the gray value contrast between the marks and the calibration 
    /// plate and the homogeneity of the used illumination.
    /// </summary>
    public void eval_caltab_contrast_homogeneity(HObject ho_Image, 
                                                HObject ho_Marks,
                                                out HTuple hv_Contrast, 
                                                out HTuple hv_ContrastScore, 
                                                out HTuple hv_HomogeneityScore)
    {
        // Local iconic variables

          HObject ho_Region, ho_RegionDilation;

          // Local control variables

          HTuple hv_Number, hv_Min, hv_Max, hv_Range;
          HTuple hv_MinContrast, hv_MaxContrast, hv_DeviationMax;

          // Initialize local and output iconic variables
          HOperatorSet.GenEmptyObj(out ho_Region);
          HOperatorSet.GenEmptyObj(out ho_RegionDilation);

          hv_ContrastScore = 0.0;
          hv_Contrast = 0.0;
          hv_HomogeneityScore = 0.0;
          HOperatorSet.CountObj(ho_Marks, out hv_Number);
          if ((int)(new HTuple(hv_Number.TupleLess(4))) != 0)
          {
          ho_Region.Dispose();
          ho_RegionDilation.Dispose();

          return;
          }
          ho_Region.Dispose();
          HOperatorSet.GenRegionContourXld(ho_Marks, out ho_Region, "margin");
          ho_RegionDilation.Dispose();
          HOperatorSet.DilationCircle(ho_Region, out ho_RegionDilation, 5.5);
          HOperatorSet.MinMaxGray(ho_RegionDilation, ho_Image, 3, out hv_Min, out hv_Max,
          out hv_Range);
          //Calculate contrast score
          hv_Contrast = hv_Range.TupleMean();
          hv_MinContrast = 70;
          hv_MaxContrast = 160;
          if ((int)(new HTuple(hv_Contrast.TupleGreater(hv_MinContrast))) != 0)
          {
          hv_ContrastScore = (hv_Contrast - hv_MinContrast) / (hv_MaxContrast - hv_MinContrast);
          hv_ContrastScore = ((hv_ContrastScore.TupleConcat(1.0))).TupleMin();
          }
          //Now for the homogeneity score
          HOperatorSet.TupleDeviation(hv_Max, out hv_DeviationMax);
          hv_HomogeneityScore = 1.1 - (hv_DeviationMax / 40.0);
          hv_HomogeneityScore = ((((((hv_HomogeneityScore.TupleConcat(1.0))).TupleMin()
          )).TupleConcat(0.0))).TupleMax();
          ho_Region.Dispose();
          ho_RegionDilation.Dispose();

          return;
    }
예제 #24
0
        /// <summary>
        /// Returns an HTuple with only unique elements.
        /// </summary>
        /// <param name="input">The input HTuple.</param>
        /// <returns>The output HTuple.</returns>
        public static HTuple Unique(HTuple input)
        {
            HTuple output = new HTuple();
            int    count  = input.Length;

            if (input.Length > 0)
            {
                output = output.TupleConcat(input[0]);

                for (int i = 0; i < count; i++)
                {
                    if (output.TupleFind(input[i]) == -1)
                    {
                        output = output.TupleConcat(input[i]);
                    }
                }
            }

            return(output);
        }
예제 #25
0
 public void gen_cam_par_area_scan_division(HTuple hv_Focus, HTuple hv_Kappa, HTuple hv_Sx, HTuple hv_Sy, HTuple hv_Cx, HTuple hv_Cy, HTuple hv_ImageWidth, HTuple hv_ImageHeight, out HTuple hv_CameraParam)
 {
     hv_CameraParam    = new HTuple();
     hv_CameraParam[0] = "area_scan_division";
     hv_CameraParam    = hv_CameraParam.TupleConcat(hv_Focus);
     hv_CameraParam    = hv_CameraParam.TupleConcat(hv_Kappa);
     hv_CameraParam    = hv_CameraParam.TupleConcat(hv_Sx);
     hv_CameraParam    = hv_CameraParam.TupleConcat(hv_Sy);
     hv_CameraParam    = hv_CameraParam.TupleConcat(hv_Cx);
     hv_CameraParam    = hv_CameraParam.TupleConcat(hv_Cy);
     hv_CameraParam    = hv_CameraParam.TupleConcat(hv_ImageWidth);
     hv_CameraParam    = hv_CameraParam.TupleConcat(hv_ImageHeight);
     return;
 }
예제 #26
0
        public void FindLine(HImage image, double Row, double Column, double Phi, double Length1, double Length2, ushort pointNum, ushort EdgeWidth, ushort EdgeThresold, EdgePolarEnum edgePolar, EdgeTypeEnum edgeType, out PointF firstPoint, out PointF endPoint, out double angle, out HXLDCont[] cross, out HXLDCont line)
        {
            double[] row          = new double[pointNum];
            double[] column       = new double[pointNum];
            HTuple   _rowEdges    = new HTuple();
            HTuple   _columnEdges = new HTuple();

            image.GetImageSize(out int width, out int height);
            for (int i = 0; i <= (pointNum - 1) / 2; i++)//遍历搜索点数的一半
            {
                row[i]                   = Row - (Length2 - 2.0 * Length2 * (i + 1) / (pointNum + 1)) * Math.Cos(Phi);
                column[i]                = Column - (Length2 - 2.0 * Length2 * (i + 1) / (pointNum + 1)) * Math.Sin(Phi);
                row[pointNum - 1 - i]    = 2 * Row - row[i];
                column[pointNum - 1 - i] = 2 * Column - column[i];
            }
            for (int i = 0; i < pointNum - 1; i++)
            {
                HMeasure measure = new HMeasure(row[i], column[i], Phi, Length1, EdgeWidth, width, height, "nearest_neighbor");                                                              //获得测量矩形
                measure.MeasurePos(image, 1, EdgeThresold, edgePolar.ToString(), edgeType.ToString(), out HTuple rowEdge, out HTuple columnEdge, out HTuple Amplitude, out HTuple distance); //提取垂直于矩形或环形弧的直边
                if (rowEdge.Length > 0 && columnEdge.Length > 0)
                {
                    _rowEdges    = _rowEdges.TupleConcat(rowEdge);
                    _columnEdges = _columnEdges.TupleConcat(columnEdge);
                }
            }
            if (_rowEdges.Length > 5)
            {
                HXLDCont Contour = new HXLDCont(_rowEdges, _columnEdges);
                Contour.SmoothContoursXld(5);
                Contour.FitLineContourXld("tukey", -1, 0, 5, 2, out double rowBegin, out double columnBegin, out double rowEnd, out double columnEnd, out double nr, out double nc, out double dist);
                Contour.GenContourPolygonXld(new HTuple(rowBegin, rowEnd), new HTuple(columnBegin, columnEnd));
                cross = new HXLDCont[_rowEdges.Length];
                for (int i = 0; i < _rowEdges.Length; i++)
                {
                    HXLDCont _cross = new HXLDCont();
                    _cross.GenCrossContourXld(_rowEdges[i], _columnEdges[i], 30d, 0);
                    cross[i] = _cross;
                }
                firstPoint = new PointF((float)columnBegin, (float)rowBegin);
                endPoint   = new PointF((float)columnEnd, (float)rowEnd);
                angle      = HMisc.AngleLx(rowBegin, columnBegin, rowEnd, columnEnd) * 180 / Math.PI;
                line       = Contour;
            }
            else
            {
                firstPoint = new PointF(0, 0);
                endPoint   = new PointF(0, 0);
                cross      = null;
                line       = null;
                angle      = 0;
            }
        }
예제 #27
0
        public void ShowProfileToWindow(double[] xcoord, double[] ycoord, double[] zcoord, string[] sigleTitle, bool showMsg)
        {
            if (recordXCoord == null || recordYCoord == null || recordSigleTitle == null || recordXCoord.Length == 0 || recordYCoord.Length == 0 || recordSigleTitle.Length == 0)
            {
                return;
            }
            HObject regpot;
            HTuple  newRecordX = new HTuple(recordXCoord) * 20 - 4000;

            HOperatorSet.GenRegionPoints(out regpot, new HTuple(newRecordX), new HTuple(recordYCoord) * 20);

            HObject ImageConst;

            HOperatorSet.GenImageConst(out ImageConst, "byte", 5000, 5000);
            Action sw = () =>
            {
                hWindow_Final1.HobjectToHimage(ImageConst);
                hWindow_Final1.viewWindow.displayHobject(regpot, "green", true, 20);
            };

            this.Invoke(sw);



            if (!showMsg)
            {
                for (int i = 0; i < recordSigleTitle.Length; i++)
                {
                    Action sw1 = () =>
                    {
                        hWindow_Final1.viewWindow.dispMessage($"{recordSigleTitle[i]} +({recordZCoord[i]})", "blue", newRecordX[i], recordYCoord[i] * 20);
                    };
                    this.Invoke(sw1);
                }
            }
            HObject contour;

            newRecordX = newRecordX.TupleConcat(recordXCoord[0] * 20 - 4000);
            HOperatorSet.GenContourPolygonXld(out contour, new HTuple(newRecordX), new HTuple(recordYCoord, recordYCoord[0]) * 20);
            Action sw2 = () =>
            {
                hWindow_Final1.viewWindow.displayHobject(contour, "white");
            };

            this.Invoke(sw2);


            contour.Dispose();

            regpot.Dispose();
            ImageConst.Dispose();
        }
예제 #28
0
 private void UpDown7_ValueChanged(object sender, EventArgs e)
 {
     MinSize         = (int)UpDown7.Value;
     trackBar7.Value = (int)(UpDown7.Value);
     Hcontrast       = new HTuple();
     Hcontrast       = Hcontrast.TupleConcat(ContrastMin);
     Hcontrast       = Hcontrast.TupleConcat(ContrastMax);
     Hcontrast       = Hcontrast.TupleConcat(MinSize);
     if (Hdraw_roi.Key != (IntPtr)0)
     {
         create_display_model();
     }
 }
예제 #29
0
 public void ToHTuple(out HTuple exception)
 {
     exception    = new HTuple();
     exception[0] = (HTupleElements)this.GetErrorCode();
     if (this.GetErrorCode() < 30000)
     {
         exception[1] = (HTupleElements)this.GetErrorMessage();
     }
     if (this.user_data == null)
     {
         return;
     }
     exception = exception.TupleConcat(this.user_data);
 }
        /// <summary>
        /// Evaluates the distribution of the marks and hence the plates
        /// used for the calibration images. Precise measurements can only be
        /// achieved if the field view of the camera is covered well by the
        /// calibration plate in the images.
        /// </summary>
        public void eval_marks_distribution(HTuple hv_NRCoord,
                                            HTuple hv_NCCoord,
                                            HTuple hv_Width,
                                            HTuple hv_Height,
                                            out HTuple hv_MarksDistributionScore)
        {
            // Local iconic variables

            HObject ho_Region, ho_DistanceImage, ho_Mask;


            // Local control variables

            HTuple hv_Border, hv_Min, hv_Max, hv_Range;
            HTuple hv_ImageDiagonal, hv_MinThresh, hv_MaxThresh, hv_Ratio;
            HTuple hv_Tmp1, hv_Tmp2;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Region);
            HOperatorSet.GenEmptyObj(out ho_DistanceImage);
            HOperatorSet.GenEmptyObj(out ho_Mask);

            //Determine the distances between the marks centers
            ho_Region.Dispose();
            HOperatorSet.GenRegionPoints(out ho_Region, hv_NRCoord, hv_NCCoord);
            ho_DistanceImage.Dispose();
            HOperatorSet.DistanceTransform(ho_Region, out ho_DistanceImage, "octagonal",
                                           "false", hv_Width, hv_Height);
            //A clipping is needed because the marks cannot come close to the border
            hv_Border = (((hv_Width.TupleConcat(hv_Height))).TupleMax()) / 15;
            ho_Mask.Dispose();
            HOperatorSet.GenRectangle1(out ho_Mask, hv_Border, hv_Border, (hv_Height - 1) - hv_Border,
                                       (hv_Width - 1) - hv_Border);
            HOperatorSet.MinMaxGray(ho_Mask, ho_DistanceImage, 0, out hv_Min, out hv_Max,
                                    out hv_Range);
            HOperatorSet.DistancePp(0, 0, hv_Height - 1, hv_Width - 1, out hv_ImageDiagonal);
            hv_MinThresh = 0.3;
            hv_MaxThresh = 0.85;
            hv_Ratio     = (hv_Max / hv_ImageDiagonal) * 2.5;
            hv_Tmp1      = 1 - hv_Ratio;
            hv_Tmp2      = (hv_Tmp1 - hv_MinThresh) / (hv_MaxThresh - hv_MinThresh);
            hv_MarksDistributionScore = ((((((hv_Tmp2.TupleConcat(1.0))).TupleMin())).TupleConcat(
                                              0.0))).TupleMax();
            ho_Region.Dispose();
            ho_DistanceImage.Dispose();
            ho_Mask.Dispose();

            return;
        }
예제 #31
0
        private void load_parm()
        {
            HangleStart  = FM_data.HangleStart;
            HangleExtent = FM_data.HangleExtent;
            HscaleMin    = FM_data.HscaleMin;
            HscaleMax    = FM_data.HscaleMax;
            ContrastMin  = FM_data.ContrastMin;
            ContrastMax  = FM_data.ContrastMax;
            MinSize      = FM_data.MinSize;
            Hcontrast    = new HTuple();
            Hcontrast    = Hcontrast.TupleConcat(ContrastMin);
            Hcontrast    = Hcontrast.TupleConcat(ContrastMax);
            Hcontrast    = Hcontrast.TupleConcat(MinSize);
            HminContrast = FM_data.HminContrast;

            HminScore   = FM_data.HminScore;
            HmaxOverlap = FM_data.HmaxOverlap;
            Hgreediness = FM_data.Hgreediness;

            HShapeModelID = FM_data.HShapeModelID;
            modelpath     = FM_data.modelpath;

            //int temp = HangleStart[0].I;
            UpDown1.Value   = (decimal)HangleStart[0].D;
            trackBar1.Value = (int)UpDown1.Value;
            UpDown2.Value   = (decimal)HangleExtent[0].D;
            trackBar2.Value = (int)UpDown2.Value;
            UpDown3.Value   = (decimal)HscaleMin[0].D;
            trackBar3.Value = (int)(UpDown3.Value * 10);
            UpDown4.Value   = (decimal)HscaleMax[0].D;
            trackBar4.Value = (int)(UpDown4.Value * 10);
            UpDown5.Value   = (decimal)ContrastMin[0].I;
            trackBar5.Value = (int)UpDown5.Value;
            UpDown6.Value   = (decimal)ContrastMax[0].I;
            trackBar6.Value = (int)UpDown6.Value;
            UpDown7.Value   = (decimal)MinSize[0].I;
            trackBar7.Value = (int)UpDown7.Value;
            UpDown8.Value   = (decimal)HminContrast[0].I;
            trackBar8.Value = (int)UpDown8.Value;

            UpDown9.Value    = (decimal)HminScore[0].D;
            trackBar9.Value  = (int)(UpDown9.Value * 10);
            UpDown10.Value   = (decimal)HmaxOverlap[0].D;
            trackBar10.Value = (int)(UpDown10.Value * 10);
            UpDown11.Value   = (decimal)Hgreediness[0].D;
            trackBar11.Value = (int)(UpDown11.Value * 10);

            textBox3.Text = modelpath;
        }
        /// <summary>
        /// Gets the mark centers and the poses extracted from
        /// the set of calibration images 
        /// </summary>
        /// <param name="rows">
        /// Tuple of row coordinates of all marks from
        /// the entire set of calibration images
        /// </param>
        /// <param name="cols">
        /// Tuple of column coordinates of all marks from 
        /// the entire set of calibration images
        /// </param>
        /// <returns>
        /// Tuple of estimated poses for the entire set
        /// of calibration images
        /// </returns>
        public HTuple getCalibrationData(out HTuple rows, out HTuple cols)
        {
            int count = CalibData.Count;
            HTuple pose = new HTuple();
            rows = new HTuple();
            cols = new HTuple();
            CalibImage image;

            for (int i = 0; i < count; i++)
            {
                image = (CalibImage)CalibData[i];
                pose = pose.TupleConcat(image.GetEstimatedPose());
                rows = rows.TupleConcat(image.GetMarkCenterRows());
                cols = cols.TupleConcat(image.GetMarkCenterColumns());
            }
            return pose;
        }
    /// <summary>
    /// Generate a contour in form of an arrow.
    /// </summary>
    private void gen_arrow_cont(out HObject ho_Arrow, 
                              HTuple hv_Row1, 
                              HTuple hv_Column1,
                              HTuple hv_Row2, 
                              HTuple hv_Column2)
    {
        // Local iconic variables

        HObject ho_Cross1, ho_Cross2, ho_CrossP1, ho_CrossP2;

        // Local control variables

        HTuple hv_Length, hv_Angle, hv_MinArrowLength;
        HTuple hv_DRow, hv_DCol, hv_ArrowLength, hv_Phi, hv_P1R;
        HTuple hv_P1C, hv_P2R, hv_P2C;

        // Initialize local and output iconic variables
        HOperatorSet.GenEmptyObj(out ho_Arrow);
        HOperatorSet.GenEmptyObj(out ho_Cross1);
        HOperatorSet.GenEmptyObj(out ho_Cross2);
        HOperatorSet.GenEmptyObj(out ho_CrossP1);
        HOperatorSet.GenEmptyObj(out ho_CrossP2);

        //Generate a contour in form of a arrow
        hv_Length = 7;
        hv_Angle = 40;
        hv_MinArrowLength = 2;
        hv_DRow = hv_Row2 - hv_Row1;
        hv_DCol = hv_Column2 - hv_Column1;
        hv_ArrowLength = (((hv_DRow * hv_DRow) + (hv_DCol * hv_DCol))).TupleSqrt();
        if ((int)(new HTuple(hv_ArrowLength.TupleLess(hv_MinArrowLength))) != 0)
        {
          hv_Length = 0;
        }
        HOperatorSet.TupleAtan2(hv_DRow, -hv_DCol, out hv_Phi);
        hv_P1R = hv_Row2 - (hv_Length * (((hv_Phi - (hv_Angle.TupleRad()))).TupleSin()));
        hv_P1C = hv_Column2 + (hv_Length * (((hv_Phi - (hv_Angle.TupleRad()))).TupleCos()));
        hv_P2R = hv_Row2 - (hv_Length * (((hv_Phi + (hv_Angle.TupleRad()))).TupleSin()));
        hv_P2C = hv_Column2 + (hv_Length * (((hv_Phi + (hv_Angle.TupleRad()))).TupleCos()));
        ho_Cross1.Dispose();
        HOperatorSet.GenCrossContourXld(out ho_Cross1, hv_Row1, hv_Column1, 6, 0.785398);
        ho_Cross2.Dispose();
        HOperatorSet.GenCrossContourXld(out ho_Cross2, hv_Row2, hv_Column2, 6, 0.785398);
        ho_CrossP1.Dispose();
        HOperatorSet.GenCrossContourXld(out ho_CrossP1, hv_P1R, hv_P1C, 6, 0.785398);
        ho_CrossP2.Dispose();
        HOperatorSet.GenCrossContourXld(out ho_CrossP2, hv_P2R, hv_P2C, 6, 0.785398);
        ho_Arrow.Dispose();
        HOperatorSet.GenContourPolygonXld(out ho_Arrow, ((((((hv_Row1.TupleConcat(hv_Row2))).TupleConcat(
        hv_P1R))).TupleConcat(hv_Row2))).TupleConcat(hv_P2R), ((((((hv_Column1.TupleConcat(
        hv_Column2))).TupleConcat(hv_P1C))).TupleConcat(hv_Column2))).TupleConcat(
        hv_P2C));
        ho_Cross1.Dispose();
        ho_Cross2.Dispose();
        ho_CrossP1.Dispose();
        ho_CrossP2.Dispose();

        return;
    }
    /// <summary>
    /// Evaluates the distribution of the marks and hence the plates
    /// used for the calibration images. Precise measurements can only be
    /// achieved if the field view of the camera is covered well by the
    /// calibration plate in the images.
    /// </summary>
    public void eval_marks_distribution(HTuple hv_NRCoord, 
                                       HTuple hv_NCCoord, 
                                       HTuple hv_Width,
                                       HTuple hv_Height, 
                                       out HTuple hv_MarksDistributionScore)
    {
        // Local iconic variables

          HObject ho_Region, ho_DistanceImage, ho_Mask;

          // Local control variables

          HTuple hv_Border, hv_Min, hv_Max, hv_Range;
          HTuple hv_ImageDiagonal, hv_MinThresh, hv_MaxThresh, hv_Ratio;
          HTuple hv_Tmp1, hv_Tmp2;

          // Initialize local and output iconic variables
          HOperatorSet.GenEmptyObj(out ho_Region);
          HOperatorSet.GenEmptyObj(out ho_DistanceImage);
          HOperatorSet.GenEmptyObj(out ho_Mask);

          //Determine the distances between the marks centers
          ho_Region.Dispose();
          HOperatorSet.GenRegionPoints(out ho_Region, hv_NRCoord, hv_NCCoord);
          ho_DistanceImage.Dispose();
          HOperatorSet.DistanceTransform(ho_Region, out ho_DistanceImage, "octagonal",
          "false", hv_Width, hv_Height);
          //A clipping is needed because the marks cannot come close to the border
          hv_Border = (((hv_Width.TupleConcat(hv_Height))).TupleMax()) / 15;
          ho_Mask.Dispose();
          HOperatorSet.GenRectangle1(out ho_Mask, hv_Border, hv_Border, (hv_Height - 1) - hv_Border,
          (hv_Width - 1) - hv_Border);
          HOperatorSet.MinMaxGray(ho_Mask, ho_DistanceImage, 0, out hv_Min, out hv_Max,
          out hv_Range);
          HOperatorSet.DistancePp(0, 0, hv_Height - 1, hv_Width - 1, out hv_ImageDiagonal);
          hv_MinThresh = 0.3;
          hv_MaxThresh = 0.85;
          hv_Ratio = (hv_Max / hv_ImageDiagonal) * 2.5;
          hv_Tmp1 = 1 - hv_Ratio;
          hv_Tmp2 = (hv_Tmp1 - hv_MinThresh) / (hv_MaxThresh - hv_MinThresh);
          hv_MarksDistributionScore = ((((((hv_Tmp2.TupleConcat(1.0))).TupleMin())).TupleConcat(
          0.0))).TupleMax();
          ho_Region.Dispose();
          ho_DistanceImage.Dispose();
          ho_Mask.Dispose();

          return;
    }