Example #1
0
        public bool FindDataCode(HImage img, bool train = false)
        {
            if (!SearchRegion.IsInitialized())
            {
                SearchRegion = img.GetDomain();
            }

            if (!train)
            {
                Display(1);
            }


            HImage reduceImg = img.ReduceDomain(SearchRegion);
            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;
                SearchRegion.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;
                        SearchRegion.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);
        }