Example #1
0
        /// <inheritdoc />
        protected override void LogAnnotation(AnnotationData annotation)
        {
            StringBuilder message = new StringBuilder();
            message.AppendFormat("[{0}] ", annotation.Type.ToString().ToLower());
            message.Append(annotation.Message);

            if (annotation.CodeLocation != CodeLocation.Unknown)
            {
                message.Append("\n\tLocation: ");
                message.Append(annotation.CodeLocation);
            }

            if (annotation.CodeLocation.Line == 0 && annotation.CodeReference != CodeReference.Unknown)
            {
                message.Append("\n\tReference: ");
                message.Append(annotation.CodeReference);
            }

            if (!string.IsNullOrEmpty(annotation.Details))
            {
                message.Append("\n\tDetails: ");
                message.Append(annotation.Details);
            }

            FacadeCategory category = GetCategoryForAnnotation(annotation.Type);
            testListener.WriteLine(message.ToString(), category);
        }
        /// <summary>
        /// Initializes the event arguments.
        /// </summary>
        /// <param name="report">The report.</param>
        /// <param name="annotation">The annotation that was added.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="report"/> is null.</exception>
        public AnnotationDiscoveredEventArgs(Report report, AnnotationData annotation)
        {
            if (report == null)
                throw new ArgumentNullException("report");
            if (annotation == null)
                throw new ArgumentNullException("annotation");

            this.report = report;
            this.annotation = annotation;
        }
        private void AddListViewItem(AnnotationData annotationData, int imgIndex)
        {
            var lvi = new ListViewItem(FilterText(annotationData.Message), imgIndex);
            
            lvi.SubItems.AddRange(new[] 
            { 
                FilterText(annotationData.Details), 
                annotationData.CodeLocation.ToString(), 
                annotationData.CodeReference.ToString() 
            });

            lvi.Tag = annotationData;
            annotationsListView.Items.Add(lvi);
        }
        protected override void LogAnnotation(AnnotationData annotation)
        {
            StringBuilder message = new StringBuilder();
            message.Append(annotation.Message);

            if (annotation.Type == AnnotationType.Info && annotation.CodeLocation != CodeLocation.Unknown)
            {
                message.Append("\nLocation: ");
                message.Append(annotation.CodeLocation);
            }

            if (annotation.CodeLocation.Line == 0 && annotation.CodeReference != CodeReference.Unknown)
            {
                message.Append("\nReference: ");
                message.Append(annotation.CodeReference);
            }

            if (!string.IsNullOrEmpty(annotation.Details))
            {
                message.Append("\nDetails: ");
                message.Append(annotation.Details);
            }

            switch (annotation.Type)
            {
                case AnnotationType.Info:
                    taskLoggingHelper.LogMessage(MessageImportance.Normal, message.ToString());
                    break;

                case AnnotationType.Error:
                    taskLoggingHelper.LogError(null, null, null, annotation.CodeLocation.Path,
                        annotation.CodeLocation.Line, annotation.CodeLocation.Column, 0, 0, message.ToString());
                    break;

                case AnnotationType.Warning:
                    taskLoggingHelper.LogWarning(null, null, null, annotation.CodeLocation.Path,
                        annotation.CodeLocation.Line, annotation.CodeLocation.Column, 0, 0, message.ToString());
                    break;
            }
        }
Example #5
0
        private void copySelectedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (m_SeletedAnnotation != null)
            {
                if (m_CopyAnnotation != null)
                {
                    m_CopyAnnotation.Clear();
                }
                foreach (AnnotationData tempAnnotation in m_SeletedAnnotation)
                {
                    AnnotationData tempCopyAnnotation = new AnnotationData();
                    tempCopyAnnotation.GUID           = Guid.NewGuid();
                    tempCopyAnnotation.AnnotationType = tempAnnotation.AnnotationType;
                    tempCopyAnnotation.StartPoint     = tempAnnotation.StartPoint;
                    tempCopyAnnotation.EndPoint       = tempAnnotation.EndPoint;
                    tempCopyAnnotation.FillColor      = tempAnnotation.FillColor;
                    tempCopyAnnotation.Description    = tempAnnotation.Description;
                    if (tempAnnotation.FontType != null)
                    {
                        tempCopyAnnotation.FontType           = new AnnoTextFont();
                        tempCopyAnnotation.FontType.Name      = tempAnnotation.FontType.Name;
                        tempCopyAnnotation.FontType.Size      = tempAnnotation.FontType.Size;
                        tempCopyAnnotation.FontType.TextColor = tempAnnotation.FontType.TextColor;
                    }

                    tempCopyAnnotation.Name           = tempAnnotation.Name;
                    tempCopyAnnotation.PenColor       = tempAnnotation.PenColor;
                    tempCopyAnnotation.PenWidth       = tempAnnotation.PenWidth;
                    tempCopyAnnotation.Selected       = false;
                    tempCopyAnnotation.TextContent    = tempAnnotation.TextContent;
                    tempCopyAnnotation.TextRotateType = tempAnnotation.TextRotateType;

                    m_CopyAnnotation.Add(tempCopyAnnotation);
                }
            }
        }
        public void Randomize(RandomizerOptions options, Action <string> notify = null, string outPath = null, bool sekiro = false, Preset preset = null, bool encrypted = true)
        {
            // sekiro = false;
            string distDir = sekiro ? "dists" : "dist";

            if (!Directory.Exists(distDir))
            {
                // From Release/Debug dirs
                distDir = $@"..\..\..\{distDir}";
            }
            if (!Directory.Exists(distDir))
            {
                throw new Exception("Missing data directory");
            }
            if (outPath == null)
            {
                outPath = Directory.GetCurrentDirectory();
            }

            Console.WriteLine($"Options and seed: {options}");
            Console.WriteLine();
            int seed = (int)options.Seed;

            notify?.Invoke("Loading game data");
            string modDir = null;

            if (options["mergemods"])
            {
                string        modPath    = sekiro ? "mods" : "mod";
                DirectoryInfo modDirInfo = new DirectoryInfo($@"{outPath}\..\{modPath}");
                if (!modDirInfo.Exists)
                {
                    throw new Exception($"Can't merge mods: {modDirInfo.FullName} not found");
                }
                modDir = modDirInfo.FullName;
                if (new DirectoryInfo(outPath).FullName == modDir)
                {
                    throw new Exception($"Can't merge mods: already running from 'mods' directory");
                }
            }
            GameData game = new GameData(distDir, sekiro);

            game.Load(modDir);
            // game.SearchParamInt(15200090); return;
            if (modDir != null)
            {
                Console.WriteLine();
            }

            // Prologue
            if (options["enemy"])
            {
                Console.WriteLine("Ctrl+F 'Boss placements' or 'Miniboss placements' or 'Basic placements' to see enemy placements.");
            }
            if (options["item"] || !sekiro)
            {
                Console.WriteLine("Ctrl+F 'Hints' to see item placement hints, or Ctrl+F for a specific item name.");
            }
            Console.WriteLine();
#if !DEBUG
            for (int i = 0; i < 50; i++)
            {
                Console.WriteLine();
            }
#endif

            // Slightly different high-level algorithm for each game. As always, can try to merge more in the future.
            if (sekiro)
            {
                Events      events = new Events(@"dists\Base\sekiro-common.emedf.json");
                EventConfig eventConfig;
                using (var reader = File.OpenText("dists/Base/events.txt"))
                {
                    IDeserializer deserializer = new DeserializerBuilder().Build();
                    eventConfig = deserializer.Deserialize <EventConfig>(reader);
                }

                EnemyLocations locations = null;
                if (options["enemy"])
                {
                    notify?.Invoke("Randomizing enemies");
                    locations = new EnemyRandomizer(game, events, eventConfig).Run(options, preset);
                    if (!options["enemytoitem"])
                    {
                        locations = null;
                    }
                }
                if (options["item"])
                {
                    notify?.Invoke("Randomizing items");
                    SekiroLocationDataScraper scraper = new SekiroLocationDataScraper();
                    LocationData   data = scraper.FindItems(game);
                    AnnotationData anns = new AnnotationData(game, data);
                    anns.Load(options);
                    anns.AddEnemyLocations(locations);

                    SkillSplitter.Assignment split = null;
                    if (!options["norandom_skills"] && options["splitskills"])
                    {
                        split = new SkillSplitter(game, data, anns, events).SplitAll();
                    }

                    Permutation perm = new Permutation(game, data, anns, explain: false);
                    perm.Logic(new Random(seed), options, preset);

                    notify?.Invoke("Editing game files");
                    PermutationWriter write = new PermutationWriter(game, data, anns, events, eventConfig);
                    write.Write(new Random(seed + 1), perm, options);
                    if (!options["norandom_skills"])
                    {
                        SkillWriter skills = new SkillWriter(game, data, anns);
                        skills.RandomizeTrees(new Random(seed + 2), perm, split);
                    }
                    if (options["edittext"])
                    {
                        HintWriter hints = new HintWriter(game, data, anns);
                        hints.Write(options, perm);
                    }
                }
                MiscSetup.SekiroCommonPass(game, events, options);

                notify?.Invoke("Writing game files");
                if (!options["dryrun"])
                {
                    game.SaveSekiro(outPath);
                }
                return;
            }
            else
            {
                Events events = new Events(@"dist\Base\ds3-common.emedf.json");

                LocationDataScraper scraper = new LocationDataScraper(logUnused: false);
                LocationData        data    = scraper.FindItems(game);
                AnnotationData      ann     = new AnnotationData(game, data);
                ann.Load(options);
                ann.AddSpecialItems();

                notify?.Invoke("Randomizing");
                Random      random      = new Random(seed);
                Permutation permutation = new Permutation(game, data, ann, explain: false);
                permutation.Logic(random, options, null);

                notify?.Invoke("Editing game files");
                random = new Random(seed + 1);
                PermutationWriter writer = new PermutationWriter(game, data, ann, events, null);
                writer.Write(random, permutation, options);
                random = new Random(seed + 2);
                CharacterWriter characters = new CharacterWriter(game, data);
                characters.Write(random, options);

                notify?.Invoke("Writing game files");
                if (!options["dryrun"])
                {
                    game.SaveDS3(outPath, encrypted);
                }
            }
        }
Example #7
0
        private void toolStripCbxFont_TextChanged(object sender, EventArgs e)
        {
            if (m_ImageCore != null && m_ImageCore.ImageBuffer.CurrentImageIndexInBuffer != -1)
            {
                List <AnnotationData> tempAllAnnotation = (List <AnnotationData>)m_ImageCore.ImageBuffer.GetMetaData(m_ImageCore.ImageBuffer.CurrentImageIndexInBuffer, EnumMetaDataType.enumAnnotation);

                foreach (AnnotationData annotation in m_SeletedAnnotation)
                {
                    AnnotationType type = annotation.AnnotationType;
                    if (type == AnnotationType.enumText)
                    {
                        for (short sIndex = 0; sIndex < tempAllAnnotation.Count; sIndex++)
                        {
                            if (tempAllAnnotation[sIndex].GUID == annotation.GUID)
                            {
                                AnnotationData temp               = tempAllAnnotation[sIndex];
                                AnnotationData annoNew            = new AnnotationData();
                                AnnotationData tempCopyAnnotation = new AnnotationData();
                                annoNew.GUID           = Guid.NewGuid();
                                annoNew.AnnotationType = temp.AnnotationType;
                                Point startPoint = temp.StartPoint;
                                Point endPoint   = temp.EndPoint;

                                if (startPoint.X > endPoint.X)
                                {
                                    int x = startPoint.X;
                                    startPoint.X = endPoint.X;
                                    endPoint.X   = x;
                                }

                                if (startPoint.Y > endPoint.Y)
                                {
                                    int y = startPoint.Y;
                                    startPoint.Y = endPoint.Y;
                                    endPoint.Y   = y;
                                }
                                annoNew.StartPoint  = startPoint;
                                annoNew.EndPoint    = endPoint;
                                annoNew.FillColor   = temp.FillColor;
                                annoNew.Description = temp.Description;
                                if (temp.FontType != null)
                                {
                                    annoNew.FontType           = new AnnoTextFont();
                                    annoNew.FontType.Name      = temp.FontType.Name;
                                    annoNew.FontType.Size      = int.Parse(toolStripCbxFont.Text);
                                    annoNew.FontType.TextColor = temp.FontType.TextColor;
                                }

                                annoNew.Name           = temp.Name;
                                annoNew.PenColor       = temp.PenColor;
                                annoNew.PenWidth       = temp.PenWidth;
                                annoNew.Selected       = temp.Selected;
                                annoNew.TextContent    = temp.TextContent;
                                annoNew.TextRotateType = temp.TextRotateType;
                                tempAllAnnotation.RemoveAt(sIndex);
                                tempAllAnnotation.Insert(sIndex, annoNew);
                            }
                        }
                    }
                }

                m_ImageCore.ImageBuffer.SetMetaData(m_ImageCore.ImageBuffer.CurrentImageIndexInBuffer, EnumMetaDataType.enumAnnotation, tempAllAnnotation, true);
            }
        }
 public static AnnotationState CreateFromAnnotation(AnnotationData annotation)
 {
     return new AnnotationState(annotation.Type,
         annotation.Message, annotation.Details,
         ReSharperReflectionPolicy.GetDeclaredElementResolver(annotation.CodeElement));
 }
Example #9
0
 /// <summary>
 /// Logs an annotation.
 /// </summary>
 /// <param name="annotation">The annotation to log.</param>
 protected virtual void LogAnnotation(AnnotationData annotation)
 {
     annotation.Log(Logger, true);
 }
Example #10
0
        public KeyItemsPermutation(RandomizerOptions options, LocationData data, AnnotationData ann, EnemyLocations enemies, bool explain)
        {
            this.data    = data;
            this.ann     = ann;
            this.explain = explain;

            Dictionary <string, bool> config      = ann.GetConfig(options.GetLogicOptions());
            Dictionary <string, Expr> configExprs = config.ToDictionary(e => e.Key, e => e.Value ? Expr.TRUE : Expr.FALSE);

            Dictionary <LocationScope, (UniqueCategory, int)>      counts     = ann.GetUniqueCounts();
            Dictionary <string, Dictionary <UniqueCategory, int> > areaCounts = ann.AllAreas.ToDictionary(e => e.Key, e =>
            {
                Dictionary <UniqueCategory, int> dict = Node.EmptyCounts();
                foreach (LocationScope scope in e.Value.Where(s => counts.ContainsKey(s)))
                {
                    (UniqueCategory cat, int count) = counts[scope];
                    dict[cat] += count;
                }
                return(dict);
            });

            Dictionary <string, string> equivalentGraph = new Dictionary <string, string>();

            void processDependencies(AreaAnnotation area, ISet <string> frees, bool assignItems)
            {
                string           name           = area.Name;
                HashSet <string> dependentAreas = new HashSet <string>();
                bool             other          = false;

                foreach (string free in frees)
                {
                    if (ann.Items.ContainsKey(free))
                    {
                        items.Add(free);
                        if (assignItems)
                        {
                            if (itemEvents.ContainsKey(free))
                            {
                                throw new Exception($"Internal error: {free} activates multiple events");
                            }
                            AddMulti(itemEvents, free, name);
                            if (area.AlwaysBefore != null)
                            {
                                AddMulti(itemEvents, free, area.AlwaysBefore);
                            }
                        }
                        other = true;
                    }
                    else if (ann.Areas.ContainsKey(free))
                    {
                        dependentAreas.Add(free);
                    }
                    else if (ann.Events.ContainsKey(free))
                    {
                        if (ann.EventAreas.TryGetValue(free, out string evArea))
                        {
                            dependentAreas.Add(evArea);
                        }
                        else
                        {
                            other = true;
                        }
                    }
                    else
                    {
                        throw new Exception($"Internal error: Unknown dependency {free} in requirements for {area.Name}");
                    }
                }
                if (dependentAreas.Count == 1 && !other)
                {
                    equivalentGraph[name] = dependentAreas.First();
                    if (explain)
                    {
                        Console.WriteLine($"Collapsed events for key item generation: {name} -> {frees.First()}");
                    }
                }
                // This is used for equivalence graph things. Should probably use this information in weight groups instead of actually combining the areas
                AddMulti(combinedAreas, name, name);
                // Weight base is used to specify that a key item, if placed in the base area, should also apply to this other area.
                AddMulti(combinedWeights, name, name);
                if (area.WeightBase != null)
                {
                    AddMulti(combinedWeights, area.WeightBase, name);
                }
            }

            foreach (AreaAnnotation ev in ann.Events.Values)
            {
                string name = ev.Name;
                Expr   req  = ev.ReqExpr.Substitute(configExprs).Simplify();
                if (req.IsFalse())
                {
                    // Can happen with DLC
                    unusedAreas.Add(ev.Name);
                    continue;
                }
                processDependencies(ev, req.FreeVars(), true);
                // Events are not dynamically placed anywhere, nor is anything placed inside of them, so they are always added to the graph upfront
                nodes[name] = new Node
                {
                    Name        = name,
                    Req         = req,
                    Counts      = Node.EmptyCounts(),
                    CumKeyCount = -1,
                };
            }
            foreach (AreaAnnotation area in ann.Areas.Values)
            {
                string name = area.Name;
                Expr   req  = area.ReqExpr.Substitute(configExprs).Simplify();
                if (req.IsFalse())
                {
                    // Can happen with DLC
                    unusedAreas.Add(area.Name);
                    continue;
                }
                // Proper aliases are already represented using the BaseArea slot property, skip those
                if (ann.AreaAliases[name] != name)
                {
                    continue;
                }
                processDependencies(area, req.FreeVars(), false);
                // This is where we used to skip combined areas in DS3, but now weight bases are added automatically
                nodes[name] = new Node
                {
                    Name        = name,
                    Counts      = areaCounts[name],
                    Req         = req,
                    Weight      = 1,
                    CumKeyCount = -1
                };
                areas.Add(name);
            }
            // Quick collapse of equivalence graph
            Dictionary <string, string> equivalent = new Dictionary <string, string>();

            string getBaseName(string name)
            {
                if (equivalent.ContainsKey(name))
                {
                    return(equivalent[name]);
                }
                else if (equivalentGraph.ContainsKey(name))
                {
                    string root = getBaseName(equivalentGraph[name]);
                    equivalent[name] = root;
                    AddMulti(combinedAreas, root, name);
                    return(root);
                }
                else
                {
                    return(name);
                }
            };
            foreach (KeyValuePair <string, string> equivalence in equivalentGraph)
            {
                getBaseName(equivalence.Key);
            }
            // TODO: Remove combinedAreas
            foreach (KeyValuePair <string, List <string> > entry in combinedAreas)
            {
                foreach (string alias in entry.Value)
                {
                    if (alias != entry.Key)
                    {
                        AddMulti(combinedWeights, entry.Key, alias);
                    }
                }
            }
            foreach (KeyValuePair <string, HashSet <string> > entry in combinedWeights.Where(e => e.Value.Count > 1).ToList())
            {
                foreach (string sharedArea in entry.Value.ToList())
                {
                    entry.Value.UnionWith(combinedWeights[sharedArea]);
                    combinedWeights[sharedArea] = entry.Value;
                }
            }
            if (explain)
            {
                HashSet <string> explained = new HashSet <string>();
                foreach (KeyValuePair <string, HashSet <string> > entry in combinedWeights)
                {
                    if (explained.Contains(entry.Key))
                    {
                        continue;
                    }
                    Console.WriteLine($"Combined group: [{string.Join(",", entry.Value)}]");
                    explained.UnionWith(entry.Value);
                }
            }

            // TODO: Make the dictionaries less of a slog to produce
            combinedAreas = combinedWeights.ToDictionary(e => e.Key, e => e.Value.ToList());

            // Last step - calculate rough measures of area difficulty, in terms of minimal number of items required for the area
            int getCumulativeCounts(string name)
            {
                Node node = nodes[name];

                if (node.CumKeyCount != -1)
                {
                    return(node.KeyCount + node.CumKeyCount);
                }
                List <string> deps  = node.Req.FreeVars().Where(free => areas.Contains(free) || ann.Events.ContainsKey(free)).ToList();
                int           count = deps.Select(free => getCumulativeCounts(free)).DefaultIfEmpty().Max();

                node.CumKeyCount = count;
                return(node.KeyCount + count);
            };
            foreach (Node node in nodes.Values)
            {
                if (unusedAreas.Contains(node.Name))
                {
                    continue;
                }
                getCumulativeCounts(node.Name);
                if (explain)
                {
                    Console.WriteLine($"{node.Name} ({node.Counts[UniqueCategory.KEY_SHOP]} shop / {node.KeyCount} area / ({node.Counts[UniqueCategory.QUEST_LOT]} quest / {node.CumKeyCount} cumulative): {node.Req}");
                }
            }
        }
 public SkillWriter(GameData game, LocationData data, AnnotationData ann)
 {
     this.game = game;
     this.data = data;
     this.ann  = ann;
 }
Example #12
0
 public static AnnotationState CreateFromAnnotation(AnnotationData annotation)
 {
     return(new AnnotationState(annotation.Type,
                                annotation.Message, annotation.Details,
                                ReSharperReflectionPolicy.GetDeclaredElementResolver(annotation.CodeElement)));
 }
Example #13
0
    private void spawnAnnotationFetchingTask(int frameNo, AnnotationsFetcher fetcher,
                                             float th,
                                             OnAnnotationFetched onAnnotationFetched = null)
    {
        fetcher.fetchAnnotation(frameNo, delegate(string jsonArrayString)
        {
            var now            = System.DateTime.Now;
            string fetcherName = fetcher.getServiceName();
            float threshold    = th;

            int frameNumber    = frameNo;
            string debugString = jsonArrayString.Replace(System.Environment.NewLine, "");

            Debug.LogFormat((ILogComponent)this, "fetched {3} annotations JSON for {0}, length {1}: {2}",
                            frameNumber, jsonArrayString.Length, debugString, fetcherName);

            try {
                if (onAnnotationFetched != null)
                {
                    onAnnotationFetched(now, jsonArrayString);
                }
            }
            catch (System.Exception e) {
                Debug.LogExceptionFormat(e, "caught exception while callback, annotation: {0}",
                                         debugString.Substring(0, 100));
            }

            try
            {
                Dictionary <int, FrameObjectData> frameObjects = frameBuffer_.Dequeue();
                FrameObjectData frameObjectData;

                if (frameObjects.TryGetValue(frameNumber, out frameObjectData))
                {
                    // some pre-processing for the received string
                    // TBD: this needs to be replaced with JSON deserialization, need to update edge too
                    string[] testDebug  = jsonArrayString.Split(']');
                    string formatDebug  = testDebug[0] + "]";
                    string str          = "{ \"annotationData\": " + formatDebug + "}";
                    AnnotationData data = JsonUtility.FromJson <AnnotationData>(str);

#if DEVELOPMENT_BUILD
                    for (int i = 0; i < data.annotationData.Length; i++)
                    {
                        Debug.LogFormat((ILogComponent)this,
                                        "{7} annotation {0}: label {1} prob {2} xleft {3} xright {4} ytop {5} ybottom {6}",
                                        i, data.annotationData[i].label, data.annotationData[i].prob,
                                        data.annotationData[i].xleft, data.annotationData[i].xright,
                                        data.annotationData[i].ytop, data.annotationData[i].ybottom,
                                        fetcherName);
                    }
#endif

                    Debug.LogFormat((ILogComponent)this,
                                    "processing {5} annotation for frame #{0}, cam pos {1}, cam rot {2}, points {3}, lifetime {4} sec",
                                    frameNumber, frameObjectData.camPos, frameObjectData.camRot, frameObjectData.points,
                                    Mathf.Abs((float)(frameObjectData.timestamp - timestamp_)), fetcherName);

                    // filter out annotations with probability below threshold

                    List <AnnotationData.ArrayEntry> filteredAnnotations = new List <AnnotationData.ArrayEntry>();

                    for (int i = 0; i < data.annotationData.Length; ++i)
                    {
                        if (data.annotationData[i].prob >= threshold)
                        {
                            filteredAnnotations.Add(data.annotationData[i]);
                        }
                    }

                    Debug.LogFormat("{0} annotations above threshold (filtered out {0} annotations)",
                                    filteredAnnotations.Count, data.annotationData.Length - filteredAnnotations.Count);

                    if (filteredAnnotations.Count > 0)
                    {
                        int boxCount = filteredAnnotations.Count;
                        // TBD: this needs to be pooled
                        BoxData boxData = new BoxData();

                        // TBD: this needs to be hidden in a method/constructor
                        boxData.frameNumber = frameNumber;
                        boxData.count       = boxCount;
                        boxData.points      = frameObjectData.points;
                        boxData.numPoints   = frameObjectData.numPoints;
                        boxData.cam         = frameObjectData.cam;
                        boxData.camPos      = frameObjectData.camPos;
                        boxData.camRot      = frameObjectData.camRot;
                        boxData.timestamp   = frameObjectData.timestamp;
                        boxData.label       = new string[boxCount];
                        boxData.xleft       = new float[boxCount];
                        boxData.xright      = new float[boxCount];
                        boxData.ytop        = new float[boxCount];
                        boxData.ybottom     = new float[boxCount];
                        boxData.prob        = new float[boxCount];

                        for (int i = 0; i < boxCount; i++)
                        {
                            // safety checks
                            if (data.annotationData[i].ytop > 1)
                            {
                                data.annotationData[i].ytop = 1;
                            }
                            if (data.annotationData[i].ybottom < 0)
                            {
                                data.annotationData[i].ybottom = 0;
                            }
                            boxData.label[i] = filteredAnnotations[i].label;

                            // since we flipped the image, flip bbox coordinates again
                            // only y coordinates get flipped though, and it works.
                            // I think this has something to do with how Viewport coordinates
                            // are represented...
                            boxData.xleft[i]   = filteredAnnotations[i].xleft;
                            boxData.xright[i]  = filteredAnnotations[i].xright;
                            boxData.ytop[i]    = 1 - filteredAnnotations[i].ytop;
                            boxData.ybottom[i] = 1 - filteredAnnotations[i].ybottom;
                            boxData.prob[i]    = filteredAnnotations[i].prob;

                            Debug.LogFormat((ILogComponent)this, "will render {6}: {0} xleft {1} xright {2} ytop {3} ybottom {4} prob {5}",
                                            boxData.label[i], boxData.xleft[i], boxData.xright[i],
                                            boxData.ytop[i], boxData.ybottom[i], boxData.prob[i],
                                            fetcherName);
                        }

                        //boxBufferToCalc.Enqueue(annoData);
                        boundingBoxBufferToCalc_.Enqueue(boxData);
                    }
                }
                else
                {
                    // frame object was not in the pool, lifetime expired
                    Debug.LogFormat((ILogComponent)this, "received {0} annotations but frame expired",
                                    fetcherName);
                }
            }
            catch (System.Exception e)
            {
                Debug.LogExceptionFormat(e, "while parsing {0} annotation {1}...",
                                         fetcherName, debugString.Substring(0, 100));
            }
        });
    }
Example #14
0
    public List <AnnotationData> GetAllAnnotationData(string content)
    {
        List <AnnotationData> list     = new List <AnnotationData>();
        int            len             = content.Length;
        bool           isSingleLine    = false;
        bool           isMultiLine     = false;
        AnnotationData data            = null;
        StringBuilder  textBuilder     = null;
        bool           isBeforeContent = true;

        for (int i = 0; i < len; i++)
        {
            Char c = content[i];
            while (WHITE_SPACE.IndexOf(c) != -1)
            {
                if (ENTER_SPACE.IndexOf(c) != -1)
                {
                    if (isSingleLine)
                    {
                        data.text                   = textBuilder.ToString();
                        data.originalText           = data.startStr + data.text + data.endStr;
                        data.endIndex               = i - 1;
                        data.isBeforeContent        = isBeforeContent;
                        data.containsSensitiveWords = IsContainWords(data.originalText, _sensitiveWords);
                        list.Add(data);
                    }
                    isSingleLine = false;
                }
                if (isMultiLine || isSingleLine)
                {
                    textBuilder.Append(c);
                }
                // Debug.LogFormat("i={0}, c={1}", i, c.ToString());

                if (i + 1 >= len)
                {
                    break;
                }
                i++;
                c = content[i];
            }

            if (!isSingleLine && !isMultiLine)
            {
                if (IsAnnotationStart(content, i))
                {
                    isMultiLine     = true;
                    data            = new AnnotationData();
                    data.startIndex = i;
                    data.startStr   = GetAnnotationStartStr();
                    data.endStr     = GetAnnotationEndStr();
                    textBuilder     = new StringBuilder();
                    i = i + GetMultiLineAnnotationStartStrLen() - 1;
                    continue;
                }
                else if (IsSingleLineAnnotationStart(content, i))
                {
                    isSingleLine    = true;
                    data            = new AnnotationData();
                    data.startIndex = i;
                    data.startStr   = GetAnnotationStartStr(true);
                    data.endStr     = GetAnnotationEndStr(true);
                    textBuilder     = new StringBuilder();
                    i = i + GetSingleLineAnnotationStartStrLen() - 1;
                    continue;
                }
            }
            else if (isMultiLine)
            {
                if (IsAnnotationEnd(content, i))
                {
                    i                           = i + GetMultiLineAnnotationEndStrLen() - 1;
                    data.text                   = textBuilder.ToString();
                    data.originalText           = data.startStr + data.text + data.endStr;
                    data.endIndex               = i;
                    data.isBeforeContent        = isBeforeContent;
                    data.containsSensitiveWords = IsContainWords(data.originalText, _sensitiveWords);
                    list.Add(data);
                    isMultiLine = false;
                    continue;
                }
            }

            if (isMultiLine || isSingleLine)
            {
                textBuilder.Append(c);
            }
            else
            {
                isBeforeContent = false;
            }

            if (i + 1 >= len)
            {
                if (isSingleLine)
                {
                    data.text                   = textBuilder.ToString();
                    data.endIndex               = i;
                    data.originalText           = data.startStr + data.text + data.endStr;
                    data.isBeforeContent        = isBeforeContent;
                    data.containsSensitiveWords = IsContainWords(data.originalText, _sensitiveWords);
                    list.Add(data);
                }
                break;
            }
        }
        return(list);
    }
Example #15
0
		private void ApplyAnnotation(AnnotationData annot, FixedPage page, int pageNumber, GlyphData[] pageLabels, Canvas canvas)
		{
			foreach (var location in CalculateAnnotationLocations(pageLabels, annot))
			{
				_annotatedPages.Add(pageNumber);
				
				var annotationText = new TextBlock(new Run(annot.Annotation.Text)
				{
					Foreground = GetForegroundBrush(annot.Annotation.ForegroundColor),
					FontSize = annot.Annotation.TextSize,
					FontWeight = annot.Annotation.FontWeight ?? FontWeights.Normal,
					FontFamily = new FontFamily(string.IsNullOrEmpty(annot.Annotation.FontName)
						? "Arial"
						: annot.Annotation.FontName),
					FontStyle = annot.Annotation.IsItalic 
						? FontStyles.Italic
						: FontStyles.Normal
				});

				if (annot.Annotation.CustomTransform != null)
				{
					annotationText.RenderTransform = annot.Annotation.CustomTransform;
				}

				Canvas.SetLeft(annotationText, location.X);
				Canvas.SetTop(annotationText, location.Y);
				canvas.Children.Add(annotationText);
			}
		}
Example #16
0
        private AnnotationData ParseAnnotation()
        {
            var data = new AnnotationData();

            string[] firstLine = GetNextOutputLine().Split(' ');
            data.Hash       = firstLine[0];
            data.SourceLine = int.Parse(firstLine[1]) - 1;
            data.ResultLine = int.Parse(firstLine[2]) - 1;
            data.LineCount  = int.Parse(firstLine[3]);

            while (true)
            {
                string line = GetNextOutputLine();

                int separator = line.IndexOf(' ');
                if (separator == -1)
                {
                    continue;
                }

                string key   = line.Substring(0, separator);
                string value = line.Substring(separator + 1);

                switch (key)
                {
                case "author":
                    data.Author = value;
                    break;

                case "author-mail":
                    data.AuthorMail = value;
                    break;

                case "author-time":
                    data.AuthorTime = ParseDateTime(value);
                    break;

                case "author-tz":
                    data.AuthorTimeZone = value;
                    break;

                case "committer":
                    data.Committer = value;
                    break;

                case "committer-mail":
                    data.CommitterMail = value;
                    break;

                case "committer-time":
                    data.CommitterTime = ParseDateTime(value);
                    break;

                case "committer-tz":
                    data.CommitterTimeZone = value;
                    break;

                case "previous":
                    data.IsEdit = true;
                    break;

                case "summary":
                    data.Message = value;
                    break;

                case "filename":
                    data.FileName = value;
                    return(data);
                }
            }
        }
Example #17
0
    void Start()
    {
        AnnotationData[] dataArr = new AnnotationData[5]; //sampledata
        for (int i = 0; i < 5; i++)                       //populate sample data
        {
            dataArr[i].timestamp      = 54386223 + i;
            dataArr[i].annotationData = new AnnotationData.ArrayEntry[5];
            for (int j = 0; j < 5; j++)
            {
                dataArr[i].annotationData[j].xleft   = 0.98765 + j;
                dataArr[i].annotationData[j].xright  = 0.98765 + j;
                dataArr[i].annotationData[j].ytop    = 0.98765 + j;
                dataArr[i].annotationData[j].ybottom = 0.98765 + j;
                dataArr[i].annotationData[j].label   = "chair";
                var p = j - 1 + 0.98765;
                dataArr[i].annotationData[j].prob = p / j;
            }
        }

        dataArr[3].timestamp = dataArr[2].timestamp;

        var client   = new MongoClient(connectionString);
        var server   = client.GetServer();
        var database = server.GetDatabase("db");
        var entries  = database.GetCollection <BsonDocument>("entries");

        //loop for receiving data, in this case just iterating through sampledata
        foreach (var item in dataArr)
        {
            List <string> temp = new List <string>();
            List <string> seen = new List <string>();
            List <string> objs = new List <string>();

            foreach (var k in item.annotationData)
            {
                temp.Add(k.label);
            }

            foreach (var curr in temp)
            {
                if (seen.Contains(curr) == true)
                {
                    continue;
                }

                seen.Add(curr);
                int count = 0;

                for (int i = 0; i < temp.Count; i++)
                {
                    string s = temp[i];
                    if (s == curr)
                    {
                        objs.Add(curr + count);
                        count++;
                    }
                }
            }
            Debug.Log(objs);

            //$in
            BsonArray bArr  = new BsonArray(objs);
            var       match = new BsonDocument {
                { "$match",
                  new BsonDocument {
                      { "labels", new BsonDocument {
                                                                 { "$in", bArr }
                                                             } }
                  } }
            };
            var unwind = new BsonDocument {
                { "$unwind", "$labels" }
            };
            var group = new BsonDocument {
                { "$group", new BsonDocument {
                      { "_id", "$id" },
                      { "matches", new BsonDocument {
                                                                 { "$sum", 1 }
                                                             } }
                  } }
            };
            var sort = new BsonDocument {
                { "$sort", new BsonDocument {
                      { "matches", -1 }
                  } }
            };
            var cursor = new BsonDocument {
                { "cursor", new BsonDocument {
                  } }
            };
            var pipeline = new[] { match, unwind, match, group, sort };

            //query = new BsonDocument{{"$in": new BsonArray(new[] {})}}
            //foreach(var elem in objs):
            //	query["$in"].append(elem.encode("utf-8"))
            //	query = {"labels": query}

            //cursor = entr.aggregate(
            //	[{"$match": query},
            //	{"$unwind": "$labels"},
            //	{"$match": query},
            //	{"$group": {
            //		"_id":"$_id",
            //		"matches": {"$sum":1}
            //	}},
            //	{"$sort": {"matches": -1}}]
            //)

            AggregateArgs args = new AggregateArgs();
            args.Pipeline = pipeline;

            var aggregate = entries.Aggregate(args);            //.Match(c => c.objs.Any(i => c.labels.Contains(i))).Unwind(c => c.labels).Match(c => c.objs.Any(i => c.labels.Contains(i))).Group(new BsonDocument{{"_id", "$_id"}, {"matches", new BsonDocument("$sum", 1)}}).Sort(new BsonDocument{{"matches", -1}}); //.Limit(20)

            //var examples = aggregate.ResultDocuments;

            foreach (var example in aggregate)
            {
                Console.WriteLine(example);
            }
        }
    }
Example #18
0
        private IEnumerable <Point> CalculateAnnotationLocations(GlyphData[] pageLabels, AnnotationData annot)
        {
            if (annot.Annotation.PositionMethod == PositioningMethod.Absolute)
            {
                yield return(annot.Annotation.Position);
            }

            IEnumerable <GlyphData> matches;

            switch (annot.Annotation.MatchMethod)
            {
            case null:
            case LabelMatchMethod.ExactMatch:
                matches = pageLabels.Where(g => g.Glyphs.UnicodeString == annot.LabelMatchText);
                break;

            case LabelMatchMethod.ExactMatchIgnoreCase:
                matches = pageLabels.Where(g => g.LowerCaseText == annot.LabelMatchText);
                break;

            case LabelMatchMethod.RegularExpression:
                matches = pageLabels.Where(g => annot.LabelMatcher.IsMatch(g.LowerCaseText));
                break;

            default:
                throw new ArgumentOutOfRangeException("Invalid MatchMethod");
            }

            foreach (var match in matches)
            {
                var glyphs    = match.Glyphs;
                var anchorPos = glyphs.RenderTransform.Transform(
                    new Point(glyphs.OriginX, glyphs.OriginY));
                var pos = new Point(annot.Annotation.Position.X + anchorPos.X,
                                    (annot.Annotation.Position.Y + anchorPos.Y) - annot.Annotation.TextSize);

                yield return(pos);
            }
        }
Example #19
0
 /// <summary>
 /// Logs an annotation.
 /// </summary>
 /// <param name="annotation">The annotation to log.</param>
 protected virtual void LogAnnotation(AnnotationData annotation)
 {
     annotation.Log(Logger, true);
 }
Example #20
0
        private TabPage initTabPage(string pageName, IList<byte> data, int pageNumber = 0)
        {
            var page = new TabPage(pageName);
            
            var annotationData = new AnnotationData();
            annotationData.PageName = pageName;
            annotationData.data = data;
            annotationData.pageNumber = pageNumber;
            page.Tag = annotationData;
            page.Controls.Add(addAnnotationPage(page));
            return page;

        }
Example #21
0
		private IEnumerable<Point> CalculateAnnotationLocations(GlyphData[] pageLabels, AnnotationData annot)
		{
			if (annot.Annotation.PositionMethod == PositioningMethod.Absolute)
			{
				yield return annot.Annotation.Position;
			}

			IEnumerable<GlyphData> matches;

			switch (annot.Annotation.MatchMethod)
			{
				case null:
				case LabelMatchMethod.ExactMatch:
					matches = pageLabels.Where(g => g.Glyphs.UnicodeString == annot.LabelMatchText);
					break;
				case LabelMatchMethod.ExactMatchIgnoreCase:
					matches = pageLabels.Where(g => g.LowerCaseText == annot.LabelMatchText);
					break;
				case LabelMatchMethod.RegularExpression:
					matches = pageLabels.Where(g => annot.LabelMatcher.IsMatch(g.LowerCaseText));
					break;
				default:
					throw new ArgumentOutOfRangeException("Invalid MatchMethod");
			}

			foreach (var match in matches)
			{
				var glyphs = match.Glyphs;
				var anchorPos = glyphs.RenderTransform.Transform(
					new Point(glyphs.OriginX, glyphs.OriginY));
				var pos = new Point(annot.Annotation.Position.X + anchorPos.X,
					(annot.Annotation.Position.Y + anchorPos.Y) - annot.Annotation.TextSize);

				yield return pos;
			}
		}
 /// <summary>
 /// The annotation data property is changed.
 /// </summary>
 /// <param name="annotationDataCollection">The annotation data collection.</param>
 /// <param name="annotationData">The annotation data.</param>
 /// <param name="e">The <see cref="ObjectPropertyChangedEventArgs"/> instance containing the event data.</param>
 protected virtual void OnAnnotationDataPropertyChanged(
     AnnotationDataCollection annotationDataCollection, AnnotationData annotationData, ObjectPropertyChangedEventArgs e)
 {
 }
Example #23
0
        /// <summary>
        /// Returns the comment type.
        /// </summary>
        /// <param name="annotation">The parent annotation.</param>
        /// <returns>
        /// The comment type.
        /// </returns>
        public static string GetCommentType(AnnotationData annotation)
        {
            string result = string.Empty;

            if (annotation != null)
            {
                Type type = annotation.GetType();

                if (type == typeof(RectangleAnnotationData))
                {
                    result = "Rectangle";
                }
                else if (type == typeof(EllipseAnnotationData))
                {
                    result = "Ellipse";
                }
                else if (type == typeof(HighlightAnnotationData))
                {
                    result = "Highlight";
                }
                else if (type == typeof(EmbeddedImageAnnotationData))
                {
                    result = "Embedded Image";
                }
                else if (type == typeof(ReferencedImageAnnotationData))
                {
                    result = "Referenced Image";
                }
                else if (type == typeof(TextAnnotationData))
                {
                    result = "Text";
                }
                else if (type == typeof(StickyNoteAnnotationData))
                {
                    result = "Sticky Note";
                }
                else if (type == typeof(FreeTextAnnotationData))
                {
                    result = "Free Text";
                }
                else if (type == typeof(StampAnnotationData))
                {
                    result = "Stamp";
                }
                else if (type == typeof(LinkAnnotationData))
                {
                    result = "Link";
                }
                else if (type == typeof(ArrowAnnotationData))
                {
                    result = "Arrow";
                }
                else if (type == typeof(LineAnnotationData))
                {
                    result = "Line";
                }
                else if (type == typeof(LinesAnnotationData))
                {
                    result = "Lines";
                }
                else if (type == typeof(PolygonAnnotationData))
                {
                    result = "Polygon";
                }
                else if (type == typeof(RulerAnnotationData))
                {
                    result = "Ruler";
                }
                else if (type == typeof(RulersAnnotationData))
                {
                    result = "Rulers";
                }
                else if (type == typeof(AngleAnnotationData))
                {
                    result = "Angle";
                }
                else if (type == typeof(ArcAnnotationData))
                {
                    result = "Arc";
                }
                else if (type == typeof(TriangleAnnotationData))
                {
                    result = "Triangle";
                }
                else if (type == typeof(MarkAnnotationData))
                {
                    result = "Mark";
                }
                else if (type == typeof(GroupAnnotationData))
                {
                    result = "Group";
                }
            }

            return(result);
        }
    public void OnImageAvailable(TextureReaderApi.ImageFormatType format, int width, int height, IntPtr pixelBuffer, int bufferSize)
    {
        try{
            System.DateTime current      = System.DateTime.Now;
            long            elapsedTicks = current.Ticks - begin.Ticks;
            System.TimeSpan elapsedSpan  = new System.TimeSpan(elapsedTicks);
            timestamp = elapsedSpan.TotalSeconds;
            //Debug.Log("before call to ndnrtc");
            int publishedFrameNo = NdnRtc.videoStream.processIncomingFrame(format, width, height, pixelBuffer, bufferSize);
            Debug.Log("Published frame number: " + publishedFrameNo);

            if (publishedFrameNo >= 0)
            {
                Debug.Log("create frame object frame number: " + publishedFrameNo);
                Debug.Log("create frame object timestamp: " + timestamp);
                Debug.Log("create frame object position: " + Frame.Pose.position);
                Debug.Log("create frame object rotation: " + Frame.Pose.rotation);
                Debug.Log("create frame object camera: " + camForCalcThread.ToString());
                frameMgr.CreateFrameObject(publishedFrameNo, timestamp, Frame.Pose.position, Frame.Pose.rotation, camForCalcThread);
                //frameMgr.CreateFrameObject (imgBuffer, publishedFrameNo, timestamp, Vector3.zero, Quaternion.identity, offset.m_uOffset, offset.m_vOffset, camForCalcThread);

                //frameObjectBuffer.Enqueue (frameMgr.frameObjects [publishedFrameNo]);
                frameBuffer.Enqueue(frameMgr.frameObjects);
                Debug.Log("frame buffer enqueue: " + publishedFrameNo);
                // spawn fetching task for annotations of this frame
                // once successfully received, delegate callback will be called
                aFetcher_.fetchAnnotation(publishedFrameNo, delegate(string jsonArrayString) {
                    int frameNumber = publishedFrameNo;             // storing frame number locally
                    string debuglog = jsonArrayString.Replace(System.Environment.NewLine, " ");
                    Debug.Log("Received annotations JSON (frame " + frameNumber + "): " + debuglog);
                    //Debug.Log("annotations string length: " + jsonArrayString.Length);
                    string[] testDebug = jsonArrayString.Split(']');
                    string formatDebug = testDebug[0] + "]";
                    try{
                        Dictionary <int, FrameObjectData> frameObjects = frameBuffer.Dequeue();
                        FrameObjectData temp;
                        if (frameObjects.TryGetValue(frameNumber, out temp))
                        {
                            //AnnotationData[] data = JsonHelper.FromJson<AnnotationData>(jsonArrayString);
                            //try to print out how many characters the jsonArrayString has
                            string str          = "{ \"annotationData\": " + formatDebug + "}";
                            AnnotationData data = JsonUtility.FromJson <AnnotationData>(str);
                            for (int i = 0; i < data.annotationData.Length; i++)
                            {
                                if (data.annotationData[i].prob >= 0.5f)
                                {
                                    Debug.Log("test: " + data.annotationData.Length);
                                    Debug.Log("test label: " + data.annotationData[i].label + " test xleft: " + data.annotationData[i].xleft
                                              + " test xright: " + data.annotationData[i].xright + " test ytop: " + (1 - data.annotationData[i].ytop) + " test ybottom: " + (1 - data.annotationData[i].ybottom));
                                    //						Debug.Log("test xleft: " + data.annotationData[i].xleft);
                                    //						Debug.Log("test xright: " + data.annotationData[i].xright);
                                    //						Debug.Log("test ytop: " + data.annotationData[i].ytop);
                                    //						Debug.Log("test ybottom: " + data.annotationData[i].ybottom);

                                    // example how to fetch model from content-publisher
                                    // Therese, please check this is the right place in code where models should be requested
                                    // (prob. model doesn't need to be fetched every frame for same object)
                                    //fetchModel(data.annotationData[i].label);
                                }
                            }
                            //				FrameObjectData temp;
                            //				bool success = frameObjectBuffer.TryDequeue(out temp);
                            //				if(success)
                            //				//FrameObjectData temp = frameBuffer.Dequeue();
                            //				{
                            //					Debug.Log("Frame info: " + frameNumber);
                            //					Debug.Log ("Frame info camera position: " + temp.camPos);
                            //					Debug.Log ("Frame info camera rotation: " + temp.camRot);
                            //					Debug.Log ("Frame info points number: " + temp.numPoints);
                            //					Debug.Log ("Frame info points: " + temp.points.ToString());
                            //				}


                            Debug.Log("Frame number annotations: " + frameNumber);
                            Debug.Log("Frame info camera position: " + temp.camPos);
                            Debug.Log("Frame info camera rotation: " + temp.camRot);
                            //Debug.Log ("Frame info points number: " + temp.numPoints);
                            Debug.Log("Frame info points: " + temp.points.ToString());
                            Debug.Log("test time difference: " + (Mathf.Abs((float)(temp.timestamp - timestamp))) + " frame number: " + publishedFrameNo);

                            //int boxCount = Mathf.Min(data.annotationData.Length, 2);
                            int boxCount = data.annotationData.Length;

                            BoxData annoData = new BoxData();
                            Debug.Log("box created boxdata");
                            annoData.frameNumber = frameNumber;
                            annoData.count       = boxCount;
                            annoData.points      = temp.points;
                            annoData.numPoints   = temp.numPoints;
                            annoData.cam         = temp.cam;
                            annoData.camPos      = temp.camPos;
                            annoData.camRot      = temp.camRot;
                            annoData.timestamp   = temp.timestamp;
                            annoData.label       = new string[boxCount];
                            annoData.xleft       = new float[boxCount];
                            annoData.xright      = new float[boxCount];
                            annoData.ytop        = new float[boxCount];
                            annoData.ybottom     = new float[boxCount];
                            annoData.prob        = new float[boxCount];

                            for (int i = 0; i < boxCount; i++)
                            {
                                annoData.label[i]   = data.annotationData[i].label;
                                annoData.xleft[i]   = 1 - data.annotationData[i].xright;
                                annoData.xright[i]  = 1 - data.annotationData[i].xleft;
                                annoData.ytop[i]    = data.annotationData[i].ybottom;
                                annoData.ybottom[i] = data.annotationData[i].ytop;
                                annoData.prob[i]    = data.annotationData[i].prob;
                            }

                            Debug.Log("Received annotations box enqueue");
                            //boxBufferToCalc.Enqueue(annoData);
                            boundingBoxBufferToCalc.Enqueue(annoData);
                        }
                        else
                        {
                            //frame object was not in the pool, lifetime expired
                            Debug.Log("Received annotations but frame expired");
                        }
                    }
                    catch (System.Exception e)
                    {
                        Debug.Log("exception caught annotations: " + e);
                        string debug = jsonArrayString.Replace(System.Environment.NewLine, " ");
                        Debug.Log("exception caught string: " + debug);
                        string str = "{ \"annotationData\": " + debug + "}";
                        Debug.Log("exception caught string with format: " + str);
                    }
                });

                openFaceFetcher_.fetchAnnotation(publishedFrameNo, delegate(string jsonArrayString) {
                    int frameNumber = publishedFrameNo;             // storing frame number locally
                    string debuglog = jsonArrayString.Replace(System.Environment.NewLine, " ");
                    Debug.Log("Received OpenFace annotations JSON (frame " + frameNumber + "): " + debuglog);
                    string[] testDebug = jsonArrayString.Split(']');
                    string formatDebug = testDebug[0] + "]";
                    try{
                        Dictionary <int, FrameObjectData> frameObjects = frameBuffer.Dequeue();
                        FrameObjectData temp;
                        if (frameObjects.TryGetValue(frameNumber, out temp))
                        {
                            string str          = "{ \"annotationData\": " + formatDebug + "}";
                            AnnotationData data = JsonUtility.FromJson <AnnotationData>(str);
                            for (int i = 0; i < data.annotationData.Length; i++)
                            {
                                //if(data.annotationData[i].prob >= 0.7f)
                                {
                                    Debug.Log("openface test: " + data.annotationData.Length);
                                    Debug.Log("openface test label: " + data.annotationData[i].label + " test xleft: " + data.annotationData[i].xleft
                                              + " test xright: " + data.annotationData[i].xright + " test ytop: " + (data.annotationData[i].ytop) + " test ybottom: " + (data.annotationData[i].ybottom));
                                    //						Debug.Log("test xleft: " + data.annotationData[i].xleft);
                                    //						Debug.Log("test xright: " + data.annotationData[i].xright);
                                    //						Debug.Log("test ytop: " + data.annotationData[i].ytop);
                                    //						Debug.Log("test ybottom: " + data.annotationData[i].ybottom);
                                }
                            }
                            //int boxCount = Mathf.Min(data.annotationData.Length, 2);
                            int boxCount = data.annotationData.Length;

                            BoxData annoData = new BoxData();
                            Debug.Log("box created boxdata");
                            annoData.frameNumber = frameNumber;
                            annoData.count       = boxCount;
                            annoData.points      = temp.points;
                            annoData.numPoints   = temp.numPoints;
                            annoData.cam         = temp.cam;
                            annoData.camPos      = temp.camPos;
                            annoData.camRot      = temp.camRot;
                            annoData.timestamp   = temp.timestamp;
                            annoData.label       = new string[boxCount];
                            annoData.xleft       = new float[boxCount];
                            annoData.xright      = new float[boxCount];
                            annoData.ytop        = new float[boxCount];
                            annoData.ybottom     = new float[boxCount];
                            annoData.prob        = new float[boxCount];

                            for (int i = 0; i < boxCount; i++)
                            {
                                if (data.annotationData[i].ytop > 1)
                                {
                                    data.annotationData[i].ytop = 1;
                                }
                                if (data.annotationData[i].ybottom < 0)
                                {
                                    data.annotationData[i].ybottom = 0;
                                }
                                annoData.label[i]   = data.annotationData[i].label;
                                annoData.xleft[i]   = data.annotationData[i].xleft;
                                annoData.xright[i]  = data.annotationData[i].xright;
                                annoData.ytop[i]    = data.annotationData[i].ytop;
                                annoData.ybottom[i] = data.annotationData[i].ybottom;
                                annoData.prob[i]    = 1;
                            }

                            Debug.Log("Received openface annotations box enqueue");
                            //boxBufferToCalc.Enqueue(annoData);
                            boundingBoxBufferToCalc.Enqueue(annoData);
                        }
                        else
                        {
                            //frame object was not in the pool, lifetime expired
                            Debug.Log("Received openface annotations but frame expired");
                        }
                    }
                    catch (System.Exception e)
                    {
                        Debug.Log("exception caught openface annotations: " + e);
                        string debug = jsonArrayString.Replace(System.Environment.NewLine, " ");
                        Debug.Log("exception caught openface string: " + debug);
                        string str = "{ \"annotationData\": " + debug + "}";
                        Debug.Log("exception caught openface string with format: " + str);
                    }
                });
            }
            else
            {
                // frame was dropped by the encoder and was not published
            }
        }
        catch (System.Exception e)
        {
            Debug.Log("exception caught video" + e.ToString());
        }
    }