예제 #1
0
        public override AbstractTrackPoint CreateTrackPoint(bool _manual, int _x, int _y, double _fSimilarity, long _t, Bitmap _CurrentImage, List <AbstractTrackPoint> _previousPoints)
        {
            // Creates a TrackPoint from the input image at the given coordinates.
            // Find features in the search window.

            // Scale-space image of the search window.
            int       searchLeft  = _x - (m_SearchWindowSize.Width / 2);
            int       searchTop   = _y - (m_SearchWindowSize.Height / 2);
            Rectangle searchZone  = new Rectangle(searchLeft, searchTop, m_SearchWindowSize.Width, m_SearchWindowSize.Height);
            Bitmap    searchImage = new Bitmap(m_SearchWindowSize.Width, m_SearchWindowSize.Height, PixelFormat.Format24bppRgb);
            Graphics  g           = Graphics.FromImage(searchImage);
            Rectangle rDst        = new Rectangle(0, 0, m_SearchWindowSize.Width, m_SearchWindowSize.Height);

            g.DrawImage(_CurrentImage, rDst, searchZone, GraphicsUnit.Pixel);
            //g.Dispose();

            IplImage pIplImage = IplImage.LoadImage(searchImage);

            pIplImage = pIplImage.BuildIntegral(null);

            List <Ipoint> ipts          = new List <Ipoint>();
            CFastHessian  pCFastHessian = new CFastHessian(pIplImage, ref ipts, m_iOctaves, m_iIntervals, m_iInitSample, m_fThreshold, m_iInterpolationSteps);

            // Fill the scale-space image with actual data and finds the local extrema.
            pCFastHessian.getIpoints();

            // Fill the descriptor field, orientation and laplacian of the feature.
            Surf pSurf = new Surf(pIplImage, ipts);

            pSurf.getDescriptors(m_bUpright);

            // Save algorithm-related data in the point.
            TrackPointSURF tps = new TrackPointSURF(_x, _y, _t);

            tps.FoundFeatures = ipts;

            tps.SearchWindow = new Point(searchLeft, searchTop);

            if (_previousPoints.Count == 0 || _manual)
            {
                // Find the closest point from the user's point.
                int    iClosest      = -1;
                double fBestDistance = double.MaxValue;
                if (ipts.Count > 0)
                {
                    Point userPoint = new Point(_x, _y);
                    for (int i = 0; i < ipts.Count; i++)
                    {
                        double fDistance = CalibrationHelper.PixelDistance(new PointF((float)_x, (float)_y), new PointF(ipts[i].x + searchLeft, ipts[i].y + searchTop));
                        if (fDistance < fBestDistance)
                        {
                            fBestDistance = fDistance;
                            iClosest      = i;
                        }
                    }

                    tps.MatchedFeature = tps.FoundFeatures[iClosest];
                    tps.X = (int)(tps.MatchedFeature.x + searchLeft);
                    tps.Y = (int)(tps.MatchedFeature.y + searchTop);

                    log.Debug(String.Format("Initializing of the tracking. Closest feature to user's point : {0:0.00}", fBestDistance));
                    log.Debug(String.Format("Tracking result (init): [{0};{1}], user selection was: [{2};{3}]", tps.X, tps.Y, _x, _y));
                }
                else
                {
                    // Ouch! The point selected by the user is in a no-feature zone.
                    tps = null;
                    log.Debug(String.Format("Tracking impossible from this point. Selected point is in No-feature zone."));
                }
            }

            return(tps);
        }