⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 c#写的读fpf文件的程序
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


namespace ReadFpf
{
    public partial class Form1 : Form
    {
        /*  String lengths    */
        public const int FPF_CAMERA_TYPE_LEN = 31;   /* Camera name string */
        public const int FPF_CAMERA_PARTN_LEN = 31;   /* Camera part number string */
        public const int FPF_CAMERA_SN_LEN = 31;   /* Scanner serial number string */
        public const int FPF_LENS_TYPE_LEN = 31;   /* Lens name string */
        public const int FPF_LENS_PARTN_LEN = 31;   /* Lens part number string */
        public const int FPF_LENS_SN_LEN = 31;   /* Lens serial number string */
        public const int FPF_FILTER_TYPE_LEN = 31;   /* Filter name string */
        public const int FPF_FILTER_PARTN_LEN = 31;   /* Filter part number string */
        public const int FPF_FILTER_SN_LEN = 31;   /* Filter serial number string */


        public const int FPF_IMAGE_DATA_T_LEN = 120;   /* The image data structure (120 bytes) */
        public const int FPF_CAMDATA_T_LEN = 360;   /* The camera data structure (360 bytes) */
        public const int FPF_OBJECT_PAR_T_LEN = 104;   /* The object parameters data structure (104 bytes) */
        public const int FPF_DATETIME_T_LEN = 92;   /* The date and time data structure (92 bytes) */
        public const int FPF_SCALING_T_LEN = 88;   /* The scaling data structure (88 bytes) */
        public const int FPFHEADER_T_LEN = 982;   /* The scaling data structure (88 bytes) */


        struct FPF_IMAGE_DATA_T
        {
            public unsafe fixed char fpfID[32];                 /*  "FLIR Public Image Format" */
            public ulong version;         /*  = 1 */
            public ulong pixelOffset;     /*  Offset to pixel values from start of fpfID. */
            public ushort ImageType;       /*  Temperature = 0, 
                                               Diff Temp = 2, 
                                               Object Signal = 4,
                                               Diff Object Signal = 5, etc */
            public ushort pixelFormat;     /*  0 = short integer = 2 bytes
                                               1 = long integer = 4 bytes 
                                               2 = float (single precision)  = 4 bytes
                                               3 = double (double precision) = 8 bytes */

            public ushort xSize;
            public ushort ySize;

            public ulong trig_count;      /* external trig counter */
            public ulong frame_count;     /* frame number in sequence */

            public unsafe fixed long spareLong[16];            /* = 0 */
        };

        struct FPF_CAMDATA_T
        {
            public unsafe fixed char camera_name[FPF_CAMERA_TYPE_LEN + 1];
            public unsafe fixed char camera_partn[FPF_CAMERA_PARTN_LEN + 1];
            public unsafe fixed char camera_sn[FPF_CAMERA_SN_LEN + 1];

            public float camera_range_tmin;
            public float camera_range_tmax;

            public unsafe fixed char lens_name[FPF_LENS_TYPE_LEN + 1];
            public unsafe fixed char lens_partn[FPF_LENS_PARTN_LEN + 1];
            public unsafe fixed char lens_sn[FPF_LENS_SN_LEN + 1];

            public unsafe fixed char filter_name[FPF_FILTER_TYPE_LEN + 1];
            public unsafe fixed char filter_partn[FPF_FILTER_PARTN_LEN + 1];
            public unsafe fixed char filter_sn[FPF_FILTER_SN_LEN + 1];

            public unsafe fixed long spareLong[16];/* = 0 */
        };

        struct FPF_OBJECT_PAR_T
        {
            public float emissivity;               /* 0 - 1 */
            public float objectDistance;           /* Meters */
            public float ambTemp;                  /* Reflected Ambient temperature in Kelvin */
            public float atmTemp;                  /* Atmospheric temperature in Kelvin */
            public float relHum;                   /* 0 - 1 */
            public float compuTao;                 /* Computed atmospheric transmission 0 - 1*/
            public float estimTao;                 /* Estimated atmospheric transmission 0 - 1*/
            public float refTemp;                  /* Reference temperature in Kelvin */
            public float extOptTemp;               /* Kelvin */
            public float extOptTrans;              /* 0 - 1 */
            public unsafe fixed long spareLong[16];  /* = 0 */
        } ;

        struct FPF_DATETIME_T
        {
            public int Year;
            public int Month;
            public int Day;
            public int Hour;
            public int Minute;
            public int Second;
            public int MilliSecond;
            public unsafe fixed long spareLong[16]; /* = 0 */
        } ;

        struct FPF_SCALING_T
        {
            public float tMinCam;                  /* Camera scale min, in current output */
            public float tMaxCam;                  /* Camera scale max */
            public float tMinCalc;                 /* Calculated min (almost true min) */
            public float tMaxCalc;                 /* Calculated max (almost true max) */
            public float tMinScale;                /* Scale min */
            public float tMaxScale;                /* Scale max */
            public unsafe fixed long spareLong[16];  /* = 0 */
        };

        struct FPFHEADER_T
        {
            public FPF_IMAGE_DATA_T imgData;
            public FPF_CAMDATA_T camData;
            public FPF_OBJECT_PAR_T objPar;
            public FPF_DATETIME_T datetime;
            public FPF_SCALING_T scaling;
            public unsafe fixed long spareLong[32];  /* = 0 */
        };

        public Form1()
        {
            InitializeComponent();
        }

        private void button_Read_FPF_Click(object sender, EventArgs e)
        {
            unsafe{
            OpenFileDialog open_Fpf_Dialog = new OpenFileDialog();
            open_Fpf_Dialog.Title = "打开(Open)";
            open_Fpf_Dialog.Filter = "FLIR Public Image Files (*.fpf)|*.fpf|All Files (*.*)|*.*||";
            try
            {
                if (open_Fpf_Dialog.ShowDialog() == DialogResult.OK)
                {
                    FileStream   stream   =   new   FileStream(open_Fpf_Dialog.FileName,FileMode.Open);
                    //FPF_IMAGE_DATA_T imgData=new FPF_IMAGE_DATA_T();
                    FPFHEADER_T fpf_Header = new FPFHEADER_T();
                    int i = 0;
                    byte[] buffer;
                    Byte* pB;
                    //BinaryReader br = new BinaryReader(stream,Encoding.Unicode);

                    //获得FPF_IMAGE_DATA_T类型的数据;
                    buffer = new byte[FPF_IMAGE_DATA_T_LEN];
                    stream.Read(buffer, 0, FPF_IMAGE_DATA_T_LEN);
                    i = 0;
                    for (int j = 0; j < 32; j++)
                    {
                        fpf_Header.imgData.fpfID[j] = (char)(buffer[i++]);
                    }
                    fpf_Header.imgData.version = (ulong)((buffer[i++]) + (buffer[i++] << 8) + (buffer[i++] << 16) + (buffer[i++] << 24)); ;
                    fpf_Header.imgData.pixelOffset = (ulong)((buffer[i++]) + (buffer[i++] << 8) + (buffer[i++] << 16) + (buffer[i++] << 24));
                    fpf_Header.imgData.ImageType = (ushort)((buffer[i++]) + (buffer[i++] << 8));
                    fpf_Header.imgData.pixelFormat = (ushort)((buffer[i++]) + (buffer[i++] << 8));
                    fpf_Header.imgData.xSize = (ushort)((buffer[i++]) + (buffer[i++] << 8));
                    fpf_Header.imgData.ySize = (ushort)((buffer[i++]) + (buffer[i++] << 8));
                    fpf_Header.imgData.trig_count = (ulong)((buffer[i++]) + (buffer[i++] << 8) + (buffer[i++] << 16) + (buffer[i++] << 24));
                    fpf_Header.imgData.frame_count = (ulong)((buffer[i++]) + (buffer[i++] << 8) + (buffer[i++] << 16) + (buffer[i++] << 24));
                    for (int j = 0; j < 16; j++)
                    {
                        fpf_Header.imgData.spareLong[j] = (long)((buffer[i++]) + (buffer[i++] << 8) + (buffer[i++] << 16) + (buffer[i++] << 24));
                    }
                    
                    //获得FPF_CAMDATA_T类型的数据;
                    buffer = new byte[FPF_CAMDATA_T_LEN];
                    stream.Read(buffer, 0, FPF_CAMDATA_T_LEN);
                    i = 0;
                    for (int j = 0; j < FPF_CAMERA_TYPE_LEN + 1; j++)
                    {
                        fpf_Header.camData.camera_name[j] = (char)(buffer[i++]);
                    }
                    for (int j = 0; j < FPF_CAMERA_PARTN_LEN + 1; j++)
                    {
                        fpf_Header.camData.camera_partn[j] = (char)(buffer[i++]);
                    }
                    for (int j = 0; j < FPF_CAMERA_SN_LEN + 1; j++)
                    {
                        fpf_Header.camData.camera_sn[j] = (char)(buffer[i++]);
                    }
                    pB = (Byte*)(&fpf_Header.camData.camera_range_tmin);
                    for (int j = 0; j < 8; j++)
                    {
                        pB[j] = (buffer[i++]);
                    }
                    //fpf_Header.camData.camera_range_tmin = (float)((buffer[i++]) + (buffer[i++] << 8) + (buffer[i++] << 16) + (buffer[i++] << 24));
                    //fpf_Header.camData.camera_range_tmax = (float)((buffer[i++]) + (buffer[i++] << 8) + (buffer[i++] << 16) + (buffer[i++] << 24));
                    for (int j = 0; j < FPF_LENS_TYPE_LEN + 1; j++)
                    {
                        fpf_Header.camData.lens_name[j] = (char)(buffer[i++]);
                    }
                    for (int j = 0; j < FPF_LENS_PARTN_LEN + 1; j++)
                    {
                        fpf_Header.camData.lens_partn[j] = (char)(buffer[i++]);
                    }
                    for (int j = 0; j < FPF_LENS_SN_LEN + 1; j++)
                    {
                        fpf_Header.camData.lens_sn[j] = (char)(buffer[i++]);
                    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -