protected override void loadObjectAdditionalFromXml(XmlNode objectNode) { XmlNode markersNode = objectNode.SelectSingleNode(MARKERS); if (markersNode == null) return; foreach (XmlNode markerNode in markersNode.SelectNodes(MARKER)) { int frame = int.Parse(markerNode.Attributes[FRAME].Value); String markType = markerNode.Attributes[TYPE].Value; switch (markType.ToUpper()) { case "LOCATION": var lm = new PolygonLocationMark2D(frame, new List<PointF>()); lm.readFromXml(markerNode); this.setBounding(frame, lm); break; case "DELETE": this.delete(frame); break; } } XmlNode markers3DNodes = objectNode.SelectSingleNode(MARKERS3D); if (markers3DNodes != null) foreach (XmlNode markerNode in markers3DNodes.SelectNodes(MARKER)) { int frame = int.Parse(markerNode.Attributes[FRAME].Value); var lm = new PolygonLocationMark3D(frame, new List<Point3>()); lm.readFromXml(markerNode); set3DBounding(frame, lm); } }
public override float Score(Point testPoint) { float score = 0; var rigJoints = rigFigure.rigJoints.Values.Cast<PointF>().ToList(); if (rigJoints.Count != 0) { var convexHull = Utils.getConvexHull(rigJoints); PolygonLocationMark2D temp = new PolygonLocationMark2D(frameNo, convexHull); return temp.Score(testPoint); } return score; }
private void cancelDrawing() { newObjectContextPanel.Visible = false; if (drawingButtonSelected[rectangleDrawing]) { //startPoint = new Point(); //endPoint = new Point(); boundingBoxLocationMark = new RectangleLocationMark(-1, new RectangleF()); startPoint = null; drawingNewRectangle = false; } if (drawingButtonSelected[polygonDrawing]) { polygonPointsLocationMark = new PolygonLocationMark2D(-1, new List<PointF>()); drawingNewPolygon = editingPolygon = false; } draggingSelectBoxes = false; selectBoxes = new List<RectangleF>(); invalidatePictureBoard(); }
//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); }
private void doneEditPolygon() { polygonPointsLocationMark = new PolygonLocationMark2D(-1, new List<PointF>()); drawingNewPolygon = editingPolygon = false; }
public void setBounding(int frameNumber, List<PointF> boundingPolygon, float scale, PointF translation) { List<PointF> inverseScaleBoundingPolygon = boundingPolygon.scaleBound(1 / scale, new PointF(-translation.X / scale, -translation.Y / scale)); var ob = new PolygonLocationMark2D(frameNumber, inverseScaleBoundingPolygon); objectMarks[frameNumber] = ob; }
public void setCopyBounding(int frameNumber) { int nextMarker = objectMarks.Keys.FirstOrDefault(x => x > frameNumber); // Forward copy if (nextMarker > 0) { if (objectMarks[nextMarker].GetType() == typeof(RectangleLocationMark)) { var ob = new RectangleLocationMark(frameNumber, ((RectangleLocationMark)objectMarks[nextMarker]).boundingBox); objectMarks[frameNumber] = ob; } if (objectMarks[nextMarker].GetType() == typeof(PolygonLocationMark2D)) { var ob = new PolygonLocationMark2D(frameNumber, ((PolygonLocationMark2D)objectMarks[nextMarker]).boundingPolygon); objectMarks[frameNumber] = ob; } return; } // Backward copy try { int prevMarker = objectMarks.Keys.Last(x => x < frameNumber && objectMarks[x].GetType() != typeof(DeleteLocationMark)); if (objectMarks[prevMarker].GetType() == typeof(RectangleLocationMark)) { var ob = new RectangleLocationMark(frameNumber, ((RectangleLocationMark)objectMarks[nextMarker]).boundingBox); objectMarks[frameNumber] = ob; } if (objectMarks[prevMarker].GetType() == typeof(PolygonLocationMark2D)) { var ob = new PolygonLocationMark2D(frameNumber, ((PolygonLocationMark2D)objectMarks[nextMarker]).boundingPolygon); objectMarks[frameNumber] = ob; } return; } catch (InvalidOperationException exc) { Console.WriteLine(exc); } }
private void pictureBoardPaintOnVideoFile(PaintEventArgs e) { try { if (videoReader != null && currentSession != null) { calculateLinear(); foreach (Object o in currentSession.getObjects()) { if (o != selectedObject || o.genType != Object.GenType.MANUAL) { Pen p = new Pen(o.color, o.borderSize); p.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; LocationMark2D r = o.getScaledLocationMark(frameTrackBar.Value, scale, translation); if (r != null) { // Clip to upper body for Rig object if (r is RigLocationMark2D) { switch (options.showRigOption) { case Options.ShowRig.SHOW_UPPER: r = ((RigLocationMark2D)r).getUpperBody(); break; } } r.drawOnGraphics(e.Graphics, p); } } } if (selectedObject != null) { LocationMark lm = null; if (!editingAtAFrame) { lm = selectedObject.getScaledLocationMark(frameTrackBar.Value, 1, new PointF()); } else { if (selectedObject is RectangleObject) { lm = boundingBoxLocationMark.getScaledLocationMark(1, new PointF()); } if (selectedObject is PolygonObject) { lm = polygonPointsLocationMark.getScaledLocationMark(1, new PointF()); } } if (lm != null) { if (selectedObject is RectangleObject) { boundingBoxLocationMark = lm as RectangleLocationMark; } if (selectedObject is PolygonObject) { polygonPointsLocationMark = lm as PolygonLocationMark2D; selectBoxes = (polygonPointsLocationMark.getScaledLocationMark(scale, translation) as PolygonLocationMark2D).getCornerSelectBoxes(boxSize); calculateCentroid(); } } else { if (selectedObject is RectangleObject) { boundingBoxLocationMark = new RectangleLocationMark(-1, new RectangleF()); selectBoxes = new List<RectangleF>(); } if (selectedObject is PolygonObject) { polygonPointsLocationMark = new PolygonLocationMark2D(-1, new List<PointF>()); selectBoxes = new List<RectangleF>(); calculateCentroid(); } } } Pen pen = null; if (selectedObject == null) { pen = new Pen(boundingColor, (float)boundingBorder); } else { pen = new Pen(selectedObject.color, selectedObject.borderSize); } pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash; // Currently drawing or selecting a rectangle object if (drawingButtonSelected[rectangleDrawing] || (selectedObject != null && selectedObject is RectangleObject)) { if (videoReader != null) { //float lowerX = Math.Min(startPoint.Value.X, endPoint.Value.X); //float lowerY = Math.Min(startPoint.Value.Y, endPoint.Value.Y); //float higherX = Math.Max(startPoint.Value.X, endPoint.Value.X); //float higherY = Math.Max(startPoint.Value.Y, endPoint.Value.Y); //RectangleF boundingBox = new RectangleF(lowerX, lowerY, higherX - lowerX, higherY - lowerY); //boundingBoxLocationMark = new RectangleLocationMark(-1, boundingBox).getScaledLocationMark(1 / scale, // new PointF(-translation.X / scale, -translation.Y / scale)) as RectangleLocationMark; RectangleF boundingBox = (boundingBoxLocationMark.getScaledLocationMark(scale, translation) as RectangleLocationMark).boundingBox; selectBoxes = boundingBox.getCornerSelectBoxes(boxSize); e.Graphics.DrawRectangle(pen, boundingBox); foreach (RectangleF r in selectBoxes) { e.Graphics.DrawRectangle(new Pen(Color.Black), r); e.Graphics.FillRectangle(new SolidBrush(Color.White), r); } } } if (polygonPointsLocationMark == null) { polygonPointsLocationMark = new PolygonLocationMark2D(-1, new List<PointF>()); } var polygonPoints = new List<PointF>(); polygonPoints = (polygonPointsLocationMark.getScaledLocationMark(scale, translation) as PolygonLocationMark2D).boundingPolygon; // Currently drawing or selecting a polygon object if (drawingButtonSelected[polygonDrawing] || (selectedObject != null && selectedObject is PolygonObject)) { if (drawingNewPolygon) { if (temporaryPoint.HasValue && polygonPoints.Count != 0) { polygonPoints.Add(temporaryPoint.Value); e.Graphics.DrawPolygon(pen, ((List<PointF>)polygonPoints).ToArray()); polygonPoints.Remove(temporaryPoint.Value); } } else { if (polygonPoints.Count != 0) { e.Graphics.DrawPolygon(pen, ((List<PointF>)polygonPoints).ToArray()); } for (int index = 0; index < selectBoxes.Count(); index++) { RectangleF r = selectBoxes[index]; e.Graphics.DrawRectangle(new Pen(Color.Black), r); if (draggingSelectBoxes && index == draggingSelectBoxIndex) { e.Graphics.FillRectangle(new SolidBrush(Color.Turquoise), r); } else { e.Graphics.FillRectangle(new SolidBrush(Color.White), r); } } if (editingAtAFrame) { if (!centroid.Equals(new Point())) { Pen dashedPen = new Pen(Color.Black); dashedPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot; Pen normalPen = new Pen(Color.Black); switch (centroidMode) { case CentroidMode.Dragging: e.Graphics.DrawLine(normalPen, centroid.X - centroidRadius + 4, centroid.Y, centroid.X + centroidRadius - 4, centroid.Y); e.Graphics.DrawLine(normalPen, centroid.X, centroid.Y - centroidRadius + 4, centroid.X, centroid.Y + centroidRadius - 4); e.Graphics.DrawEllipse(new Pen(Color.LightGray), centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius); e.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(150, 100, 100, 100)), centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius); break; case CentroidMode.Rotating: e.Graphics.DrawLine(normalPen, centroid.X - 3 * centroidRadius, centroid.Y, centroid.X + 3 * centroidRadius, centroid.Y); e.Graphics.DrawLine(normalPen, centroid.X, centroid.Y - centroidRadius + 4, centroid.X, centroid.Y + centroidRadius - 4); e.Graphics.DrawEllipse(new Pen(Color.LightGray), centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius); e.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(150, 100, 100, 100)), centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius); break; case CentroidMode.Zooming: e.Graphics.DrawLine(normalPen, centroid.X - centroidRadius, centroid.Y, centroid.X + centroidRadius, centroid.Y); e.Graphics.DrawLine(normalPen, centroid.X, centroid.Y - centroidRadius, centroid.X, centroid.Y + centroidRadius); e.Graphics.DrawLine(dashedPen, centroid.X - 2 * centroidRadius, centroid.Y, centroid.X, centroid.Y - 2 * centroidRadius); e.Graphics.DrawLine(dashedPen, centroid.X - 2 * centroidRadius, centroid.Y, centroid.X, centroid.Y + 2 * centroidRadius); e.Graphics.DrawLine(dashedPen, centroid.X + 2 * centroidRadius, centroid.Y, centroid.X, centroid.Y - 2 * centroidRadius); e.Graphics.DrawLine(dashedPen, centroid.X + 2 * centroidRadius, centroid.Y, centroid.X, centroid.Y + 2 * centroidRadius); e.Graphics.DrawEllipse(new Pen(Color.LightGray), centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius); e.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(150, 100, 100, 100)), centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius); break; case CentroidMode.None: e.Graphics.DrawLine(normalPen, centroid.X - centroidRadius + 4, centroid.Y, centroid.X + centroidRadius - 4, centroid.Y); e.Graphics.DrawLine(normalPen, centroid.X, centroid.Y - centroidRadius + 4, centroid.X, centroid.Y + centroidRadius - 4); e.Graphics.DrawEllipse(new Pen(Color.LightGray), centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius); e.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(50, 100, 100, 100)), centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius); break; } } } } } // Selecting other kind of objects if (selectedObject != null && !(selectedObject is PolygonObject) && !(selectedObject is RectangleObject)) { LocationMark2D lm = selectedObject.getScaledLocationMark(frameTrackBar.Value, scale, translation); if (lm != null) { selectBoxes = lm.getCornerSelectBoxes(boxSize); foreach (RectangleF r in selectBoxes) { e.Graphics.DrawRectangle(new Pen(Color.Black), r); e.Graphics.FillRectangle(new SolidBrush(Color.White), r); } } } } } catch (Exception exp) { Console.WriteLine(exp); } }
private void pictureBoard_MouseMove(object sender, MouseEventArgs e) { if (currentSession == null) return; // These two lines should be together if (videoReader == null && depthReader == null) return; calculateLinear(); var boundingBox = (boundingBoxLocationMark.getScaledLocationMark(scale, translation) as RectangleLocationMark).boundingBox; var endPoint = new PointF(boundingBox.X + boundingBox.Width, boundingBox.Y + boundingBox.Height); if (drawingButtonSelected[rectangleDrawing] && drawingNewRectangle) { endPoint = e.Location; boundingBoxLocationMark = new RectangleLocationMark(-1, getRectangleFromStartAndEndPoint(startPoint.Value.scalePoint(scale, translation), endPoint)). getScaledLocationMark(1 / scale, new PointF(-translation.X / scale, -translation.Y / scale)) as RectangleLocationMark; invalidatePictureBoard(); return; } if (drawingButtonSelected[rectangleDrawing] || (selectedObject != null && selectedObject is RectangleObject)) { if (draggingSelectBoxes) { switch (draggingSelectBoxIndex) { // The first four case are corners // Use e.Location as 1 corner and use another box center point as the opposite corner case 0: startPoint = e.Location; endPoint = selectBoxes[3].getCenter(); this.Cursor = Cursors.SizeNWSE; break; case 1: startPoint = e.Location; endPoint = selectBoxes[2].getCenter(); this.Cursor = Cursors.SizeNESW; break; case 2: startPoint = e.Location; endPoint = selectBoxes[1].getCenter(); this.Cursor = Cursors.SizeNESW; break; case 3: startPoint = e.Location; endPoint = selectBoxes[0].getCenter(); this.Cursor = Cursors.SizeNWSE; break; case 4: startPoint = new PointF(selectBoxes[0].getCenter().X, e.Location.Y); endPoint = selectBoxes[3].getCenter(); this.Cursor = Cursors.SizeNS; break; case 5: startPoint = new PointF(selectBoxes[1].getCenter().X, e.Location.Y); endPoint = selectBoxes[2].getCenter(); this.Cursor = Cursors.SizeNS; break; case 6: startPoint = new PointF(e.Location.X, selectBoxes[2].getCenter().Y); endPoint = selectBoxes[3].getCenter(); this.Cursor = Cursors.SizeWE; break; case 7: startPoint = new PointF(e.Location.X, selectBoxes[3].getCenter().Y); endPoint = selectBoxes[0].getCenter(); this.Cursor = Cursors.SizeWE; break; // Center point case 8: startPoint = new PointF(e.Location.X - (selectBoxes[2].X - selectBoxes[1].X) / 2, e.Location.Y - (selectBoxes[1].Y - selectBoxes[0].Y) / 2); endPoint = new PointF(e.Location.X + (selectBoxes[2].X - selectBoxes[1].X) / 2, e.Location.Y + (selectBoxes[1].Y - selectBoxes[0].Y) / 2); this.Cursor = Cursors.Hand; break; } boundingBoxLocationMark = new RectangleLocationMark(-1, getRectangleFromStartAndEndPoint(startPoint.Value, endPoint)). getScaledLocationMark(1 / scale, new PointF(-translation.X / scale, -translation.Y / scale)) as RectangleLocationMark; invalidatePictureBoard(); } else { this.Cursor = Cursors.Default; } } if (drawingButtonSelected[polygonDrawing]) { if (drawingNewPolygon) { temporaryPoint = e.Location; invalidatePictureBoard(); } } if (drawingButtonSelected[polygonDrawing] || (selectedObject != null && selectedObject is PolygonObject)) { if (draggingSelectBoxes) { polygonPointsLocationMark.boundingPolygon[draggingSelectBoxIndex] = e.Location.scalePoint(1 / scale, new PointF(-translation.X / scale, -translation.Y / scale)); selectBoxes[draggingSelectBoxIndex] = new Rectangle(e.Location.X - (boxSize - 1) / 2, e.Location.Y - (boxSize - 1) / 2, boxSize, boxSize); calculateCentroid(); invalidatePictureBoard(); return; } // polygonPoints are real coordinates on pictureBoard var polygonPoints = new List<PointF>(); polygonPoints.AddRange(polygonPointsLocationMark.boundingPolygon); polygonPoints = polygonPoints.Select(value => value.scalePoint(scale, translation)).ToList(); switch (centroidMode) { case CentroidMode.Dragging: { PointF oldCentroid = getCentroid(polygonPoints); PointF dragTranslation = new PointF(e.Location.X - oldCentroid.X, e.Location.Y - oldCentroid.Y); for (int i = 0; i < polygonPoints.Count; i++) { polygonPoints[i] = new PointF(polygonPoints[i].X + dragTranslation.X, polygonPoints[i].Y + dragTranslation.Y); } centroid = e.Location; List<RectangleF> listOfSelectBox = new List<RectangleF>(); foreach (PointF p in polygonPoints) { listOfSelectBox.Add(new RectangleF(p.X - (boxSize - 1) / 2, p.Y - (boxSize - 1) / 2, boxSize, boxSize)); } selectBoxes = listOfSelectBox; invalidatePictureBoard(); break; } case CentroidMode.Rotating: { // Using the difference on vertical direction to measure rotating angle float verticalDiff = centroid.Y - e.Location.Y; float alpha = verticalDiff / 180; for (int i = 0; i < polygonPoints.Count; i++) { PointF rotateTranslation = new PointF(tempoPolygonPoints[i].X - centroid.X, tempoPolygonPoints[i].Y - centroid.Y); PointF rotatedTranslation = new PointF((float)(rotateTranslation.X * Math.Cos(alpha) - rotateTranslation.Y * Math.Sin(alpha)) , (float)(rotateTranslation.X * Math.Sin(alpha) + rotateTranslation.Y * Math.Cos(alpha))); polygonPoints[i] = new PointF(centroid.X + rotatedTranslation.X, centroid.Y + rotatedTranslation.Y); } selectBoxes = (polygonPointsLocationMark.getScaledLocationMark(scale, translation) as PolygonLocationMark2D).getCornerSelectBoxes(boxSize); break; } case CentroidMode.Zooming: { // Using the difference on vertical direction to measure zooming scale float verticalDiff = centroid.Y - e.Location.Y; float alpha = verticalDiff / 100; for (int i = 0; i < polygonPoints.Count; i++) { PointF zoomTranslation = new PointF(tempoPolygonPoints[i].X - centroid.X, tempoPolygonPoints[i].Y - centroid.Y); PointF scaledTranslation = new PointF((float)(zoomTranslation.X * Math.Exp(alpha)) , (float)(zoomTranslation.Y * Math.Exp(alpha))); polygonPoints[i] = new PointF(centroid.X + scaledTranslation.X, centroid.Y + scaledTranslation.Y); } selectBoxes = (polygonPointsLocationMark.getScaledLocationMark(scale, translation) as PolygonLocationMark2D).getCornerSelectBoxes(boxSize); break; } case CentroidMode.None: break; } // Update polygonPointsLocationMark polygonPointsLocationMark = new PolygonLocationMark2D(polygonPointsLocationMark.frameNo, polygonPoints.Select(value => value.scalePoint(1 / scale, new PointF(-translation.X / scale, -translation.Y / scale))).ToList()); } if (drawingButtonSelected[zoomDrawing]) { whenZoomButtonAndMouseMove(e); } }