예제 #1
0
        private void GetParameters(object sender, RoutedEventArgs e)
        {
            //Deserialize object file
            String          dir = AppDomain.CurrentDomain.BaseDirectory + @"instTest\";
            BinaryFormatter bf  = new BinaryFormatter();
            FileStream      fs  = File.OpenRead(dir + "params.dat");

            object[] input = bf.Deserialize(fs) as object[];
            matlabParam = input[0] as object[];
            imageparam  = input[1] as int[];

            //Convert text file into IPI list for Testing Module
            // *** NOT for Preparation Module ***
            IpiList = new List <ImagePreperationItem>();
            string[] lines = System.IO.File.ReadAllLines(dir + "ipi.cfg");
            foreach (string line in lines)
            {
                string[]             v   = line.Split('%');
                ImagePreperationItem ipi = new ImagePreperationItem(null, v[0]);
                ipi.SignalName = v[1];
                ipi.Value      = Convert.ToDouble(v[2]);
                IpiList.Add(ipi);
            }

            Loaded.Text = "Loaded";
        }
예제 #2
0
        void ProcessImage(object obj)
        {
            IplImage img = obj as IplImage;

            matlab.Execute(@"cd '" + imgPath + "'");

            /* b 1.5 - 1.8 FPS */
            // Define the output
            object result1 = null;

            // Call the MATLAB function recog
            byte[,] matlabImage = ImageConverter.IplImageToMatlabImage(img);
            matlab.Feval("recog", 4, out result1, matlabImage, parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5]);
            /* end b 1.5 - 1.8 FPS*/

            /* c 6ms */

            // Display result
            Result = result1 as object[];

            double[,] eArray = Result[0] as double[, ];

            //Get smallest Euclidean Distance and index of smallest distance is the index where corresponding signal and its value are stored.
            int index = indexOfSmallest(eArray);

            if (index > -1)
            {
                ImagePreperationItem ipi = ipiList[index];
                candb.UpdateSignalValue(ipi.SignalName, ipi.Value);
                can.CANTransmit(candb.GetMessageFromSignal(ipi.SignalName)[0]);
                //This 4 lines of code allows me to interact with GUI from separate thread (this)
                Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
                {
                    UpdateSignals(ipi.SignalName, ipi.Value);
                }));
            }

            //can.CANMultipleTransmit(candb.GetMessageFromSignal(ipi.SignalName));
            /* c end 6ms */
        }