基于大疆dij_irp.exe进行红外测温

/// <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;
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值