Beispiel #1
0
        private void init()
        {
            var path                  = Path.Combine(Directory.GetParent(Environment.CurrentDirectory).FullName, "Resources", "PrototypeTemplatesBW");
            var generatedScales       = EnumerableExtensions.GetRange(60, 170, 3);
            var generatedOrientations = EnumerableExtensions.GetRange(-90, +90, (int)((180f / GlobalParameters.NUM_OF_QUNATIZED_ORIENTATIONS) / 2 / 2 /*user factor - last "2"*/));

            Console.WriteLine("Generating templates.... Please wait!");
            var templates = OpenHandTemplate.CreateRange(path, "*.bmp", generatedScales, generatedOrientations);

            ModelRepository.Initialize(templates);
            //drawTemplatesToFiles(templates, "C:/generatedTemplates");

            Console.WriteLine("Initializing particle filter!");
            particleFilter = ParticleFilter.UnifromParticleSpreadInitializer(
                NUMBER_OF_PARTICLES,
                new DoubleRange[]
            {
                //template type
                new DoubleRange(0, ModelRepository.PrototypeCount - 1),

                //scale
                new DoubleRange(70, 150),

                //rotation
                new DoubleRange(-15, 15)
            },
                ModelParticle.FromParameters).ToList();

            initialParticles = particleFilter.Select(x => (ModelParticle)x.Clone()).ToList();
            resetClock       = new Stopwatch(); resetClock.Start();
        }
        private static ITemplate create(IEnumerable <PointF> normalizedPoints,
                                        int scale,
                                        int rotation,
                                        string label = "")
        {
            var pointTransform = Transforms2D.Combine
                                 (
                Transforms2D.Scale(scale, scale),
                Transforms2D.Rotation((float)Angle.ToRadians(rotation))
                                 );

            var transformedPts = normalizedPoints.Transform(pointTransform).ToList();

            var boundingRect = transformedPts.BoundingRect();
            var offset       = boundingRect.Location;

            transformedPts = transformedPts.Transform(Transforms2D.Translation(-offset.X, -offset.Y)).ToList();

            var template = new OpenHandTemplate();

            var features = new List <Feature>();

            //var validIdxRange = CardinalSpline.ValidIndicesRange(transformedPts.Count);
            //for (int i = validIdxRange.Min; i <= validIdxRange.Max; i++)
            for (int i = CardinalSpline.MIN_INDEX; i < (transformedPts.Count - 1 - CardinalSpline.MAX_INDEX_OFFSET); i++)
            {
                var intPt = transformedPts[i].Round();

                var direction = CardinalSpline.NormalAt(transformedPts, CONTOUR_TENSION, i);
                var orientDeg = (int)Angle.ToDegrees(Math.Atan2(direction.Y, direction.X));
                orientDeg = (int)Angle.NormalizeDegrees(orientDeg + 180);

                var feature = createFeature(intPt.X, intPt.Y, orientDeg);
                features.Add(feature);
            }

            template.Features   = features.ToArray();
            template.Size       = Size.Round(boundingRect.Size);
            template.ClassLabel = label;

            return(template);
        }
        private static ITemplate create(IEnumerable<PointF> normalizedPoints,
                                        int scale,
                                        int rotation,
                                        string label = "")
        {
            var pointTransform = Transforms2D.Combine
                            (
                               Transforms2D.Scale(scale, scale),
                               Transforms2D.Rotation((float)Angle.ToRadians(rotation))
                            );

            var transformedPts = normalizedPoints.Transform(pointTransform).ToList();

            var boundingRect = transformedPts.BoundingRect();
            var offset = boundingRect.Location;
            transformedPts = transformedPts.Transform(Transforms2D.Translation(-offset.X, -offset.Y)).ToList();

            var template = new OpenHandTemplate();

            var features = new List<Feature>();
            //var validIdxRange = CardinalSpline.ValidIndicesRange(transformedPts.Count);
            //for (int i = validIdxRange.Min; i <= validIdxRange.Max; i++)
            for (int i = CardinalSpline.MIN_INDEX; i < (transformedPts.Count - 1 - CardinalSpline.MAX_INDEX_OFFSET); i++)
            {
                var intPt = transformedPts[i].Round();

                var direction = CardinalSpline.NormalAt(transformedPts, CONTOUR_TENSION, i);
                var orientDeg = (int)Angle.ToDegrees(Math.Atan2(direction.Y, direction.X));
                orientDeg = (int)Angle.NormalizeDegrees(orientDeg + 180);

                var feature = createFeature(intPt.X, intPt.Y, orientDeg);
                features.Add(feature);
            }

            template.Features = features.ToArray();
            template.Size = Size.Round(boundingRect.Size);
            template.ClassLabel = label;

            return template;
        }