private void SaveCSV(object videoFileName) { Dispatcher.Invoke(() => btnSaveActivity.Content = "Saving..."); var fileInfo = new FileInfo(videoFileName.ToString()); using (var writer = new StreamWriter(fileInfo.FullName + "_Motion_" + Controller.GetCSVfileEnding(), false)) { writer.WriteLine("Frame, Changed Pixels"); Activity.ForEach(a => writer.WriteLine("{0}, {1}", a.X, a.Y)); writer.Flush(); } Dispatcher.InvokeAsync(() => btnSaveActivity.Content = "Saved!"); new Thread(() => { Thread.Sleep(2000); Dispatcher.InvokeAsync(() => { btnSaveActivity.Content = "Save Activity Data"; }); }) { IsBackground = true } .Start(); }
/// <summary> /// CSVs are saved in same folder as the video, with "_tracker_", username, and timestamp appended. /// </summary> private FileInfo GetDefaultCsvPath(string videoFile) { var csvFile = new FileInfo(videoFile).FullName + "_Tracker_" + Controller.GetCSVfileEnding(); return(new FileInfo(csvFile)); }
public void SaveCSV(object videoFileName) { if (string.IsNullOrWhiteSpace(videoFileName.ToString())) { return; } if (AppSettings.Default.VideoLabelColumn.Split(',').Length != AppSettings.Default.VideoLabel.Split(',').Length) { MessageBox.Show("Make sure the number of commas (',') is the same in both the column label and column value field."); return; } var fileInfo = new FileInfo(videoFileName.ToString()); using (var writer = new StreamWriter(fileInfo.FullName + "_Tracker_" + Controller.GetCSVfileEnding(), false)) { writer.WriteLine ( AppSettings.Default.VideoLabelColumn + ", Frame, TreatmentSensor, " + "PER-X, PER-Y, " + "LeftSector, RightSector, " + "LeftFlagellumTip-X, LeftFlagellumTip-Y, RightFlagellumTip-X, RightFlagellumTip-Y, " + "LeftFlagellumBase-X, LeftFlagellumBase-Y, RightFlagellumBase-X, RightFlagellumBase-Y, " + "RotationAngle, AntennaSensorWidth, AntennaSensorHeight, " + "AntennaSensorOffset-X, AntennaSensorOffset-Y, AntennaSensorScale-X, AntennaSensorScale-Y" //, " + //"SectorData" ); var data = Processor.Results; if (data == null) { return; } var frames = data.Keys.OrderBy(frameIndex => frameIndex).ToList(); Dispatcher.Invoke(() => btnSaveActivity.Content = "Saving..."); frames.ForEach(frameIndex => { var value = data[frameIndex]; var recordingConditions = value?.Left?.Tip?.Space; var line = string.Join(",", new object[] { AppSettings.Default.VideoLabel, frameIndex, value?.TreatmentSensorValue, value?.Proboscis?.Tip?.FramePoint.X, value?.Proboscis?.Tip?.FramePoint.Y, value?.Left?.DominantSector, value?.Right?.DominantSector, value?.Left?.Tip?.FramePoint.X, value?.Left?.Tip?.FramePoint.Y, value?.Right?.Tip?.FramePoint.X, value?.Right?.Tip?.FramePoint.Y, value?.Left?.Base.FramePoint.X, value?.Left?.Base.FramePoint.Y, value?.Right?.Base.FramePoint.X, value?.Right?.Base.FramePoint.Y, recordingConditions?.HeadAngle, recordingConditions?.HeadDims.X, recordingConditions?.HeadDims.Y, recordingConditions?.HeadOffset.X, recordingConditions?.HeadOffset.Y, recordingConditions?.ScaleX, recordingConditions?.ScaleX }); //string sectorData = ""; //if (value.Left.SectorCounts != null && value.Right.SectorCounts != null) //{ // sectorData = string.Join(",", value.Left.SectorCounts) + "," + string.Join(",", value.Right.SectorCounts); //} writer.WriteLine(line);// + ", " + sectorData); }); writer.Flush(); } Dispatcher.InvokeAsync(() => btnSaveActivity.Content = "Saved!"); new Thread(() => { Thread.Sleep(2000); Dispatcher.InvokeAsync(() => { btnSaveActivity.Content = "Save Activity Data"; }); }) { IsBackground = true } .Start(); }