/// <summary>
/// 大疆红外图像
/// </summary>
public class InfraImage : IDisposable
{
private string exe;
private string img;
private string outPut;
private int width;
private int height;
private Mat mat;
public InfraImage(string img)
{
this.exe = AppDomain.CurrentDomain.BaseDirectory+@"\温度解析\dji_irp.exe";
if (!File.Exists(exe))
{
throw new Exception($"温度解析程序 {exe} 不存在");
}
this.img = img;
if (!File.Exists(img))
{
throw new Exception($"图像 {img} 不存在");
}
outPut = Path.Combine(Path.GetDirectoryName(img), Path.GetFileNameWithoutExtension(img) + ".raw");
if (!File.Exists(outPut))
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
convertImg(img, outPut);
stopwatch.Stop();
Console.WriteLine($"{stopwatch.ElapsedMilliseconds}毫秒");
}
System.Windows.Size imageSize = FileInfoHelper.GetImageSizee(img);
width = (int)imageSize.Width;
height = (int)imageSize.Height;
var res = File.ReadAllBytes(outPut);
mat = new Mat(width, height, MatType.CV_32FC1, res);
}
/// <summary>
/// 最大和最小温度
/// </summary>
/// <param name="min"></param>
/// <param name="max"></param>
public void getMaxMinTemp(out double min, out double max)
{
mat.MinMaxIdx(out double _min, out double _max);
min = _min;
max = _max;
Console.WriteLine($"{min} {max}");
}
/// <summary>
/// 平均温度
/// </summary>
/// <returns></returns>
public double getAverTemp()
{
var mean = mat.Mean();
return mat.Mean().Val0;
}
/// <summary>
/// 获取温度
/// </summary>
/// <param name="v1"></param>
/// <param name="v2"></param>
/// <returns></returns>
public float getTemp(int row, int col)
{
return mat.Get<float>(row, col);
}
public void Dispose()
{
if (!mat.IsDisposed)
{
mat.Dispose();
}
}
private void convertImg(string img, string outPut)
{
Process process = new Process();
process.StartInfo.FileName = exe;
process.StartInfo.Arguments = $"dji_irp.exe -s {img} -a measure -o {outPut} --measurefmt float32";
// 必须禁用操作系统外壳程序
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
//启动进程
process.Start();
//准备读出输出流和错误流
string outputData = string.Empty;
string errorData = string.Empty;
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.OutputDataReceived += (sender, e) =>
{
outputData += (e.Data + "\n");
};
process.ErrorDataReceived += (sender, e) =>
{
errorData += (e.Data + "\n");
};
//等待退出
process.WaitForExit();
//返回流结果
string output = outputData;
string error = errorData;
}
}
基于大疆dij_irp.exe进行红外测温
最新推荐文章于 2024-05-22 19:21:18 发布