public Form1() { InitializeComponent(); resize = new FxVector2f(targetRes.x / (float)origRes.x, targetRes.y / (float)origRes.y); // create a shop shopPlan = FxMatrixF.Load("Katopsi.jpg", ColorSpace.Grayscale); shopPlan = shopPlan.Resize(targetRes.x, targetRes.y); shop = new Shop("Unisol", shopPlan); // simulation = new SimulationSimple(shop, 10, simulationMethod1); simulationMethod2_Setup(); simulation = new SimulationSimple(shop, 1, simulationMethod2); // Defind entrance for the shop shop.entrancePositionsDirection.Add(new Tuple<FxVector2f, FxVector2f>(new FxVector2f(1800 * resize.x, 500 * resize.y), new FxVector2f(-1, 0))); // load a person image for the moving image imPerson = FxMatrixF.Load("person.jpg", ColorSpace.Grayscale); // imPerson.Exec(x => (x > 0.1) ? 0 : 1); imPerson.MedianFilt(); imPersonMask = imPerson < 0.5f; // Init the matrix to be HD mat = new FxMatrixF(targetRes.x, targetRes.y); mat.DrawMatrix(shopPlan, new FxVector2f(0, 0), new FxVector2f(mat.Width, mat.Height), FxMatrixF.DrawInterpolationMethod.NearestNeighbor); // Add image element to canvas to showing the matrix im = new ImageElement(mat); canvas1.AddElement(im, true); }
public SerialInput() { InitializeComponent(); // init the serial port serialPort = new SerialPort(); // Set the read/write timeouts serialPort.ReadTimeout = -1; serialPort.WriteTimeout = -1; serialPort.Parity = Parity.None; serialPort.DataBits = 8; serialPort.StopBits = StopBits.Two; serialPort.Handshake = Handshake.None; serialPort.NewLine = "\r\n"; // Linked to ui console uiconsole = MainForm.UIConsole; if (isColor) { imageMask = new FxMatrixMask(64, 64); } imageMask = new FxMatrixMask(64, 64); imageMaskColorMap = new ColorMap(ColorMapDefaults.Jet); // Create a visual view imageMaskView = new ImageElement(imageMask.ToFxMatrixF(), imageMaskColorMap); canvas1.AddElement(imageMaskView, false); imageView = new ImageElement(imageMask.ToFxMatrixF(), imageMaskColorMap); imageView._Position.x = imageMaskView.Size.X + 10f; imageView._Position.Y = 0; canvas1.AddElement(imageView, false); canvas1.FitView(); // add the timer for the fps measure fpsTimer = new System.Windows.Forms.Timer(); fpsTimer.Interval = 1000; watch.Start(); fpsTimer.Tick += (s, te) => { watch.Stop(); float fps = fpsCount * 1000.0f / watch.ElapsedMilliseconds; //uiconsole.WriteLine("FPS:" + fps.ToString()); //Console.WriteLine("FPS:" + fps.ToString()); fpsLabel.Text = fps.ToString(); fpsCount = 0; watch.Reset(); watch.Start(); }; fpsTimer.Start(); }
private void button1_Click(object sender, EventArgs e) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // load the image that the user have select FxImages im = FxTools.FxImages_safe_constructors(new Bitmap(openFileDialog1.FileName)); // create a new image element ImageElement imE = new ImageElement(im); // add the element on canva canvas1.AddElement(imE); } }
public PeopleOverview(FxMatrixF im) { InitializeComponent(); // add building ImageElement ie = new ImageElement(im, new ColorMap(ColorMapDefaults.Bones)); ie.Name = "Katopsi"; ie.lockMoving = true; canvas1.AddElement(ie); // add geometry plot gpe = new GeometryPlotElement(); gpe.Name = "People"; gpe.lockMoving = true; canvas1.AddElement(gpe); }
public SerialCapture() { InitializeComponent(); LoadConfigurations(); imageMask = new FxMatrixMask(64, 64); imageMaskColorMap = new ColorMap(ColorMapDefaults.Jet); // Create a visual view imageMaskView = new ImageElement(imageMask.ToFxMatrixF(), imageMaskColorMap); canvas1.AddElement(imageMaskView, false); imageView = new ImageElement(imageMask.ToFxMatrixF(), imageMaskColorMap); imageView._Position.x = imageMaskView.Size.X + 10f; imageView._Position.Y = 0; canvas1.AddElement(imageView, false); canvas1.FitView(); }
protected override void Show(IDialogVisualizerService windowService, IVisualizerObjectProvider objectProvider) { object obj = objectProvider.GetObject(); FxMatrixF mat; if (obj is FxMatrixF || obj is FxMatrix<float>) mat = obj as FxMatrixF; else if (obj is FxMatrixMask) mat = (obj as FxMatrixMask).ToFxMatrixF(); else return; /* Form form = new Form(); form.Text = string.Format("Width: {0}, Height: {1}", mat.Width, mat.Height); form.ClientSize = new Size(mat.Width, mat.Height); form.FormBorderStyle = FormBorderStyle.FixedToolWindow; */ Canvas canvas = new Canvas(); canvas.Dock = DockStyle.Fill; canvas.Location = new System.Drawing.Point(0, 0); canvas.Margin = new System.Windows.Forms.Padding(4); canvas.Name = "canvas1"; canvas.Size = new System.Drawing.Size(mat.Width, mat.Height+32); canvas.MinimumSize = new System.Drawing.Size(mat.Width, mat.Height + 32); canvas.Zoom = new System.Drawing.SizeF(1F, 1F); ImageElement im = new ImageElement(mat, new global::FxMaths.Images.ColorMap(global::FxMaths.Images.ColorMapDefaults.Jet)); canvas.AddElement(im); canvas.FitView(); //form.Controls.Add(canvas); //form.Show(); windowService.ShowDialog(canvas); }
private void KinectForm_Load(object sender, EventArgs e) { // Look through all sensors and start the first connected one. // This requires that a Kinect is connected at the time of app startup. // To make your app robust against plug/unplug, // it is recommended to use KinectSensorChooser provided in Microsoft.Kinect.Toolkit foreach(var potentialSensor in KinectSensor.KinectSensors) { if(potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if(null == this.sensor) { this.Text = "No kinnect Ready"; return; } Size depthImageSize = GetImageSize(DepthFormat); depthWidth = (int)depthImageSize.Width; depthHeight = (int)depthImageSize.Height; Size colorImageSize = GetImageSize(ColorFormat); colorWidth = (int)colorImageSize.Width; colorHeight = (int)colorImageSize.Height; // Turn on the depth and color streams to receive frames sensor.DepthStream.Enable(DepthFormat); sensor.ColorStream.Enable(ColorFormat); sensor.DepthStream.Range = DepthRange.Near; frameDataLength = sensor.DepthStream.FramePixelDataLength; sensor.AllFramesReady += sensor_AllFramesReady; int depthImageArraySize = depthWidth * depthHeight; int colorImageArraySize = colorWidth * colorHeight * sizeof(int); // Create local color pixels buffer colorImagePixels = new byte[colorImageArraySize]; // Create local depth pixels buffer depthImagePixels = new DepthImagePixel[depthImageArraySize]; // Allocate the depth-color mapping points colorCoordinates = new ColorImagePoint[depthImageArraySize]; // allocate the Matrix colorImageMatrix = new FxMatrixF(colorWidth, colorHeight); depthImageMatrix = new FxMatrixF(depthWidth, depthHeight); depthImageMatrixAve = new FxMatrixF(depthWidth, depthHeight); // create a new image element colorImageElement = new ImageElement(colorImageMatrix); depthImageElement = new ImageElement(depthImageMatrix); depthImageElement.MouseClickEvent += depthImageElement_MouseClickEvent; canvas1.AddElements(colorImageElement,false); canvas1.AddElements(depthImageElement, false); depthImageElement.Position = new FxMaths.Vector.FxVector2f(colorWidth, 0); G = new FxMatrixMask(depthWidth, depthHeight, false); s = new FxMatrixF(depthWidth, depthHeight, 1f); m = new FxMatrixF(depthWidth, depthHeight, 1f); // init the dispatcher class dispatcher = Dispatcher.CurrentDispatcher; // Start the sensor! try { this.sensor.Start(); } catch(IOException ex) { // Device is in use this.sensor = null; this.Text = ex.Message; return; } catch(InvalidOperationException ex) { // Device is not valid, not supported or hardware feature unavailable this.sensor = null; this.Text = ex.Message; return; } // Initialize and start the FPS timer this.fpsTimer = new DispatcherTimer(); this.fpsTimer.Tick += new EventHandler(this.FpsTimerTick); this.fpsTimer.Interval = new TimeSpan(0, 0, 1); this.fpsTimer.Start(); this.lastFPSTimestamp = DateTime.UtcNow; }
private void ellipseDetectionToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // load image imMat = FxMatrixF.Load(ofd.FileName); ieEllipseImage = new ImageElement(imMat, new ColorMap(ColorMapDefaults.Jet)); ieEllipseImage.lockMoving = true; canvas_ellipse.AddElement(ieEllipseImage); // add plot element gpeEllipseImage = new GeometryPlotElement(); canvas_ellipse.AddElement(gpeEllipseImage); var contours = new FxContour(imMat<0.2f); WriteLine("Num Contours : " + contours.NumChains); int i = 0; float pe_pos_y = ieEllipseImage._Position.y; foreach (var cont in contours.ChainList) { // draw the rectanges in main image FxVector2f start = cont.RectStart ; FxVector2f end = start + cont.RectSize; FxMaths.Geometry.Rectangle r = new FxMaths.Geometry.Rectangle(start, end); gpeEllipseImage.AddGeometry(r, false); // draw the centroids FxVector2f cen = cont.GetCentroid(); var l = new FxMaths.Geometry.Line(cen - new FxVector2f(0, 2), cen + new FxVector2f(0, 2)); l.LineWidth = 0.5f; gpeEllipseImage.AddGeometry(l, false); l = new FxMaths.Geometry.Line(cen - new FxVector2f(2, 0), cen + new FxVector2f(2, 0)); l.LineWidth = 0.5f; gpeEllipseImage.AddGeometry(l, false); // add the numbering of the contours var t = new TextElement(i.ToString()); t._Position = cen; t.FontColor = SharpDX.Color.Green; t._TextFormat.fontSize = 16.0f; canvas_ellipse.AddElement(t); // show the chain vector in plot { FxVectorF vec_i = new FxVectorF(cont.Count); FxVectorF vec_r = new FxVectorF(cont.Count); vec_i[0] = cont[0].i; vec_r[0] = cont[0].r; for (int j = 1; j < cont.Count; j++) { vec_i[j] = vec_i[j - 1] + cont[j].i; vec_r[j] = vec_r[j - 1] + cont[j].r; } // show the plot of this vector var pe = new PloterElement(vec_i, PlotType.Lines, System.Drawing.Color.Blue); pe._Position.x = ieEllipseImage._Position.x + ieEllipseImage.Size.x; pe._Position.y = pe_pos_y; pe.AddPlot(vec_r, PlotType.Lines, System.Drawing.Color.Red); pe.CenterYOrigin(); pe.FitPlots(); canvas_ellipse.AddElement(pe); // update the y of pe for the next one pe_pos_y += pe.Size.y; // debug the ellipse for (int j = 0; j < cont.Count; j++) { imMat[(int)(vec_r[j] + cont.StartPoint.x), (int)(vec_i[j] + cont.StartPoint.y)] = 0.8f/contours.NumChains + 0.1f; } ieEllipseImage.UpdateInternalImage(imMat, new ColorMap(ColorMapDefaults.Jet)); } i++; } canvas_ellipse.ReDraw(); } }
private void toolStripButton_ellipse_extract_Click(object sender, EventArgs e) { // extract the rectangle that contain if ((imMat as object != null) && (rect != null)) { int numLabels; // get the sub matrix var subMat = imMat.GetSubMatrix(rect.StartPoint, rect.EndPoint) as FxMatrixF; // make binary the image based on the start and end point of rectangle float t = subMat[0, 0]; if (t > subMat[subMat.Width - 1, subMat.Height - 1]) t = subMat[subMat.Width - 1, subMat.Height - 1]; var binMat = subMat < t - 0.02f; // find the labels of the image var labels = binMat.Labeling(out numLabels); var imSub = new ImageElement(binMat.ToFxMatrixF(), new ColorMap(ColorMapDefaults.Jet)); imSub._Position.x = ieEllipseImage.Size.x + ieEllipseImage.Position.x; imSub.lockMoving = true; canvas_ellipse.AddElement(imSub, false, false); var imSub2 = new ImageElement(labels, new ColorMap(ColorMapDefaults.Jet)); imSub2._Position.x = ieEllipseImage.Size.x + ieEllipseImage.Position.x; imSub2._Position.y = imSub.Size.y + imSub.Position.y; imSub2.lockMoving = true; canvas_ellipse.AddElement(imSub2, false, false); WriteLine("Num Labels : " + numLabels.ToString()); var contours = new FxContour(binMat, 10, 300); WriteLine("Num Contours : " + contours.NumChains); results = new FxMatrixF(3, contours.NumChains); int i=0; foreach (var x in contours.ChainList) { float delta = 1; // draw the rectanges in the sub image FxVector2f start = x.RectStart + imSub2._Position + new FxVector2f(1, 1); FxVector2f end = start + x.RectSize; FxMaths.Geometry.Rectangle r = new FxMaths.Geometry.Rectangle(start, end); gpeEllipseImage.AddGeometry(r, false); // draw the rectanges in main image start = x.RectStart + rect.StartPoint + new FxVector2f(-delta, -delta); end = start + x.RectSize + new FxVector2f(2 * delta, 2 * delta); r = new FxMaths.Geometry.Rectangle(start, end); gpeEllipseImage.AddGeometry(r, false); // draw the centroids FxVector2f cen = x.GetCentroid() + rect.StartPoint; var l = new FxMaths.Geometry.Line(cen - new FxVector2f(0, 2), cen + new FxVector2f(0, 2)); l.LineWidth = 0.5f; gpeEllipseImage.AddGeometry(l, false); l = new FxMaths.Geometry.Line(cen - new FxVector2f(2, 0), cen + new FxVector2f(2, 0)); l.LineWidth = 0.5f; gpeEllipseImage.AddGeometry(l, false); // calculate the depth float[] depth = new float[4]; FxVector2f pos = x.RectStart + rect.StartPoint; depth[0] = imMat[pos.x - delta, pos.y - delta]; depth[1] = imMat[pos.x + x.RectSize.x + delta, pos.y - delta]; depth[2] = imMat[pos.x - delta, pos.y + x.RectSize.y + delta]; depth[3] = imMat[pos.x + x.RectSize.x + delta, pos.y + x.RectSize.y + delta]; results[2, i] = (depth[0] + depth[1] + depth[2] + depth[3]) / 4.0f; // save centroid results[0, i] = cen.x; results[1, i] = cen.y; // print the centroid WriteLine("[" + i.ToString() + "] Depth:" + results[2, i].ToString() + " Pixels:" + x.Count + " Centroid: " + cen.ToString()); i++; // show the vector of one blob if (i == 1) { FxVectorF vec_i = new FxVectorF(x.Count); FxVectorF vec_r = new FxVectorF(x.Count); vec_i[0] = x[0].i; vec_r[0] = x[0].r; for (int j = 1; i < x.Count; j++) { vec_i[j] = vec_i[j - 1] + x[j].i; vec_r[j] = vec_r[j - 1] + x[j].r; } } } canvas_ellipse.ReDraw(); results.SaveCsv("ellipseResults.csv"); } }
FxMatrixF results = null; // Results of centers private void toolStripButton_EllipseOpenImage_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); if(ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { imMat = FxMatrixF.LoadCsv(ofd.FileName); ieEllipseImage = new ImageElement(imMat, new ColorMap(ColorMapDefaults.Jet)); ieEllipseImage.lockMoving = true; canvas_ellipse.AddElement(ieEllipseImage); } }
public KinectV2Form(Engine engine) { InitializeComponent(); #if false // save localy the graphic engine this.engine = engine; // set the first viewport RenderArea_Viewport = new GraphicsEngine.Core.Viewport(RenderArea.Width, RenderArea.Height, RenderArea.Handle, Format.R8G8B8A8_UNorm); ViewportManager.AddViewport(RenderArea_Viewport); // set the moving camera Engine.g_MoveCamera = RenderArea_Viewport.m_Camera; #endif // allocate the Matrix colorImageMatrix = new FxMatrixF(640, 480); depthImageMatrix = new FxMatrixF(640, 480); depthImageMatrixAve = new FxMatrixF(640, 480); // create a new image element colorImageElement = new ImageElement(colorImageMatrix); depthImageElement = new ImageElement(depthImageMatrix); canvas1.AddElement(colorImageElement, false); canvas1.AddElement(depthImageElement, false); }
private void addImageToolStripMenuItem_Click(object sender, EventArgs e) { Viewport2D viewport = null; if (dockPanel1.ActiveContent is Viewport2D) { viewport = (Viewport2D)dockPanel1.ActiveContent; } else if (dockPanel1.ActiveDocument is Viewport2D) { viewport = (Viewport2D)dockPanel1.ActiveDocument; } if (viewport != null) { if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { // load the image that the user have select FxImages im = FxTools.FxImages_safe_constructors(new Bitmap(openFileDialog1.FileName)); // create a new image element ImageElement imE = new ImageElement(im); // add the element on canva viewport.AddElement(imE); } } }