示例#1
0
        /// <summary>
        /// Finds the model in the test image. If the model
        /// hasn't been created or needs to be recreated (due to
        /// user changes made to the GUI components),
        /// then the model is created first.
        /// </summary>
        public bool detectShapeModel()
        {
            HTuple levels, rtmp;

            rtmp = new HTuple();
            double t2, t1;

            if (tImage == null)
            {
                return(false);
            }

            if (createNewModelID && !onExternalModelID)
            {
                if (!createShapeModel())
                {
                    return(false);
                }
            }

            try
            {
                levels = new HTuple(new int [] { parameterSet.mNumLevel,
                                                 parameterSet.mLastPyramidLevel });
                t1 = HSystem.CountSeconds();
                tImage.FindScaledShapeModel(ModelID,
                                            parameterSet.mStartingAngle,
                                            parameterSet.mAngleExtent,
                                            parameterSet.mMinScale,
                                            parameterSet.mMaxScale,
                                            parameterSet.mMinScore,
                                            parameterSet.mNumMatches,
                                            parameterSet.mMaxOverlap,
                                            new HTuple(parameterSet.mSubpixel),
                                            levels,
                                            parameterSet.mGreediness,
                                            out tResult.mRow,
                                            out tResult.mCol,
                                            out tResult.mAngle,
                                            out tResult.mScaleRow,
                                            out tResult.mScore);
                t2                = HSystem.CountSeconds();
                tResult.mTime     = 1000.0 * (t2 - t1);
                tResult.count     = tResult.mRow.Length;
                tResult.mScaleCol = tResult.mScaleRow;
            }
            catch (HOperatorException e)
            {
                if (!onTimer)
                {
                    exceptionText = e.Message;
                    NotifyParamObserver(MatchingParam.H_ERR_MESSAGE);
                }

                return(false);
            }

            NotifyIconObserver(MatchingAssistant.UPDATE_DETECTION_RESULT);
            return(true);
        }
示例#2
0
        private void CoreOnNewImage(HImage hImage, Guid tmpSessionId)
        {
            lock (OnNewImageLock)
            {
                double startTime = HSystem.CountSeconds();

                if (lastGrabImg[0] != null)
                {
                    lastGrabImg[0].Dispose();
                }
                lastGrabImg[0] = hImage.CopyImage();

                HImage rotateImage = hImage.RotateImage(new HTuple(rotazione[0]), "constant");
                //HImage rotateImage = rotateImage_.MirrorImage("column");
                //rotateImage_.Dispose();

                hImage.Dispose();

                cts = new CancellationTokenSource(Properties.Settings.Default.TimeoutAlgoritmo);

                ArrayList       iconicVarList;
                ElaborateResult result;
                ElaborateImage(rotateImage, cts, out iconicVarList, out result);
                double tAnalisi = HSystem.CountSeconds();
                tAnalisi = (tAnalisi - startTime) * 1000.0;

                result.ElapsedTime = tAnalisi;

                RaiseNewImageToDisplayEvent(iconicVarList, result);
            }
        }
示例#3
0
        public override void FindModel()
        {
            HImage img = InputImg;

            if (SearchRegion == null || !SearchRegion.IsInitialized())
            {
                SearchRegion = img.GetDomain();
            }

            if (createNewModelID)
            {
                if (!CreateNccModel())
                {
                    return;
                }
            }

            if (!nCCModel.IsInitialized())
            {
                throw new Exception("无创建的模板");
            }

            HRegion domain          = img.GetDomain();
            HRegion differentdomain = domain.Difference(SearchRegion);
            HImage  searchImg       = img.PaintRegion(differentdomain, 0.0, "fill");
            HImage  cropImg         = searchImg.ReduceDomain(SearchRegion);

            domain.Dispose();
            differentdomain.Dispose();

            OutputResult.Reset();


            try
            {
                double t1, t2;
                t1 = HSystem.CountSeconds();
                HOperatorSet.FindNccModel(cropImg, nCCModel, nCCParam.mStartingAngle, nCCParam.mAngleExtent, nCCParam.MinScore,
                                          nCCParam.NumMatches, nCCParam.mMaxOverlap, nCCParam.SubPixel, 0, out OutputResult.Row, out OutputResult.Col, out OutputResult.Angle, out OutputResult.Score);

                OutputResult.TemplateHand = nCCModel;
                t2 = HSystem.CountSeconds();
                OutputResult.Time  = 1000.0 * (t2 - t1);
                OutputResult.Count = OutputResult.Row.Length;
            }
            catch (HOperatorException ex)
            {
                if (ex.GetErrorCode() != 9400)
                {
                    throw ex;
                }
            }

            searchImg.Dispose();
            cropImg.Dispose();
        }
示例#4
0
        //////////////////////////////////////////////////////////////////////////////
        //  IPRun() - The thread function IPRun performs the image processing.
        //            It waits for the grabbing thread to indicate a new image in the
        //            image list. After calling the operator FindDataCode2D, the
        //            result values are stored in the ResultContainer instance
        //            resultData, which can be entered only after the previous result
        //            values were displayed (containerIsFree-event).
        //////////////////////////////////////////////////////////////////////////////
        public void IPRun()
        {
            // -------------------  INIT ----------------

            HDataCode2D reader = new HDataCode2D("Data Matrix ECC 200",
                                                 new HTuple(), new HTuple());

            reader.SetDataCode2dParam("default_parameters", "enhanced_recognition");

            // -----------  WAIT FOR EVENTS  ---------------

            while (newImgEvent.WaitOne())
            {
                newImgMutex.WaitOne();             // CriticalSect
                HImage image = (HImage)imgList[0]; // CriticalSect
                imgList.Remove(image);             // CriticalSect
                newImgMutex.ReleaseMutex();        // CriticalSect

                HTuple t1 = HSystem.CountSeconds();

                HTuple decodedDataStrings, resultHandle;

                HXLD symbolXLDs = reader.FindDataCode2d(image, new  HTuple(),
                                                        new HTuple(), out resultHandle, out decodedDataStrings);

                HTuple t2 = HSystem.CountSeconds();

                containerIsFreeEvent.WaitOne();
                resultDataMutex.WaitOne();                    // CriticalSect
                resultData.timeNeeded   = (1000 * (t2 - t1)); // CriticalSect
                resultData.decodedData  = decodedDataStrings; // CriticalSect
                resultData.resultImg    = image;              // CriticalSect
                resultData.resultHandle = resultHandle;       // CriticalSect
                resultData.symbolData   = symbolXLDs;         // CriticalSect
                containerIsFreeEvent.Reset();                 // CriticalSect
                resultDataMutex.ReleaseMutex();               // CriticalSect
                newResultEvent.Set();

                mainForm.Invoke(delegateDisplay);

                if (delegatedStopEvent.WaitOne(0, true))
                {
                    break;
                }
            }
            // --------  RESET/CLOSE ALL HANDLES  ---------

            mainForm.threadAcq.Join();
            mainForm.Invoke(delegateControlReset);

            reader.Dispose();

            newResultEvent.Reset();

            return;
        }
示例#5
0
        private void CoreOnNewImage(HImage[] hImage, Guid tmpSessionId)
        {
            lock (OnNewImageLock)
            {
                double startTime = HSystem.CountSeconds();

                HImage[] rotateImage = new HImage[hImage.Length];

                Parallel.For(0, Properties.Settings.Default.NumeroCamereTappo, i =>
                {
                    if (lastGrabImg[i] != null)
                    {
                        lastGrabImg[i].Dispose();
                    }
                    // |MP 25-1-19
                    if (null != hImage[i])
                    {
                        lastGrabImg[i] = hImage[i].CopyImage();

                        HImage rotateImage_ = hImage[i].RotateImage(new HTuple(rotazione[i]), "constant");
                        rotateImage[i]      = rotateImage_.MirrorImage("column");
                        rotateImage_.Dispose();

                        hImage[i].Dispose();
                    }
                    hImage[i] = null;
                });

                cts = new CancellationTokenSource(Properties.Settings.Default.TimeoutAlgoritmo);

                ArrayList[]       iconicVarList;
                ElaborateResult[] result;
                ElaborateImage(rotateImage, cts, out iconicVarList, out result);
                double tAnalisi = HSystem.CountSeconds();
                tAnalisi = (tAnalisi - startTime) * 1000.0;

                for (int i = 0; i < result.Length; i++)
                {
                    result[i].ElapsedTime = tAnalisi;
                }

                RaiseNewImageToDisplayEvent(iconicVarList, result);
            }
        }
示例#6
0
        private void Action()
        {
            double    S1, S2;
            HTuple    RowCheck, ColumnCheck, AngleCheck, Score;
            HHomMat2D Matrix = new HHomMat2D();
            HRegion   ModelRegionTrans;
            HTuple    Rect1RowCheck, Rect1ColCheck;
            HTuple    Rect2RowCheck, Rect2ColCheck;
            HRegion   Rectangle1 = new HRegion();
            HRegion   Rectangle2 = new HRegion();
            HMeasure  Measure1, Measure2;
            HTuple    RowEdgeFirst1, ColumnEdgeFirst1;
            HTuple    AmplitudeFirst1, RowEdgeSecond1;
            HTuple    ColumnEdgeSecond1, AmplitudeSecond1;
            HTuple    IntraDistance1, InterDistance1;
            HTuple    RowEdgeFirst2, ColumnEdgeFirst2;
            HTuple    AmplitudeFirst2, RowEdgeSecond2;
            HTuple    ColumnEdgeSecond2, AmplitudeSecond2;
            HTuple    IntraDistance2, InterDistance2;
            HTuple    MinDistance;
            int       NumLeads;

            HSystem.SetSystem("flush_graphic", "false");
            Img.GrabImage(Framegrabber);
            Img.DispObj(Window);

            // Find the IC in the current image.
            S1 = HSystem.CountSeconds();
            ShapeModel.FindShapeModel(Img, 0,
                                      new HTuple(360).TupleRad().D,
                                      0.7, 1, 0.5, "least_squares",
                                      4, 0.9, out RowCheck, out ColumnCheck,
                                      out AngleCheck, out Score);
            S2 = HSystem.CountSeconds();
            MatchingTimeLabel.Text = "Time: " +
                                     String.Format("{0,4:F1}", (S2 - S1) * 1000) + "ms";
            MatchingScoreLabel.Text = "Score: ";

            if (RowCheck.Length == 1)
            {
                MatchingScoreLabel.Text = "Score: " +
                                          String.Format("{0:F5}", Score.D);
                // Rotate the model for visualization purposes.
                Matrix.VectorAngleToRigid(new HTuple(Row), new HTuple(Column), new HTuple(0.0),
                                          RowCheck, ColumnCheck, AngleCheck);

                ModelRegionTrans = ModelRegion.AffineTransRegion(Matrix, "false");
                Window.SetColor("green");
                Window.SetDraw("fill");
                ModelRegionTrans.DispObj(Window);
                // Compute the parameters of the measurement rectangles.
                Matrix.AffineTransPixel(Rect1Row, Rect1Col,
                                        out Rect1RowCheck, out Rect1ColCheck);
                Matrix.AffineTransPixel(Rect2Row, Rect2Col,
                                        out Rect2RowCheck, out Rect2ColCheck);

                // For visualization purposes, generate the two rectangles as
                // regions and display them.
                Rectangle1.GenRectangle2(Rect1RowCheck.D, Rect1ColCheck.D,
                                         RectPhi + AngleCheck.D,
                                         RectLength1, RectLength2);
                Rectangle2.GenRectangle2(Rect2RowCheck.D, Rect2ColCheck.D,
                                         RectPhi + AngleCheck.D,
                                         RectLength1, RectLength2);
                Window.SetColor("blue");
                Window.SetDraw("margin");
                Rectangle1.DispObj(Window);
                Rectangle2.DispObj(Window);
                // Do the actual measurements.
                S1       = HSystem.CountSeconds();
                Measure1 = new HMeasure(Rect1RowCheck.D, Rect1ColCheck.D,
                                        RectPhi + AngleCheck.D,
                                        RectLength1, RectLength2,
                                        ImgWidth, ImgHeight, "bilinear");
                Measure2 = new HMeasure(Rect2RowCheck.D, Rect2ColCheck.D,
                                        RectPhi + AngleCheck.D,
                                        RectLength1, RectLength2,
                                        ImgWidth, ImgHeight, "bilinear");
                Measure1.MeasurePairs(Img, 2, 90,
                                      "positive", "all",
                                      out RowEdgeFirst1,
                                      out ColumnEdgeFirst1,
                                      out AmplitudeFirst1,
                                      out RowEdgeSecond1,
                                      out ColumnEdgeSecond1,
                                      out AmplitudeSecond1,
                                      out IntraDistance1,
                                      out InterDistance1);
                Measure2.MeasurePairs(Img, 2, 90,
                                      "positive", "all",
                                      out RowEdgeFirst2,
                                      out ColumnEdgeFirst2,
                                      out AmplitudeFirst2,
                                      out RowEdgeSecond2,
                                      out ColumnEdgeSecond2,
                                      out AmplitudeSecond2,
                                      out IntraDistance2,
                                      out InterDistance2);
                S2 = HSystem.CountSeconds();
                MeasureTimeLabel.Text = "Time: " +
                                        String.Format("{0,5:F1}", (S2 - S1) * 1000) + "ms";
                Window.SetColor("red");
                Window.DispLine(RowEdgeFirst1 - RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeFirst1 - RectLength2 * Math.Sin(AngleCheck),
                                RowEdgeFirst1 + RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeFirst1 + RectLength2 * Math.Sin(AngleCheck));
                Window.DispLine(RowEdgeSecond1 - RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeSecond1 - RectLength2 * Math.Sin(AngleCheck),
                                RowEdgeSecond1 + RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeSecond1 + RectLength2 * Math.Sin(AngleCheck));
                Window.DispLine(RowEdgeFirst2 - RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeFirst2 - RectLength2 * Math.Sin(AngleCheck),
                                RowEdgeFirst2 + RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeFirst2 + RectLength2 * Math.Sin(AngleCheck));
                Window.DispLine(RowEdgeSecond2 - RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeSecond2 - RectLength2 * Math.Sin(AngleCheck),
                                RowEdgeSecond2 + RectLength2 * Math.Cos(AngleCheck),
                                ColumnEdgeSecond2 + RectLength2 * Math.Sin(AngleCheck));
                NumLeads             = IntraDistance1.Length + IntraDistance2.Length;
                MeasureNumLabel.Text = "Number of leads: " +
                                       String.Format("{0:D2}", NumLeads);
                MinDistance           = InterDistance1.TupleConcat(InterDistance2).TupleMin();
                MeasureDistLabel.Text = "Minimum lead distance: " +
                                        String.Format("{0:F3}", MinDistance.D);
                HSystem.SetSystem("flush_graphic", "true");
                // Force the graphics window update by displaying an offscreen pixel
                Window.DispLine(-1.0, -1.0, -1.0, -1.0);
            }
        }
示例#7
0
        public HXLDCont FindShapeModel(HImage img,
                                       HShapeModel model,
                                       FindModelParameter findModelParameter,
                                       out HTuple row,
                                       out HTuple column,
                                       out HTuple angle,
                                       out HTuple scale,
                                       out HTuple score)
        {
            var t1 = HSystem.CountSeconds();

            model.SetShapeModelParam("timeout", 10000);
            try
            {
                img.FindScaledShapeModel(
                    model,
                    findModelParameter.angleStart,
                    findModelParameter.angleExtent,
                    findModelParameter.scaleMin,
                    findModelParameter.scaleMax,
                    findModelParameter.minScore,
                    findModelParameter.numMatches,
                    findModelParameter.maxOverlap,
                    findModelParameter.subPixel,
                    findModelParameter.numLevels,
                    findModelParameter.greediness,
                    out row,
                    out column,
                    out angle,
                    out scale,
                    out score);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                row                   =
                    column            =
                        angle         =
                            scale     =
                                score = new HTuple();
            }

            var t2    = HSystem.CountSeconds();
            var mTime = 1000.0 * (t2 - t1);

            System.Diagnostics.Debug.WriteLine(mTime.ToString());

            var modelContours = Model.GetShapeModelContours(1);
            var homMat2D      = new HHomMat2D();

            //HTuple Width, Height;
            //Img.GetImageSize(out Width, out Height);

            if (score.Length <= 0)
            {
                return(null);
            }
            homMat2D.VectorAngleToRigid(0, 0, 0, row, column, angle);

            var contoursAffinTrans = modelContours.AffineTransContourXld(homMat2D);

            return(contoursAffinTrans);
        }
示例#8
0
        public void FindShapeModel(HImage Img, HWindow window, double row1, double col1, double row2, double col2, double rowMark, double colMark)
        {
            double    S1, S2;
            HTuple    RowCheck, ColumnCheck, AngleCheck, Score;
            HHomMat2D Matrix = new HHomMat2D();
            HRegion   ModelRegionTrans;
            HTuple    row1Check, col1Check;
            HTuple    row2Check, col2Check;
            HRegion   Rectangle1 = new HRegion();

            //HRegion           Rectangle2 = new HRegion();
            //HMeasure          Measure1, Measure2;
            //HTuple            RowEdgeFirst1, ColumnEdgeFirst1;
            //HTuple            AmplitudeFirst1, RowEdgeSecond1;
            //HTuple            ColumnEdgeSecond1, AmplitudeSecond1;
            //HTuple            IntraDistance1, InterDistance1;
            //HTuple            RowEdgeFirst2, ColumnEdgeFirst2;
            //HTuple            AmplitudeFirst2, RowEdgeSecond2;
            //HTuple            ColumnEdgeSecond2, AmplitudeSecond2;
            //HTuple            IntraDistance2, InterDistance2;
            //HTuple            MinDistance;
            //int               NumLeads;

            //HSystem.SetSystem("flush_graphic", "false");
            //Img.GrabImage(Framegrabber);
            //Img.DispObj(Window);

            // Find the IC in the current image.
            S1 = HSystem.CountSeconds();
            ShapeModel.FindShapeModel(Img, 0,
                                      new HTuple(360).TupleRad().D,
                                      0.7, 1, 0.5, "least_squares",
                                      4, 0.9, out RowCheck, out ColumnCheck,
                                      out AngleCheck, out Score);
            S2 = HSystem.CountSeconds();
            if (RowCheck.Length == 1)
            {
                //MatchingScoreLabel.Text = "Score: " +
                //    String.Format("{0:F5}", Score.D);
                // Rotate the model for visualization purposes.
                //创建严格的仿射变换VectorAngleToRigid
                Matrix.VectorAngleToRigid(new HTuple((row1 + row2) / 2), new HTuple((col1 + col2) / 2), new HTuple(0.0),
                                          RowCheck - rowMark + rowOrg, ColumnCheck - colMark + colOrg, AngleCheck);
                //根据Matrix变换ModelRegion
                ModelRegionTrans = ModelRegion.AffineTransRegion(Matrix, "false");
                window.SetColor("red");
                window.SetDraw("margin");
                window.SetLineWidth(2);
                ModelRegionTrans.DispObj(window);
                // Compute the parameters of the measurement rectangles.
                Matrix.AffineTransPixel(new HTuple(row1), new HTuple(col1),
                                        out row1Check, out col1Check);
                Matrix.AffineTransPixel(new HTuple(row2), new HTuple(col2),
                                        out row2Check, out col2Check);
                Rectangle1.GenRectangle1(row1Check, col1Check, row2Check, col2Check);
                window.SetColor("green");
                window.SetDraw("margin");
                window.SetLineWidth(1);
                Rectangle1.DispObj(window);
                window.SetColor("gold");
                window.DispLine(RowCheck - 15, ColumnCheck, RowCheck + 15, ColumnCheck);
                window.DispLine(RowCheck, ColumnCheck - 15, RowCheck, ColumnCheck + 45);


                // For visualization purposes, generate the two rectangles as
                // regions and display them.
                //Rectangle1.GenRectangle2(Rect1RowCheck.D, Rect1ColCheck.D,
                //    RectPhi + AngleCheck.D,
                //    RectLength1, RectLength2);
                //Rectangle2.GenRectangle2(Rect2RowCheck.D, Rect2ColCheck.D,
                //    RectPhi + AngleCheck.D,
                //    RectLength1, RectLength2);
                //window.SetColor("blue");
                //window.SetDraw("margin");
                //Rectangle1.DispObj(window);
                //Rectangle2.DispObj(window);
            }
            //MatchingTimeLabel.Text = "Time: " +
            //    String.Format("{0,4:F1}", (S2 - S1)*1000) + "ms";
            //MatchingScoreLabel.Text = "Score: ";
            //{
            //    MatchingScoreLabel.Text = "Score: " +
            //        String.Format("{0:F5}", Score.D);
            //    // Rotate the model for visualization purposes.
            //    Matrix.VectorAngleToRigid(new HTuple(Row), new HTuple(Column), new HTuple(0.0),
            //        RowCheck, ColumnCheck, AngleCheck);

            //    ModelRegionTrans = ModelRegion.AffineTransRegion(Matrix, "false");
            //window.SetColor("green");
            //window.SetDraw("fill");
            ////ModelRegionTrans.DispObj(window);
        }
示例#9
0
        /// <summary>
        /// Finds the model in the test image. If the model
        /// hasn't been created or needs to be recreated (due to
        /// user changes made to the GUI components),
        /// then the model is created first.
        /// </summary>

        public bool detectShapeModel()
        {
            string log = "detectShapeModel:";
            HTuple levels, rtmp;

            rtmp = new HTuple();
            double t2, t1;
            bool   isSuccess = false;

            if (mTestImage == null)
            {
                return(false);
            }

            //if(createNewModelID/* && !onExternalModelID*/)
            //    if(!createShapeModel())
            //        return false;

            try
            {
                tResult.isGrayModel = false;
                int secondLevel = parameterSet.mNumLevel - 2;
                secondLevel = secondLevel > 1 ? secondLevel : 1;
                levels      = new HTuple(new int[] { parameterSet.mNumLevel, secondLevel });
                t1          = HSystem.CountSeconds();
                mTestImage.FindShapeModel(ModelID,
                                          parameterSet.mStartingAngle,
                                          parameterSet.mAngleExtent,
                                          parameterSet.mMinScore,
                                          parameterSet.mNumMatches,
                                          parameterSet.mMaxOverlap,
                                          new HTuple(parameterSet.mSubpixel),
                                          levels,
                                          parameterSet.mGreediness,
                                          out tResult.mRow,
                                          out tResult.mCol,
                                          out tResult.mAngle,
                                          out tResult.mScore);

                tResult.mRow        = tResult.mRow / parameterSet.mImageSizeScale;
                tResult.mCol        = tResult.mCol / parameterSet.mImageSizeScale;
                tResult.mImageScale = parameterSet.mImageSizeScale;
                isSuccess           = tResult.mRow.Length > 0;
                if (!isSuccess && IsEnableGrayTemplate && GrayTemplate != null && GrayTemplate.IsInitialized())
                {
                    log += "ÐÎ×´Æ¥Åäʧ°Ü";
                    double row, col;
                    mTestImage.BestMatchMg(GrayTemplate, parameterSet.mMaxError, parameterSet.mSubpixel, parameterSet.mNumLevel, "all", out row, out col, out tResult.mError);
                    isSuccess = row > 0 && col > 0;
                    if (isSuccess)
                    {
                        log                += ",»Ò¶ÈÆ¥ÅäOK";
                        tResult.mRow        = row;
                        tResult.mCol        = col;
                        tResult.mAngle      = 0;
                        tResult.mScore      = 0.701;
                        tResult.isGrayModel = true;
                    }
                    else
                    {
                        tResult.mRow   = 0;
                        tResult.mCol   = 0;
                        tResult.mAngle = 0;
                        tResult.mScore = 0;
                        log           += ",»Ò¶ÈÆ¥ÅäNG,error=" + tResult.mError.ToString();
                    }

                    Logger.Pop(log);
                }
                t2 = HSystem.CountSeconds();
                //tResult.mAngle = 0;
                tResult.mTime     = 1000.0 * (t2 - t1);
                tResult.count     = tResult.mRow.Length;
                tResult.mScaleCol = tResult.mScaleRow;
            }
            catch (HOperatorException e)
            {
                if (!onTimer)
                {
                    exceptionText = e.Message;
                    NotifyParamObserver(MatchingParam.H_ERR_MESSAGE);
                }

                return(false);
            }

            NotifyIconObserver(MatchingAssistant.UPDATE_DETECTION_RESULT);
            return(isSuccess);
        }
示例#10
0
        public override void FindModel()
        {
            OutputResult.Reset();

            HImage img = InputImg;

            if (!img.IsInitialized() || img == null)
            {
                return;
            }

            if (SearchRegion == null || !SearchRegion.IsInitialized())
            {
                SearchRegion = img.GetDomain();
            }

            if (createNewModelID)
            {
                if (!CreateModel())
                {
                    return;
                }
            }

            if (!shapeModel.IsInitialized())
            {
                throw new Exception("无创建的模板");
            }

            if (!img.IsInitialized())
            {
                throw new Exception("图片无效");
            }

            //HRegion domain = img.GetDomain();
            //HRegion differentdomain = domain.Difference(SearchRegion);
            //HImage searchImg = img.PaintRegion(differentdomain, 0.0, "fill");
            //HImage cropImg = searchImg.ReduceDomain(SearchRegion);
            //domain.Dispose();
            //differentdomain.Dispose();

            HImage cropImg = img.ReduceDomain(SearchRegion);

            try
            {
                double t1, t2;
                t1 = HSystem.CountSeconds();
                HOperatorSet.FindScaledShapeModel(cropImg, shapeModel, shapeParam.mStartingAngle, shapeParam.mAngleExtent, shapeParam.mMinScale, shapeParam.mMaxScale,
                                                  shapeParam.mMinScore, shapeParam.mNumMatches, shapeParam.mMaxOverlap, shapeParam.mSubpixel, 0, shapeParam.mGreediness,
                                                  out OutputResult.Row, out OutputResult.Col, out OutputResult.Angle, out OutputResult.Scale, out OutputResult.Score);

                OutputResult.TemplateHand = shapeModel;
                t2 = HSystem.CountSeconds();
                OutputResult.Time  = 1000.0 * (t2 - t1);
                OutputResult.Count = OutputResult.Row.Length;
            }
            catch (HOperatorException ex)
            {
                if (ex.GetErrorCode() == 6001)
                {
                    //searchImg.Dispose();
                    cropImg.Dispose();
                    GC.Collect();
                    return;
                }
                if (ex.GetErrorCode() != 9400)
                {
                    throw ex;
                }
            }

            //searchImg.Dispose();
            cropImg.Dispose();
        }
示例#11
0
        private void CoreOnNewImage(HImage[] hImage, Guid tmpSessionId)
        {
            //-----------------------------------------------
            lock (this.mIOManager.objectLock)
            {
                //this.mIOManager.SetOutput(numOutRis, false);
                //this.mIOManager.Write(); |MP
                this.mIOManager.SetOutput(numOutBusy, true);
                this.mIOManager.Write();
            }
            //-----------------------------------------------

            //Debug.WriteLine(DateTime.Now.Subtract(start).TotalMilliseconds);
            //start = DateTime.Now;

            lock (OnNewImageLock)
            {
                double startTime = HSystem.CountSeconds();

                HImage[] rotateImage = new HImage[hImage.Length];

                for (int i = 0; i < hImage.Length; i++)
                {
                    HImage rotateImage_ = hImage[i].RotateImage(new HTuple(rotazione[i]), "constant");
                    rotateImage[i] = rotateImage_.MirrorImage("column");
                    rotateImage_.Dispose();
                }

                cts = new CancellationTokenSource(Properties.Settings.Default.TimeoutAlgoritmo);

                ArrayList[]       iconicVarList;
                ElaborateResult[] result;

                ElaborateImage(rotateImage, cts, out iconicVarList, out result);

                //-----------------------------------------------
                lock (this.mIOManager.objectLock)
                {
                    this.mIOManager.SetOutput(numOutRis, result.Count(k => k.Success == true) == result.Length);
                    this.mIOManager.Write();
                    this.mIOManager.SetOutput(numOutBusy, false);
                    this.mIOManager.Write();
                }
                //-----------------------------------------------

                double tAnalisi = HSystem.CountSeconds();
                tAnalisi = (tAnalisi - startTime) * 1000.0;

                if (sessionId != tmpSessionId)
                {
                    //Sessione SCADUTA
                }
                else
                {
                    lock (lastResultLock)
                    {
                        lastResult = result;
                    }
                }

                EventHandler OnFineElaborazioneTmp = OnFineElaborazione;
                if (OnFineElaborazioneTmp != null)
                {
                    OnFineElaborazioneTmp(this, EventArgs.Empty);
                }

                if (result != null)
                {
                    for (int i = 0; i < result.Length; i++)
                    {
                        result[i].ElapsedTime = tAnalisi;
                        ManageErrorImage(iconicVarList[i], result[i]);
                    }
                }

                RaiseNewImageToDisplayEvent(iconicVarList, result);
            }
        }
示例#12
0
        //DateTime start = DateTime.Now;

        private void CoreOnNewImage(HImage hImage, Guid tmpSessionId)
        {
            //-----------------------------------------------
            lock (this.mIOManager.objectLock)
            {
                this.mIOManager.SetOutput(numOutBusy, true);
                this.mIOManager.Write();
            }
            //-----------------------------------------------

            lock (OnNewImageLock)
            {
                double startTime = HSystem.CountSeconds();

                HImage rotateImage = hImage.RotateImage(new HTuple(rotazione[0]), "constant");
                //HImage rotateImage = rotateImage_.MirrorImage("column");
                //rotateImage_.Dispose();

                cts = new CancellationTokenSource(Properties.Settings.Default.TimeoutAlgoritmo);

                ArrayList       iconicVarList;
                ElaborateResult result;

                ElaborateImage(rotateImage, cts, out iconicVarList, out result);

                //-----------------------------------------------
                lock (this.mIOManager.objectLock)
                {
                    this.mIOManager.SetOutput(numOutRis, result.Success);
                    this.mIOManager.Write();
                    this.mIOManager.SetOutput(numOutBusy, false);
                    this.mIOManager.Write();
                }
                //-----------------------------------------------

                double tAnalisi = HSystem.CountSeconds();
                tAnalisi = (tAnalisi - startTime) * 1000.0;

                result.ElapsedTime = tAnalisi;

                if (sessionId != tmpSessionId)
                {
                    //Sessione SCADUTA
                }
                else
                {
                    lock (lastResultLock)
                    {
                        lastResult = new ElaborateResult[] { result };
                    }
                }

                EventHandler OnFineElaborazioneTmp = OnFineElaborazione;
                if (OnFineElaborazioneTmp != null)
                {
                    OnFineElaborazioneTmp(this, EventArgs.Empty);
                }

                ManageErrorImage(iconicVarList, result);

                RaiseNewImageToDisplayEvent(iconicVarList, result);
            }
        }