示例#1
0
        public void GenerateSimilarBoundingBoxes_AllBoxesOutsideFrame()
        {
            // arrange - create frame size
            Size frameSize = new Size(1, 1);

            // arrange - create reference bounding box
            IBoundingBox boundingBox = new BoundingBox(new PointF(2, 2), new Size(1, 1));

            // arrange - create generation info
            SimilarBoundingBoxGenerationInfo genInfo = new SimilarBoundingBoxGenerationInfo(100, 0.1f, 0.1f);

            // get actual
            List <IBoundingBox> boundingBoxes = Service.GenerateSimilarBoundingBoxes(frameSize, boundingBox, genInfo);

            // assert
            Assert.AreEqual(0, boundingBoxes.Count);
        }
示例#2
0
        public void GenerateSimilarBoundingBoxes_AllBoxesInsideFrame()
        {
            // arrange - create frame size
            Size frameSize = new Size(5, 5);

            // arrange - create reference bounding box
            IBoundingBox boundingBox = new BoundingBox(new PointF(2, 2), new Size(1, 1));

            // arrange - create generation info
            SimilarBoundingBoxGenerationInfo genInfo = new SimilarBoundingBoxGenerationInfo(100, 0.1f, 0.1f);

            // get actual
            List <IBoundingBox> boundingBoxes = Service.GenerateSimilarBoundingBoxes(frameSize, boundingBox, genInfo);

            // assert
            Assert.AreEqual(100, boundingBoxes.Count);
            foreach (IBoundingBox bb in boundingBoxes)
            {
                Assert.AreEqual(boundingBox.Center.X, bb.Center.X, 0.1f);
                Assert.AreEqual(boundingBox.Center.Y, bb.Center.Y, 0.1f);
                Assert.AreEqual(boundingBox.Size.Width, bb.Size.Width, 0.1f);
                Assert.AreEqual(boundingBox.Size.Height, bb.Size.Height, 0.1f);
            }
        }
示例#3
0
文件: Service.cs 项目: denjiz/tld
        public static List <IBoundingBox> GenerateSimilarBoundingBoxes(Size frameSize, IBoundingBox refBb, SimilarBoundingBoxGenerationInfo info)
        {
            List <IBoundingBox> boundingBoxes = new List <IBoundingBox>();

            for (int i = 0; i < info.Count; i++)
            {
                // calculate new center
                PointF newCenter;
                if (info.MaxShift != 0)
                {
                    float  relShift = (float)(_rand.NextDouble() * 2 - 1) * info.MaxShift;
                    PointF absShift = new PointF(relShift * refBb.Size.Width, relShift * refBb.Size.Height);
                    newCenter = refBb.Center.Add(absShift);
                }
                else
                {
                    newCenter = refBb.Center;
                }

                // calculate new size
                SizeF newSize;
                if (info.MaxScale != 0)
                {
                    float scale = 1.0f + (float)(_rand.NextDouble() * 2 - 1) * info.MaxScale;
                    newSize = refBb.Size.Multiply(scale, scale);
                }
                else
                {
                    newSize = refBb.Size;
                }

                // create new bounding box
                IBoundingBox newBb = refBb.CreateInstance(newCenter, newSize);

                // if bounding box is inside the frame, add it to collection
                if (newBb.InsideFrame(frameSize))
                {
                    boundingBoxes.Add(newBb);
                }
            }

            return(boundingBoxes);
        }