Exemplo n.º 1
0
        private void SendImg()
        {
            IsSend = true;
            Task.Factory.StartNew(() =>
            {
                while (IsSend)
                {
                    byte[] bytes;
                    using (FileStream fs = new FileStream(@"D:\Test\111.jpg", FileMode.Open))
                    {
                        bytes = new byte[fs.Length];
                        fs.Read(bytes, 0, (int)fs.Length);
                    }
                    string base64txt = Convert.ToBase64String(bytes);   //bas64编码

                    AlgorithmRequestParam rparam = new AlgorithmRequestParam()
                    {
                        camNo     = "53010102",
                        image     = base64txt,
                        imageBody = base64txt
                    };
                    string jsonStr = SerializeHelper.SerializeObjectToJson(rparam);
                    ServerControl.GetInstance().ServerSendMsg(CODE_SENDIMG, Encoding.UTF8.GetBytes(jsonStr));
                    Thread.Sleep(TimeSpan.FromSeconds(3));
                }
            });
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            Console.WriteLine("程序已启动,输入Q/q退出程序!");
            ServerControl.GetInstance().ServerInit();
            string txt = string.Empty;

            while (!(txt = Console.ReadLine()).ToUpper().Equals("Q"))
            {
                Console.WriteLine(txt);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 自动校准黑体坐标
        /// </summary>
        public void AutoSetBlackBodyPoint()
        {
            Task.Factory.StartNew(() =>
            {
                while (true)
                {
                    Thread.Sleep(TimeSpan.FromSeconds(15));

                    BlackBodyPoint blackBodyPoint = new BlackBodyPoint()
                    {
                        xpoint = 55,
                        ypoint = 105
                    };
                    string jsonStr = SerializeHelper.SerializeObjectToJson(blackBodyPoint);
                    byte[] body    = Encoding.UTF8.GetBytes(jsonStr);
                    ServerControl.GetInstance().ServerSendMsg(CODE_SETPOINT, body);
                }
            });
        }
Exemplo n.º 4
0
        public async Task OnSessionDataReceived(AsyncTcpServerSession session, byte[] data, int offset, int count)
        {
            if (data == null || data.Length <= 0)
            {
                return;
            }
            byte code = data[0];                      //功能码

            byte[] bytes = new byte[data.Length - 1]; //正文数据
            Array.Copy(data, 1, bytes, 0, bytes.Length);
            string unBase64txt = Encoding.UTF8.GetString(bytes);

            byte[] unBase64Bytes = Convert.FromBase64String(unBase64txt);   //bas64解码
            if (!code.Equals(CODE_HEARTBEAT))
            {
                Console.WriteLine($"功能码:{code.ToString()},数据{Encoding.UTF8.GetString(unBase64Bytes)}");
            }
            try
            {
                switch (code)
                {
                case CODE_FACEUPLOAD:       //名单上传
                {
                    string     upLoadFaceStr = Encoding.UTF8.GetString(unBase64Bytes);
                    UpLoadFace upLoadFace    = SerializeHelper.SerializeJsonToObject <UpLoadFace>(upLoadFaceStr);
                    byte[]     imgBytes      = Convert.FromBase64String(upLoadFace.imagebytes);
                    FileReadWriteHelper.WriteBytesToFile($@"D:\Test\{DateTime.Now.ToString("yyyyMMddHHmmssfff")}.jpg", imgBytes);          //保存图片

                    ServerControl.GetInstance().faceList.Add(new FaceInfo()
                        {
                            filename     = upLoadFace.filename,
                            idnumber     = upLoadFace.idnumber,
                            imagebytes   = upLoadFace.imagebytes,
                            name         = upLoadFace.name,
                            sex          = upLoadFace.sex,
                            serialnumber = upLoadFace.serialnumber,
                            type         = upLoadFace.type
                        });
                    ServerControl.GetInstance().ServerSendMsg(CODE_FACEUPLOAD, new byte[] { SUCCESS });
                    Console.WriteLine($"名单上传成功,列表还有白名单{ServerControl.GetInstance().faceList.Where(p => p.type.Equals("white")).Count()}个,和名单{ServerControl.GetInstance().faceList.Where(p => p.type.Equals("black")).Count()}个!");
                    break;
                }

                case CODE_FACESELECT:       //名单查询
                {
                    SelectFace selectFace = new SelectFace();
                    switch (unBase64Bytes[0])
                    {
                    case WHITEFACE:
                        selectFace.faceList = ServerControl.GetInstance().faceList.Where(p => p.type.Equals("white")).ToList();
                        break;

                    case BLACKFACE:
                        selectFace.faceList = ServerControl.GetInstance().faceList.Where(p => p.type.Equals("black")).ToList();
                        break;

                    case ALLFACE:
                        selectFace.faceList = ServerControl.GetInstance().faceList;
                        break;
                    }
                    string jsonStr = SerializeHelper.SerializeObjectToJson(selectFace);
                    byte[] tBytes  = Encoding.UTF8.GetBytes(jsonStr);
                    ServerControl.GetInstance().ServerSendMsg(CODE_FACESELECT, tBytes);
                    Console.WriteLine($"名单查询成功,一共查到{selectFace.faceList.Count}个名单!");
                    break;
                }

                case CODE_FACEDELETE:       //名单删除
                {
                    string     deleteFaceStr = Encoding.UTF8.GetString(unBase64Bytes);
                    DeleteFace deleteFace    = SerializeHelper.SerializeJsonToObject <DeleteFace>(deleteFaceStr);

                    var dFace = ServerControl.GetInstance().faceList.Where(p => p.type.Equals(deleteFace.type) && p.serialnumber.Equals(deleteFace.serialnumber)).First();
                    ServerControl.GetInstance().faceList.Remove(dFace);

                    ServerControl.GetInstance().ServerSendMsg(CODE_FACEDELETE, new byte[] { SUCCESS });
                    Console.WriteLine($"名单删除成功,列表还有白名单{ServerControl.GetInstance().faceList.Where(p => p.type.Equals("white")).Count()}个,和名单{ServerControl.GetInstance().faceList.Where(p => p.type.Equals("black")).Count()}个!");
                    break;
                }

                case CODE_FACECLEAR:        //名单清除
                {
                    List <FaceInfo> clList = new List <FaceInfo>();
                    switch (unBase64Bytes[0])
                    {
                    case WHITEFACE:
                        clList = ServerControl.GetInstance().faceList.Where(p => p.type.Equals("black")).ToList();
                        break;

                    case BLACKFACE:
                        clList = ServerControl.GetInstance().faceList.Where(p => p.type.Equals("black")).ToList();
                        break;

                    case ALLFACE:
                        clList = ServerControl.GetInstance().faceList;
                        break;
                    }
                    foreach (var item in clList)
                    {
                        ServerControl.GetInstance().faceList.Remove(item);
                    }

                    ServerControl.GetInstance().ServerSendMsg(CODE_FACECLEAR, new byte[] { SUCCESS });
                    Console.WriteLine($"名单清除成功,列表还有白名单{ServerControl.GetInstance().faceList.Where(p => p.type.Equals("white")).Count()}个,和名单{ServerControl.GetInstance().faceList.Where(p => p.type.Equals("black")).Count()}个!");
                    break;
                }

                case CODE_FACCONTRAST:        //人脸对比
                {
                    switch (unBase64Bytes[0])
                    {
                    case START:
                        ServerControl.GetInstance().ServerSendMsg(CODE_FACCONTRAST, new byte[] { SUCCESS });
                        IsSend = false;
                        Console.WriteLine("启动人脸对比成功,抓图中。。。");
                        SendImg();
                        break;

                    case STOP:
                        ServerControl.GetInstance().ServerSendMsg(CODE_FACCONTRAST, new byte[] { STOPSUCCESS });
                        IsSend = false;
                        Console.WriteLine("关闭人脸对比成功!");
                        break;
                    }
                    break;
                }

                case CODE_FOLLOW:       //跟随
                {
                    switch (unBase64Bytes[0])
                    {
                    case START:
                        ServerControl.GetInstance().ServerSendMsg(CODE_FOLLOW, new byte[] { SUCCESS });
                        Console.WriteLine("启动跟随成功!");
                        break;

                    case STOP:
                        ServerControl.GetInstance().ServerSendMsg(CODE_FOLLOW, new byte[] { STOPSUCCESS });
                        Console.WriteLine("关闭跟随成功!");
                        break;

                    case RESTART:
                        ServerControl.GetInstance().ServerSendMsg(CODE_FOLLOW, new byte[] { RESTARTSUCCESS });
                        Console.WriteLine("重新跟随成功!");
                        break;
                    }
                    break;
                }

                case CODE_GETPOINT:     //获取黑体坐标
                {
                    BlackBodyPoint blackBodyPoint = new BlackBodyPoint()
                    {
                        xpoint = 55,
                        ypoint = 105
                    };
                    string jsonStr = SerializeHelper.SerializeObjectToJson(blackBodyPoint);
                    byte[] body    = Encoding.UTF8.GetBytes(jsonStr);
                    ServerControl.GetInstance().ServerSendMsg(CODE_SETPOINT, body);
                    Console.WriteLine("校准黑体坐标成功!");
                    break;
                }

                case CODE_FACEIDENTIFY:     //人脸识别
                    break;

                case CODE_FACEALARM:        //人脸报警
                    break;

                case CODE_HEARTBEAT:        //心跳
                    break;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteError(ex);
                Console.WriteLine($"解析接收数据异常:{ex.ToString()}");
            }
        }