예제 #1
0
        public static List <AnchorBox> GenerateRandomAnchorBoxes()
        {
            var anchorBoxList = new List <AnchorBox>()
            {
                new AnchorBox()
                {
                    Height = 1, Width = 1, X = 0, Y = 0
                }
            };

            foreach (int i in Enumerable.Range(0, 1000))
            {
                anchorBoxList.Add(AnchorBox.GenerateNew());
            }
            return(anchorBoxList);
        }
예제 #2
0
        private static List <System.Drawing.Rectangle> GetDetectionRectangles(INeuralNetwork neuralNetwork, Image <Bgr, Byte> originalImage, Action <double> progressUpdater)
        {
            List <System.Drawing.Rectangle> DetectedRectangles = new List <System.Drawing.Rectangle>();
            var anchorBoxes = AnchorBox.GenerateRandomAnchorBoxes();
            int counter     = 0;

            Parallel.ForEach(anchorBoxes, new ParallelOptions()
            {
                MaxDegreeOfParallelism = 10
            }, (anchorBox) => {
                (var croppedImage, var rectangle) = GetAreaUnderAnchorBox(originalImage, anchorBox);
                var catDetected = DetectCat(neuralNetwork, croppedImage);
                if (catDetected)
                {
                    DetectedRectangles.Add(rectangle);
                }
                progressUpdater(((double)counter / (double)anchorBoxes.Count()) * 100);
                counter++;
            });
            return(DetectedRectangles);
        }
예제 #3
0
        private static System.Drawing.Rectangle GetRectangleFromAnchroBox(Image <Bgr, Byte> originalImage, AnchorBox anchorBox)
        {
            int areaX      = (int)((double)(originalImage.Width) * anchorBox.X);
            int areaY      = (int)((double)(originalImage.Height) * anchorBox.Y);
            int areaWidth  = (int)((double)(originalImage.Width) * anchorBox.Width);
            int areaHeight = (int)((double)(originalImage.Height) * anchorBox.Height);

            return(new System.Drawing.Rectangle(areaX, areaY, areaWidth, areaHeight));
        }
예제 #4
0
        private static (Image <Gray, Byte>, System.Drawing.Rectangle) GetAreaUnderAnchorBox(Image <Bgr, Byte> originalImage, AnchorBox anchorBox)
        {
            var originalImageCopy = originalImage.Copy();
            var rectangle         = GetRectangleFromAnchroBox(originalImageCopy, anchorBox);

            originalImageCopy.ROI = rectangle;
            var croppedImage = LocalImage.ConvertOriginalImageToGrayScaleAndProcess(originalImageCopy.Copy());

            originalImageCopy.ROI = System.Drawing.Rectangle.Empty;
            return(croppedImage, rectangle);
        }