コード例 #1
0
        //Add object to the video
        private void addObjBtn_Click(object sender, EventArgs e)
        {
            var linear = getLinearTransform();
            Object objectToAdd = null;
            if (drawingButtonSelected[rectangleDrawing])
            {
                var relFileName = videoReader.fileName.Split(Path.DirectorySeparatorChar)[videoReader.fileName.Split(Path.DirectorySeparatorChar).Length - 1];
                objectToAdd = new RectangleObject(currentSession, null, colorDialog1.Color, (int)borderSizeNumeric.Value, relFileName);
                (objectToAdd as RectangleObject).setBounding(frameTrackBar.Value, boundingBoxLocationMark.boundingBox, 1, new PointF());
                //startPoint = new Point();
                //endPoint = new Point();
                boundingBoxLocationMark = new RectangleLocationMark(-1, new RectangleF());
                startPoint = null;
            }

            if (drawingButtonSelected[polygonDrawing])
            {
                var relFileName = videoReader.fileName.Split(Path.DirectorySeparatorChar)[videoReader.fileName.Split(Path.DirectorySeparatorChar).Length - 1];
                objectToAdd = new PolygonObject(currentSession, null, colorDialog1.Color, (int)borderSizeNumeric.Value, relFileName);
                (objectToAdd as PolygonObject).setBounding(frameTrackBar.Value, polygonPointsLocationMark.boundingPolygon, 1, new PointF());
                polygonPointsLocationMark = new PolygonLocationMark2D(-1, new List<PointF>());

                // (drawingNewPolygon, editingPolygon) = (false, false) when you're added the polygon
                drawingNewPolygon = false;
                editingPolygon = false;
            }

            if (objectToAdd != null)
            {
                currentSession.addObject(objectToAdd);
                newObjectContextPanel.Visible = false;
                selectBoxes = new List<RectangleF>();
                invalidatePictureBoard();
            }

            addObjectAnnotation(objectToAdd);
        }
コード例 #2
0
ファイル: Object.cs プロジェクト: tuandnvn/ecat
        public static List<Object> readFromXml(Session currentSession, XmlNode xmlNode)
        {
            List<Object> objects = new List<Object>();
            foreach (XmlNode objectNode in xmlNode.SelectNodes(OBJECT))
            {
                string id = objectNode.Attributes[ID].Value;
                string name = objectNode.Attributes[NAME].Value;
                string videoFile = objectNode.Attributes[FILENAME].Value;
                string objectType = objectNode.Attributes[OBJECT_TYPE].Value;
                string generate = objectNode.Attributes[GENERATE].Value;
                int borderSize = Int32.Parse(objectNode.Attributes[BORDER_SIZE].Value);
                Color color = Color.FromArgb(Int32.Parse(objectNode.Attributes[COLOR].Value));
                string shape = objectNode.Attributes[SHAPE].Value;
                String semanticType = objectNode.Attributes[SEMANTIC_TYPE].Value;

                Object o = null;

                try
                {
                    Type t = Type.GetType(shape);
                    if (t.IsSubclassOf(typeof(Object)))
                    {
                        o = (Object)Activator.CreateInstance(t, currentSession, id, color, borderSize, videoFile);
                    }
                    else
                    {
                        Console.WriteLine("One object could not be parsed. Id = " + id);
                        continue;
                    }
                }
                catch (Exception e)
                {
                    if (shape == "Rectangle")
                    {
                        o = new RectangleObject(currentSession, id, color, borderSize, videoFile);
                    }
                    else if (shape == "Polygon")
                    {
                        o = new PolygonObject(currentSession, id, color, borderSize, videoFile);
                    }
                }



                o.name = name;
                o.semanticType = semanticType;
                o.genType = (GenType)Enum.Parse(typeof(GenType), generate.ToUpper());
                o.objectType = (ObjectType)Enum.Parse(typeof(ObjectType), "_" + objectType.ToUpper());

                foreach (XmlAttribute attr in objectNode.Attributes)
                {
                    if (!(new List<String> { ID, NAME, FILENAME, OBJECT_TYPE, GENERATE, BORDER_SIZE, COLOR, SEMANTIC_TYPE, SHAPE }).Contains(attr.Name))
                    {
                        o.addProperty(attr.Name, attr.Value);
                    }
                }

                readMarkers(objectNode, o);
                o.readLinks(objectNode);

                objects.Add(o);
            }

            int performerCount = 1;
            // Add performer names to RigObject
            foreach (var o in objects)
            {
                if (o is RigObject)
                {
                    o.name = "Performer " + performerCount++;
                }
            }

            return objects;
        }