Exemplo n.º 1
0
 public void Connect()
 {
     //Init teh Matlab
     matlab = new MLApp.MLApp();
     if (matlab.Visible != 1)
         matlab.MaximizeCommandWindow();
 }
Exemplo n.º 2
0
        private void _adicionalinha()
        {
            DirectoryInfo diretoria = new DirectoryInfo(@"C:\\Users\\Marcos\\Desktop\\PDI_Matriculas\\PDI\\PDI_Reconhecimento_de_Matriculas\\Matriculas");

            FileInfo[] ficheiros       = diretoria.GetFiles();
            string     NomeFicheiro    = "";
            int        lugar           = 1;
            string     NumeroMatricula = "";

            // Instância de MatLab
            MLApp.MLApp matlab = new MLApp.MLApp();

            try
            {
                foreach (FileInfo fich in ficheiros)
                {
                    //Nome da imagem a tratar
                    NomeFicheiro = fich.Name;

                    //Substitui a palavra "FICHEIROAQUI"
                    string text = File.ReadAllText(@"C:\\Users\\Marcos\\Desktop\\PDI_Matriculas\\PDI\\PDI_Reconhecimento_de_Matriculas\\extracaoMatricula.m");
                    text = text.Replace("FICHEIROAQUI", "Matriculas/" + NomeFicheiro);
                    File.WriteAllText(@"C:\\Users\\Marcos\\Desktop\\PDI_Matriculas\\PDI\\PDI_Reconhecimento_de_Matriculas\\extracaoMatricula.m", text);

                    //Executa a funcao
                    matlab.Execute(@"cd C:\Users\Marcos\Desktop\PDI_Matriculas\PDI\PDI_Reconhecimento_de_Matriculas\");
                    matlab.Execute("extracaoMatricula");
                    //matlab.Quit();

                    //Adiciona linhas à tabela
                    TableRow tRow = new TableRow();
                    TabelaParque.Rows.Add(tRow);

                    TableCell tCellImg = new TableCell();
                    tCellImg.Text = string.Format("<img src='/PDI_Reconhecimento_de_Matriculas/Matriculas/" + NomeFicheiro + "' style=\"height: 50px;\" />");
                    tRow.Cells.Add(tCellImg);

                    TableCell tCellLugar = new TableCell();
                    tCellLugar.Text = lugar.ToString();
                    tRow.Cells.Add(tCellLugar);
                    lugar++;

                    var data = File.ReadAllText(Server.MapPath("~/PDI_Reconhecimento_de_Matriculas/numeroMatricula.txt"));
                    NumeroMatricula = data.ToString();

                    TableCell tCellMatricula = new TableCell();
                    tCellMatricula.Text = NumeroMatricula;
                    tRow.Cells.Add(tCellMatricula);

                    //Substitui de novo para a palavra "FICHEIROAQUI"
                    string texto = File.ReadAllText(@"C:\\Users\\Marcos\\Desktop\\PDI_Matriculas\\PDI\\PDI_Reconhecimento_de_Matriculas\\extracaoMatricula.m");
                    texto = texto.Replace("Matriculas/" + NomeFicheiro, "FICHEIROAQUI");
                    File.WriteAllText(@"C:\\Users\\Marcos\\Desktop\\PDI_Matriculas\\PDI\\PDI_Reconhecimento_de_Matriculas\\extracaoMatricula.m", texto);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Exemplo n.º 3
0
        public void run_frame(List <float> vector = null, List <float> angles = null)
        {
            MLApp.MLApp matlab = new MLApp.MLApp();
            string      result;

            string arguments = "";


            arguments += "gradientdescent([ ";
            foreach (float point in vector)
            {
                arguments += point.ToString() + " ";
            }
            arguments += " ]";


            foreach (float angle in angles)
            {
                arguments += "," + angle.ToString();
            }
            arguments += ")";

            this.label1.Text = arguments;

            result            = matlab.Execute(arguments);
            this.label1.Text += "\n:" + result;
        }
Exemplo n.º 4
0
        private void Done(object sender, RoutedEventArgs e)
        {
            string imgPath = AppDomain.CurrentDomain.BaseDirectory + "instTest";
            //string imgPath = @"C:\Users\Won\Documents\instTest";

            int count = 1;

            foreach (ImagePreperationItem ipi in IpiList)
            {
                // identify chosen signal
                int    index      = ipi.SignalIndex;
                string signalSt   = SignalList[index];
                string signalName = SignalToNameDictionary[signalSt];
                ipi.SignalName = signalName;

                // Resize and locate image to MATLAB directory.
                IplImage img     = new IplImage(ipi.ImageName);
                CvSize   size    = new CvSize(ImgWidth, ImgHeight);
                IplImage resized = new IplImage(size, img.Depth, img.NChannels);
                Cv.Resize(img, resized);
                WriteableBitmap   rawImage = WriteableBitmapConverter.ToWriteableBitmap(resized);
                FileStream        fs       = new System.IO.FileStream(imgPath + @"\s1\" + count + ".jpg", System.IO.FileMode.Create);
                JpegBitmapEncoder pbe      = new JpegBitmapEncoder();
                pbe.Frames.Add(BitmapFrame.Create(rawImage));
                pbe.Save(fs);
                fs.Dispose();

                count++;
            }


            /*
             * MATLAB starts learning image
             */
            MLApp.MLApp matlab = new MLApp.MLApp();
            Console.WriteLine(@"cd '" + imgPath + "'");
            matlab.Execute(@"cd '" + imgPath + "'");

            // Define the output
            object result = null;

            int imgCount = count - 1;

            // Call the MATLAB function learning
            matlab.Feval("learning", 5, out result, imgCount);

            // Display result
            parameters = result as object[];

            ImageParameters[0] = imgCount;
            ImageParameters[1] = ImgWidth;
            ImageParameters[2] = ImgHeight;

            string savePath = AppDomain.CurrentDomain.BaseDirectory + "params";

            // Save parameters and IPI list into file.
            WriteoutIpiList();
            WriteoutMatlabPrams();
        }
Exemplo n.º 5
0
 public void Disconnect()
 {
     if (matlab != null)
     {
         matlab.Quit();
         matlab = null;
     }
 }
Exemplo n.º 6
0
        private void btnCalc_Click(object sender, RoutedEventArgs e)
        {
            MLApp.MLApp session = new MLApp.MLApp();
            MatLabController.AddMatLabFilesToPath(session);
            string      filePath = MatLabController.RunScript(session, GetInputs());
            Uri         imgUri   = new Uri(filePath);
            BitmapImage imgBmp   = new BitmapImage(imgUri);

            imgGraph.Source = imgBmp;
        }
Exemplo n.º 7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            var activationContext = Type.GetTypeFromProgID("matlab.application.single");

            matlab = (MLApp.MLApp)Activator.CreateInstance(activationContext);

            gestures = new int[numberOfGestures];
            Console.WriteLine(matlab.Execute(@"cd D:\Thesis\Autoencoder5layers\"));
            //Console.WriteLine(matlab.Execute("imageData1 = []"));
            Console.WriteLine(matlab.Execute(@"load('D:\Thesis\Autoencoder5layers\PredictFinalFiles.mat')"));
            matlab.Execute("se = serial('COM4','BaudRate',115200);");
            matlab.Execute("fopen(se)");
            Console.WriteLine(matlab.Execute("pwd"));
        }
Exemplo n.º 8
0
        static void plot(DiskSpace[] disk)
        {
            string address="[ ";
            string swinger="[ ";
            for (int i = 0; i < disk.Length; i++)
            {
                address += disk[i].diskAddress + " ";
                swinger += "-" + i + " ";
            }
            address += " ]";
            swinger += "]";
            MLApp.MLApp matlab = new MLApp.MLApp();

            matlab.Execute("plot("+address+","+swinger+")");
        }
Exemplo n.º 9
0
        static void plot(DiskSpace[] disk)
        {
            string address = "[ ";
            string swinger = "[ ";

            for (int i = 0; i < disk.Length; i++)
            {
                address += disk[i].diskAddress + " ";
                swinger += "-" + i + " ";
            }
            address += " ]";
            swinger += "]";
            MLApp.MLApp matlab = new MLApp.MLApp();

            matlab.Execute("plot(" + address + "," + swinger + ")");
        }
Exemplo n.º 10
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

            var activationContext = Type.GetTypeFromProgID("matlab.application.single");
            matlab = (MLApp.MLApp)Activator.CreateInstance(activationContext);

            gestures = new int[numberOfGestures];
            Console.WriteLine(matlab.Execute(@"cd D:\Thesis\Autoencoder5layers\"));
            //Console.WriteLine(matlab.Execute("imageData1 = []"));
            Console.WriteLine(matlab.Execute(@"load('D:\Thesis\Autoencoder5layers\PredictFinalFiles.mat')"));
           matlab.Execute("se = serial('COM4','BaudRate',115200);");
           matlab.Execute("fopen(se)");
            Console.WriteLine(matlab.Execute("pwd"));
            
            

        }
Exemplo n.º 11
0
        private void button1_Click(object sender, EventArgs e)
        {
            MLApp.MLApp matlab        = null;
            Type        matlabAppType = System.Type.GetTypeFromProgID("Matlab.Application");

            matlab = System.Activator.CreateInstance(matlabAppType) as MLApp.MLApp;
            string command;

            //  string a=textBox1.Text;
            //   string b=textBox2.Text;
            command = "t=2:0.2:4*pi;y=sin(t);plot(t,y)";
            String path = System.IO.Directory.GetCurrentDirectory();//获取当前路径

            matlab.Visible = 0;
            matlab.Execute(command);
            command = @"print(gcf,   '-djpeg',   '" + path + "\\Test11');close all";
            matlab.Execute(command);
            pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
            pictureBox1.Image    = Image.FromFile(path + "\\Test11.jpg");
        }
Exemplo n.º 12
0
        //Constructor needs the path, an Image container, and a string, which will be the name of the image in the /img folder
        public MatlabPort(Image _image, String _str, String _function)
        {
            name = _str;
            image = _image;

            path = System.IO.Path.GetTempPath() + "matlabPort\\";

            System.IO.Directory.CreateDirectory(path);

            //Define the image name
            name = _str;

            //Create a Matlab instance
            matlabExe = new MLApp.MLApp();

            //Set the image container
            image = _image;

            //set the current function
            function = "h = @(x) "+ _function + ";";
        }
Exemplo n.º 13
0
        private void button1_Click(object sender, EventArgs e)
        {
            int m = dataGridView1.RowCount;

            double[]    X1     = new double[m];
            double[]    X2     = new double[m];
            double[]    Y      = new double[m];
            MLApp.MLApp matlab = new MLApp.MLApp();
            matlab.Execute(@"cd C:\Users\Admin\Desktop\ModelingFYP");
            object result = null;

            double[] res1, res2;
            for (int i = 0; i < m; i++)
            {
                X1[i] = Double.Parse(dataGridView1.Rows[i].Cells[0].Value.ToString());
                X2[i] = Double.Parse(dataGridView1.Rows[i].Cells[1].Value.ToString());
                //  Y[i] = Myfunc.Func1(X1[i], X2[i]);
                Y[i] = Double.Parse(dataGridView1.Rows[i].Cells[2].Value.ToString());
            }

            Lin mylin = new Lin(X1, X2, Y);

            res1 = mylin.DoWork();
            Quad myq = new Quad(X1, X2, Y);

            for (int i = 0; i < 3; i++)
            {
                dataGridView2.Rows[0].Cells[i].Value = res1[i];
            }
            res2 = myq.DoWork();
            for (int i = 0; i < 6; i++)
            {
                dataGridView3.Rows[0].Cells[i].Value = res2[i];
            }

            matlab.Feval("scatter", 0, out result, X1, X2, Y, res1[0], res1[1], res1[2], res2[0], res2[1], res2[2],
                         res2[3], res2[4], res2[5]);
        }
Exemplo n.º 14
0
        //Главная функция компиляции, запускающая все остальные
        public static void Compile(ref RichTextBox Lexems, ref RichTextBox Code)
        {
            Lexems.Clear();

            DError.ErrorCounter = 0;

            Check(tLex.lexBegin, " 'Начало' ");
            Check(tLex.lexName, " имя программы ");
            Check(tLex.lexSemi, " ; ");
            Check(tLex.lexGiven, " 'Уравнения' ");
            DeclEq();
            Check(tLex.lexKoef, " 'Коэффициенты' ");
            DeclKoef();
            Check(tLex.lexCauchy, " 'Условия' ");
            DeclCauchy();
            Check(tLex.lexMethod, " 'Метод' ");
            DeclMethod();
            Check(tLex.lexGet, " 'Вывести' ");
            DeclPlot();
            Check(tLex.lexEnd, " 'Конец' ");

            if (DError.ErrorCounter == 0)
            {
                GenFunSys(ref Lexems, ref Code);

                MLApp.MLApp MatLabApp = new MLApp.MLApp();

                MatLabApp.Execute("cd " + MainForm.StartPath + "\\result") ;
                MatLabApp.Visible = 1;

                if (Methods.Contains("euler"))
                {
                    GenEuler(ref Lexems, ref Code);
                    MatLabApp.Execute("t_euler");
                }

                if (Methods.Contains("heun"))
                {
                    GenHeun(ref Lexems, ref Code);
                    MatLabApp.Execute("t_heun");
                }

                if (Methods.Contains("RK2"))
                {
                    GenRK2(ref Lexems, ref Code);
                    MatLabApp.Execute("t_RK2");
                }

                if (Methods.Contains("RK4"))
                {
                    GenRK4(ref Lexems, ref Code);
                    MatLabApp.Execute("t_RK4");
                }

                if (Methods.Contains("RKF5"))
                {
                    GenRKF5(ref Lexems, ref Code);
                    MatLabApp.Execute("t_RKF5");
                }

                WaitForm waitwin = new WaitForm();
                waitwin.Show();

                MatLabApp.Quit();

            }

            DText.CloseText();
        }
        public Tuple <int, int> countdownTime(string iPEnd1, string ipEnd2, string pDistance)
        {
            MLApp.MLApp mFile = new MLApp.MLApp(); //Matlab access function through COM mechanism

            int countdownTime = 0;                 //Declare variable
            int holdTime      = 0;
            int intPDistance  = Convert.ToInt32(pDistance);

            //Calling image processing funtion
            string Output = mFile.Execute("PImagePixelCount('" + iPEnd1 + "', '" + ipEnd2 + "')");

            //Hide Matlab CP Window
            mFile.Visible = 0;
            mFile.Quit();

            string weightEnd1 = Output.Substring(8, 5);
            string weightEnd2 = Output.Substring(19, 5);

            double dWeightEnd1 = Convert.ToDouble(weightEnd1);
            double dWeightEnd2 = Convert.ToDouble(weightEnd2);

            if (dWeightEnd1 < 0.900 && dWeightEnd2 < 0.900)
            {
                countdownTime = 00;
            }
            else if (31.00 <= dWeightEnd1 || 31.00 <= dWeightEnd2)
            {
                if (intPDistance <= 10)
                {
                    countdownTime = 15;
                }
                else if (11 <= intPDistance || intPDistance <= 15)
                {
                    countdownTime = 20;
                }
                else if (intPDistance >= 20)
                {
                    countdownTime = 25;
                }
            }
            else if ((21.00 <= dWeightEnd1 && dWeightEnd1 < 30.99) || (21.00 <= dWeightEnd2 && dWeightEnd2 < 30.99))
            {
                if (intPDistance <= 10)
                {
                    countdownTime = 12;
                }
                else if (11 <= intPDistance || intPDistance <= 15)
                {
                    countdownTime = 16;
                }
                else if (intPDistance >= 20)
                {
                    countdownTime = 20;
                }
            }
            else if ((11.00 <= dWeightEnd1 && dWeightEnd1 < 20.99) || (11.00 <= dWeightEnd2 && dWeightEnd2 < 20.99))
            {
                if (intPDistance <= 10)
                {
                    countdownTime = 09;
                }
                else if (11 <= intPDistance || intPDistance <= 15)
                {
                    countdownTime = 12;
                }
                else if (intPDistance >= 20)
                {
                    countdownTime = 15;
                }

                holdTime = 30;
            }
            else if ((1.000 <= dWeightEnd1 && dWeightEnd1 < 10.99) || (1.000 <= dWeightEnd2 && dWeightEnd2 < 10.99))
            {
                if (intPDistance <= 10)
                {
                    countdownTime = 06;
                }
                else if (11 <= intPDistance || intPDistance <= 15)
                {
                    countdownTime = 08;
                }
                else if (intPDistance >= 20)
                {
                    countdownTime = 10;
                }

                holdTime = 60;
            }

            return(Tuple.Create(countdownTime, holdTime));
        }
Exemplo n.º 16
0
 private void btnSimplify_Click(object sender, EventArgs e)
 {
     MLApp.MLApp matlab = new MLApp.MLApp();
     matlab.Visible = 0;
     MessageBox.Show(matlab.Execute("syms " + txtVariable.Text + ";simplify(" + txtEquation.Text + ");disp(ans)"));
 }
        //******************************Méthode de controle de upload**********************

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var sre = new SpeechRecognitionEngine();

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
            dlg.DefaultExt = ".wav";
            dlg.Filter     = "Audio documents (.wav)|*.wav";
            Nullable <bool> result = dlg.ShowDialog();

            if (result == true)
            {
                mediaPlayer.Open(new Uri(dlg.FileName));
                //------------------
                string SafeFileName = dlg.SafeFileName;
                string filename     = dlg.FileName;
                byte[] stream       = File.ReadAllBytes(dlg.FileName);
                AjoutAudio(SafeFileName, filename, stream);
                //-------------Appliation du filtre----
                State.Text = "Filring Sequence ... ";
                // Create the MATLAB instance
                MLApp.MLApp matlab = new MLApp.MLApp();

                // Change to the directory where the function is located
                matlab.Execute(@"cd C:\Users\Haroun3amri\Documents");

                // Define the output
                object result2 = null;

                // Call the MATLAB function myfunc
                matlab.Feval("filtre", 1, out result2, filename);
                //matlab.Feval("myfunc", 2, out result2, 3.14, 42.0, "world");
                object[] res = result2 as object[];

                MessageBox.Show("Filtrage piste audio avec succée !");



                //-----------------Ajout a la base des piste filtrées
                string        ConString = "Data Source=(localdb)\\Projects;Initial Catalog=RecoVocale;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False";
                SqlConnection con2      = new SqlConnection(ConString);
                SqlCommand    com2      = new SqlCommand("insert into filtred(FileName, FilePath, fldvoice) values(@Filename, @FilePath, @voice)", con2);
                State.Text = "Saving sequence ... ";

                //OpenFileDialog fileDialog = new OpenFileDialog();
                //fileDialog.ShowDialog();

                //byte[] stream = File.ReadAllBytes(fileDialog.FileName);
                if (stream.Length > 0)
                {
                    string FilePath2 = "C:\\Users\\Haroun3amri\\Documents\\";
                    string FileName2 = "result.wav";
                    com2.Parameters.AddWithValue("@Filename", FileName2);
                    com2.Parameters.AddWithValue("@FilePath", FilePath2);
                    com2.Parameters.AddWithValue("@voice", stream);
                    con2.Open();
                    int result3 = com2.ExecuteNonQuery();
                    if (result3 > 0)
                    {
                        MessageBox.Show("Ajout de la piste audio dans la base de donnée filtée avec succée !");
                    }
                    con2.Close();
                }
                FileNameTextBox.Text = filename;
                sre.SetInputToWaveFile(filename);
                sre.LoadGrammar(new DictationGrammar());
                //sre.RecognizeAsync(RecognizeMode.Multiple);

                State.Text                     = "Sequence Recognition ... ";
                sre.BabbleTimeout              = new TimeSpan(Int32.MaxValue);
                sre.InitialSilenceTimeout      = new TimeSpan(Int32.MaxValue);
                sre.EndSilenceTimeout          = new TimeSpan(100000000);
                sre.EndSilenceTimeoutAmbiguous = new TimeSpan(100000000);
                StringBuilder sb = new StringBuilder();
                while (true)
                {
                    try
                    {
                        var recText = sre.Recognize();
                        sb.Append(recText.Text);
                    }
                    catch (Exception ex)
                    {
                        break;
                    }
                }

                Screen.AppendText(sb.ToString());
                State.Text = "Done ... ";
            }


            DispatcherTimer timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick    += timer_Tick;
            timer.Start();
        }
Exemplo n.º 18
0
 // constructor
 public MATLAB()
 {
     //matlab = new MLAppClass();
     matlab = new MLApp.MLApp();
 }
Exemplo n.º 19
0
 private void MatLabBackground_DoWork(object sender, DoWorkEventArgs e)
 {
     BackgroundWorker worker = sender as BackgroundWorker;
     matlab = new MLApp.MLApp();
 }