コード例 #1
0
        public List <Ptype> LoadPtypes(IRuntimeStorage intent)
        {
            this.intent = intent;
            ptypeData   = LoadPtypesFromIntent();

            List <Ptype.Mutable> ptypes = new List <Ptype.Mutable>();

            foreach (PtypeMetadata data in ptypeData.Values)
            {
                ptypes.Add(data.Ptype);
            }

            return(Ptype.CreatePrototypeLibrary(ptypes));
        }
コード例 #2
0
        public static List <Tree> FindPrototypeOccurrences(Bitmap bitmap, Ptype.Mutable ptype)
        {
            List <Ptype.Mutable> ptypes = new List <Ptype.Mutable>();

            ptypes.Add(ptype);
            List <Ptype> lib = Ptype.CreatePrototypeLibrary(ptypes);

            List <Tree> foundPtypes = new List <Tree>();

            try {
                FeatureTree tree          = FeatureTree.BuildTree(lib[0].Features());
                List <Tree> foundFeatures = new List <Tree>();
                tree.MultiThreadedMatch(bitmap, foundFeatures);

                foreach (Ptype p in lib)
                {
                    p.Model.Finder.FindOccurrences(p, bitmap, foundFeatures, foundPtypes);
                }
            } catch {
            }

            return(foundPtypes);
        }
コード例 #3
0
        public bool UpdatePtypes(List <AnnotatedNode> annotations, List <Ptype> newLib)
        {
            bool anyRemoved  = RemoveDeletedAnnotations(annotations, ptypeData);
            bool needsUpdate = LoadDataFromAnnotations(annotations, ptypeData) || anyRemoved;

            Dictionary <string, Bitmap> images = new Dictionary <string, Bitmap>();

            foreach (AnnotatedNode n in annotations)
            {
                if (!images.ContainsKey(n.ImageId))
                {
                    images.Add(n.ImageId, (Bitmap)n.Root["capturedpixels"]);
                }
            }

            List <BuildPrototypeArgs> buildargs = new List <BuildPrototypeArgs>();
            List <Ptype.Mutable>      ptypes    = new List <Ptype.Mutable>();

            foreach (PtypeMetadata data in ptypeData.Values)
            {
                if (data.NeedsUpdate)
                {
                    List <Bitmap> positives = new List <Bitmap>();
                    List <Bitmap> negatives = new List <Bitmap>();

                    foreach (Example e in data.Examples)
                    {
                        Bitmap example = Bitmap.Crop(images[e.ImageId], e.Region);
                        if (e.IsPositive)
                        {
                            positives.Add(example);
                        }
                        else
                        {
                            negatives.Add(example);
                        }
                    }

                    Examples           examples = new Examples(positives, negatives);
                    BuildPrototypeArgs args     = new BuildPrototypeArgs(examples, ModelInstances.Get(data.Ptype.Model), data.Ptype.Id);

                    buildargs.Add(args);
                }
                else
                {
                    ptypes.Add(data.Ptype);
                }
            }


            ptypes.AddRange(Ptype.BuildFromExamples(buildargs));

            foreach (Ptype.Mutable ptype in ptypes)
            {
                PtypeMetadata data = ptypeData[ptype.Id];
                data.Ptype.Features = ptype.Features;
                data.Ptype.Regions  = ptype.Regions;
                data.Ptype.Model    = ptype.Model;
            }

            SavePtypesToIntent(intent, ptypeData.Values);

            newLib.AddRange(Ptype.CreatePrototypeLibrary(ptypes));

            return(needsUpdate);
        }