public static DetailInfo DetailInfo(ThermalImageFile th) { ImageParameters imageParameters = th.ThermalParameters; CameraInformation camera = th.CameraInformation; DetailInfo detailInfo = new DetailInfo(); //文件信息 detailInfo.Title = th.Title; //图片名 detailInfo.Width = th.Size.Width; detailInfo.Height = th.Size.Height; detailInfo.Max = th.Statistics.Max.Value; //全图最高温 detailInfo.Min = th.Statistics.Min.Value; //全图最低温 detailInfo.Average = th.Statistics.Average.Value; //全图平均温 detailInfo.DateTaken = (th.DateTaken - startTime).TotalMilliseconds.ToString(); //拍摄日期 毫秒数 //图像目标参数 detailInfo.AtmosphericTemperature = Math.Round(imageParameters.AtmosphericTemperature, 2).ToString(); //大气温度 //相机信息 detailInfo.Lens = camera.Lens; //相机镜头信息 detailInfo.Model = camera.Model; //相机模型信息 detailInfo.Range_max = Math.Round(camera.Range.Maximum, 2).ToString(); //测量范围 detailInfo.Range_min = Math.Round(camera.Range.Minimum, 2).ToString(); //测量范围 detailInfo.SerialNumber = camera.SerialNumber; //相机的序列号 //图像目标参数 detailInfo.DistanceUnit = th.DistanceUnit.ToString(); //距离单位 detailInfo.Distance = imageParameters.Distance; //到被聚焦对象的距离 detailInfo.Emissivity = imageParameters.Emissivity; //红外图像的默认发射率 detailInfo.RelativeHumidity = imageParameters.RelativeHumidity; //相对湿度(0.0 - 1.0) detailInfo.ReflectedTemperature = imageParameters.ReflectedTemperature; //反射温度 return(detailInfo); }
/// <summary> /// 在图片上画框 /// </summary> /// <param name="thermal">红外图对象</param> /// <param name="pic_info">起始点</param> /// <param name="p1">终止点</param> /// <param name="RectColor">矩形框颜色</param> /// <param name="LineWidth">矩形框边界</param> /// <param name="ds">边界样式</param> // /// <param name="HotSpot">最高温度点</param> // /// <param name="ColdSpot">最低温度点</param> /// <returns>Bitmap 画上矩形和标记出最高、低温度点的图</returns> public Bitmap DrawRectangleInPicture(ThermalImageFile thermal, List <Rect_param> param_list, Color RectColor, int LineWidth, DashStyle ds) { if (thermal == null) { return(null); } Graphics g = Graphics.FromImage(thermal.Image); g.SmoothingMode = SmoothingMode.AntiAlias; //使绘图质量最高,即消除锯齿 g.InterpolationMode = InterpolationMode.HighQualityBicubic; g.CompositingQuality = CompositingQuality.HighQuality; Brush brush = new SolidBrush(RectColor); Pen pen = new Pen(brush, LineWidth); pen.DashStyle = ds; //边界样式 //获取目标区域信息 并 标记高低温点 (画小三角) GetTargetResult(thermal, param_list, g); foreach (var item in this.result_Rect_Info_lsit) { g.DrawRectangle(pen, item.target_rect); //画框 DrawStringMsg(g, item); //画框序号 和 图片左上角信息 } brush.Dispose(); pen.Dispose(); g.Dispose(); return(thermal.Image); }
/// <summary> /// 解析路径下的红外图片,获取相关信息 /// </summary> /// <param name="file_path">文件路径</param> /// <param name="pic_info">识别区域信息</param> /// <returns></returns> public void OpenPicAsync(string file_path, List <Rect_param> pic_param_list) { try { using (ThermalImageFile th = new ThermalImageFile(file_path)) //打开热成像图片文件 { //拼接结果文件路径 string savepath = System.IO.Path.Combine(FileManage.GetResultFolderPath(), FileManage.GenerateFileName(th.Title)); //处理图片,获取结果信息 using (Bitmap saveimage = DrawRectangleInPicture(th, pic_param_list, Color.FromArgb(117, 251, 253), 2, DashStyle.Solid)) { saveimage.Save(savepath); //保存结果图片 //this.result_file_name = System.IO.Path.GetFileName(savepath); // 保存结果文件路径 this.result_file_name = savepath; // 保存结果文件路径 } this.picBaseInfo = DetailInfo(th); } } catch (Exception ex) { //if (System.IO.File.Exists(file_path)) //删除非红外图片 // System.IO.File.Delete(file_path); throw new MyException("解析对象不是红外图片!" + ex.ToString()); } }
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(); } }
private IList <ThermalData> ExtractTemperatureReadings(ThermalImageFile thermalImage) { IList <ThermalData> thermalData = new List <ThermalData>(); // Load Raw PixelData double[,] rawThermalData = thermalImage.ImageProcessing.GetPixelsArray(); for (int y = 0; y <= thermalImage.Size.Height - 1; y++) { for (int x = 0; x <= thermalImage.Size.Width - 1; x++) { // Get ThermalValue from Image ThermalValue thermalValue = thermalImage.GetValueAt(new Point(x, y)); // Build Data Object and Add to ThermalData List thermalData.Add(new ThermalData { X = x, Y = y, RawValue = rawThermalData[y, x], TemperatureValue = thermalValue.Value, TemperatureUnit = (Enums.TemperatureUnit)Enum.Parse(typeof(Enums.TemperatureUnit), thermalImage.TemperatureUnit.ToString()) }); } } return(thermalData); }
private void button4_Click(object sender, EventArgs e) { //create an instance of the Thermal object called image1 var image1 = new ThermalImageFile(@"C:\Users\sarosh.niazi\Desktop\Images\IR_2019-05-06_0007.jpg"); //get relative temperature for image1; returns the value in label2 label2.Text = image1.ThermalParameters.ReflectedTemperature.ToString("F2") + ("° C"); }
public void button1_Click(object sender, EventArgs e) { //create an instance of the Thermal object called image1 var image1 = new ThermalImageFile(@"C:\Users\sarosh.niazi\Desktop\Images\IR_2019-05-06_0007.jpg"); //set the image in pictureBox1 to the one in the path pictureBox1.Image = image1.Image; }
public static string DetailInfoFromPic(string filepath) { using (ThermalImageFile th = new ThermalImageFile(filepath)) { string json = JsonConvert.SerializeObject(DetailInfo(th)); return(json); } }
/// <summary> /// Extracts the first frame of the video as a reference. This reference image will be used as a safety net /// in case something goes wrong with the compression or decompression. In the future this step may be removed. /// </summary> /// <param name="sourceFile"></param> private void ExtractSnapshot(string sourceFile) { using (var thermalImage = new ThermalImageFile(sourceFile)) { var filename = $"{sourceFile}.jpg"; thermalImage.SaveSnapshot(filename); Publish(Commands.Upload, filename); } }
private void button2_Click(object sender, EventArgs e) { //create an instance of the Thermal object called image1 var image1 = new ThermalImageFile(@"C:\Users\sarosh.niazi\Desktop\Images\IR_2019-05-06_0007.jpg"); //get emissivity for image1; returns the value in label1 label1.Text = image1.ThermalParameters.Emissivity.ToString("F2"); }
public bool IsThermalImage(string filename) { if (ThermalImageFile.IsThermalImage(filename)) { return(true); } Console.WriteLine("图片不是热成像图片文件,无法打开"); return(false); }
public void button3_Click(object sender, EventArgs e) { //create an instance of the Thermal object called image1 var image1 = new ThermalImageFile(@"C:\Users\sarosh.niazi\Desktop\Images\IR_2019-05-06_0007.jpg"); //changes the palette of image1 image1.Palette = PaletteManager.Arctic; //set the image in pictureBox1 to the one with a new palette pictureBox1.Image = image1.Image; }
public static void Compress(string sourceFile, string outputVideoFile, Mode mode) { Log.Info($"Compressing {sourceFile} with H.264 to {outputVideoFile}. Using compression mode {mode}"); using (var thermalImage = new ThermalImageFile(sourceFile)) { // loop through every frame and calculate min and max values var(minValue, maxValue) = FindMinMaxValues(thermalImage); // Find bounding box of moving train var boundingBoxes = new[]
private void PlaybackForm_Load(object sender, EventArgs e) { _imageFile = new ThermalImageFile(Path); _imageFile.Changed += _imageFile_Changed; pictureBox1.Image = _imageFile.Image; if (_imageFile.ThermalSequencePlayer.Count() > 1) { _timer.Interval = 20; _timer.Tick += _timer_Tick; _timer.Start(); } }
private void Open_Click(object sender, EventArgs e) { OpenFileDialog fd = new OpenFileDialog(); fd.Filter = "Image files (*.jpg)|*.jpg"; fd.InitialDirectory = Environment.SpecialFolder.MyPictures.ToString(); fd.RestoreDirectory = true; if (fd.ShowDialog() == DialogResult.OK) { filename = fd.FileName; ThermalImageFile th = new ThermalImageFile(filename); var img = th.Image; pictureBox1.Image = (Image)img.Clone(); th.Dispose(); } }
public static Object GetOnlyMode(string path) { try { using (ThermalImageFile th = new ThermalImageFile(path)) { th.Fusion.Mode = th.Fusion.VisualOnly; //可见光模式 ImageConverter imgconv = new ImageConverter(); byte[] bytes = (byte[])imgconv.ConvertTo(th.Image, typeof(byte[])); System.IO.Stream stream = new System.IO.MemoryStream(bytes); return(stream); } } catch (Exception ex) { return("请求对象不是红外图片原始文件,无法打开可见光模式!" + ex.Message.ToString());; } }
/// <summary> /// 标记指定矩形区域内的最高和最低温度点 /// </summary> /// <param name="th">红外图片对象</param> /// <param name="rect">指定矩形</param> public void GetTargetResult(ThermalImageFile th, List <Rect_param> param_list, Graphics g) { List <Result_pic_info> templist = new List <Result_pic_info>(); foreach (var rect in param_list) { Rectangle target_rect = new Rectangle(rect.x, rect.y, rect.width, rect.height); double[] tempertureRect = th.GetValues(target_rect); //Math.Round(d, 2).ToString() Point pt_max = GetMaxPointInRectangle(tempertureRect, target_rect); //获取高温点坐标 Point pt_min = GetMinPointInRectangle(tempertureRect, target_rect); //获取高温点坐标 var value = GetMaxMinInRectangle(tempertureRect); //标记点 FillTriangle_1(g, pt_max, Dire.UP); FillTriangle_1(g, pt_min, Dire.DOWN); //结果数值列表 templist.Add(new Result_pic_info(value.rect_max, value.rect_min, value.rect_avg, pt_max, pt_min, rect.id, target_rect)); } this.result_Rect_Info_lsit = templist; }
private FlirImage ProcessImage(ThermalImageFile thermalImage) { FlirImage flirImageData = new FlirImage { DateTaken = thermalImage.DateTaken, Description = thermalImage.Description, Height = thermalImage.Height, MaxSignalValue = thermalImage.MaxSignalValue, MinSignalValue = thermalImage.MinSignalValue, Precision = thermalImage.Precision, TemperatureUnit = (Enums.TemperatureUnit)Enum.Parse(typeof(Enums.TemperatureUnit), thermalImage.TemperatureUnit.ToString()), Width = thermalImage.Width, ThermalData = ExtractTemperatureReadings(thermalImage), Title = thermalImage.Title }; if (thermalImage.CameraInformation != null) { flirImageData.CameraInfo = new CameraInfo { Filter = thermalImage.CameraInformation.Filter, Fov = thermalImage.CameraInformation.Fov, Lens = thermalImage.CameraInformation.Lens, Model = thermalImage.CameraInformation.Model, RangeMax = thermalImage.CameraInformation.Range.Maximum, RangeMin = thermalImage.CameraInformation.Range.Minimum, SerialNumber = thermalImage.CameraInformation.SerialNumber } } ; if (thermalImage.CompassInformation != null) { flirImageData.CompassInfo = new Models.CompassInfo { Degrees = thermalImage.CompassInformation.Degrees, Pitch = thermalImage.CompassInformation.Pitch, Roll = thermalImage.CompassInformation.Roll } } ; if (thermalImage.GpsInformation != null) { flirImageData.GpsInfo = new GpsInfo { Altitude = thermalImage.GpsInformation.Altitude, Dop = thermalImage.GpsInformation.Dop, Latitude = thermalImage.GpsInformation.Latitude, Longitude = thermalImage.GpsInformation.Longitude, MapDatum = thermalImage.GpsInformation.MapDatum, Satellites = thermalImage.GpsInformation.Satellites } } ; if (thermalImage.ThermalParameters != null) { flirImageData.ThermalParameters = new ThermalParameters { AtmosphericTemperature = thermalImage.ThermalParameters.AtmosphericTemperature, Distance = thermalImage.ThermalParameters.Distance, Emissivity = thermalImage.ThermalParameters.Emissivity, ExternalOpticsTemperature = thermalImage.ThermalParameters.ExternalOpticsTemperature, ExternalOpticsTransmission = thermalImage.ThermalParameters.ExternalOpticsTransmission, ReferenceTemperature = thermalImage.ThermalParameters.ReferenceTemperature, ReflectedTemperature = thermalImage.ThermalParameters.ReflectedTemperature, RelativeHumidity = thermalImage.ThermalParameters.RelativeHumidity, Transmission = thermalImage.ThermalParameters.Transmission } } ; return(flirImageData); }
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); } }
public ImageProcessor(string imageFilePath) { FlirImageFile = new ThermalImageFile(imageFilePath); _flirImageData = ProcessImage(FlirImageFile); }