before candybox editor update
This commit is contained in:
76
Plugins/CandyboxPlugin/Forms/MapEditor.cs
Normal file
76
Plugins/CandyboxPlugin/Forms/MapEditor.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using CandyboxPlugin.Recipe;
|
||||
using MaterialSkin.Controls;
|
||||
using OpenCvSharp;
|
||||
using OpenCvSharp.Extensions;
|
||||
using Point = OpenCvSharp.Point;
|
||||
|
||||
namespace Lindt.Candybox.Demo
|
||||
{
|
||||
public partial class MapEditor : MaterialForm
|
||||
{
|
||||
private readonly Mat _original;
|
||||
private HistoRecipe _recipe;
|
||||
|
||||
public MapEditor(Mat original, HistoRecipe currentRecipe)
|
||||
{
|
||||
_original = original;
|
||||
InitializeComponent();
|
||||
|
||||
_recipe = currentRecipe.Clone();
|
||||
|
||||
_recipe.ProcessImage(original);
|
||||
|
||||
Mat matContours2;
|
||||
if (_recipe.LearnedParameters.CandyParameters.Count==0)
|
||||
{
|
||||
Mat matContours = new Mat(new OpenCvSharp.Size(512, 512), MatType.CV_8UC3, Scalar.Black);
|
||||
Cv2.DrawContours(matContours, _recipe.LastContours, -1, Scalar.White, -1);
|
||||
|
||||
matContours2 = matContours.Resize(new OpenCvSharp.Size(1800, 1408));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
Mat matContours = new Mat(new OpenCvSharp.Size(512, 512), MatType.CV_8UC3, Scalar.Black);
|
||||
Cv2.DrawContours(matContours, _recipe.LastContours, -1, Scalar.White, -1);
|
||||
|
||||
matContours2 = matContours.Resize(new OpenCvSharp.Size(1800, 1408));
|
||||
|
||||
}
|
||||
|
||||
udMemoryBuffer.Value = _recipe.LearnedParameters.Configuration.MemoryBuffer;
|
||||
|
||||
|
||||
maskControl1.Mask = matContours2.ToBitmap();
|
||||
maskControl1.Original = original.Clone().ToBitmap();
|
||||
}
|
||||
|
||||
private void materialRaisedButton3_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<Point[]> contours = new List<Point[]>();
|
||||
foreach (Point[] contour in maskControl1.LastContours)
|
||||
{
|
||||
contours.Add(contour.Select(x => new Point(x.X/1800f*512f, x.Y / 1408f * 512f)).ToArray());
|
||||
}
|
||||
|
||||
_recipe.LearnedParameters.Configuration.MemoryBuffer = (int)udMemoryBuffer.Value;
|
||||
_recipe.LearnContours(contours.ToArray(), _original);
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
}
|
||||
|
||||
private void materialRaisedButton1_Click(object sender, EventArgs e)
|
||||
{
|
||||
DialogResult = DialogResult.Cancel;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user