public static (IRHeader, byte[]) UnPack(byte[] s)
        {
            int      _ir_size = Marshal.SizeOf(typeof(IRHeader));
            var      ir_bytes = s.Take(_ir_size).ToArray();
            IRHeader ret      = null;

            using (MemoryStream ms = new MemoryStream(ir_bytes))
            {
                IFormatter br = new BinaryFormatter();
                ret = (br.Deserialize(ms) as IRHeader);
            }

            return(ret, s.Skip(_ir_size).ToArray());
        }
        public static byte[] PackImg(IRHeader header, ndarray img, int quality = 95, string img_fmt = ".jpg")
        {
            int[] encodeParams = null;
            OpenCvSharp.ImageEncodingParam imageEncodingParam = new ImageEncodingParam(ImwriteFlags.JpegQuality, quality);
            if (img_fmt.ToLower() == ".jpg" || img_fmt.ToLower() == ".jpeg")
            {
                encodeParams = new int[] { }
            }
            ;

            Cv2.ImEncode(img_fmt, new Mat(img.GetMemPtr()), out var buf, imageEncodingParam);
            return(Pack(header, buf));
        }
    }
        public static byte[] Pack(IRHeader header, byte[] s)
        {
            List <byte> bytes     = new List <byte>();
            IFormatter  formatter = new BinaryFormatter();

            using (MemoryStream stream = new MemoryStream())
            {
                formatter.Serialize(stream, header);
                bytes = stream.ToArray().ToList();
            }

            bytes.AddRange(s);
            return(bytes.ToArray());
        }