private Task DoLoadFromFile(object o)
        {
            return(Task.Factory.StartNew(() =>
            {
                Parent.SyncContext.Post(c =>
                {
                    CustomDialog customDialog = new CustomDialog()
                    {
                        Title = "Select calibration file"
                    };

                    var dataContext = new ReplaySelectDialogModel(obj =>
                    {
                        Parent.SyncContext.Post(d =>
                        {
                            Task.Factory.StartNew(async() =>
                            {
                                ReplaySelectDialogModel replaySelectDialogModel = obj as ReplaySelectDialogModel;
                                if (replaySelectDialogModel.SelectedFile != null)
                                {
                                    MetroDialogSettings settings = new MetroDialogSettings()
                                    {
                                        AnimateShow = false,
                                        AnimateHide = false
                                    };
                                    var controller = await Parent.DialogCoordinator.ShowProgressAsync(Parent, "Please wait...", "Loading calibration images!", settings: Parent.MetroDialogSettings);
                                    controller.SetCancelable(false);
                                    controller.SetIndeterminate();

                                    string file = null;
                                    string outputPath = null;

                                    Parent.SyncContext.Send(async d2 =>
                                    {
                                        file = replaySelectDialogModel.SelectedFile.FullPath;
                                        outputPath = Path.Combine(Path.GetTempPath(), "firefly", Guid.NewGuid().ToString());
                                    }, null);

                                    RawDataReader reader = new RawDataReader(file, RawReaderMode.Camera0);
                                    reader.Open();
                                    MemoryImageExporter exporter = new MemoryImageExporter();
                                    exporter.AddFromReader(reader, delegate(double percent)
                                    {
                                        double value = percent;
                                        value = value > 1 ? 1 : value;
                                        controller.SetProgress(value);
                                    });

                                    reader.Close();

                                    Parent.SyncContext.Post(d2 =>
                                    {
                                        int i = 0;
                                        int count = exporter.Images.Count;
                                        foreach (Mat m in exporter.Images)
                                        {
                                            //double value = 0.5 + i / count * 0.5;
                                            //value = value > 1 ? 1 : value;
                                            //controller.SetProgress(value);

                                            if (i++ % 20 == 0)
                                            {
                                                int squaresX = Parent.SettingContainer.Settings.CalibrationSettings.ChArucoCalibrationSettings.SquaresX;
                                                int squaresY = Parent.SettingContainer.Settings.CalibrationSettings.ChArucoCalibrationSettings.SquaresY;
                                                float squareLength = Parent.SettingContainer.Settings.CalibrationSettings.ChArucoCalibrationSettings.SquareLength;
                                                float markerLength = Parent.SettingContainer.Settings.CalibrationSettings.ChArucoCalibrationSettings.MarkerLength;
                                                PredefinedDictionaryName dictionary = Parent.SettingContainer.Settings.CalibrationSettings.ChArucoCalibrationSettings.Dictionary;

                                                ChArUcoImageContainer cauic = new ChArUcoImageContainer(squaresX, squaresY, squareLength, markerLength, dictionary);
                                                CvImageContainer container = new CvImageContainer();
                                                container.CvImage = m;
                                                cauic.OriginalImage = container;
                                                Images.Add(cauic);
                                            }
                                        }

                                        controller.CloseAsync();
                                    }, null);
                                }
                            }, TaskCreationOptions.LongRunning);
                            Parent.DialogCoordinator.HideMetroDialogAsync(Parent, customDialog);
                        }, null);
                    });
                    Parent.ReplayViewModel.Refresh();
                    dataContext.FilesForReplay.AddRange(Parent.ReplayViewModel.FilesForReplay.Where(x => !x.Item1.IsRemote));
                    customDialog.Content = new ReplaySelectDialog {
                        DataContext = dataContext
                    };

                    Parent.DialogCoordinator.ShowMetroDialogAsync(Parent, customDialog);
                }, null);
            }));
        }
Esempio n. 2
0
        private Action <ReplaySelectDialogModel> OnReplaySelectDialogClose(bool response, CustomDialog customDialog)
        {
            return(obj =>
            {
                Parent.SyncContext.Send(d =>
                {
                    Parent.DialogCoordinator.HideMetroDialogAsync(Parent, customDialog);
                }, null);

                Parent.SyncContext.Post(d =>
                {
                    Task.Factory.StartNew(async() =>
                    {
                        ReplaySelectDialogModel replaySelectDialogModel = obj as ReplaySelectDialogModel;
                        if (replaySelectDialogModel.SelectedFile != null)
                        {
                            MetroDialogSettings settings = new MetroDialogSettings()
                            {
                                AnimateShow = false,
                                AnimateHide = false
                            };
                            var controller = await Parent.DialogCoordinator.ShowProgressAsync(Parent, "Please wait...", "Photometric calibration!", settings: Parent.MetroDialogSettings);
                            controller.SetCancelable(false);
                            controller.SetIndeterminate();

                            string file = null;
                            string outputPath = null;

                            double fxO = 0.0;
                            double fyO = 0.0;
                            double cxO = 0.0;
                            double cyO = 0.0;

                            double fxN = 0.0;
                            double fyN = 0.0;
                            double cxN = 0.0;
                            double cyN = 0.0;

                            double k1 = 0.0;
                            double k2 = 0.0;
                            double k3 = 0.0;
                            double k4 = 0.0;

                            int width = 0;
                            int height = 0;
                            List <double> responseValues = new List <double>();
                            Parent.SyncContext.Send(d2 =>
                            {
                                file = replaySelectDialogModel.SelectedFile.FullPath;
                                outputPath = Path.Combine(Path.GetTempPath(), "firefly", Guid.NewGuid().ToString());

                                fxO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(0, 0);
                                fyO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(1, 1);
                                cxO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(0, 2);
                                cyO = Parent.CameraViewModel.OrginalCameraMatrix.GetValue(1, 2);

                                fxN = Parent.CameraViewModel.NewCameraMatrix.GetValue(0, 0);
                                fyN = Parent.CameraViewModel.NewCameraMatrix.GetValue(1, 1);
                                cxN = Parent.CameraViewModel.NewCameraMatrix.GetValue(0, 2);
                                cyN = Parent.CameraViewModel.NewCameraMatrix.GetValue(1, 2);

                                k1 = Parent.CameraViewModel.DistortionCoefficients.GetValue(0, 0);
                                k2 = Parent.CameraViewModel.DistortionCoefficients.GetValue(0, 1);
                                k3 = Parent.CameraViewModel.DistortionCoefficients.GetValue(0, 2);
                                k4 = Parent.CameraViewModel.DistortionCoefficients.GetValue(0, 3);

                                if (!response)
                                {
                                    responseValues.AddRange(ResponseValues.Select(f => f.Y));
                                }

                                width = Parent.CameraViewModel.ImageWidth;
                                height = Parent.CameraViewModel.ImageHeight;
                            }, null);

                            RawDataReader reader = new RawDataReader(file, RawReaderMode.Camera0);

                            reader.Open();

                            PhotometricCalibratrionExporter exporter = new PhotometricCalibratrionExporter(fxO, fyO, cxO, cyO, fxN, fyN, cxN, cyN, width, height, k1, k2, k3, k4, outputPath, response, responseValues);
                            exporter.Open();
                            exporter.AddFromReader(reader, delegate(double percent)
                            {
                                double value = percent * 0.33;
                                value = value > 1 ? 1 : value;
                                controller.SetProgress(value);
                            });
                            exporter.Close();
                            reader.Close();

                            Process p = new Process();
                            p.StartInfo.RedirectStandardOutput = true;
                            p.StartInfo.UseShellExecute = false;
                            p.StartInfo.WorkingDirectory = outputPath;
                            p.StartInfo.CreateNoWindow = true;
                            p.EnableRaisingEvents = true;

                            string options = "";

                            if (response)
                            {
                                p.StartInfo.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Tools", "responseCalib.exe");
                            }
                            else
                            {
                                p.StartInfo.FileName = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Tools", "vignetteCalib.exe");
                                options = "facW=7 facH=7";
                            }
                            p.StartInfo.Arguments = string.Format("{0}\\ -noGUI -showPercent {1}", outputPath, options);

                            p.OutputDataReceived += new DataReceivedEventHandler((s, e) =>
                            {
                                Debug.WriteLine(e.Data);
                                if (!string.IsNullOrEmpty(e.Data))
                                {
                                    foreach (string line in e.Data.Split('\n'))
                                    {
                                        if (line.StartsWith("percent: "))
                                        {
                                            double percent = double.Parse(line.Replace("percent: ", ""), CultureInfo.InvariantCulture);
                                            double value = 0.33 + percent * 0.66;
                                            value = value > 1 ? 1 : value;
                                            controller.SetProgress(value);
                                        }
                                    }
                                }
                            }
                                                                                 );

                            p.Exited += new EventHandler((s, e) =>
                            {
                                Parent.SyncContext.Post(async x =>
                                {
                                    if (response)
                                    {
                                        ParseResponseResult(outputPath);
                                    }
                                    else
                                    {
                                        ParseVignetteResult(outputPath);
                                    }
                                    Directory.Delete(outputPath, true);
                                    await controller.CloseAsync();
                                }, null);
                            });

                            p.Start();
                            p.BeginOutputReadLine();
                        }
                    }, TaskCreationOptions.LongRunning);
                }, null);
            });
        }
Esempio n. 3
0
        private Task DoExportVideo(object o)
        {
            return(Task.Factory.StartNew(async() =>
            {
                ReplayFile file = o as ReplayFile;
                RawDataReader reader = null;

                string fullPath = null;
                bool isRemote = false;
                System.Windows.Forms.OpenFileDialog openFileDialog = null;
                System.Windows.Forms.SaveFileDialog saveFileDialog = null;
                bool open = false;
                bool save = false;

                CameraViewModel cvm = null;

                Parent.SyncContext.Send(c =>
                {
                    cvm = Parent.CameraViewModel;
                    fullPath = file.FullPath;
                    isRemote = file.IsRemote;
                    openFileDialog = new System.Windows.Forms.OpenFileDialog();
                    openFileDialog.Filter = "Matlab (*.mat) | *.mat";
                    open = openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK;

                    saveFileDialog = new System.Windows.Forms.SaveFileDialog();
                    saveFileDialog.Filter = "Video (*.mp4) | *.mp4";
                    save = saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                }, null);

                if (open && save && !isRemote)
                {
                    MetroDialogSettings settings = new MetroDialogSettings()
                    {
                        AnimateShow = false,
                        AnimateHide = false
                    };

                    var controller = await Parent.DialogCoordinator.ShowProgressAsync(Parent, "Please wait...", "Export video file!", settings: Parent.MetroDialogSettings);

                    controller.SetCancelable(false);

                    reader = new RawDataReader(fullPath, RawReaderMode.Imu0 | RawReaderMode.Camera0, null, false);
                    controller.SetIndeterminate();
                    reader.Open();

                    VIMatlabImporter matlabImporter = new VIMatlabImporter(openFileDialog.FileName);

                    matlabImporter.Open();

                    VIVideoRenderer renderer = new VIVideoRenderer(saveFileDialog.FileName, 1920, 1080, Parent.SyncContext, cvm.OrginalCameraMatrix, cvm.CenteredCameraMatrix, cvm.DistortionCoefficients);

                    renderer.Open();

                    renderer.Render(matlabImporter, reader, delegate(double percent)
                    {
                        controller.SetProgress(percent);
                    });

                    renderer.Close();
                    matlabImporter.Close();

                    reader.Close();
                    await controller.CloseAsync();
                }
            }));
        }
Esempio n. 4
0
        private Task DoStart(object o)
        {
            return(Task.Factory.StartNew(() =>
            {
                ReplayFile file = o as ReplayFile;
                RawDataReader reader = null;
                string fullPath = null;
                Parent.SyncContext.Send(c =>
                {
                    if (!IsReplaying)
                    {
                        IsReplaying = true;
                        fullPath = file.FullPath;
                        file.IsPlaying = true;
                    }
                    else
                    {
                        file.IsPlaying = true;
                        file.IsPaused = false;
                    }
                }, null);

                if (!string.IsNullOrEmpty(fullPath))
                {
                    reader = new RawDataReader(fullPath, RawReaderMode.Imu0 | RawReaderMode.Camera0);
                    reader.Open();

                    Parent.IOProxy.ChangeSlamStatus(Proxy.SlamStatusOverall.Restart, true);

                    Parent.IOProxy.ReplayOffline(reader, new Action <TimeSpan>((t) =>
                    {
                        Parent.SyncContext.Post(c =>
                        {
                            ReplayTime = t;
                        }, null);
                    }), new Action(() =>
                    {
                        //Parent.IOProxy.ChangeSlamStatus(Proxy.SlamStatusOverall.Stop);
                        Parent.SyncContext.Post(c =>
                        {
                            IsReplaying = false;
                            file.IsPlaying = false;
                            file.IsPaused = false;
                            IsStopping = false;
                        }, null);
                    }), delegate()
                    {
                        bool isPaused = false;

                        Parent.SyncContext.Send(c =>
                        {
                            isPaused = file.IsPaused;
                        }, null);

                        return isPaused;
                    },
                                                 delegate()
                    {
                        return IsStopping;
                    });
                }
            }));
        }
Esempio n. 5
0
        private Task DoExport(object o)
        {
            return(Task.Factory.StartNew(async() =>
            {
                ReplayFile file = o as ReplayFile;
                RawDataReader reader = null;

                string fullPath = null;
                bool isRemote = false;
                System.Windows.Forms.SaveFileDialog saveFileDialog = null;
                bool save = false;

                Parent.SyncContext.Send(c =>
                {
                    fullPath = file.FullPath;
                    isRemote = file.IsRemote;
                    saveFileDialog = new System.Windows.Forms.SaveFileDialog();
                    saveFileDialog.Filter = "Matlab (*.mat) | *.mat";
                    save = saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK;
                }, null);

                if (save)
                {
                    MetroDialogSettings settings = new MetroDialogSettings()
                    {
                        AnimateShow = false,
                        AnimateHide = false
                    };

                    var controller = await Parent.DialogCoordinator.ShowProgressAsync(Parent, "Please wait...", "Export data to Matlab!", settings: Parent.MetroDialogSettings);

                    controller.SetCancelable(false);

                    if (isRemote)
                    {
                        reader = new RawDataReader(fullPath, RawReaderMode.Imu0, new RemoteDataStore(Parent.SettingContainer.Settings.ConnectionSettings.SelectedConnection.IpAddress, Parent.SettingContainer.Settings.ConnectionSettings.SelectedConnection.Username, Parent.SettingContainer.Settings.ConnectionSettings.SelectedConnection.Password));
                        reader.Open(delegate(double percent)
                        {
                            double value = percent * 0.66;
                            value = value > 1 ? 1 : value;
                            controller.SetProgress(value);
                        });
                    }
                    else
                    {
                        reader = new RawDataReader(fullPath, RawReaderMode.Imu0 | RawReaderMode.Camera0, null, true);
                        controller.SetIndeterminate();
                        reader.Open();
                    }

                    RawMatlabExporter matlabExporter = new RawMatlabExporter(saveFileDialog.FileName, MatlabFormat.Imu0 | MatlabFormat.Camera0);

                    matlabExporter.Open();
                    if (isRemote)
                    {
                        matlabExporter.AddFromReader(reader, delegate(double percent)
                        {
                            double value = percent * 0.33 + 0.66;
                            value = value > 1 ? 1 : value;
                            controller.SetProgress(value);
                        });
                    }
                    else
                    {
                        matlabExporter.AddFromReader(reader, delegate(double percent)
                        {
                            controller.SetProgress(percent);
                        });
                    }
                    matlabExporter.Close();

                    reader.Close();
                    await controller.CloseAsync();
                }
            }));
        }