// Procedures
        public static void ReadData(HObject ho_Image, out HObject ho_SymbolXLDs, out HTuple hv_flag,
                                    out HTuple hv_DecodedDataStrings, out HTuple hv_Row, out HTuple hv_Column)
        {
            // Local iconic variables

            HObject ho_GrayImage1 = null;

            // Local control variables

            HTuple hv_Grayval = null, hv_channels = null;
            HTuple hv_DataCodeHandle = null, hv_ResultHandles = null;
            HTuple hv_Area = new HTuple(), hv_PointOrder = new HTuple();

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_SymbolXLDs);
            HOperatorSet.GenEmptyObj(out ho_GrayImage1);
            hv_Row    = new HTuple();
            hv_Column = new HTuple();
            hv_flag   = 0;
            HOperatorSet.GetGrayval(ho_Image, 0, 0, out hv_Grayval);
            hv_channels = new HTuple(hv_Grayval.TupleLength());
            if ((int)(new HTuple(hv_channels.TupleNotEqual(1))) != 0)
            {
                ho_GrayImage1.Dispose();
                HOperatorSet.Rgb1ToGray(ho_Image, out ho_GrayImage1);
            }
            else
            {
                ho_GrayImage1.Dispose();
                HOperatorSet.CopyImage(ho_Image, out ho_GrayImage1);
            }
            HOperatorSet.CreateDataCode2dModel("Data Matrix ECC 200", "default_parameters",
                                               "enhanced_recognition", out hv_DataCodeHandle);
            ho_SymbolXLDs.Dispose();
            HOperatorSet.FindDataCode2d(ho_GrayImage1, out ho_SymbolXLDs, hv_DataCodeHandle,
                                        new HTuple(), new HTuple(), out hv_ResultHandles, out hv_DecodedDataStrings);
            HOperatorSet.ClearDataCode2dModel(hv_DataCodeHandle);



            if ((int)(new HTuple((new HTuple(hv_DecodedDataStrings.TupleLength())).TupleNotEqual(
                                     0))) != 0)
            {
                hv_flag = 1;
                HOperatorSet.AreaCenterXld(ho_SymbolXLDs, out hv_Area, out hv_Row, out hv_Column,
                                           out hv_PointOrder);
            }
            else
            {
                hv_flag = 0;
            }
            ho_GrayImage1.Dispose();

            return;
        }
        /// <summary>
        /// Extracts the calibration plate and the marks on this plate
        /// for the supplied image
        /// </summary>
        public void find_caltab_edges(HObject ho_Image,
                                      out HObject ho_Caltab,
                                      out HObject ho_Marks,
                                      HTuple hv_DescriptionFileName)
        {
            // Stack for temporary objects
            HObject[] OTemp = new HObject[20];
            long      SP_O  = 0;

            // Local iconic variables

            HObject ho_ImageMean, ho_RegionDynThresh, ho_RegionBorder;
            HObject ho_RegionOpening1, ho_ConnectedRegions1, ho_SelectedRegions4;
            HObject ho_SelectedRegions5, ho_RegionBorder2, ho_RegionTrans;
            HObject ho_RegionErosion, ho_RegionBorder1, ho_RegionDilation2;
            HObject ho_RegionDifference1, ho_RegionOpening, ho_ConnectedRegions;
            HObject ho_SelectedRegions2, ho_SelectedRegions, ho_RegionFillUp;
            HObject ho_SelectedRegions1, ho_RegionIntersection, ho_RegionFillUp1;
            HObject ho_RegionDifference, ho_CaltabCandidates, ho_ObjectSelected = null;
            HObject ho_ConnectedMarks = null, ho_ObjectSelectedCaltab = null;
            HObject ho_RegionFillUpCand, ho_MarksCand, ho_RegionDilation1;
            HObject ho_ImageReduced, ho_DefaultEdges, ho_UnionContours;
            HObject ho_SelectedXLD, ho_SelectedXLD1;


            // Local control variables

            HTuple hv_ExpDefaultCtrlDummyVar, hv_Width;
            HTuple hv_Height, hv_EstimatedCaltabSize, hv_EstimatedMarkSize;
            HTuple hv_Number, hv_X, hv_Y, hv_Z, hv_NumDescrMarks, hv_Index;
            HTuple hv_NumberMarks = new HTuple(), hv_Anisometry = new HTuple();
            HTuple hv_Bulkiness = new HTuple(), hv_StructureFactor = new HTuple();
            HTuple hv_AreaMarks = new HTuple(), hv_Row = new HTuple();
            HTuple hv_Column = new HTuple(), hv_Rectangularity, hv_SortedIndex;
            HTuple hv_IndexBest, hv_MinContrast, hv_NumberCand, hv_Area;
            HTuple hv_Dummy, hv_DummyS, hv_AreaMedian;

            // Initialize local and output iconic variables
            HOperatorSet.GenEmptyObj(out ho_Caltab);
            HOperatorSet.GenEmptyObj(out ho_Marks);
            HOperatorSet.GenEmptyObj(out ho_ImageMean);
            HOperatorSet.GenEmptyObj(out ho_RegionDynThresh);
            HOperatorSet.GenEmptyObj(out ho_RegionBorder);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening1);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions4);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions5);
            HOperatorSet.GenEmptyObj(out ho_RegionBorder2);
            HOperatorSet.GenEmptyObj(out ho_RegionTrans);
            HOperatorSet.GenEmptyObj(out ho_RegionErosion);
            HOperatorSet.GenEmptyObj(out ho_RegionBorder1);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation2);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference1);
            HOperatorSet.GenEmptyObj(out ho_RegionOpening);
            HOperatorSet.GenEmptyObj(out ho_ConnectedRegions);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions2);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp);
            HOperatorSet.GenEmptyObj(out ho_SelectedRegions1);
            HOperatorSet.GenEmptyObj(out ho_RegionIntersection);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUp1);
            HOperatorSet.GenEmptyObj(out ho_RegionDifference);
            HOperatorSet.GenEmptyObj(out ho_CaltabCandidates);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelected);
            HOperatorSet.GenEmptyObj(out ho_ConnectedMarks);
            HOperatorSet.GenEmptyObj(out ho_ObjectSelectedCaltab);
            HOperatorSet.GenEmptyObj(out ho_RegionFillUpCand);
            HOperatorSet.GenEmptyObj(out ho_MarksCand);
            HOperatorSet.GenEmptyObj(out ho_RegionDilation1);
            HOperatorSet.GenEmptyObj(out ho_ImageReduced);
            HOperatorSet.GenEmptyObj(out ho_DefaultEdges);
            HOperatorSet.GenEmptyObj(out ho_UnionContours);
            HOperatorSet.GenEmptyObj(out ho_SelectedXLD);
            HOperatorSet.GenEmptyObj(out ho_SelectedXLD1);

            //
            ho_Marks.Dispose();
            HOperatorSet.GenEmptyObj(out ho_Marks);
            ho_Caltab.Dispose();
            HOperatorSet.GenEmptyObj(out ho_Caltab);
            HOperatorSet.GetImagePointer1(ho_Image, out hv_ExpDefaultCtrlDummyVar, out hv_ExpDefaultCtrlDummyVar,
                                          out hv_Width, out hv_Height);
            hv_EstimatedCaltabSize = (((((hv_Width.TupleConcat(hv_Height))).TupleMax()) / 2.5)).TupleRound()
            ;
            hv_EstimatedMarkSize = ((hv_EstimatedCaltabSize / 12.0)).TupleRound();
            ho_ImageMean.Dispose();
            HOperatorSet.MeanImage(ho_Image, out ho_ImageMean, hv_EstimatedMarkSize * 3, hv_EstimatedMarkSize * 3);
            ho_RegionDynThresh.Dispose();
            HOperatorSet.DynThreshold(ho_Image, ho_ImageMean, out ho_RegionDynThresh, 3,
                                      "light");
            ho_RegionBorder.Dispose();
            HOperatorSet.DynThreshold(ho_Image, ho_ImageMean, out ho_RegionBorder, 20, "dark");
            ho_RegionOpening1.Dispose();
            HOperatorSet.OpeningCircle(ho_RegionBorder, out ho_RegionOpening1, 1.5);
            ho_ConnectedRegions1.Dispose();
            HOperatorSet.Connection(ho_RegionOpening1, out ho_ConnectedRegions1);
            ho_SelectedRegions4.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions1, out ho_SelectedRegions4, "compactness",
                                     "and", 17, 50);
            ho_SelectedRegions5.Dispose();
            HOperatorSet.SelectShape(ho_SelectedRegions4, out ho_SelectedRegions5, "anisometry",
                                     "and", 1, 1.4);
            ho_RegionBorder2.Dispose();
            HOperatorSet.Boundary(ho_SelectedRegions5, out ho_RegionBorder2, "outer");
            ho_SelectedRegions5.Dispose();
            HOperatorSet.SelectShape(ho_RegionBorder2, out ho_SelectedRegions5, "circularity",
                                     "and", 0.006, 1);
            ho_RegionTrans.Dispose();
            HOperatorSet.ShapeTrans(ho_SelectedRegions5, out ho_RegionTrans, "rectangle2");
            ho_RegionErosion.Dispose();
            HOperatorSet.ErosionCircle(ho_RegionTrans, out ho_RegionErosion, (hv_Width / 640.0) * 5.5);
            ho_RegionBorder1.Dispose();
            HOperatorSet.Boundary(ho_RegionErosion, out ho_RegionBorder1, "inner");
            ho_RegionDilation2.Dispose();
            HOperatorSet.DilationCircle(ho_RegionBorder1, out ho_RegionDilation2, 3.5);
            ho_RegionDifference1.Dispose();
            HOperatorSet.Difference(ho_RegionDynThresh, ho_RegionDilation2, out ho_RegionDifference1
                                    );
            ho_RegionOpening.Dispose();
            HOperatorSet.OpeningCircle(ho_RegionDifference1, out ho_RegionOpening, (hv_Width / 640) * 1.5);
            ho_ConnectedRegions.Dispose();
            HOperatorSet.Connection(ho_RegionOpening, out ho_ConnectedRegions);
            ho_SelectedRegions2.Dispose();
            HOperatorSet.SelectShape(ho_ConnectedRegions, out ho_SelectedRegions2, "area",
                                     "and", (hv_EstimatedCaltabSize.TuplePow(2)) / 10, (hv_EstimatedCaltabSize.TuplePow(
                                                                                            2)) * 5);
            ho_SelectedRegions.Dispose();
            HOperatorSet.SelectShape(ho_SelectedRegions2, out ho_SelectedRegions, "compactness",
                                     "and", 1.4, 10);
            ho_RegionFillUp.Dispose();
            HOperatorSet.FillUp(ho_SelectedRegions, out ho_RegionFillUp);
            ho_SelectedRegions1.Dispose();
            HOperatorSet.SelectShape(ho_RegionFillUp, out ho_SelectedRegions1, "rectangularity",
                                     "and", 0.6, 1);
            ho_RegionIntersection.Dispose();
            HOperatorSet.Intersection(ho_SelectedRegions1, ho_RegionDynThresh, out ho_RegionIntersection
                                      );
            ho_RegionFillUp1.Dispose();
            HOperatorSet.FillUp(ho_RegionIntersection, out ho_RegionFillUp1);
            ho_RegionDifference.Dispose();
            HOperatorSet.Difference(ho_RegionFillUp1, ho_RegionIntersection, out ho_RegionDifference
                                    );
            HOperatorSet.CountObj(ho_RegionDifference, out hv_Number);
            ho_CaltabCandidates.Dispose();
            HOperatorSet.GenEmptyObj(out ho_CaltabCandidates);
            HOperatorSet.CaltabPoints(hv_DescriptionFileName, out hv_X, out hv_Y, out hv_Z);
            hv_NumDescrMarks = new HTuple(hv_X.TupleLength());
            for (hv_Index = 1; hv_Index.Continue(hv_Number, 1); hv_Index = hv_Index.TupleAdd(1))
            {
                ho_ObjectSelected.Dispose();
                HOperatorSet.SelectObj(ho_RegionDifference, out ho_ObjectSelected, hv_Index);
                ho_ConnectedMarks.Dispose();
                HOperatorSet.Connection(ho_ObjectSelected, out ho_ConnectedMarks);
                HOperatorSet.CountObj(ho_ConnectedMarks, out hv_NumberMarks);
                HOperatorSet.Eccentricity(ho_ConnectedMarks, out hv_Anisometry, out hv_Bulkiness,
                                          out hv_StructureFactor);
                HOperatorSet.AreaCenter(ho_ConnectedMarks, out hv_AreaMarks, out hv_Row, out hv_Column);
                ho_ObjectSelectedCaltab.Dispose();
                HOperatorSet.SelectObj(ho_RegionIntersection, out ho_ObjectSelectedCaltab,
                                       hv_Index);
                if ((int)((new HTuple((new HTuple((new HTuple(hv_NumberMarks.TupleGreaterEqual(
                                                                  10))).TupleAnd(new HTuple(hv_NumberMarks.TupleLess(hv_NumDescrMarks + 20))))).TupleAnd(
                                          new HTuple(((((hv_Anisometry.TupleSort())).TupleSelect((new HTuple(hv_Anisometry.TupleLength()
                                                                                                             )) / 2))).TupleLess(2))))).TupleAnd(new HTuple((new HTuple(hv_AreaMarks.TupleMean()
                                                                                                                                                                        )).TupleGreater(20)))) != 0)
                {
                    OTemp[SP_O] = ho_CaltabCandidates.CopyObj(1, -1);
                    SP_O++;
                    ho_CaltabCandidates.Dispose();
                    HOperatorSet.ConcatObj(OTemp[SP_O - 1], ho_ObjectSelectedCaltab, out ho_CaltabCandidates
                                           );
                    OTemp[SP_O - 1].Dispose();
                    SP_O = 0;
                }
            }
            ho_RegionFillUpCand.Dispose();
            HOperatorSet.FillUp(ho_CaltabCandidates, out ho_RegionFillUpCand);
            HOperatorSet.Rectangularity(ho_RegionFillUpCand, out hv_Rectangularity);
            if ((int)(new HTuple((new HTuple(hv_Rectangularity.TupleLength())).TupleEqual(
                                     0))) != 0)
            {
                ho_ImageMean.Dispose();
                ho_RegionDynThresh.Dispose();
                ho_RegionBorder.Dispose();
                ho_RegionOpening1.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions4.Dispose();
                ho_SelectedRegions5.Dispose();
                ho_RegionBorder2.Dispose();
                ho_RegionTrans.Dispose();
                ho_RegionErosion.Dispose();
                ho_RegionBorder1.Dispose();
                ho_RegionDilation2.Dispose();
                ho_RegionDifference1.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_SelectedRegions.Dispose();
                ho_RegionFillUp.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_RegionIntersection.Dispose();
                ho_RegionFillUp1.Dispose();
                ho_RegionDifference.Dispose();
                ho_CaltabCandidates.Dispose();
                ho_ObjectSelected.Dispose();
                ho_ConnectedMarks.Dispose();
                ho_ObjectSelectedCaltab.Dispose();
                ho_RegionFillUpCand.Dispose();
                ho_MarksCand.Dispose();
                ho_RegionDilation1.Dispose();
                ho_ImageReduced.Dispose();
                ho_DefaultEdges.Dispose();
                ho_UnionContours.Dispose();
                ho_SelectedXLD.Dispose();
                ho_SelectedXLD1.Dispose();

                return;
            }
            hv_SortedIndex = hv_Rectangularity.TupleSortIndex();
            hv_IndexBest   = (((hv_SortedIndex.TupleInverse())).TupleSelect(0)) + 1;
            ho_Caltab.Dispose();
            HOperatorSet.SelectObj(ho_RegionFillUpCand, out ho_Caltab, hv_IndexBest);
            ho_RegionFillUp.Dispose();
            HOperatorSet.FillUp(ho_Caltab, out ho_RegionFillUp);
            ho_MarksCand.Dispose();
            HOperatorSet.Difference(ho_RegionFillUp, ho_RegionDynThresh, out ho_MarksCand
                                    );
            ho_RegionBorder.Dispose();
            HOperatorSet.Boundary(ho_MarksCand, out ho_RegionBorder, "inner");
            ho_RegionDilation1.Dispose();
            HOperatorSet.DilationCircle(ho_RegionBorder, out ho_RegionDilation1, 9.5);
            ho_ImageReduced.Dispose();
            HOperatorSet.ReduceDomain(ho_Image, ho_RegionDilation1, out ho_ImageReduced);
            hv_MinContrast = 10;
            ho_DefaultEdges.Dispose();
            HOperatorSet.EdgesSubPix(ho_ImageReduced, out ho_DefaultEdges, "canny", 2, hv_MinContrast / 2,
                                     hv_MinContrast);
            HOperatorSet.CountObj(ho_DefaultEdges, out hv_NumberCand);
            if ((int)(new HTuple(hv_NumberCand.TupleLess(10))) != 0)
            {
                ho_ImageMean.Dispose();
                ho_RegionDynThresh.Dispose();
                ho_RegionBorder.Dispose();
                ho_RegionOpening1.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions4.Dispose();
                ho_SelectedRegions5.Dispose();
                ho_RegionBorder2.Dispose();
                ho_RegionTrans.Dispose();
                ho_RegionErosion.Dispose();
                ho_RegionBorder1.Dispose();
                ho_RegionDilation2.Dispose();
                ho_RegionDifference1.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_SelectedRegions.Dispose();
                ho_RegionFillUp.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_RegionIntersection.Dispose();
                ho_RegionFillUp1.Dispose();
                ho_RegionDifference.Dispose();
                ho_CaltabCandidates.Dispose();
                ho_ObjectSelected.Dispose();
                ho_ConnectedMarks.Dispose();
                ho_ObjectSelectedCaltab.Dispose();
                ho_RegionFillUpCand.Dispose();
                ho_MarksCand.Dispose();
                ho_RegionDilation1.Dispose();
                ho_ImageReduced.Dispose();
                ho_DefaultEdges.Dispose();
                ho_UnionContours.Dispose();
                ho_SelectedXLD.Dispose();
                ho_SelectedXLD1.Dispose();

                return;
            }
            ho_UnionContours.Dispose();
            HOperatorSet.UnionCocircularContoursXld(ho_DefaultEdges, out ho_UnionContours,
                                                    0.5, 0.1, 0.2, 30, 10, 10, "true", 1);
            ho_SelectedXLD.Dispose();
            HOperatorSet.SelectShapeXld(ho_UnionContours, out ho_SelectedXLD, "area", "and",
                                        30, 10000);
            ho_SelectedXLD1.Dispose();
            HOperatorSet.SelectShapeXld(ho_SelectedXLD, out ho_SelectedXLD1, "circularity",
                                        "and", 0.4, 1);
            ho_MarksCand.Dispose();
            HOperatorSet.SelectShapeXld(ho_SelectedXLD1, out ho_MarksCand, "compactness",
                                        "and", 1, 1.5);
            HOperatorSet.AreaCenterXld(ho_MarksCand, out hv_Area, out hv_Dummy, out hv_Dummy,
                                       out hv_DummyS);
            HOperatorSet.CountObj(ho_MarksCand, out hv_Number);
            if ((int)(new HTuple(hv_Number.TupleLess(4))) != 0)
            {
                ho_ImageMean.Dispose();
                ho_RegionDynThresh.Dispose();
                ho_RegionBorder.Dispose();
                ho_RegionOpening1.Dispose();
                ho_ConnectedRegions1.Dispose();
                ho_SelectedRegions4.Dispose();
                ho_SelectedRegions5.Dispose();
                ho_RegionBorder2.Dispose();
                ho_RegionTrans.Dispose();
                ho_RegionErosion.Dispose();
                ho_RegionBorder1.Dispose();
                ho_RegionDilation2.Dispose();
                ho_RegionDifference1.Dispose();
                ho_RegionOpening.Dispose();
                ho_ConnectedRegions.Dispose();
                ho_SelectedRegions2.Dispose();
                ho_SelectedRegions.Dispose();
                ho_RegionFillUp.Dispose();
                ho_SelectedRegions1.Dispose();
                ho_RegionIntersection.Dispose();
                ho_RegionFillUp1.Dispose();
                ho_RegionDifference.Dispose();
                ho_CaltabCandidates.Dispose();
                ho_ObjectSelected.Dispose();
                ho_ConnectedMarks.Dispose();
                ho_ObjectSelectedCaltab.Dispose();
                ho_RegionFillUpCand.Dispose();
                ho_MarksCand.Dispose();
                ho_RegionDilation1.Dispose();
                ho_ImageReduced.Dispose();
                ho_DefaultEdges.Dispose();
                ho_UnionContours.Dispose();
                ho_SelectedXLD.Dispose();
                ho_SelectedXLD1.Dispose();

                return;
            }
            hv_AreaMedian = ((hv_Area.TupleSort())).TupleSelect(hv_Number / 2);
            ho_Marks.Dispose();
            HOperatorSet.SelectShapeXld(ho_MarksCand, out ho_Marks, "area", "and", hv_AreaMedian - (hv_AreaMedian * 0.5),
                                        hv_AreaMedian + (hv_AreaMedian * 0.5));
            ho_ImageMean.Dispose();
            ho_RegionDynThresh.Dispose();
            ho_RegionBorder.Dispose();
            ho_RegionOpening1.Dispose();
            ho_ConnectedRegions1.Dispose();
            ho_SelectedRegions4.Dispose();
            ho_SelectedRegions5.Dispose();
            ho_RegionBorder2.Dispose();
            ho_RegionTrans.Dispose();
            ho_RegionErosion.Dispose();
            ho_RegionBorder1.Dispose();
            ho_RegionDilation2.Dispose();
            ho_RegionDifference1.Dispose();
            ho_RegionOpening.Dispose();
            ho_ConnectedRegions.Dispose();
            ho_SelectedRegions2.Dispose();
            ho_SelectedRegions.Dispose();
            ho_RegionFillUp.Dispose();
            ho_SelectedRegions1.Dispose();
            ho_RegionIntersection.Dispose();
            ho_RegionFillUp1.Dispose();
            ho_RegionDifference.Dispose();
            ho_CaltabCandidates.Dispose();
            ho_ObjectSelected.Dispose();
            ho_ConnectedMarks.Dispose();
            ho_ObjectSelectedCaltab.Dispose();
            ho_RegionFillUpCand.Dispose();
            ho_MarksCand.Dispose();
            ho_RegionDilation1.Dispose();
            ho_ImageReduced.Dispose();
            ho_DefaultEdges.Dispose();
            ho_UnionContours.Dispose();
            ho_SelectedXLD.Dispose();
            ho_SelectedXLD1.Dispose();

            return;
        }
Exemple #3
0
        /// <summary>
        /// 涮新定位点
        /// </summary>
        /// <param name="itoolDateFather_"></param>
        public void ShuaXinDingWeiDian(IToolDateFather itoolDateFather_, Object ioutSide_)
        {
            if (itoolDateFather_.IrectShuJuPianYi != null)//更新定位点
            {
                #region  判断是不是直线
                if (ioutSide_ is IOutsideLineROI)//判断是不是直线
                {
                    IOutsideLineROI IOutSide_ = (IOutsideLineROI)ioutSide_;

                    HTuple oneRow_, oneCol_, twoRow_, twoCol_;

                    HTuple  hv_modMat2D, crossRow_ = new HTuple(), crossCol_ = new HTuple(), Nr, Nc, Dist;
                    HObject contour_;
                    HOperatorSet.VectorAngleToRigid(itoolDateFather_.GenSuiDian_Y_Row, itoolDateFather_.GeuSuiDian_X_Col, itoolDateFather_.GenSuiDian_A, itoolDateFather_.IrectShuJuPianYi.Row, itoolDateFather_.IrectShuJuPianYi.Column, itoolDateFather_.IrectShuJuPianYi.Angle, out hv_modMat2D);

                    crossRow_[0] = IOutSide_.Row1.D;
                    crossRow_[1] = IOutSide_.Row2.D;
                    crossCol_[0] = IOutSide_.Cols1.D;
                    crossCol_[1] = IOutSide_.Cols2.D;
                    HOperatorSet.GenContourPolygonXld(out contour_, crossRow_, crossCol_);

                    HOperatorSet.AffineTransContourXld(contour_, out contour_, hv_modMat2D);

                    HOperatorSet.FitLineContourXld(contour_, "tukey", -1, 0, 5, 2, out oneRow_, out oneCol_, out twoRow_, out twoCol_, out Nr, out Nc, out Dist);

                    IOutSide_.Row1  = oneRow_;
                    IOutSide_.Row2  = twoRow_;
                    IOutSide_.Cols1 = oneCol_;
                    IOutSide_.Cols2 = twoCol_;
                    contour_.Dispose();
                }
                #endregion

                #region  判断是不是矩形1
                if (ioutSide_ is IOutsideRectangle1ROI)//判断是不是矩形1
                {
                }
                #endregion

                #region  判断是不是圆
                if (ioutSide_ is IOutsideCricleROI)//判断是不是圆
                {
                    IOutsideCricleROI IOutSide_ = (IOutsideCricleROI)ioutSide_;
                    HTuple            hv_modMat2D;
                    HObject           hv_Cirle;
                    HTuple            Area_, Column_, Row_;

                    HOperatorSet.VectorAngleToRigid(itoolDateFather_.GenSuiDian_Y_Row, itoolDateFather_.GeuSuiDian_X_Col, itoolDateFather_.GenSuiDian_A, itoolDateFather_.IrectShuJuPianYi.Row, itoolDateFather_.IrectShuJuPianYi.Column, itoolDateFather_.IrectShuJuPianYi.Angle, out hv_modMat2D);

                    //HOperatorSet.GenCircle(out hv_Cirle, IOutSide_.Center_row_y, IOutSide_.Center_column_x, IOutSide_.Radius);
                    //HOperatorSet.AffineTransRegion(hv_Cirle, out hv_Cirle, hv_modMat2D, "nearest_neighbor");
                    //HOperatorSet.AreaCenter(hv_Cirle, out Area_, out Row_, out Column_);

                    HOperatorSet.GenCircleContourXld(out hv_Cirle, IOutSide_.Center_row_y, IOutSide_.Center_column_x, IOutSide_.Radius, 0, 6.28318, "positive", 1);
                    HOperatorSet.AffineTransContourXld(hv_Cirle, out hv_Cirle, hv_modMat2D);
                    HTuple pointOrder;
                    HOperatorSet.AreaCenterXld(hv_Cirle, out Area_, out Row_, out Column_, out pointOrder);

                    hv_Cirle.Dispose();
                    IOutSide_.Center_column_x = Column_;
                    IOutSide_.Center_row_y    = Row_;
                }
                #endregion

                #region  判断是不是矩形2
                if (ioutSide_ is IOutsideRectangle2ROI)//判断是不是矩形2
                {
                    HTuple  hv_modMat2D, mid_row_, mid_col_, phi_, area_;
                    HObject ho_ROI_0;
                    IOutsideRectangle2ROI IOutSide_ = (IOutsideRectangle2ROI)ioutSide_;
                    HOperatorSet.GenRectangle2(out ho_ROI_0, IOutSide_.Mid_row_y, IOutSide_.Mid_col_x, -IOutSide_.Phi, IOutSide_.Len1, IOutSide_.Len2);
                    HOperatorSet.VectorAngleToRigid(itoolDateFather_.GenSuiDian_Y_Row, itoolDateFather_.GeuSuiDian_X_Col, itoolDateFather_.GenSuiDian_A, itoolDateFather_.IrectShuJuPianYi.Row, itoolDateFather_.IrectShuJuPianYi.Column, itoolDateFather_.IrectShuJuPianYi.Angle, out hv_modMat2D);

                    HOperatorSet.AffineTransRegion(ho_ROI_0, out ho_ROI_0, hv_modMat2D, "nearest_neighbor");

                    HOperatorSet.AreaCenter(ho_ROI_0, out area_, out mid_row_, out mid_col_);

                    HOperatorSet.OrientationRegion(ho_ROI_0, out phi_);
                    IOutSide_.Mid_col_x = mid_col_;
                    IOutSide_.Mid_row_y = mid_row_;
                    IOutSide_.Phi       = -phi_;

                    ho_ROI_0.Dispose();
                }
                #endregion

                #region  刷新定位点
                itoolDateFather_.GenSuiDian_A     = itoolDateFather_.IrectShuJuPianYi.Angle;
                itoolDateFather_.GenSuiDian_Y_Row = itoolDateFather_.IrectShuJuPianYi.Row;
                itoolDateFather_.GeuSuiDian_X_Col = itoolDateFather_.IrectShuJuPianYi.Column;
                #endregion
            }
        }
Exemple #4
0
        /// <summary>
        /// 一次对位,求补偿值
        /// </summary>
        /// <param name="xuanZhuanZhongXin_X"></param>
        /// <param name="xuanZhuanZhongXin_Y"></param>
        /// <param name="muBanDian_X"></param>
        /// <param name="muBanDian_Y"></param>
        /// <param name="muBanDian_A"></param>
        /// <param name="dangQianZuoBiao_X"></param>
        /// <param name="dangQianZuoBiao_Y"></param>
        /// <param name="dangQianJiaoDu"></param>
        /// <param name="xuanZhuanHouDeZuoBiao_X"></param>
        /// <param name="xuanZhuanHouDeZuoBiao_Y"></param>
        /// <returns></returns>
        public static bool yiCiDuiWeiQiuBuChangZhi(double xuanZhuanZhongXin_X, double xuanZhuanZhongXin_Y, double muBanDian_X, double muBanDian_Y, double muBanDian_A, double dangQianZuoBiao_X, double dangQianZuoBiao_Y, double dangQianJiaoDu, out double buChangZhi_X, out double buChangZhi_Y, out double BuChangZhi_A)
        {
            bool ok = false;

            #region  创建halcon变量
            buChangZhi_X = 0;
            buChangZhi_Y = 0;
            BuChangZhi_A = 0;

            HTuple  hv_modMat2D;
            HTuple  hv_xuanZhuanZhongXin_X, hv_xuanZhuanZhongXin_Y, hv_muBanDian_X, hv_muBanDian_Y, hv_muBanDian_A, hv_dangQianZuoBiao_X, hv_dangQianZuoBiao_Y, hv_dangQianJiaoDu, hv_xuanZhuanHouDe_X, hv_xuanZhuanHouDe_Y, hv_JiaoDuPianCha;
            HObject hv_circle, hv_circleTran;
            HOperatorSet.GenEmptyObj(out hv_circle);
            HOperatorSet.GenEmptyObj(out hv_circleTran);
            #endregion

            #region   赋值
            hv_xuanZhuanZhongXin_X = xuanZhuanZhongXin_X;
            hv_xuanZhuanZhongXin_Y = xuanZhuanZhongXin_Y;

            hv_muBanDian_X = muBanDian_X;
            hv_muBanDian_Y = muBanDian_Y;
            hv_muBanDian_A = muBanDian_A;

            hv_dangQianZuoBiao_X = dangQianZuoBiao_X;
            hv_dangQianZuoBiao_Y = dangQianZuoBiao_Y;
            hv_dangQianJiaoDu    = dangQianJiaoDu;
            #endregion

            #region  生成要转换的xld
            HTuple hv_rad;
            HOperatorSet.TupleRad(360, out hv_rad);
            HOperatorSet.GenCircleContourXld(out hv_circle, hv_dangQianZuoBiao_Y, hv_dangQianZuoBiao_X, 60, 0, hv_rad, "positive", 1.0);
            #endregion

            #region   求旋转矩阵
            hv_JiaoDuPianCha = hv_muBanDian_A - hv_dangQianJiaoDu;
            HOperatorSet.HomMat2dIdentity(out hv_modMat2D);
            HOperatorSet.HomMat2dRotate(hv_modMat2D, hv_JiaoDuPianCha, hv_xuanZhuanZhongXin_X, hv_xuanZhuanZhongXin_Y, out hv_modMat2D);
            #endregion

            #region   旋转xld   得出旋转后的点位
            HTuple hv_area, hv_point;
            HOperatorSet.AffineTransContourXld(hv_circle, out hv_circleTran, hv_modMat2D);
            HOperatorSet.AreaCenterXld(hv_circleTran, out hv_area, out hv_xuanZhuanHouDe_Y, out hv_xuanZhuanHouDe_X, out hv_point);
            #endregion

            #region   清空缓存
            hv_circleTran.Dispose();
            hv_circle.Dispose();
            #endregion

            #region  计算出来的值转换
            BuChangZhi_A = hv_JiaoDuPianCha.D;
            buChangZhi_X = (hv_muBanDian_X - hv_xuanZhuanHouDe_X).D;
            buChangZhi_Y = (hv_muBanDian_Y - hv_xuanZhuanHouDe_Y).D;
            #endregion

            ok = true;
            return(ok);
        }