private Transform NewShape() { // Get random number based on available shapes list count int shapeNum = Random.Range(0, app.model.game.availableShapes.Count); // Grab shape data ShapeModel shapeData = app.model.game.availableShapes[shapeNum]; // Create new transform Transform shape = new GameObject(shapeData.name).transform; Material targetMat = CubeMat(); // Create cubes & set color for (int i = 0; i < shapeData.blocksPositions.Length; i++) { // Create cube Transform cube = Instantiate(app.model.game.cubePrefab, shape.transform).transform; // Place cube based on data cube.localPosition = shapeData.blocksPositions[i]; Material[] mats = new Material[2]; mats[0] = app.model.game.cubeSquaresMatt; mats[1] = targetMat; cube.GetComponent <MeshRenderer>().materials = mats; } return(shape); }
public void GetOrderdShapeModelTest(int modelCount) { //assign var finder = new ShapeFinder(); var random = new Random(); double[] row = new double[modelCount]; double[] col = new double[modelCount]; double[] angle = new double[modelCount]; double[] score = new double[modelCount]; row = row.Select(p => random.NextDouble()).ToArray(); col = col.Select(p => random.NextDouble()).ToArray(); angle = angle.Select(p => random.NextDouble()).ToArray(); score = score.Select(p => random.NextDouble()).ToArray(); var model = new ShapeModel() { ModelId = new HalconDotNet.HTuple(), Row = new HalconDotNet.HTuple(row), Col = new HalconDotNet.HTuple(col), Angle = new HalconDotNet.HTuple(angle), Score = new HalconDotNet.HTuple(score), }; var colMin = model.Col.DArr.Min(); //act var orderedModel = finder.GetOrderdShapeModel(model); //assert Assert.True(colMin == orderedModel.Col[0].D); }
/// <summary> /// Method <c>GameTimer_Tick()</c> /// Represents the that should happen every timer tick. /// Ex: the _shape should move down if it can, if not a new shape /// is generated at the top. /// Checks for game over condition and calls the method that clears full /// rows. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void GameTimer_Tick(object sender, EventArgs e) { _shape.MoveDown(); if (!_shape.ValidMoveDown() && !_gameOver) { _shape.MarkPosition(); _shape = _nextShape; _shape.CenterShape(); NextBlock.Clear(); _nextShape = _shapeFactory.BuildRandomShape(); NextBlock.AddRange(_nextShape.ShapeBlocks); Blocks.AddRange(_shape.ShapeBlocks); if (GameOverCondition()) { _gameOver = true; _timer.Stop(); GameOver gameOverWindow = new GameOver(); gameOverWindow.ShowDialog(); } CheckForPoints(); } }
/// <summary> /// Method <c> RestartGame</c> Restarts the game, setting all state to default, /// and clears all items that would be bound to the gui. /// </summary> public void RestartGame() { // reset game variables _timeInterval = 500; _gameOver = false; _paused = false; PauseMessage = ""; Score = 0; Level = 1; // clear collections Blocks.Clear(); NextBlock.Clear(); HeldBlock.Clear(); GameBoard.ClearGrid(); _timer.Interval = new TimeSpan(0, 0, 0, 0, _timeInterval); // create shapes _shape = _shapeFactory.BuildRandomShape(); _nextShape = _shapeFactory.BuildRandomShape(); NextBlock.AddRange(_nextShape.ShapeBlocks); Blocks.AddRange(_shape.ShapeBlocks); _timer.Start(); }
private ShapeMatchResult FindShapeModel() { HImage img = OnGetImage(); if (img == null) { throw new Exception("匹配错误,图片无效"); } shapeXLDModel.InputImg.Dispose(); shapeXLDModel.InputImg = img; shapeXLDModel.FindModel(); if (shapeXLDModel.OutputResult.Count > 0) { if (calibratePPControl != null) { ShapeModel.dev_display_shape_matching_results( calibratePPControl.HWindowControl.HalconWindow, shapeXLDModel.shapeModel, "green", shapeXLDModel.OutputResult.Row, shapeXLDModel.OutputResult.Col, shapeXLDModel.OutputResult.Angle, shapeXLDModel.OutputResult.Scale, shapeXLDModel.OutputResult.Scale, 0); calibratePPControl.HWindowControl.HalconWindow.DispCross(shapeXLDModel.OutputResult.Row, shapeXLDModel.OutputResult.Col, 30, shapeXLDModel.OutputResult.Angle); } } return(shapeXLDModel.OutputResult); }
public T[] Interects(ShapeModel shape, float margin = 0.1f) { var intersections = Shapes.Where(i => i.Geometry.Intersects(shape.Geometry)); var validGeoms = new List <T>(); foreach (var geo in intersections) { if (geo.Geometry.IsValid) { if (geo.Geometry.Covers(shape.Geometry) || shape.Geometry.Covers(geo.Geometry)) { validGeoms.Add(geo); } else { var inter = geo.Geometry.Intersection(shape.Geometry); if (!inter.IsEmpty) { if (inter.Area >= Math.Min(shape.Geometry.Area, geo.Geometry.Area) * margin) { validGeoms.Add(geo); } } } } else { validGeoms.Add(geo); } } return(validGeoms.ToArray()); }
ShapeModel smodel; //shape model #endregion Fields #region Constructors public FaceTracker(string filepath) { points = new List<Point[]> (); string jsonText = null; using (System.IO.StreamReader reader = new System.IO.StreamReader(filepath)) { jsonText = reader.ReadToEnd (); reader.Close (); } // TextAsset textAsset = Resources.Load (filename) as TextAsset; // string jsonText = textAsset.text; IDictionary json = (IDictionary)Json.Deserialize (jsonText); IDictionary ft = (IDictionary)json ["ft object"]; detector = new FaceDetector (); detector.read (ft ["detector"]); smodel = new ShapeModel (); smodel.read (ft ["smodel"]); pmodel = new PatchModels (); pmodel.read (ft ["pmodel"]); }
PatchModels pmodel; //feature detectors public FaceTracker (string filepath) { points = new List<Point[]> (); string jsonText = null; #if UNITY_WSA var data = File.ReadAllBytes(filepath); jsonText = Encoding.UTF8.GetString(data, 0, data.Length); #else jsonText = File.ReadAllText(filepath); #endif // TextAsset textAsset = Resources.Load (filename) as TextAsset; // string jsonText = textAsset.text; IDictionary json = (IDictionary)Json.Deserialize (jsonText); IDictionary ft = (IDictionary)json ["ft object"]; detector = new FaceDetector (); detector.read (ft ["detector"]); smodel = new ShapeModel (); smodel.read (ft ["smodel"]); pmodel = new PatchModels (); pmodel.read (ft ["pmodel"]); }
/// <summary> /// Render the shape /// </summary> /// <param name="position"></param> /// <param name="series"></param> /// <param name="items"></param> /// <returns></returns> public override void CreateItem(int position, string series, IList <IPointModel> items) { var currentModel = GetModel(position, series, items); if (currentModel?.Point == null) { return; } var size = Panel.W / (Composer.MaxIndex - Composer.MinIndex) / 3; var shapeModel = new ShapeModel { Size = 1, Color = currentModel.Color ?? Color }; var points = new Point[] { Composer.GetPixels(Panel, position, currentModel.Point), Composer.GetPixels(Panel, position, currentModel.Point), Composer.GetPixels(Panel, position, currentModel.Point) }; points[0].Y -= size * currentModel.Direction; points[1].X += size; points[2].X -= size; Panel.CreateShape(points, shapeModel); }
PatchModels pmodel; //feature detectors public FaceTracker(string filepath) { points = new List <Point[]> (); string jsonText = null; using (System.IO.StreamReader reader = new System.IO.StreamReader(filepath)) { jsonText = reader.ReadToEnd(); reader.Close(); } // TextAsset textAsset = Resources.Load (filename) as TextAsset; // string jsonText = textAsset.text; IDictionary json = (IDictionary)Json.Deserialize(jsonText); IDictionary ft = (IDictionary)json ["ft object"]; detector = new FaceDetector(); detector.read(ft ["detector"]); smodel = new ShapeModel(); smodel.read(ft ["smodel"]); pmodel = new PatchModels(); pmodel.read(ft ["pmodel"]); }
PatchModels pmodel; //feature detectors public FaceTracker(string filepath) { points = new List <Point[]> (); string jsonText = null; #if UNITY_WSA var data = File.ReadAllBytes(filepath); jsonText = Encoding.UTF8.GetString(data, 0, data.Length); #else jsonText = File.ReadAllText(filepath); #endif // TextAsset textAsset = Resources.Load (filename) as TextAsset; // string jsonText = textAsset.text; IDictionary json = (IDictionary)Json.Deserialize(jsonText); IDictionary ft = (IDictionary)json ["ft object"]; detector = new FaceDetector(); detector.read(ft ["detector"]); smodel = new ShapeModel(); smodel.read(ft ["smodel"]); pmodel = new PatchModels(); pmodel.read(ft ["pmodel"]); }
public override void UpdateShape() { var shapeModel = new ShapeModel { Size = 1, Color = Color }; var pointMin = new Point(0, 0); var pointMax = new Point(0, 0); foreach (var level in IndexLevels) { var pixelLevel = Composer.GetPixels(Panel, level, 0); pointMin.X = pointMax.X = pixelLevel.X; pointMin.Y = 0; pointMax.Y = Panel.H; Panel.CreateLine(pointMin, pointMax, shapeModel); } foreach (var level in ValueLevels) { var pixelLevel = Composer.GetPixels(Panel, 0, level); pointMin.Y = pointMax.Y = pixelLevel.Y; pointMin.X = 0; pointMax.X = Panel.W; Panel.CreateLine(pointMin, pointMax, shapeModel); } }
void Save(ShapeModel shape) { using (ShapeDBContext db = new ShapeDBContext()) { db.Shapes.Add(shape); db.SaveChanges(); } }
/// <summary> /// Adds the row to the top /// </summary> /// <param name="shapeModel">The shape model.</param> public static void AddRowTop(this ShapeModel shapeModel) { var maxColumns = shapeModel.LastColumn(); shapeModel.Blocks.ForEach(b => b.Row = b.Row + 1); for (var col = 0; col < maxColumns; col++) { var newBlock = BlockModel.Create(col + 1, 1); shapeModel.Blocks.Add(newBlock); } }
private void Frm_CheckStick_Load(object sender, EventArgs e) { hWndCtrller = new HWndCtrllerEx(hWindowControl1); hWndCtrller.ChangeGraphicSettings("DrawMode", "margin"); hWndCtrller.ChangeGraphicSettings("Color", "green"); ((HWndCtrllerEx)hWndCtrller).Paint += Frm_CheckStick_Paint; hWindowControl1.SizeChanged += (s, ev) => { hWndCtrller.Repaint(); }; hWindowControl1.HMouseMove += HWindowControl1_HMouseMove; hWindowControl1.HMouseUp += HWindowControl1_HMouseUp; hWindowControl1.HMouseWheel += HWindowControl1_HMouseWheel; hWndCtrller.RegisterROICtroller(ctrller); ShapeModel model = VisionProject.Instance.visionTool.checkStick.Location; if (model.ModelImg != null && model.ModelImg.IsInitialized()) { hWndCtrller.AddIconicVar(model.ModelImg.Clone()); hWndCtrller.Repaint(); } hWindowControl1.HalconWindow.SetColor("blue"); foreach (var item in VisionProject.Instance.visionTool.checkStick.CheckRegion) { if (item != null && item.IsInitialized()) { this.hWindowControl1.HalconWindow.DispObj(item); } } trackBar1.Value = (int)VisionProject.Instance.visionTool.checkStick.Threshold; DrawRegionCtrlFlag = 0; if (VisionProject.Instance.visionApi.CheckStick.Count == 4) { label3.Text = string.Format("上:X={0:0.00},Y={1:0.00},R={2:0.00}", VisionProject.Instance.visionApi.CheckStick[0].X, VisionProject.Instance.visionApi.CheckStick[0].Y, VisionProject.Instance.visionApi.CheckStick[0].R); label5.Text = string.Format("下:X={0:0.00},Y={1:0.00},R={2:0.00}", VisionProject.Instance.visionApi.CheckStick[1].X, VisionProject.Instance.visionApi.CheckStick[1].Y, VisionProject.Instance.visionApi.CheckStick[1].R); label4.Text = string.Format("左:X={0:0.00},Y={1:0.00},R={2:0.00}", VisionProject.Instance.visionApi.CheckStick[2].X, VisionProject.Instance.visionApi.CheckStick[2].Y, VisionProject.Instance.visionApi.CheckStick[2].R); label6.Text = string.Format("右:X={0:0.00},Y={1:0.00},R={2:0.00}", VisionProject.Instance.visionApi.CheckStick[3].X, VisionProject.Instance.visionApi.CheckStick[3].Y, VisionProject.Instance.visionApi.CheckStick[3].R); } }
public Broadcaster() { _hubContext = GlobalHost.ConnectionManager.GetHubContext <MoveShapeHub>(); _model = new ShapeModel(); _modelUpdated = false; var broadcastLoop = new Timer( BroadcastShape, null, _broadcastInterval, _broadcastInterval ); }
/// <summary> /// Adds the column. /// </summary> /// <param name="shapeModel">The shape model.</param> public static void AddColumnLeft(this ShapeModel shapeModel) { var maxRow = shapeModel.LastRow(); shapeModel.Blocks.ForEach(b => b.Column = b.Column + 1); for (var row = 0; row < maxRow; row++) { var newBlock = BlockModel.Create(1, row + 1); shapeModel.Blocks.Add(newBlock); } }
private void SetTempleteModel(ShapeModel shape, HImage img) { if (img != null) { if (shape.InputImg != null) { shape.InputImg.Dispose(); } shape.InputImg = img; shape.ShowSetting(); } }
protected override ValidationResult IsValid(object value, ValidationContext validationContext) { ShapeModel model = (ShapeModel)validationContext.ObjectInstance; for (int i = 0; i < ids.Length; i++) { if (model.ShapeTypeId.Equals(ids[i]) && IsEven(model.Height)) { return(new ValidationResult(messages[i])); } } return(null); }
/// <summary> /// Adds the column. /// </summary> /// <param name="shapeModel">The shape model.</param> public static void AddColumnRight(this ShapeModel shapeModel) { var maxRow = shapeModel.LastRow(); var maxColumns = shapeModel.LastColumn(); var newColumn = maxColumns + 1; for (var row = 0; row < maxRow; row++) { var newBlock = BlockModel.Create(newColumn, row + 1); shapeModel.Blocks.Add(newBlock); } }
/// <summary> /// Adds the row at the bottom /// </summary> /// <param name="shapeModel">The shape model.</param> public static void AddRowBottom(this ShapeModel shapeModel) { var maxRow = shapeModel.LastRow(); var maxColumns = shapeModel.LastColumn(); var newRow = maxRow + 1; for (var col = 0; col < maxColumns; col++) { var newBlock = BlockModel.Create(col + 1, newRow); shapeModel.Blocks.Add(newBlock); } }
public ActionResult Save(ShapeViewModel viewModel) { ShapeModel shape = viewModel.Shape; if (ModelState.IsValid) { ShapeModel newShape = new ShapeModel { ShapeTypeId = shape.ShapeTypeId, Height = shape.Height, Label = shape.Label, LabelRow = shape.LabelRow }; Save(shape); } return(View("Index", viewModel)); }
/// <summary> /// Processes the supplied shape, setting properties on the shape as required. /// </summary> /// <param name="shape">The <see cref="Shape"/> which is to be represented in the worksheet</param> /// <param name="shapeModel">The <see cref="ShapeModel"/> which models the instance of the <see cref="DrawingSpreadsheet.Shape">OpenXML shape</see> in the Excel workbook</param> private static void ProcessDynamicShape(Shape shape, ShapeModel shapeModel) { if (shapeModel == null) { throw new ArgumentNullException("shapeModel"); } System.Windows.Media.Color?fillColour = BindingContainer.ConvertToNullableColour(shape.FillColour); if (fillColour.HasValue) { UpdateShapeFillColour(shapeModel.Shape, fillColour.Value); } }
public ShapeModel CalculateArea(ShapeModel objShape) { double Area = 0; if (objShape != null) { int D1 = Convert.ToInt32(objShape.Dimension1); if (objShape.Shape == Convert.ToInt32(ShapeEnum.Square)) { Area = (D1 * D1); } else if (objShape.Shape == Convert.ToInt32(ShapeEnum.Rectangle)) { int D2 = Convert.ToInt32(objShape.Dimension2); Area = (D1 * D2); } else if (objShape.Shape == Convert.ToInt32(ShapeEnum.Triangle)) { int D2 = Convert.ToInt32(objShape.Dimension2); Area = (D1 * D2) / 2; } else if (objShape.Shape == Convert.ToInt32(ShapeEnum.Circle)) { Area = PI * (D1 * D1); } else if (objShape.Shape == Convert.ToInt32(ShapeEnum.Sector)) { int D2 = Convert.ToInt32(objShape.Dimension2); Area = ((D1 * D1) * D2) / 2; } else if (objShape.Shape == Convert.ToInt32(ShapeEnum.Eclipse)) { int D2 = Convert.ToInt32(objShape.Dimension2); Area = PI * (D1 * D2); } else if (objShape.Shape == Convert.ToInt32(ShapeEnum.Trapezoid)) { int D2 = Convert.ToInt32(objShape.Dimension2); int D3 = Convert.ToInt32(objShape.Dimension3); Area = ((D1 + D2) * D3) / 2; } else if (objShape.Shape == Convert.ToInt32(ShapeEnum.Parallelogram)) { int D2 = Convert.ToInt32(objShape.Dimension2); Area = (D1 * D2); } objShape.Area = "Area of " + (ShapeEnum)objShape.Shape + " is " + Convert.ToString(Area) + "."; } return(objShape); }
ShapeModel Last() { ShapeModel shape = new ShapeModel { }; using (ShapeDBContext db = new ShapeDBContext()) { if (db.Shapes.Count() > 0) { shape = db.Shapes.ToList().Last <ShapeModel>(); } } return(shape); }
public Broadcaster() { // Save our hub context so we can easily use it // to send to its connected clients _hubContext = GlobalHost.ConnectionManager.GetHubContext <MoveShapeHub>(); _model = new ShapeModel(); _modelUpdated = false; // Start the broadcast loop _broadcastLoop = new Timer( BroadcastShape, null, BroadcastInterval, BroadcastInterval); }
/// <summary> /// Crops the image. /// </summary> /// <param name="shapeModel">The shape model.</param> public static void CropImage(this ShapeModel shapeModel) { var rowsToRemove = shapeModel.GetRowsToRemove(); var columnsToRemove = shapeModel.GetColumnsToRemove(); foreach (var row in rowsToRemove) { shapeModel.RemoveRow(row); } foreach (var column in columnsToRemove) { shapeModel.RemoveColumn(column); } }
public static ShapeModel CreateTestShapeModelWith1Edge() { List <ShapeEdge> edges = new List <ShapeEdge>(); edges.Add(new ShapeEdge(0, 1)); List <ShapeEdgeParams> edgeParams = new List <ShapeEdgeParams>(); edgeParams.Add(new ShapeEdgeParams(0.15, 0.05)); Dictionary <Tuple <int, int>, ShapeEdgePairParams> edgePairParams = new Dictionary <Tuple <int, int>, ShapeEdgePairParams>(); return(ShapeModel.Create(new ShapeStructure(edges), edgeParams, edgePairParams, 0, 40, 10)); }
static ShapeModel CreateSimpleShapeModel1() { List <ShapeEdge> edges = new List <ShapeEdge>(); edges.Add(new ShapeEdge(0, 1)); List <ShapeEdgeParams> edgeParams = new List <ShapeEdgeParams>(); edgeParams.Add(new ShapeEdgeParams(0.2, 0.1)); Dictionary <Tuple <int, int>, ShapeEdgePairParams> edgePairParams = new Dictionary <Tuple <int, int>, ShapeEdgePairParams>(); return(ShapeModel.Create(new ShapeStructure(edges), edgeParams, edgePairParams)); }
private static void TestMeanShapeImpl(ShapeModel shapeModel, double eps) { Size imageSize = new Size(100, 160); Shape meanShape = shapeModel.FitMeanShape(imageSize.Width, imageSize.Height); // Check GDT vs usual approach double energy = TestShapeEnergyCalculationApproachesImpl( shapeModel, meanShape.VertexPositions, meanShape.EdgeWidths, imageSize, 3501, 1001, eps); // Check if energy is zero Assert.AreEqual(0, energy, eps); // Check if shape is inside given rect); foreach (Vector vertex in meanShape.VertexPositions) Assert.IsTrue(new RectangleF(0, 0, imageSize.Width, imageSize.Height).Contains((float)vertex.X, (float)vertex.Y)); }
private void button7_Click(object sender, EventArgs e) { HImage hImage = VisionProject.Instance.Camera[0].GetCurrentImage(); ctrller.Reset(); hWndCtrller.AddIconicVar(hImage.Clone()); DrawRegionCtrlFlag = 0; hWndCtrller.Repaint(); ShapeModel model = VisionProject.Instance.visionTool.checkStick.Location; if (model.InputImg != null) { model.InputImg.Dispose(); } model.InputImg = hImage; }
/// <summary> /// validate user data and return details of Shape if validation is valid /// </summary> /// <param name="userInput"></param> /// <returns></returns> public ShapeModel ValidateData(string userInput) { ShapeModel model = new ShapeModel(); try { bool isValidRequiredStatement, isValidOptionalStatement = true; if (userInput.Split(" ").Length >= 8) { var splitStatement = userInput.Split("and"); isValidRequiredStatement = ValidateRequiredStatement(splitStatement[0].Trim()); if (splitStatement.Length > 1) { for (int j = 1; j < splitStatement.Length; j++) { isValidOptionalStatement = ValidateAdditionalStatement(splitStatement[j].Trim()); if (!isValidOptionalStatement) { break; } } } if (isValidRequiredStatement && isValidOptionalStatement) { model = GetShapeDetails(splitStatement); } else { model.ErrorMessage = ErrorConstants.inValidInput; } } else { model.ErrorMessage = ErrorConstants.inValidInput; } } catch (Exception ex) { model.ErrorMessage = $"{ErrorConstants.UnhandledError} {ex.Message}"; } return(model); }
public void TestLengthAngleRepresentation() { ShapeModel model = TestHelper.CreateLetterShapeModel(); Shape meanShape = model.FitMeanShape(100, 100); ShapeLengthAngleRepresentation lengthAngleRepresentation = meanShape.GetLengthAngleRepresentation(); Shape meanShape2 = model.BuildShapeFromLengthAngleRepresentation(lengthAngleRepresentation); for (int i = 0; i < model.Structure.VertexCount; ++i) { Assert.AreEqual(meanShape.VertexPositions[i].X, meanShape2.VertexPositions[i].X, 1e-6); Assert.AreEqual(meanShape.VertexPositions[i].Y, meanShape2.VertexPositions[i].Y, 1e-6); } for (int i = 0; i < model.Structure.Edges.Count; ++i) { Assert.AreEqual(meanShape.EdgeWidths[i], meanShape2.EdgeWidths[i], 1e-6); } }
private static double TestShapeEnergyCalculationApproachesImpl( ShapeModel model, IEnumerable<Vector> vertices, IEnumerable<double> edgeWidths, Size imageSize, int lengthGridSize, int angleGridSize, double eps) { // Create shape model and calculate energy in normal way Shape shape = new Shape(model.Structure, vertices, edgeWidths); double energy1 = model.CalculateEnergy(shape); // Calculate energy via generalized distance transforms ShapeConstraints constraints = ShapeConstraints.CreateFromShape(shape); ShapeEnergyLowerBoundCalculator calculator = new ShapeEnergyLowerBoundCalculator(lengthGridSize, angleGridSize); double energy2 = calculator.CalculateLowerBound(imageSize, model, constraints); Assert.AreEqual(energy1, energy2, eps); return energy1; }
private static void TestShapeTermsImpl(string testName, ShapeModel shapeModel, IEnumerable<VertexConstraints> vertexConstraints, IEnumerable<EdgeConstraints> edgeConstraints, Size imageSize) { ShapeConstraints constraintSet = ShapeConstraints.CreateFromConstraints(shapeModel.Structure, vertexConstraints, edgeConstraints); // Get CPU results Image2D<ObjectBackgroundTerm> shapeTermsCpu = new Image2D<ObjectBackgroundTerm>(imageSize.Width, imageSize.Height); CpuShapeTermsLowerBoundCalculator calculatorCpu = new CpuShapeTermsLowerBoundCalculator(); calculatorCpu.CalculateShapeTerms(shapeModel, constraintSet, shapeTermsCpu); Image2D.SaveToFile(shapeTermsCpu, -1000, 1000, String.Format("./{0}_cpu.png", testName)); // Get GPU results Image2D<ObjectBackgroundTerm> shapeTermsGpu = new Image2D<ObjectBackgroundTerm>(imageSize.Width, imageSize.Height); GpuShapeTermsLowerBoundCalculator calculatorGpu = new GpuShapeTermsLowerBoundCalculator(); calculatorGpu.CalculateShapeTerms(shapeModel, constraintSet, shapeTermsGpu); Image2D.SaveToFile(shapeTermsGpu, -1000, 1000, String.Format("./{0}_gpu.png", testName)); // Compare with CPU results for (int x = 0; x < imageSize.Width; ++x) for (int y = 0; y < imageSize.Height; ++y) { Assert.AreEqual(shapeTermsCpu[x, y].ObjectTerm, shapeTermsGpu[x, y].ObjectTerm, 1e-2f); Assert.AreEqual(shapeTermsCpu[x, y].BackgroundTerm, shapeTermsGpu[x, y].BackgroundTerm, 1e-2f); } }
private void OnLearnShapeModelButtonClick(object sender, RoutedEventArgs e) { this.shapeModel = ShapeModel.Learn( from imageInfo in this.imageInfos select imageInfo.Shape.FitToSize(this.algorithmProperties.LearnedObjectSize, this.algorithmProperties.LearnedObjectSize), this.shapeModel.ConstrainedEdgePairs); for (int i = 0; i < this.shapeModel.Structure.Edges.Count; ++i) { ShapeEdgeParams @params = this.shapeModel.GetEdgeParams(i); LogMessage("Edge {0}: mean width ratio is {1:0.000}, deviation is {2:0.000}", i, @params.WidthToEdgeLengthRatio, @params.WidthToEdgeLengthRatioDeviation); } foreach (Tuple<int, int> constrainedEdgePair in this.shapeModel.ConstrainedEdgePairs) { ShapeEdgePairParams @params = this.shapeModel.GetEdgePairParams( constrainedEdgePair.Item1, constrainedEdgePair.Item2); LogMessage("Edge pair ({0}, {1}):", constrainedEdgePair.Item1, constrainedEdgePair.Item2); LogMessage("mean length ratio is {0}, deviation is {1}", @params.MeanLengthRatio, @params.LengthDiffDeviation); LogMessage("mean angle is {0}, deviation is {1}", @params.MeanAngle, @params.AngleDeviation); } }
private void OnLoadShapeModelButtonClick(object sender, RoutedEventArgs e) { OpenFileDialog openDialog = new OpenFileDialog(); openDialog.Filter = "Shape models|*.shp"; openDialog.RestoreDirectory = true; bool? result = openDialog.ShowDialog(); if (result != true) return; this.shapeModel = ShapeModel.LoadFromFile(openDialog.FileName); for (int i = 0; i < imageInfos.Count; ++i) { Shape meanShape = this.shapeModel.FitMeanShape(imageInfos[i].Image.PixelWidth, imageInfos[i].Image.PixelHeight); imageInfos[i].Shape = meanShape; } this.UpdateControlsAccordingToCurrentState(); }
public void UpdateModel(ShapeModel shapeModel) { Clients.AllExcept(Context.ConnectionId).updateShape(shapeModel); }
public void UpdateModel(ShapeModel clienteModel) { clienteModel.LastUpdateBy = Context.ConnectionId; Clients.AllExcept(clienteModel.LastUpdateBy).updateShape(clienteModel); }