private void Export_Click(object sender, EventArgs e) { SaveFileDialog fde = new SaveFileDialog(); fde.Filter = "CSV file(*.csv)|*.csv"; fde.InitialDirectory = Environment.SpecialFolder.MyDocuments.ToString(); fde.RestoreDirectory = true; if (fde.ShowDialog() == DialogResult.OK) { System.IO.StreamWriter file = new System.IO.StreamWriter(fde.FileName); ThermalImageFile th = new ThermalImageFile(filename); double[,] pixel_array = th.ImageProcessing.GetPixelsArray(); //array containing the raw signal data for (int y = 0; y < th.Height; y++) { string line = string.Empty; for (int x = 0; x < th.Width; x++) { int pixel_int = (int)pixel_array[y, x]; //casting the signal value to int double pixel_temp = th.GetValueFromSignal(pixel_int); //converting signal to temperature line += pixel_temp.ToString("0.00") + ";"; //"building" each line } file.WriteLine(line); //writing a line to the excel sheet } file.Flush(); file.Close(); th.Dispose(); } }
public async void SaveToCsv(double[,] pixel_array) { var UnixTimestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds().ToString(); //_cam1.GetImage().SaveSnapshot(m_imagefolder+"\\"+ UnixTimestamp); //ThermalImage th = new ThermalImage(); //byte[] arr = _cam1.GetImage().GetData(); //th.Load(arr); double pixel_temp = 0; string line = UnixTimestamp + ","; //double[,] pixel_array = _cam1.GetImage().ImageProcessing.GetPixelsArray(); //array containing the raw signal data for (int y = 0; y < th.Height; y++) { for (int x = 0; x < th.Width; x++) { int pixel_int = (int)pixel_array[y, x]; //casting the signal value to int pixel_temp = th.GetValueFromSignal(pixel_int); //converting signal to temperature line += pixel_temp.ToString("0.00") + ","; //"building" each line } } line += "\r\n"; //System.IO.File.AppendAllText(m_csvfilename, line); m_allcvs += line; }
public async void SaveToCsv(double[,] pixel_array) { var UnixTimestamp = new DateTimeOffset(DateTime.UtcNow).ToUnixTimeMilliseconds().ToString(); //_cam1.GetImage().SaveSnapshot(m_imagefolder+"\\"+ UnixTimestamp); //ThermalImage th = new ThermalImage(); //byte[] arr = _cam1.GetImage().GetData(); //th.Load(arr); double pixel_temp = 0; string line = UnixTimestamp + ","; //double[,] pixel_array = _cam1.GetImage().ImageProcessing.GetPixelsArray(); //array containing the raw signal data for (int y = 0; y < th.Height; y++) { for (int x = 0; x < th.Width; x++) { int pixel_int = (int)pixel_array[y, x]; //casting the signal value to int pixel_temp = th.GetValueFromSignal(pixel_int); //converting signal to temperature line += pixel_temp.ToString("0.00") + ","; //"building" each line } } line += "\r\n"; m_allcvs += line; //System.IO.File.AppendAllText(m_csvfilename, line); /* * byte[] encodedText = Encoding.Unicode.GetBytes(line); * * using (FileStream sourceStream = new FileStream(m_csvfilename, * FileMode.Append, FileAccess.Write, FileShare.None, * bufferSize: 4096, useAsync: true)) * { * await sourceStream.WriteAsync(encodedText, 0, encodedText.Length); * }; */ }
public static int Paljpgmake(string fname_a, string fname_b) { if (new DriveInfo(Directory.GetCurrentDirectory().Substring(0, 2)).TotalFreeSpace < 1073741824L) { return(2); } try { double num1 = 1000.0; double num2 = -1000.0; PaletteMake.jpgname = fname_b; PaletteMake.palname = fname_a; Palette palette = PaletteManager.Open(PaletteMake.palname); ThermalImageFile thermalImageFile = new ThermalImageFile(PaletteMake.jpgname); thermalImageFile.Fusion.Mode = (FusionMode)thermalImageFile.Fusion.VisualOnly; Bitmap image = thermalImageFile.Image; int width = thermalImageFile.Width; int height = thermalImageFile.Height; double num3 = 0.0; double num4 = 0.0; double[] numArray = new double[width * height]; double[,] pixelsArray = thermalImageFile.ImageProcessing.GetPixelsArray(); for (int index1 = 0; index1 < thermalImageFile.Height; ++index1) { string empty = string.Empty; for (int index2 = 0; index2 < thermalImageFile.Width; ++index2) { int signal = (int)pixelsArray[index1, index2]; double valueFromSignal = thermalImageFile.GetValueFromSignal(signal); numArray[width * index1 + index2] = valueFromSignal; num3 += valueFromSignal * valueFromSignal; num4 += valueFromSignal; if (num1 > numArray[width * index1 + index2]) { num1 = numArray[width * index1 + index2]; } if (num2 < numArray[width * index1 + index2]) { num2 = numArray[width * index1 + index2]; } } } int num5 = width * height; double num6 = Math.Sqrt((num3 - num4 * num4 / (double)num5) / (double)num5); double num7 = num4 / (double)num5; double num8 = num7 - num6 * 3.0; double num9 = num7 + num6 * 3.0; thermalImageFile.Dispose(); Bitmap bitmap = new Bitmap(width, height); for (int y = 0; y < height; ++y) { for (int x = 0; x < width; ++x) { int index = numArray[width * y + x] >= num8 ? (numArray[width * y + x] <= num9 ? (int)((numArray[width * y + x] - num8) / (num9 - num8) * (double)byte.MaxValue) : (int)byte.MaxValue) : 0; Color paletteColor = palette.PaletteColors[index]; byte r = paletteColor.R; paletteColor = palette.PaletteColors[index]; byte g = paletteColor.G; paletteColor = palette.PaletteColors[index]; byte b = paletteColor.B; bitmap.SetPixel(x, y, Color.FromArgb((int)r, (int)g, (int)b)); } } string[] strArray1 = PaletteMake.jpgname.Split('.'); string[] strArray2 = PaletteMake.palname.Split('.')[0].Split('\\'); string filename = strArray1[0] + "_" + strArray2[strArray2.Length - 1] + ".jpg"; bitmap.Save(filename); return(0); } catch (Exception ex) { return(1); } }