예제 #1
0
 private VideoInterpreter(PrefabInterpretationLogic logic)
 {
     _interpretationLogic = logic;
     _running             = true;
     _interpretQueue      = new Queue <int>();
     _elementAdded        = new AutoResetEvent(false);
 }
예제 #2
0
        public void SetLayerChainItems(PrefabInterpretationLogic logic)
        {
            if (logic is LayerInterpretationLogic)
            {
                LayerInterpretationLogic            layerLog   = logic as LayerInterpretationLogic;
                List <string>                       layernames = new List <string>();
                List <Dictionary <string, object> > parameters = new List <Dictionary <string, object> >();

                ChainLoader.GetLayerNamesAndParameters(layerLog.LayerDirectory, layernames, parameters);


                LayerChainItems = new ObservableCollection <LayerChainItem>();
                if (layerLog.Layers != null)
                {
                    for (int i = 0; i < layernames.Count; i++)
                    {
                        LayerChainItem item = new LayerChainItem();
                        item.Name     = System.IO.Path.GetFileNameWithoutExtension(layernames[i]);
                        item.FullPath = layernames[i];
                        foreach (string key in parameters[i].Keys)
                        {
                            string val = parameters[i][key] as string;
                            if (val != null)
                            {
                                item.ParameterKeys.Add(key);
                                item.ParameterValues.Add(val);
                            }
                        }

                        LayerChainItems.Add(item);
                    }
                }

                //List<string> dirs = new List<string>();
                //dirs.Add(layerLog.LayerDirectory);
                //var alllayers = ChainLoader.GetAllLayerNames(dirs);

                //AllLayers = new ObservableCollection<LayerChainItem>();

                //foreach (string layer in alllayers)
                //{
                //    LayerChainItem item = new LayerChainItem();
                //    item.Name = System.IO.Path.GetFileNameWithoutExtension(layer);
                //    string path = System.IO.Path.GetDirectoryName(layer);

                //    if (System.IO.Path.Equals(path, layerLog.LayerDirectory))
                //    {
                //        item.FullPath = item.Name;
                //    }else
                //         item.FullPath = layer;

                //    AllLayers.Add(item);

                //}
            }
            else
            {
                Visibility = System.Windows.Visibility.Collapsed;
            }
        }
예제 #3
0
        public static VideoInterpreter FromVideoOrImage(string aviFileLocation, PrefabInterpretationLogic logic)
        {
            VideoInterpreter i = new VideoInterpreter(logic);

            i._frames = new VideoFrames(aviFileLocation);

            i._interpretFrame = new Thread(i._interpretFrame_DoWork);
            i._interpretFrame.Priority = ThreadPriority.Highest;
            i._interpretFrame.Start();

            i._framesCollection = new VirtualizingCollection<BitmapSource>(i.FrameCount, i.GetFramesInRange);

            return i;
        }
예제 #4
0
        public static VideoInterpreter FromVideoOrImage(string aviFileLocation, PrefabInterpretationLogic logic)
        {
            VideoInterpreter i = new VideoInterpreter(logic);

            i._frames = new VideoFrames(aviFileLocation);

            i._interpretFrame          = new Thread(i._interpretFrame_DoWork);
            i._interpretFrame.Priority = ThreadPriority.Highest;
            i._interpretFrame.Start();

            i._framesCollection = new VirtualizingCollection <BitmapSource>(i.FrameCount, i.GetFramesInRange);

            return(i);
        }
예제 #5
0
        public void SetLayerChainItems(PrefabInterpretationLogic logic)
        {
            if (logic is LayerInterpretationLogic)
            {
                LayerInterpretationLogic layerLog = logic as LayerInterpretationLogic;
                List<string> layernames = new List<string>();
                List<Dictionary<string, object>> parameters = new List<Dictionary<string, object>>();

                ChainLoader.GetLayerNamesAndParameters(layerLog.LayerDirectory, layernames, parameters);

                
                LayerChainItems = new ObservableCollection<LayerChainItem>();
                if (layerLog.Layers != null)
                {
                    for (int i = 0; i < layernames.Count; i ++ )
                    {
                        LayerChainItem item = new LayerChainItem();
                        item.Name = System.IO.Path.GetFileNameWithoutExtension(layernames[i]);
                        item.FullPath = layernames[i];
                        foreach (string key in parameters[i].Keys)
                        {

                            string val = parameters[i][key] as string;
                            if (val != null)
                            {
                                item.ParameterKeys.Add(key);
                                item.ParameterValues.Add(val);

                            }
                        }

                        LayerChainItems.Add(item);
                    }
                }

                //List<string> dirs = new List<string>();
                //dirs.Add(layerLog.LayerDirectory);
                //var alllayers = ChainLoader.GetAllLayerNames(dirs);

                //AllLayers = new ObservableCollection<LayerChainItem>();

                //foreach (string layer in alllayers)
                //{
                //    LayerChainItem item = new LayerChainItem();
                //    item.Name = System.IO.Path.GetFileNameWithoutExtension(layer);
                //    string path = System.IO.Path.GetDirectoryName(layer);
                    
                //    if (System.IO.Path.Equals(path, layerLog.LayerDirectory))
                //    {
                //        item.FullPath = item.Name;
                //    }else
                //         item.FullPath = layer;

                //    AllLayers.Add(item);

                //}
            }
            else
            {
                Visibility = System.Windows.Visibility.Collapsed;
            }
        }
예제 #6
0
        public void SetProperties(Tree node, Tree root, Bitmap wholeScreenshot, string ptypeLib,
                                  PrefabInterpretationLogic interpLogic, Bitmap image = null,
                                  IEnumerable <string> annotationLibs = null)
        {
            Annotations.Clear();
            AnnotationLibraries.Clear();

            List <string> keys = new List <string>(node.GetTags().Select(kvp => kvp.Key));

            foreach (string key in keys)
            {
                if (!key.Equals("ptype") && !key.Equals("invalidated"))
                {
                    object attribute = node[key];
                    if (attribute == null)
                    {
                        attribute = "";
                    }

                    AnnotationKeyValuePair annotation = new AnnotationKeyValuePair(key, attribute.ToString());
                    annotation.IsEditingChanged += new DependencyPropertyChangedEventHandler(annotation_IsEditingChanged);
                    Annotations.Add(annotation);
                }
            }



            Node = node;

            if (node.HasTag("type"))
            {
                switch (node["type"].ToString())
                {
                case "ptype":

                    Ptype ptype = (Ptype)node["ptype"];
                    var   exs   = PtypeSerializationUtility.GetTrainingExamples(ptypeLib, ptype.Id);
                    Prototype = new ViewablePrototypeItem(ptype, ptypeLib, exs.Positives, exs.Negatives, image);
                    break;

                case "content":
                case "feature":
                    Prototype = new ViewablePrototypeItem(null, ptypeLib, new List <ImageAnnotation>(), new List <ImageAnnotation>(), image);
                    break;

                default:
                    break;
                }
            }

            SetAnnotationLibraries(annotationLibs);

            StaticMetadata = "x=" + node.Left + ", y=" + node.Top + ", width=" + node.Width + ", height=" + node.Height;

            NodePath = PathDescriptor.GetPath(node, root);

            if (image != null)
            {
                //string bitmapid = wholeScreenshot.GetHashCode().ToString();


                //var annotations = interpLogic.GetAnnotationsMatchingNode(node, root, bitmapid);

                //string annotationsStr = "[\n";

                //foreach (string lib in annotations.Keys)
                //{
                //    foreach (IAnnotation ia in annotations[lib])
                //    {
                //        annotationsStr += "{\"library\" : \"" + lib + "\"\n";
                //        annotationsStr += "\"id\" : \"" + ia.Id + "\"\n";
                //        annotationsStr += ", \"data\"" + JsonConvert.SerializeObject(ia.Data) + "\n";
                //        annotationsStr += "}";
                //        annotationsStr += ",";
                //    }
                //}

                //annotationsStr.Remove(annotationsStr.Length - 1);
                //annotationsStr += "\n]";
                //AnnotationValueBox.Text = annotationsStr;
            }
        }
예제 #7
0
        public void SetProperties(Tree node, Tree root, Bitmap wholeScreenshot, string ptypeLib,
            PrefabInterpretationLogic interpLogic, Bitmap image = null, 
            IEnumerable<string> annotationLibs = null)
        {

            Annotations.Clear();
            AnnotationLibraries.Clear();

            List<string> keys = new List<string>(node.GetTags().Select(kvp => kvp.Key));

            foreach (string key in keys)
            {
                if (!key.Equals("ptype") && !key.Equals("invalidated"))
                {
                    object attribute = node[key];
                    if (attribute == null)
                        attribute = "";

                    AnnotationKeyValuePair annotation = new AnnotationKeyValuePair(key, attribute.ToString());
                    annotation.IsEditingChanged += new DependencyPropertyChangedEventHandler(annotation_IsEditingChanged);
                    Annotations.Add(annotation);
                }
            }

            
            
            Node = node;
            
            if (node.HasTag("type"))
            {
                switch (node["type"].ToString())
                {
                    case "ptype":

                         Ptype ptype = (Ptype)node["ptype"];
                         var exs  = PtypeSerializationUtility.GetTrainingExamples(ptypeLib, ptype.Id);
                         Prototype = new ViewablePrototypeItem(ptype, ptypeLib, exs.Positives, exs.Negatives, image);
                        break;

                    case "content":
                    case "feature":
                        Prototype = new ViewablePrototypeItem(null, ptypeLib, new List<ImageAnnotation>(), new List<ImageAnnotation>(), image);
                        break;

                    default:
                        break;
                }
            }
            
            SetAnnotationLibraries(annotationLibs);

            StaticMetadata = "x=" + node.Left + ", y=" + node.Top + ", width=" + node.Width + ", height=" + node.Height;

            NodePath = PathDescriptor.GetPath(node, root);

            if(image != null)
            {
                //string bitmapid = wholeScreenshot.GetHashCode().ToString();


                //var annotations = interpLogic.GetAnnotationsMatchingNode(node, root, bitmapid);

                //string annotationsStr = "[\n";

                //foreach (string lib in annotations.Keys)
                //{
                //    foreach (IAnnotation ia in annotations[lib])
                //    {
                //        annotationsStr += "{\"library\" : \"" + lib + "\"\n";
                //        annotationsStr += "\"id\" : \"" + ia.Id + "\"\n";
                //        annotationsStr += ", \"data\"" + JsonConvert.SerializeObject(ia.Data) + "\n";
                //        annotationsStr += "}";
                //        annotationsStr += ",";
                //    }
                //}

                //annotationsStr.Remove(annotationsStr.Length - 1);
                //annotationsStr += "\n]";
                //AnnotationValueBox.Text = annotationsStr;
            }
           
        }
예제 #8
0
        void LoadInterpretationLogic(object sender, DoWorkEventArgs e)
        {


            if (_prefabInterpretationLogic == null)
            {
                
                switch (_studyCondition)
                {
                    case StudyCondition.Debug:
                    case StudyCondition.Layers:
                        _prefabInterpretationLogic = new LayerInterpretationLogic(TargetLayersDir);
                        break;

                    case StudyCondition.Single:
                        _prefabInterpretationLogic = new PrefabSingleLogic(SingleLayersDir);
                        break;
                }
            }

            try
            {
                _prefabInterpretationLogic.Load();
            }
            catch (Exception exp)
            {
                
                Dispatcher.BeginInvoke(_updateThread, UpdateType.LoadLayersFailed, exp);
                return;
            }

            if (_interpreter != null)
            {

            }
            else
            {
                _interpreter = VideoInterpreter.FromVideoOrImage(null, _prefabInterpretationLogic);
                _interpreter.FrameInterpreted += new EventHandler<VideoInterpreter.InterpretedFrame>(_interpreter_FrameInterpreted);
                _interpreter.RectsSnapped += new EventHandler<RectsSnappedArgs>(_interpreter_RectsSnapped);
                _interpreter.PrototypesBuilt += new EventHandler<PrototypesEventArgs>(_interpreter_PrototypesBuilt);
                _interpreter.PrototypesRemoved += new EventHandler<PrototypesEventArgs>(_interpreter_PrototypesRemoved);

            }

            UpdateLayers(e.Argument);
        }
예제 #9
0
        private void LoadPrefabDep(object sender, DoWorkEventArgs e)
        {
            _prefabInterpretationLogic = new PrefabSingleLogic(SingleLayersDir);
            _prefabInterpretationLogic.Load();
            UpdateLayers(e.Argument);

        }
예제 #10
0
        public static VideoInterpreter FromMultipleScreenshots(IEnumerable<string> files, PrefabInterpretationLogic logic)
        {
            VideoInterpreter i = new VideoInterpreter(logic);
            List<System.Drawing.Bitmap> screenshots = new List<System.Drawing.Bitmap>();
            foreach(string file in files)
            {
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(file);
                screenshots.Add(bmp);
            }


            i._frames = VideoFrames.FromMultipleScreenshots(screenshots);
            i._interpretFrame = new Thread(i._interpretFrame_DoWork);
            i._interpretFrame.Priority = ThreadPriority.Highest;
            i._interpretFrame.Start();
            i._framesCollection = new VirtualizingCollection<BitmapSource>(i.FrameCount, i.GetFramesInRange);

            return i;
        }
예제 #11
0
 private VideoInterpreter(PrefabInterpretationLogic logic) 
 {
     _interpretationLogic = logic;
     _running = true;
     _interpretQueue = new Queue<int>();
     _elementAdded = new AutoResetEvent(false);
 }
예제 #12
0
        public static VideoInterpreter FromMultipleScreenshots(IEnumerable <string> files, PrefabInterpretationLogic logic)
        {
            VideoInterpreter             i           = new VideoInterpreter(logic);
            List <System.Drawing.Bitmap> screenshots = new List <System.Drawing.Bitmap>();

            foreach (string file in files)
            {
                System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(file);
                screenshots.Add(bmp);
            }


            i._frames                  = VideoFrames.FromMultipleScreenshots(screenshots);
            i._interpretFrame          = new Thread(i._interpretFrame_DoWork);
            i._interpretFrame.Priority = ThreadPriority.Highest;
            i._interpretFrame.Start();
            i._framesCollection = new VirtualizingCollection <BitmapSource>(i.FrameCount, i.GetFramesInRange);

            return(i);
        }
예제 #13
0
        public void SetLayerChainItems(PrefabInterpretationLogic logic)
        {
            LayerChainItems = new ObservableCollection<LayerChainItem>();

            if (logic is LayerInterpretationLogic)
            {
                LayerInterpretationLogic layerLog = logic as LayerInterpretationLogic;
                _layerInterpretLogic = layerLog;
                List<string> layernames = new List<string>();
                List<Dictionary<string, object>> parameters = new List<Dictionary<string, object>>();

                ChainLoader.GetLayerNamesAndParameters(layerLog.LayerDirectory, layernames, parameters);

                
                

                    for (int i = 0; i < layernames.Count; i ++ )
                    {
                        
                        LayerChainItem item = new LayerChainItem();
                        item.Name = System.IO.Path.GetFileName(layernames[i]);
                        item.RelativePath = layernames[i];

                        item.FullPath = System.IO.Path.GetFullPath(layerLog.LayerDirectory + "/" + layernames[i]);

                        foreach (string key in parameters[i].Keys)
                        {

                            object val = parameters[i][key];
                            if (val != null)
                            {
                                item.ParameterKeys.Add(key);
                                item.ParameterValues.Add(val);

                            }
                        }

                        LayerChainItems.Add(item);
                    }
                

                //List<string> dirs = new List<string>();
                //dirs.Add(layerLog.LayerDirectory);
                //var alllayers = ChainLoader.GetAllLayerNames(dirs);

                //AllLayers = new ObservableCollection<LayerChainItem>();

                //foreach (string layer in alllayers)
                //{
                //    LayerChainItem item = new LayerChainItem();
                //    item.Name = System.IO.Path.GetFileName(layer);
                //    string path = System.IO.Path.GetDirectoryName(layer);
                    
                //    if (System.IO.Path.Equals(path, layerLog.LayerDirectory))
                //    {
                //        item.RelativePath = item.Name;
                //    }else
                //         item.RelativePath = layer;

                //    item.FullPath = System.IO.Path.GetFullPath(layerLog.LayerDirectory + "/" + layer);

                //    AllLayers.Add(item);

                //}
            }
            else
            {
                LayerChainItem item = new LayerChainItem();
                item.Name = "prefab_identification_layers";
                item.RelativePath = "..\\prefab_identification_layers";
                item.FullPath =  System.IO.Path.GetFullPath(logic.LayerDirectory + "/" + item.RelativePath);
                item.DeleteButtonVisibility = System.Windows.Visibility.Collapsed;
                LayerChainItems.Add(item);
                
                item = new LayerChainItem();
                item.Name = "interpret_tree.py";
                item.RelativePath = "interpret_tree.py";
                item.FullPath =  System.IO.Path.GetFullPath(logic.LayerDirectory + "/" + item.RelativePath);
                item.DeleteButtonVisibility = System.Windows.Visibility.Collapsed;
                LayerChainItems.Add(item);

                AddLayerButton.Visibility = Visibility.Collapsed;
                LibrariesPanel.Visibility = Visibility.Collapsed;
            }
        }
예제 #14
0
        public void SetLayerChainItems(PrefabInterpretationLogic logic)
        {
            LayerChainItems = new ObservableCollection <LayerChainItem>();

            if (logic is LayerInterpretationLogic)
            {
                LayerInterpretationLogic layerLog = logic as LayerInterpretationLogic;
                _layerInterpretLogic = layerLog;
                List <string> layernames = new List <string>();
                List <Dictionary <string, object> > parameters = new List <Dictionary <string, object> >();

                ChainLoader.GetLayerNamesAndParameters(layerLog.LayerDirectory, layernames, parameters);



                for (int i = 0; i < layernames.Count; i++)
                {
                    LayerChainItem item = new LayerChainItem();
                    item.Name         = System.IO.Path.GetFileName(layernames[i]);
                    item.RelativePath = layernames[i];

                    item.FullPath = System.IO.Path.GetFullPath(layerLog.LayerDirectory + "/" + layernames[i]);

                    foreach (string key in parameters[i].Keys)
                    {
                        object val = parameters[i][key];
                        if (val != null)
                        {
                            item.ParameterKeys.Add(key);
                            item.ParameterValues.Add(val);
                        }
                    }

                    LayerChainItems.Add(item);
                }


                //List<string> dirs = new List<string>();
                //dirs.Add(layerLog.LayerDirectory);
                //var alllayers = ChainLoader.GetAllLayerNames(dirs);

                //AllLayers = new ObservableCollection<LayerChainItem>();

                //foreach (string layer in alllayers)
                //{
                //    LayerChainItem item = new LayerChainItem();
                //    item.Name = System.IO.Path.GetFileName(layer);
                //    string path = System.IO.Path.GetDirectoryName(layer);

                //    if (System.IO.Path.Equals(path, layerLog.LayerDirectory))
                //    {
                //        item.RelativePath = item.Name;
                //    }else
                //         item.RelativePath = layer;

                //    item.FullPath = System.IO.Path.GetFullPath(layerLog.LayerDirectory + "/" + layer);

                //    AllLayers.Add(item);

                //}
            }
            else
            {
                LayerChainItem item = new LayerChainItem();
                item.Name                   = "prefab_identification_layers";
                item.RelativePath           = "..\\prefab_identification_layers";
                item.FullPath               = System.IO.Path.GetFullPath(logic.LayerDirectory + "/" + item.RelativePath);
                item.DeleteButtonVisibility = System.Windows.Visibility.Collapsed;
                LayerChainItems.Add(item);

                item                        = new LayerChainItem();
                item.Name                   = "interpret_tree.py";
                item.RelativePath           = "interpret_tree.py";
                item.FullPath               = System.IO.Path.GetFullPath(logic.LayerDirectory + "/" + item.RelativePath);
                item.DeleteButtonVisibility = System.Windows.Visibility.Collapsed;
                LayerChainItems.Add(item);

                AddLayerButton.Visibility = Visibility.Collapsed;
                LibrariesPanel.Visibility = Visibility.Collapsed;
            }
        }