private List <DetectedDoor> CollectDoors(List <DetectedDoor> doors)
        {
            List <DetectedDoor> doorsToRemove = new List <DetectedDoor>();

            for (int i = 0; i < doors.Count(); ++i)
            {
                DetectedDoor door1 = doors[i];

                for (int j = i + 1; j < doors.Count(); ++j)
                {
                    DetectedDoor door2 = doors[j];

                    if (door1.BoundingBox.Contains(door2.BoundingBox))
                    {
                        door1.Confidence = DetectedDoor.DetectionConfidence.HIGH;
                        doorsToRemove.Add(door2);
                    }
                    else if (door2.BoundingBox.Contains(door1.BoundingBox))
                    {
                        door2.Confidence = DetectedDoor.DetectionConfidence.HIGH;
                        doorsToRemove.Add(door1);
                    }
                }
            }

            foreach (DetectedDoor door in doorsToRemove)
            {
                doors.Remove(door);
            }

            return(doors);
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            if (!obj.GetType().Equals(this.GetType()))
            {
                return(false);
            }

            DetectedDoor other = (DetectedDoor)obj;

            return(this.BoundingBox == other.BoundingBox &&
                   this.Confidence == other.Confidence &&
                   this.RelativeAngle == other.RelativeAngle &&
                   this.RelativeDistance == other.RelativeDistance);
        }
        public List <DetectedDoor> GetDoors(object data)
        {
            DFrame depthFrame = data as DFrame;

            if (depthFrame == null)
            {
                return(null);
            }
            List <DetectedDoor> doors = new List <DetectedDoor>();

            //Image<Bgr, Byte> smoothed = img.SmoothGaussian(15);
            //Image<Gray, Byte> threshold = FilterColor(smoothed);
            //threshold = SimplifyImage(threshold, 100);

            // new method

            //new method end
            using (MemStorage stor = new MemStorage())
            {
                Bitmap bmp = depthFrame.GetDoorNaviBitmap();
                //Bitmap bmp2 = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), bmp.PixelFormat);
                //Image<Bgr, Byte> img = new Image<Bgr, Byte>(bmp2);
                Image <Gray, Byte> grey;
                try
                {
                    grey = new Image <Gray, Byte>(bmp);
                }
                catch (Exception)
                {
                    return(null);
                }

                //CvInvoke.cvInRangeS(img.Ptr, new MCvScalar(0.0, 0.0, 0.0), new MCvScalar(250.0, 250.0, 250.0), grey.Ptr);

                //new method
                CvInvoke.cvErode(grey.Ptr, grey.Ptr, (IntPtr)null, 1);
                CvInvoke.cvDilate(grey.Ptr, grey.Ptr, (IntPtr)null, 2);
                Image <Gray, Byte> cannyEdges = grey.Canny(180, 120);
                LineSegment2D[]    lines      = cannyEdges.HoughLinesBinary(
                    1,              //Distance resolution in pixel-related units
                    Math.PI / 45.0, //Angle resolution measured in radians.
                    20,             //threshold
                    5,              //min Line width
                    10              //gap between lines
                    )[0];           //Get the lines from the first channel

                LineSegment2D[] container = null;

                container = FilterAndMergeVerticalLines(lines, 1);
                container = FilterShortLines(container, 100);
                container = FindVerticalDoorFrameLines(container, 500, grey);

                if (container != null)
                {
                    int       boxX      = container[0].P1.X;
                    int       boxY      = container[0].P1.Y;
                    int       boxWidth  = container[1].P1.X - boxX;
                    int       boxHeight = container[1].P2.Y - boxY;
                    Rectangle newBox    = new Rectangle(boxX, boxY, boxWidth, boxHeight);
                    int       centerX   = (newBox.Left + newBox.Right) / 2;
                    int       centerY   = (newBox.Bottom + newBox.Top) / 2;
                    DetectedDoor.DetectionConfidence confidence = GetConfidence(newBox, grey.Size);
                    int          centerXOffset = centerX - (grey.Size.Width / 2);
                    double       angle         = -Math.Atan2(-centerY, centerXOffset) - Math.PI / 2;
                    double       distance      = GetEstimatedDistance(newBox, grey.Size);
                    DetectedDoor newDoor       = new DetectedDoor(newBox, grey.Size, confidence, angle, distance, DetectedDoor.DetectMethod.DEPTH);
                    doors.Add(newDoor);
                }
                //new method end

                /** old method
                 *
                 * //CvInvoke.cvErode(grey.Ptr, grey.Ptr, (IntPtr)null, 4);
                 * //CvInvoke.cvDilate(grey.Ptr, grey.Ptr, (IntPtr)null, 2);
                 *
                 * //Contour<System.Drawing.Point> contours = grey.FindContours(
                 * //   Emgu.CV.CvEnum.CHAIN_APPROX_METHOD.CV_CHAIN_APPROX_TC89_L1,
                 * //   Emgu.CV.CvEnum.RETR_TYPE.CV_RETR_EXTERNAL);
                 *
                 * ////grey = new Image<Gray, byte>(grey.Width, grey.Height, new Gray(0));
                 * //for (; contours != null; contours = contours.HNext)
                 * //{
                 * //    Contour<System.Drawing.Point> contour = contours.ApproxPoly(contours.Perimeter * 0.08, stor);
                 * //    if (contour.Area < 80000 && contour.Area > 3000 && contour.Total == 4) //hard code for now, will update later
                 * //    {
                 * //        DetectedDoor newDoor = DoorFromContour(contour, depthFrame.get_DepthData(), grey.Size);
                 * //        if(newDoor != null)
                 * //            doors.Add(newDoor);
                 * //    }
                 * //}
                 *
                 **/
            }
            return(doors);
        }
        public List <DetectedDoor> GetDoors(object data)
        {
            IFrame infraredFrame = data as IFrame;

            if (infraredFrame == null)
            {
                return(null);
            }
            List <DetectedDoor> doors = new List <DetectedDoor>();

            //Image<Bgr, Byte> smoothed = img.SmoothGaussian(15);
            //Image<Gray, Byte> threshold = FilterColor(smoothed);
            //threshold = SimplifyImage(threshold, 100);

            // new method

            //new method end
            using (MemStorage stor = new MemStorage())
            {
                Bitmap bmp = infraredFrame.GetBMP();
                //Bitmap bmp2 = bmp.Clone(new Rectangle(0, 0, bmp.Width, bmp.Height), bmp.PixelFormat);
                //Image<Bgr, Byte> img = new Image<Bgr, Byte>(bmp2);
                Image <Gray, Byte> grey;
                try
                {
                    grey = new Image <Gray, Byte>(bmp);
                }
                catch (Exception)
                {
                    return(null);
                }

                //CvInvoke.cvInRangeS(img.Ptr, new MCvScalar(0.0, 0.0, 0.0), new MCvScalar(250.0, 250.0, 250.0), grey.Ptr);

                //new method
                CvInvoke.cvErode(grey.Ptr, grey.Ptr, (IntPtr)null, 1);
                CvInvoke.cvDilate(grey.Ptr, grey.Ptr, (IntPtr)null, 2);
                Image <Gray, Byte> cannyEdges = grey.Canny(180, 120);
                LineSegment2D[]    lines      = cannyEdges.HoughLinesBinary(
                    1,              //Distance resolution in pixel-related units
                    Math.PI / 45.0, //Angle resolution measured in radians.
                    20,             //threshold
                    5,              //min Line width
                    10              //gap between lines
                    )[0];           //Get the lines from the first channel

                LineSegment2D[] container = null;

                container = FilterAndMergeVerticalLines(lines, 1);
                container = FilterShortLines(container, 100);
                container = FindVerticalDoorFrameLines(container, 500, grey);

                if (container != null)
                {
                    int       boxX      = container[0].P1.X;
                    int       boxY      = container[0].P1.Y;
                    int       boxWidth  = container[1].P1.X - boxX;
                    int       boxHeight = container[1].P2.Y - boxY;
                    Rectangle newBox    = new Rectangle(boxX, boxY, boxWidth, boxHeight);
                    int       centerX   = (newBox.Left + newBox.Right) / 2;
                    int       centerY   = (newBox.Bottom + newBox.Top) / 2;
                    DetectedDoor.DetectionConfidence confidence = GetConfidence(newBox, grey.Size);
                    int          centerXOffset = centerX - (grey.Size.Width / 2);
                    double       angle         = -Math.Atan2(-centerY, centerXOffset) - Math.PI / 2;
                    DetectedDoor newDoor       = new DetectedDoor(newBox, grey.Size, confidence, angle, 0, DetectedDoor.DetectMethod.INFRARED);
                    doors.Add(newDoor);
                }
            }
            return(doors);
        }