public Ptype.Mutable BuildPrototype(IBuildPrototypeArgs args) { Examples eargs = args.Examples; List <Bitmap> positives = eargs.Positives; List <Bitmap> negatives = eargs.Negatives; Bitmap feature = Utils.CombineBitmapsAndMakeDifferencesTransparent(positives); foreach (Bitmap neg in negatives) { if (Utils.MatchesIgnoringTransparentPixels(feature, neg)) { return(null); } } Dictionary <string, Bitmap> dict = new Dictionary <string, Bitmap>(); dict.Add("part", feature); try { return(new Ptype.Mutable(dict, new Dictionary <String, Region>())); } catch { return(null); } }
/// <summary> /// Parameterizes a prototype using a branch and bound search algorithm. /// </summary> /// <param name="positives">Positive example bitmaps</param> /// <param name="negatives">Negative example bitmaps</param> /// <returns></returns> public Ptype.Mutable BuildPrototype(IBuildPrototypeArgs args) { Examples eargs = args.Examples; IEnumerable <Bitmap> positives = eargs.Positives; IEnumerable <Bitmap> negatives = eargs.Negatives; Dictionary <string, Part> parts = _partGetter.GetParts(positives, negatives); IEnumerable <Constraint> constraints = _constraintGetter.GetConstraints(parts, positives, negatives); State state = new State(parts, constraints, positives, negatives); //Run an initial constraint propagation to reduce the branching factor AC_3(false, constraints); return(Search(state)); }
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; }
public BuildPrototypeArgs(Examples examples, Model model, string id) { this.Id = id; this.examples = examples; this.Model = model; }