Ejemplo n.º 1
0
        public static int Insert(Database db, REct oRect)
        {
            StringBuilder sbField = new StringBuilder();
            StringBuilder sbValue = new StringBuilder();
            sbField.Append("INSERT INTO  [REct](");
            sbValue.Append("values (");
            //sbField.Append("[RectID]");
            //sbValue.AppendFormat("'{0}'", oRect.RectID);
            sbField.Append("[X]");
            sbValue.AppendFormat("{0}", oRect.X);
            sbField.Append(",[Y]");
            sbValue.AppendFormat(",{0}", oRect.Y);
            sbField.Append(",[W]");
            sbValue.AppendFormat(",{0}", oRect.W);
            sbField.Append(",[H])");
            sbValue.AppendFormat(",{0})", oRect.H);
            string cmdText = sbField.ToString() + " " + sbValue.ToString();

            try
            {
                cmdText = cmdText.Replace("\r\n", "");
                db.ExecuteNonQuery(CommandType.Text, cmdText);
                int id = int.Parse(db.ExecuteScalar(CommandType.Text, "SELECT     ident_current('REct')").ToString());
                return id;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }
Ejemplo n.º 2
0
        public int Insert(ref string errMessage, REct oRect)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            try
            {
                return REctDataAccess.Insert(db, oRect);

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return -1;
            }
        }
Ejemplo n.º 3
0
        public void AnalysisFile()
        {
            try
            {
                int pictureId;
                int rectId;
                int vehicleId;
                int trackId;
                int faceId;
                xmlDoc.Load(@"c:\1.0.xml");
                XmlNodeList xml_vehicles,xml_camera,xml_vehicles_tract_rects,xml_faces;

                xml_camera = xmlDoc.SelectSingleNode("/pr/cameras").ChildNodes;
                foreach (XmlNode camitem in xml_camera)
                {

                    XmlElement xcam=(XmlElement)camitem;
                    CapturePicture ocap=new CapturePicture();
                    ocap.CameraID = Convert.ToInt32(xcam.GetAttribute("id"));
                    XmlNode xml_time = xmlDoc.SelectSingleNode("/pr/cameras/camera/timeid");
                    ocap.Datetime = new DateTime(long.Parse(xml_time.InnerText));
                    string errMessage = "";
                    ocap.FilePath = SystemParametersBusiness.Instance.ListSystemParameter["CapPicPath"] + @"\" + ocap.CameraID +
                        @"\" + ocap.Datetime.ToString(@"yyyy\\MM\\dd\\HH\\") + ocap.CameraID +ocap.Datetime.ToString(@"_yyyy_MM_dd_HH_mm_ss_fff")+".jpg";
                    pictureId = CapturePictureBusiness.Instance.Insert(ref errMessage, ocap);

                    xml_vehicles=xmlDoc.SelectSingleNode("/pr/cameras/camera/objects/vehicles").ChildNodes;
                    foreach (XmlNode veh_item in xml_vehicles)
                    {
                        XmlNode xml_vehicles_rect = xmlDoc.SelectSingleNode("/pr/cameras/camera/objects/vehicles/vehicle/rect");
                        XmlElement xml_vehicles_rect1 = (XmlElement)xml_vehicles_rect;
                        REct rect1 = new REct();
                        rect1.X = Convert.ToInt32(xml_vehicles_rect1.GetAttribute("x"));
                        rect1.Y = Convert.ToInt32(xml_vehicles_rect1.GetAttribute("y"));
                        rect1.W = Convert.ToInt32(xml_vehicles_rect1.GetAttribute("w"));
                        rect1.H = Convert.ToInt32(xml_vehicles_rect1.GetAttribute("h"));
                        rectId = REctBusiness.Instance.Insert(ref errMessage, rect1);

                        Vehicle oveh=new Vehicle();
                        XmlElement xveh=(XmlElement)veh_item;
                        oveh.VehicleID=Convert.ToInt32(xveh.GetAttribute("id"));
                        oveh.platenumber=Convert.ToString(xveh.GetAttribute("platenumber"));
                        oveh.speed=Convert.ToSingle(xveh.GetAttribute("speed"));
                        if (Convert.ToInt32(xveh.GetAttribute("stemagainst"))==1)
                        {
                            oveh.stemagainst = true;
                        }
                        else
                        {
                            oveh.stemagainst = false;
                        }
                        if (Convert.ToInt32(xveh.GetAttribute("accident")) == 1)
                        {
                            oveh.accident = true;
                        }
                        else
                        {
                            oveh.accident = false;
                        }
                        if (Convert.ToInt32(xveh.GetAttribute("stop")) == 1)
                        {
                            oveh.stop = true;
                        }
                        else
                        {
                            oveh.stop = false;
                        }
                        if (Convert.ToInt32(xveh.GetAttribute("linechange")) == 1)
                        {
                            oveh.linechange = true;
                        }
                        else
                        {
                            oveh.linechange = false;
                        }
                        oveh.platecolor=Convert.ToString(xveh.GetAttribute("platecolor"));
                        oveh.vehiclecolor=Convert.ToString(xveh.GetAttribute("vehiclecolor"));
                        oveh.PictureID = pictureId;
                        oveh.REctId = rectId;
                        vehicleId = VehicleBusiness.Instance.Insert(ref errMessage, oveh);

                        xml_vehicles_tract_rects = xmlDoc.SelectSingleNode("/pr/cameras/camera/objects/vehicles/vehicle/track").ChildNodes;
                        foreach (XmlNode xml_vehicles_tract_rects_item in xml_vehicles_tract_rects)
                        {
                            REct rect2 = new REct();
                            XmlElement xml_vehicles_tract_rects_item1 = (XmlElement)xml_vehicles_tract_rects_item;
                            rect2.X = Convert.ToInt32(xml_vehicles_tract_rects_item1.GetAttribute("x"));
                            rect2.Y = Convert.ToInt32(xml_vehicles_tract_rects_item1.GetAttribute("y"));
                            rect2.W = Convert.ToInt32(xml_vehicles_tract_rects_item1.GetAttribute("w"));
                            rect2.H = Convert.ToInt32(xml_vehicles_tract_rects_item1.GetAttribute("h"));
                            rectId = REctBusiness.Instance.Insert(ref errMessage, rect2);
                        }
                        Track track = new Track();
                        track.REct = rectId;
                        trackId = TrackBusiness.Instance.Insert(ref errMessage, track);

                    }
                    xml_faces = xmlDoc.SelectSingleNode("/pr/cameras/camera/objects/faces").ChildNodes;
                    foreach (XmlNode xml_faces_item in xml_faces)
                    {
                        //XmlElement xml_faces_item1 = (XmlElement)xml_faces_item;
                        XmlNode xml_faces_item_rect = xmlDoc.SelectSingleNode("/pr/cameras/camera/objects/faces/face/rect");
                        XmlElement xml_faces_item_rect1 = (XmlElement)xml_faces_item_rect;
                        REct rect3 = new REct();
                        rect3.X = Convert.ToInt32(xml_faces_item_rect1.GetAttribute("x"));
                        rect3.Y = Convert.ToInt32(xml_faces_item_rect1.GetAttribute("y"));
                        rect3.W = Convert.ToInt32(xml_faces_item_rect1.GetAttribute("w"));
                        rect3.H = Convert.ToInt32(xml_faces_item_rect1.GetAttribute("h"));
                        rectId = REctBusiness.Instance.Insert(ref errMessage, rect3);
                        XmlNode xml_faces_item_score = xmlDoc.SelectSingleNode("/pr/cameras/camera/objects/faces/face/score");
                        Face face = new Face();
                        face.RectID = rectId;
                        face.PictureID = pictureId;
                        face.score = Convert.ToSingle(xml_faces_item_score.InnerText);
                        faceId = FaceBusiness.Instance.Insert(ref errMessage, face);

                    }

            }

            }
            catch (Exception ex)
            {

                XtraMessageBox.Show(ex.ToString());
            }
        }
        public void Handle(byte[] bytes)
        {
            try
            {
                logger.Info("开始解析车牌数据");
                //获取xml
                XmlDocument xmlDocument = new XmlDocument() ;
                xmlDocument.LoadXml(BitConverter.ToString(bytes,4));

                string errMessage = "";
                int cameraid;
                DateTime timeid;
                XmlNodeList xml_cameras, xml_vehicles;
                xml_cameras = xmlDocument.SelectSingleNode("/pr/cameras").ChildNodes;
                foreach (XmlNode xmlItem in xml_cameras)
                {
                    XmlElement camera = (XmlElement)xmlItem;
                    cameraid = Convert.ToInt32(camera.GetAttribute("id"));
                    timeid = new DateTime(long.Parse(camera.GetAttribute("timeid")));
                    if (!CapturePictureBusiness.Instance.IsExistCapturePicture(ref errMessage, cameraid, timeid))
                    {
                        //将改图像从TempPicture表移动到CapturePicture//先获取临时图像GetTempPicture,再移动图像MoveTempPicture
                        //图像还在临时图像库中
                        TempPicture tempPicture = TempPictureBusiness.Instance.GetTempPicture(ref errMessage, cameraid, timeid);
                        string destFile = TempPictureBusiness.Instance.MoveTempPicture(ref errMessage, tempPicture);
                        CapturePicture capturePictureinsert = new CapturePicture() { CameraID = cameraid, Datetime = timeid, FilePath = destFile };
                        CapturePictureBusiness.Instance.Insert(ref errMessage, capturePictureinsert);
                    }
                    //识别结果入库
                    CapturePicture oCapturePicture = CapturePictureBusiness.Instance.GetCapturePicture(ref errMessage, cameraid, timeid);

                    xml_vehicles = xmlItem.FirstChild.ChildNodes;//获得faces节点
                    foreach (XmlNode vehicleItem in xml_vehicles)
                    {
                        XmlNode vehicleNode = vehicleItem.FirstChild;
                        XmlNode vehicleRectNode = vehicleNode.FirstChild;
                        XmlElement vehicleElement = (XmlElement)vehicleNode;
                        XmlElement vehicleRectElement = (XmlElement)vehicleRectNode;
                        REct vehicleRect = new REct();
                        vehicleRect.X = Convert.ToInt32(vehicleRectElement.GetAttribute("x"));
                        vehicleRect.Y = Convert.ToInt32(vehicleRectElement.GetAttribute("y"));
                        vehicleRect.W = Convert.ToInt32(vehicleRectElement.GetAttribute("w"));
                        vehicleRect.H = Convert.ToInt32(vehicleRectElement.GetAttribute("h"));
                        int rectId = REctBusiness.Instance.Insert(ref errMessage, vehicleRect);
                        Vehicle vehicle = new Vehicle();
                        vehicle.platenumber = Convert.ToString(vehicleElement.GetAttribute("platenumber"));
                        vehicle.speed = Convert.ToSingle(vehicleElement.GetAttribute("speed"));
                        if (Convert.ToInt32(vehicleElement.GetAttribute("stemagainst")) == 1)
                        {
                            vehicle.stemagainst = true;
                        }
                        else
                        {
                            vehicle.stemagainst = false;
                        }
                        if (Convert.ToInt32(vehicleElement.GetAttribute("accident")) == 1)
                        {
                            vehicle.accident = true;
                        }
                        else
                        {
                            vehicle.accident = false;
                        }
                        if (Convert.ToInt32(vehicleElement.GetAttribute("stop")) == 1)
                        {
                            vehicle.stop = true;
                        }
                        else
                        {
                            vehicle.stop = false;
                        }
                        if (Convert.ToInt32(vehicleElement.GetAttribute("linechange")) == 1)
                        {
                            vehicle.linechange = true;
                        }
                        else
                        {
                            vehicle.linechange = false;
                        }

                        vehicle.platecolor = Convert.ToString(vehicleElement.GetAttribute("platecolor"));
                        vehicle.vehiclecolor = Convert.ToString(vehicleElement.GetAttribute("vehiclecolor"));
                        vehicle.confidence = Convert.ToSingle(vehicleElement.GetAttribute("confidence"));
                        vehicle.REctId = rectId;
                        vehicle.PictureID = oCapturePicture.PictureID;
                        int vehicleId = VehicleBusiness.Instance.Insert(ref errMessage, vehicle);

                    }

                }
                //解析车牌数据并入库
                /*******************处理流程:

             * 1)解析xml文件,获取cameraid和DateTime
             * 2)根据cameraid和DateTime判断改图像是否已经进入CapturePicture表
             * 3)如果是;转5;
             * 4)如果否,将改图像从TempPicture表移动到CapturePicture//先获取临时图像GetTempPicture,再移动图像MoveTempPicture
             * 5)识别结果入库
             */

                logger.Info("结束解析车牌数据");
            }
            catch (Exception ex)
            {
                logger.Error("解析车牌数据错误:" + FromASCIIByteArray(bytes));
            }
        }
        public void Handle(byte[] bytes)
        {
            try
            {
                logger.Info("开始解析人脸数据");

                //获取xml
                XmlDocument xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(BitConverter.ToString(bytes, 4));

                string errMessage = "";
                int cameraid =-1;
                DateTime timeid = new DateTime(1,1,1);
                XmlNodeList xml_cameras,xml_faces;
                xml_cameras = xmlDocument.SelectSingleNode("/pr/cameras").ChildNodes;
                foreach (XmlNode xmlItem in xml_cameras)
                {
                    XmlElement camera = (XmlElement)xmlItem;
                    cameraid = Convert.ToInt32(camera.GetAttribute("id"));
                    timeid = new DateTime(long.Parse(camera.GetAttribute("timeid")));
                    if (!CapturePictureBusiness.Instance.IsExistCapturePicture(ref errMessage, cameraid, timeid))
                    {
                        //将改图像从TempPicture表移动到CapturePicture//先获取临时图像GetTempPicture,再移动图像MoveTempPicture
                        //图像还在临时图像库中
                        TempPicture tempPicture = TempPictureBusiness.Instance.GetTempPicture(ref errMessage, cameraid, timeid);
                        string destFile = TempPictureBusiness.Instance.MoveTempPicture(ref errMessage, tempPicture);
                        CapturePicture capturePictureinsert = new CapturePicture(){CameraID = cameraid,Datetime = timeid,FilePath = destFile};
                        CapturePictureBusiness.Instance.Insert(ref errMessage, capturePictureinsert);

                    }
                    //识别结果入库
                    CapturePicture oCapturePicture = CapturePictureBusiness.Instance.GetCapturePicture(ref errMessage,cameraid,timeid);
                    xml_faces = xmlItem.FirstChild.ChildNodes;//获得faces节点
                    string facePath = SystemParametersBusiness.Instance.ListSystemParameter["FacePicPath"] + @"\" + cameraid +
                        @"\" + timeid.ToString(@"yyyy\\MM\\dd\\HH\\") + cameraid + timeid.ToString(@"_yyyy_MM_dd_HH_mm_ss_fff");
                    int i = 1;
                    foreach (XmlNode faceItem in xml_faces)
                    {
                        XmlNode rectNode = faceItem.FirstChild;
                        XmlNode scoreNode = faceItem.LastChild;
                        XmlElement rectElement = (XmlElement)rectNode;
                        XmlElement scoreElement = (XmlElement)scoreNode;
                        REct facerect = new REct();
                        facerect.X = Convert.ToInt32(rectElement.GetAttribute("x"));
                        facerect.Y = Convert.ToInt32(rectElement.GetAttribute("y"));
                        facerect.W = Convert.ToInt32(rectElement.GetAttribute("w"));
                        facerect.H = Convert.ToInt32(rectElement.GetAttribute("h"));
                        int RectId = REctBusiness.Instance.Insert(ref errMessage, facerect);

                        //抠图
                        Image newImage = Image.FromFile(oCapturePicture.FilePath);
                        Bitmap tmpbitmap = new Bitmap(facerect.W+1, facerect.H+1);
                        Rectangle rectSrt = new Rectangle(facerect.X, facerect.Y, facerect.W, facerect.H);
                        Rectangle rectDst = new Rectangle(0, 0, facerect.W, facerect.H);
                        Graphics graphic = Graphics.FromImage(tmpbitmap);
                        graphic.DrawImage(newImage, rectDst, rectSrt, GraphicsUnit.Pixel);
                        string faceFile = facePath +"_" + i + ".jpg";
                        string path = Path.GetDirectoryName(faceFile);
                        if (!Directory.Exists(path))
                        {
                            Directory.CreateDirectory(path);
                        }
                        tmpbitmap.Save(faceFile, ImageFormat.Jpeg);

                        Face xmlface = new Face();
                        xmlface.score = Convert.ToSingle(scoreElement.InnerText);
                        xmlface.RectID = RectId;
                        xmlface.PictureID = oCapturePicture.PictureID;
                        xmlface.FacePath = faceFile;
                        int faceId = FaceBusiness.Instance.Insert(ref errMessage, xmlface);
                    }

                }
                //解析人脸数据并入库
                /*******************处理流程:

             * 1)解析xml文件,获取cameraid和DateTime
             * 2)根据cameraid和DateTime判断改图像是否已经进入CapturePicture表
             * 3)如果是;转5;
             * 4)如果否,将改图像从TempPicture表移动到CapturePicture//先获取临时图像GetTempPicture,再移动图像MoveTempPicture
             * 5)识别结果入库
             */

                CurrentFace = FaceBusiness.Instance.GetFace(ref errMessage, cameraid, timeid);
                OnDataChanged(this, new DataChangeEventArgs(GetType().Name));
                logger.Info("结束解析人脸数据");
            }
            catch (Exception ex)
            {
                logger.Error("解析人脸数据错误:" + FromASCIIByteArray(bytes));
            }
        }