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(); }
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(); }
public FxContour(FxMatrixMask mask, int minPix = 0, int maxPix = int.MaxValue) { int maskSize = mask.Width * mask.Height; var stack = new Stack<Tuple<int, int>>(1000); var remainMask = mask.Copy(); var labelMap = new FxMatrixF(mask.Width, mask.Height); ChainList = new List<FxContourChain>(); int labelCount = 1; var maskG = mask.ToFxMatrixF().Gradient(FxMatrixF.GradientMethod.Roberts) > 0; for (int i = 1; i < maskSize - 1; i++) { /* check if we have edge */ if (maskG[i]) { int x; int y = Math.DivRem(i, mask.Width, out x); labelMap[x, y] = labelCount; maskG[x, y] = false; // create a new chain FxContourChain newChain = new FxContourChain(x, y); /* propacate the search in sub pixels */ Labeling_addStack(stack, x, y); while (stack.Count > 0) { var dxy = stack.Pop(); x = dxy.Item1; y = dxy.Item2; if (x < 1 || (x >= mask.Width - 1) || y < 1 || (y >= mask.Height - 1)) continue; if (maskG[x, y] && check(maskG, x, y)) { // add the labeling labelMap[x, y] = labelCount; maskG[x, y] = false; // add the new point to the chain newChain.PushPoint(x, y); Labeling_addStack(stack, x, y); } } labelCount++; // calc boundary rect // add the new chain to the list ChainList.Add(newChain); } } // filter the chain based on min/max size if (minPix != 0 || maxPix != int.MaxValue) { List<FxContourChain> tmpChainList = ChainList; ChainList = new List<FxContourChain>(); foreach(FxContourChain c in tmpChainList) { if (c.Count > minPix && c.Count < maxPix) ChainList.Add(c); } } }