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

            HXLDCont rContours;

            for (int i = 0; i < row.Length; i++)
            {
                HHomMat2D mat1 = new HHomMat2D();
                mat1.VectorAngleToRigid(0, 0, 0, row[i].D, column[i].D, angle[i].D);
                mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D);
                //图像偏移
                rContours = mat1.AffineTransContourXld(modelXldCont);
                //获取模板集合
                resultXLDCont = resultXLDCont.ConcatObj(rContours);
                rContours.Dispose();
                rContours.GenCrossContourXld(row[i].D, column[i].D, 10, angle[i].D);
                resultXLDCont = resultXLDCont.ConcatObj(rContours);
                rContours.Dispose();
            }
        }
        public void GenDetectionRegionResult(HRegion modelRegion)
        {
            if (resultRegion == null)
            {
                resultRegion = new HRegion();
            }
            if (resultRegion != null && resultRegion.IsInitialized())
            {
                resultRegion.Dispose();
            }
            resultRegion.GenEmptyObj();

            HRegion temp = new HRegion();

            for (int i = 0; i < row.Length; i++)
            {
                HHomMat2D mat1 = new HHomMat2D();
                mat1.VectorAngleToRigid(
                    createShapeModel.refCoordinates[0].D,
                    createShapeModel.refCoordinates[1].D,
                    createShapeModel.refCoordinates[2].D,
                    row[i].D, column[i].D, angle[i].D);
                mat1 = mat1.HomMat2dScale(scale[i].D, scale[i].D, row[i].D, column[i].D);
                //图像偏移
                temp = mat1.AffineTransRegion(modelRegion, "nearest_neighbor");
                //获取模板集合
                resultRegion = resultRegion.ConcatObj(temp);
                temp.Dispose();
            }
        }
示例#3
0
        /// <summary>
        /// Gets the detected contour.
        /// </summary>
        /// <returns>Detected contour</returns>
        public HXLDCont getDetectionResults()
        {
            HXLDCont rContours = new HXLDCont();

            hmat.HomMat2dIdentity();

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



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

                rContours = hmat.AffineTransContourXld(mContour);



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

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

            return(mContResults);
        }
示例#4
0
        public HXLDCont GetMatchModelCont(int index)
        {
            HXLDCont hXLD = GetModelCont();

            if (hXLD == null)
            {
                return(null);
            }

            HXLDCont cont = null;

            if (index < OutputResult.Count)
            {
                HHomMat2D mat2d = new HHomMat2D();
                mat2d = mat2d.HomMat2dScale(OutputResult.Scale[index], OutputResult.Scale[index], 0d, 0d);
                mat2d = mat2d.HomMat2dRotate(OutputResult.Angle[index], 0d, 0d);
                mat2d = mat2d.HomMat2dTranslate(OutputResult.Row[index].D, OutputResult.Col[index].D);

                cont = hXLD.AffineTransContourXld(mat2d);
            }

            return(cont);
        }
示例#5
0
        public bool FindDataCode(HImage img, HRegion region, bool train = false)
        {
            if (!region.IsInitialized())
            {
                region = img.GetDomain();
            }

            if (!train)
            {
                Display(0, region);
            }


            HImage reduceImg = img.ReduceDomain(region);
            HImage searchImg = reduceImg.CropDomain();

            reduceImg.Dispose();

            int width, height;

            searchImg.GetImageSize(out width, out height);

            HImage zoomImg = searchImg.ZoomImageFactor(DateCodeZoomImg, DateCodeZoomImg, "constant");

            DataCodeContour.Dispose();
            searchImg.Dispose();

            HTuple ResultHandles, DecodedDataStrings;

            if (train)
            {
                DataCodeContour = CodeReaderHand.FindDataCode2d(zoomImg, "train", "all", out ResultHandles, out DecodedDataStrings);
            }
            else
            {
                DataCodeContour = CodeReaderHand.FindDataCode2d(zoomImg, "stop_after_result_num", 1, out ResultHandles, out DecodedDataStrings);
            }


            if (DecodedDataStrings.Length > 0)
            {
                DataCodeString = DecodedDataStrings[0].S;

                HHomMat2D mat = new HHomMat2D();
                HHomMat2D scalMat = mat.HomMat2dScale(1 / DateCodeZoomImg, 1 / DateCodeZoomImg, 0.0, 0.0);
                double    row, col;
                region.AreaCenter(out row, out col);
                HHomMat2D tranMat = scalMat.HomMat2dTranslate(row - height / 2.0, col - width / 2.0);

                HXLDCont tranDataCodeContour = tranMat.AffineTransContourXld(DataCodeContour);
                DataCodeContour.Dispose();
                DataCodeContour = tranDataCodeContour;

                if (!train)
                {
                    Display(2);
                    Display(3);
                }
            }
            else
            {
                if (UseBrighten)
                {
                    HImage brightenImg = zoomImg.ScaleImage(UseBrightenValue, 0.0);
                    DataCodeContour = CodeReaderHand.FindDataCode2d(brightenImg, "stop_after_result_num", 1, out ResultHandles, out DecodedDataStrings);
                    if (DecodedDataStrings.Length > 0)
                    {
                        DataCodeString = DecodedDataStrings[0].S;

                        HHomMat2D mat = new HHomMat2D();
                        HHomMat2D scalMat = mat.HomMat2dScale(1 / DateCodeZoomImg, 1 / DateCodeZoomImg, 0.0, 0.0);
                        double    row, col;
                        region.AreaCenter(out row, out col);
                        HHomMat2D tranMat = scalMat.HomMat2dTranslate(row - height / 2.0, col - width / 2.0);

                        HXLDCont tranDataCodeContour = tranMat.AffineTransContourXld(DataCodeContour);
                        DataCodeContour.Dispose();
                        DataCodeContour = tranDataCodeContour;
                        if (!train)
                        {
                            Display(2);
                            Display(3);
                        }

                        return(true);
                    }
                }



                DataCodeString = string.Empty;

                if (!train)
                {
                    Display(4);
                }
                return(false);
            }



            return(true);
        }