Exemplo n.º 1
0
 public static MatImage read(string path)
 {
     using (StreamReader sr = new StreamReader(path))
     {
         try
         {
             MatImage result = readSixLieHeader(sr);
             string   aLine  = sr.ReadLine().Trim();
             UpdateLoadState(0);
             for (int lineNum = 0; lineNum < result.nrows; lineNum++)      // !string.IsNullOrEmpty(aLine)
             {
                 string[] splitLine = aLine.Split('\t', ' ');
                 for (int j = 0; j < result.ncols; j++)
                 {
                     var it = splitLine[j];
                     if (!string.IsNullOrWhiteSpace(it))
                     {
                         result.data[lineNum][j] = Convert.ToDouble(it);
                     }
                 }
                 aLine = sr.ReadLine();
             }
             UpdateLoadState(1);
             return(result);
         }
         catch (Exception e)
         {
             UpdateLoadState(-1);
             App.Current.Dispatcher.Invoke(new Action(delegate()
             {
             }));
             return(null);
         }
     }
 }
Exemplo n.º 2
0
            private MaterialWidget(MaterialsWindow window, MatImage image)
            {
                _window = window;
                _image  = image;

                image.Click += ImageOnClick;
            }
Exemplo n.º 3
0
        /// <summary>
        /// 度数法表示
        /// </summary>
        /// <returns></returns>
        public MatImage calSlope()
        {
            MatImage slope = new MatImage(oMatImage.ncols, oMatImage.nrows, oMatImage.xllcorner, oMatImage.yllcorner, oMatImage.cellsize);

            for (int i = 1; i < oMatImage.nrows - 1; i++)
            {
                for (int j = 1; j < oMatImage.ncols - 1; j++)
                {
                    var value      = oMatImage.data[i][j];
                    var valueBefor = oMatImage.data[i][j - 1];
                    var valueAfter = oMatImage.data[i][j + 1];
                    var valueUp    = oMatImage.data[i - 1][j];
                    var valueDown  = oMatImage.data[i + 1][j];
                    if (value != oMatImage.NODATA_value &&
                        valueBefor != oMatImage.NODATA_value &&
                        valueAfter != oMatImage.NODATA_value &&
                        valueUp != oMatImage.NODATA_value &&
                        valueDown != oMatImage.NODATA_value &&
                        oMatImage.cellsize > 0)
                    {
                        var we = (valueBefor - valueAfter) / (2 * oMatImage.cellsize);
                        var sn = (valueDown - valueUp) / (2 * oMatImage.cellsize);
                        slope.data[i][j] = Math.Atan(Math.Sqrt(sn * sn + we * we)) * 180.0 / Math.PI;
                    }
                }
            }
            return(slope);
        }
Exemplo n.º 4
0
 public void Process(MatImage image)
 {
     foreach (var item in FrameProcesses)
     {
         item.Process(image);
     }
 }
Exemplo n.º 5
0
        public async Task TakeAsync()
        {
            GC.Collect();

            Stopwatch sw = new Stopwatch();

            System.Console.WriteLine("take");
            sw.Start();
            camera.ExposureTime = 400;
            var raw = await camera.TakeImageAsync();

            var frame = (Ncer.Camera.Frame)(raw.Clone());

            System.Console.WriteLine("take frame:" + sw.ElapsedMilliseconds + "ms");
            if (frame == null)
            {
                MessageBox.Show("no frame");
                return;
            }
            MatImage image = MatImage.CreateFromPtr(frame.Width, frame.Height, MatType.CV_16SC1, frame.Data);

            System.Console.WriteLine("create mat:" + sw.ElapsedMilliseconds + "ms");

            var img = Utils.MatToImageSource(image.Mat);

            System.Console.WriteLine("take img:" + sw.ElapsedMilliseconds + "ms");


            this.imageMain.Source = img.Clone();
            System.Console.WriteLine("show img:" + sw.ElapsedMilliseconds + "ms");
        }
Exemplo n.º 6
0
 private void Camera_OnCameraPreviewEvent(object sender, Ncer.Camera.Frame frame)
 {
     this.Dispatcher.Invoke(() =>
     {
         MatImage image        = MatImage.CreateFromPtr(frame.Width, frame.Height, MatType.CV_16UC1, frame.Data);
         var img               = Utils.MatToImageSource(image.Mat);
         this.imageMain.Source = img.Clone();
     });
 }
Exemplo n.º 7
0
 private void btnSlope_Click(object sender, RoutedEventArgs e)
 {
     if (matImage != null && matImage.data != null)
     {
         var slopeCal = new SlopeCal(matImage);
         slopeMatImage  = slopeCal.calSlope();
         imgMain.Tag    = slopeMatImage;
         imgMain.Source = slopeMatImage.ToBitMap(curCorlor);
         curLengend     = new LegendModel()
         {
             name = "坡度", lowValue = (int)slopeMatImage.minData, highVlaue = (int)slopeMatImage.maxData, colors = curCorlor
         };
         legend.setValue(curLengend);
     }
     else
     {
         MessageBox.Show("请先加载DEM数据");
     }
 }
Exemplo n.º 8
0
        private void InitializeUI()
        {
            _guiManager  = new GuiManager(GraphicsContext.WindowSize);
            _guiRenderer = new GuiRenderer(GraphicsContext, new Faceless());
            _guiLoader   = new XmlLoader(_guiManager);
            UVMapper.Register(_guiLoader);
            MatImage.Register(_guiLoader);

            ModelPartWindow     = new ModelPartWindow(_guiLoader.Load("modelEditorSelectedModelPart.xml", _guiManager.Desktop), _editor);
            ModelPartFaceWindow = new ModelPartFaceWindow(_guiLoader.Load("modelEditorSelectedModelPartFace.xml", _guiManager.Desktop), _editor);
            ButtonPanelWindow   = new ButtonPanelWindow(_guiLoader.Load("epicEditButtons.xml", _guiManager.Desktop), _editor);
            MaterialsWindow     = new MaterialsWindow(_guiLoader.Load("materialsWindow.xml", _guiManager.Desktop), _editor);
            AnchorWindow        = new AnchorWindow(_guiLoader.Load("modelEditorSelectedAnchor.xml", _guiManager.Desktop), _editor);
            AnimationWindow     = new AnimationWindow(_guiLoader.Load("animationWindow.xml", _guiManager.Desktop), _editor);

            _editor.EditMode = EditMode.Geometry;

            _guiManager.Desktop.Transparent = true;
            StaticTaskQueue.TaskQueue.CreateRepeatingTask("UpdateUI", _guiManager.Update, 20);
        }
Exemplo n.º 9
0
        public MatImage calAspect()
        {
            MatImage aspect = new MatImage(oMatImage.ncols, oMatImage.nrows, oMatImage.xllcorner, oMatImage.yllcorner, oMatImage.cellsize, -1);

            for (int i = 1; i < oMatImage.nrows - 1; i++)
            {
                for (int j = 1; j < oMatImage.ncols - 1; j++)
                {
                    var value      = oMatImage.data[i][j];
                    var valueBefor = oMatImage.data[i][j - 1];
                    var valueAfter = oMatImage.data[i][j + 1];
                    var valueUp    = oMatImage.data[i - 1][j];
                    var valueDown  = oMatImage.data[i + 1][j];
                    if (value != oMatImage.NODATA_value &&
                        valueBefor != oMatImage.NODATA_value &&
                        valueAfter != oMatImage.NODATA_value &&
                        valueUp != oMatImage.NODATA_value &&
                        valueDown != oMatImage.NODATA_value &&
                        oMatImage.cellsize > 0)
                    {
                        var we = (valueBefor - valueAfter) / (2 * oMatImage.cellsize);
                        var sn = (valueDown - valueUp) / (2 * oMatImage.cellsize);
                        var v  = Math.Atan2(sn, we) * 180.0 / Math.PI;
                        if (we == 0 && sn == 0)
                        {
                            v = aspect.NODATA_value;
                        }
                        else if (v < 0)
                        {
                            v += 360.0;
                        }
                        aspect.data[i][j] = v;
                    }
                }
            }
            return(aspect);
        }
Exemplo n.º 10
0
        private static MatImage readSixLieHeader(StreamReader sr)
        {
            try
            {
                string   r1 = sr.ReadLine();
                string   r2 = sr.ReadLine();
                string   r3 = sr.ReadLine();
                string   r4 = sr.ReadLine();
                string   r5 = sr.ReadLine();
                string   r6 = sr.ReadLine();
                string[] sparry;

                sparry = r1.Split(' ', '\t');
                int cols = Convert.ToInt32(sparry[sparry.Length - 1].Trim());
                sparry = r2.Split(' ', '\t');
                int rows = Convert.ToInt32(sparry[sparry.Length - 1].Trim());
                sparry = r3.Split(' ', '\t');
                double xllcorner = Convert.ToDouble(sparry[sparry.Length - 1].Trim());
                sparry = r4.Split(' ', '\t');
                double yllcorner = Convert.ToDouble(sparry[sparry.Length - 1].Trim());
                sparry = r5.Split(' ', '\t');
                double cellsize = Convert.ToDouble(sparry[sparry.Length - 1].Trim());
                sparry = r6.Split(' ', '\t');
                int noValue = Convert.ToInt32(sparry[sparry.Length - 1].Trim());

                var mi = new MatImage(cols, rows, noValue);
                mi.xllcorner = xllcorner;
                mi.yllcorner = yllcorner;
                mi.cellsize  = cellsize;
                return(mi);
            }
            catch (Exception ex)
            {
                MessageBox.Show("数据格式损坏" + ex.Message);
                return(null);
            }
        }
Exemplo n.º 11
0
 private void btnLoadFile_Click(object sender, RoutedEventArgs e)
 {
     System.Windows.Forms.OpenFileDialog oFileDialog = new System.Windows.Forms.OpenFileDialog();
     oFileDialog.Filter = "文本文件(*.asc)|*.asc|所有文件(*.*)|*.*";
     if (oFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         try
         {
             string filePath = oFileDialog.FileName;
             matImage       = ReadASCFile.read(filePath);
             imgMain.Tag    = matImage;
             imgMain.Source = matImage.ToBitMap(curCorlor);
             curLengend     = new LegendModel()
             {
                 name = "DEM", lowValue = (int)matImage.minData, highVlaue = (int)matImage.maxData, colors = curCorlor
             };
             legend.setValue(curLengend);
             btnEnableInit(true);
         }
         catch (Exception ex)
         {
         }
     }
 }
Exemplo n.º 12
0
 public void Process(MatImage image)
 {
     Cv2.MedianBlur(image.Mat, image.Mat, Ksize);
 }
Exemplo n.º 13
0
 public SlopeCal(MatImage origionMatImage)
 {
     oMatImage = origionMatImage;
 }
Exemplo n.º 14
0
 public void InitData()
 {
     this.image          = new MatImage();
     contrastTool        = new ContrastTool();
     imageProcessToolkit = new ImageProcessToolkit()
 }
Exemplo n.º 15
0
 public SaveMatImage(MatImage image)
 {
     matimage = image;
 }