Ejemplo n.º 1
0
        public void findSilhouettesWeak(Image <Gray, Byte> input)
        {
            Image <Gray, Byte> fatInput    = morphologicalOperations(input);
            List <Silhouette>  silhouettes = new List <Silhouette>();

            numTargets = 0;

            var inputSize = input.Size;

            //contours method:
            Image <Gray, Byte>    filter   = new Image <Gray, byte>(inputSize);
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();

            CvInvoke.FindContours(fatInput, contours, null, Emgu.CV.CvEnum.RetrType.List, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxNone);
            for (int i = 0; i < contours.Size; i++)
            {
                double a = CvInvoke.ContourArea(contours[i]);  //  Find the area of contour
                if (a < minPixels)
                {
                    continue;
                }

                MCvScalar white = new MCvScalar(255, 255, 255);
                filter = new Image <Gray, Byte>(inputSize);
                CvInvoke.DrawContours(filter, contours, i, white, -1);
                Silhouette temp = new Silhouette(input.Copy(filter), 0);
                temp.compute();

                //these lines are diffrent in easy mode:
                if (temp.count < minPixels)
                {
                    continue;
                }
                if (temp.linearness < minLinearness)
                {
                    continue;
                }
                if (temp.gappiness < minGappiness)
                {
                    continue;
                }

                var moment = CvInvoke.Moments(contours[i], true);
                temp.centroid.X = (int)(moment.M10 / moment.M00);
                temp.centroid.Y = (int)(moment.M01 / moment.M00);
                temp.centroid   = temp.findTop(false);

                silhouettes.Add(temp);
                numTargets++;
            }

            //move local variable to global:
            this.silhouettes = silhouettes;
        }
Ejemplo n.º 2
0
        public void findSilhouettes(Image <Gray, Byte> input)
        {
            Image <Gray, Byte> fatInput    = morphologicalOperations(input);
            List <Silhouette>  silhouettes = new List <Silhouette>();

            numTargets = 0;

            var inputSize = input.Size;

            //contours method:
            Image <Gray, Byte>    filter   = new Image <Gray, byte>(inputSize);
            VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();

            CvInvoke.FindContours(fatInput, contours, null, Emgu.CV.CvEnum.RetrType.List, Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxNone);
            for (int i = 0; i < contours.Size; i++)
            {
                double a = CvInvoke.ContourArea(contours[i]);  //  Find the area of contour
                if (a < minPixels)
                {
                    continue;
                }

                MCvScalar white = new MCvScalar(255, 255, 255);
                filter = new Image <Gray, Byte>(inputSize);
                CvInvoke.DrawContours(filter, contours, i, white, -1);
                Silhouette temp = new Silhouette(input.Copy(filter), 0);
                temp.compute();
                if (temp.count < minPixels)
                {
                    continue;
                }
                if (temp.linearness < minLinearness)
                {
                    continue;
                }
                if (temp.gappiness < minGappiness)
                {
                    continue;
                }

                var moment = CvInvoke.Moments(contours[i], true);
                temp.centroid.X = (int)(moment.M10 / moment.M00);
                temp.centroid.Y = (int)(moment.M01 / moment.M00);
                temp.centroid   = temp.findTop();
                silhouettes.Add(temp);
                numTargets++;
            }

            ////recursive method:
            //for (int i = input.Rows - 1; i >= 0; i--)
            //{
            //    for (int j = input.Cols - 1; j >= 0; j--)
            //    {
            //        if (inputData[i, j, 0] == 255)
            //        {
            //            count = 0;
            //            Image<Gray, Byte> temp = new Image<Gray, Byte>(inputSize);
            //            outputData = temp.Data;

            //            crawlFrom(i, j);
            //            if (count > minPixels)
            //            {
            //                Silhouette s = new Silhouette(temp, count);
            //                if (s.linearness() / (float)s.count > minLinearness)
            //                    silhouettes.Add(s);
            //            }
            //        }
            //    }
            //}

            //filter out low linearness silhouettes:
            //silhouettes = silhouettes.Where(s => s.linearness() / (float)s.count > minLinearness).ToList();

            //move local variable to global:
            this.silhouettes = silhouettes;
        }
Ejemplo n.º 3
0
        //private void crawlFrom(int i, int j)
        //{
        //    outputData[i, j, 0] = 255;//else add pixel to output
        //    count++;//increment count
        //    inputData[i, j, 0] = 0;//blacken input image

        //    //recursively call on neighbors:
        //    if(i + 1 < height)
        //        if (inputData[i + 1, j, 0] == 255)
        //            crawlFrom(i + 1, j);

        //    if (i - 1 >= 0)
        //        if (inputData[i - 1, j, 0] == 255)
        //            crawlFrom(i - 1, j);

        //    if (j + 1 < width)
        //        if (inputData[i, j + 1, 0] == 255)
        //            crawlFrom(i, j + 1);

        //    if (j - 1 >= 0)
        //        if (inputData[i, j - 1, 0] == 255)
        //            crawlFrom(i, j - 1);

        //}

        private Point findHead(Silhouette input)
        {
            return(new Point(input.top.X, input.top.Y - headOffset));//todo improve this?
        }