Ejemplo n.º 1
0
        public Dictionary<int, Vehicle> GetVehicleCustom(ref string errMessage, string str)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            Dictionary<int, Vehicle> list = new Dictionary<int, Vehicle>();
            try
            {
                DataSet ds = VehicleDataAccess.GetVehicleCustom(db, str);
                Vehicle vehicle;
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    vehicle = new Vehicle(ds.Tables[0].Rows[i]);
                    vehicle.CapturePicture = CapturePictureBusiness.Instance.GetCapturePicture(ref errMessage, vehicle.PictureID);
                    vehicle.CameraInfo = CameraBusiness.Instance.GetCameraInfoByCameraId(ref errMessage,
                                                                                      vehicle.CapturePicture.CameraID);
                    vehicle.VideoInfo = VideoBusiness.Instance.GetVideoInfoById(ref errMessage, vehicle.VedioId);
                    list.Add(vehicle.VehicleID, vehicle);
                }
                return list;

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return null;
            }
        }
Ejemplo n.º 2
0
        public Vehicle GetVehicle(ref string errMessage, int cameraId, DateTime captureDataTime)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            Vehicle vehicle = null;

            try
            {
                DataSet ds = VehicleDataAccess.GetVehicleCustom(db, string.Format(" and CapturePicture.CameraId={0} and  CapturePicture.DateTime='{1}'", cameraId, captureDataTime));
                vehicle = new Vehicle(ds.Tables[0].Rows[0]);
                vehicle.CapturePicture = CapturePictureBusiness.Instance.GetCapturePicture(ref errMessage, vehicle.PictureID);
                vehicle.CameraInfo = CameraBusiness.Instance.GetCameraInfoByCameraId(ref errMessage,
                                                                                  vehicle.CapturePicture.CameraID);
                vehicle.VideoInfo = VideoBusiness.Instance.GetVideoInfoById(ref errMessage, vehicle.VedioId);
                return vehicle;

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return null;
            }
        }
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));
            }
        }
Ejemplo n.º 5
0
        public int InsertVehicle(ref string errMessage, Vehicle ovehicle)
        {
            Database db = DatabaseFactory.CreateDatabase();
            errMessage = "";
            try
            {
                return AnalysisXMLDataAccess.InsertVehicle(db, ovehicle);

            }
            catch (Exception ex)
            {
                errMessage = ex.Message + ex.StackTrace;
                logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace);
                return -1;
            }
        }
Ejemplo n.º 6
0
 private void advBandedGridView1_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e)
 {
     if (advBandedGridViewVehicle.SelectedRowsCount > 0)
     {
         int getSelectedRow = this.advBandedGridViewVehicle.GetSelectedRows()[0];
         _selectedVehicle = (Vehicle)(this.advBandedGridViewVehicle.GetRowCellValue(getSelectedRow, "��������"));
         FillPicVideoVehicle(_selectedVehicle);
     }
 }
Ejemplo n.º 7
0
 private void advBandedGridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
 {
     if (advBandedGridViewVehicle.SelectedRowsCount > 0)
        {
         int getSelectedRow = this.advBandedGridViewVehicle.GetSelectedRows()[0];
         _selectedVehicle = (Vehicle)(this.advBandedGridViewVehicle.GetRowCellValue(getSelectedRow, "��������"));
         FillPicVideoVehicle(_selectedVehicle);
     }
 }
Ejemplo n.º 8
0
        private void FillPicVideoVehicle(Vehicle ovehicle)
        {
            if (File.Exists(ovehicle.CapturePicture.FilePath))
            {
                pictureEditVehicle.Image = Image.FromFile(ovehicle.CapturePicture.FilePath);
            }
            if (File.Exists(ovehicle.VideoInfo.FilePath))
            {
                if (_lastVideoPort1 != -1)
                {
                    bool ret = HikPlayer.PlayM4_CloseFile(_lastVideoPort1);
                }
                if (File.Exists(ovehicle.VideoInfo.FilePath))
                {
                    _lastVideoPort1 = 1;
                    splitContainerControlFaceVideo.Visible = true;
                    HikPlayer.PlayM4_OpenFile(_lastVideoPort1, ovehicle.VideoInfo.FilePath);
                    HikPlayer.PlayM4_Play(_lastVideoPort1, splitContainerControlFaceVideo.Panel1.Handle);
                }

            }
        }
Ejemplo n.º 9
0
        public static int Insert(Database db, Vehicle oVehicle)
        {
            StringBuilder sbField = new StringBuilder();
            StringBuilder sbValue = new StringBuilder();
            sbField.Append("INSERT INTO  [Vehicle](");
            sbValue.Append("values (");
            sbField.Append("[VehicleID]");
            sbValue.AppendFormat("{0}", oVehicle.VehicleID);
            sbField.Append(",[platenumber]");
            sbValue.AppendFormat(",'{0}'", oVehicle.platenumber);
            sbField.Append(",[speed]");
            sbValue.AppendFormat(",{0}", oVehicle.speed);
            if (oVehicle.stemagainst == true)
            {
                sbField.Append(",[stemagainst]");
                sbValue.AppendFormat(",{0}", 1);
            }
            else
            {
                sbField.Append(",[stemagainst]");
                sbValue.AppendFormat(",{0}", 0);
            }
            if (oVehicle.stop == true)
            {
                sbField.Append(",[stop]");
                sbValue.AppendFormat(",{0}", 1);
            }
            else
            {
                sbField.Append(",[stop]");
                sbValue.AppendFormat(",{0}", 0);
            }
            if (oVehicle.accident == true)
            {
                sbField.Append(",[accident]");
                sbValue.AppendFormat(",{0}", 1);
            }
            else
            {
                sbField.Append(",[accident]");
                sbValue.AppendFormat(",{0}", 0);
            }
            if (oVehicle.linechange == true)
            {
                sbField.Append(",[linechange]");
                sbValue.AppendFormat(",{0}", 1);
            }
            else
            {
                sbField.Append(",[linechange]");
                sbValue.AppendFormat(",{0}", 0);
            }
            sbField.Append(",[platecolor]");
            sbValue.AppendFormat(",'{0}'", oVehicle.platecolor);
            sbField.Append(",[vehiclecolor]");
            sbValue.AppendFormat(",'{0}'", oVehicle.vehiclecolor);
            sbField.Append(",[PictureID]");
            sbValue.AppendFormat(",{0}", oVehicle.PictureID);
            sbField.Append(",[REctId])");
            sbValue.AppendFormat(",{0})", oVehicle.REctId);

            string cmdText = sbField.ToString() + " " + sbValue.ToString();

            try
            {
                cmdText = cmdText.Replace("\r\n", "");
                return db.ExecuteNonQuery(CommandType.Text, cmdText);
                //获得倒数第二条记录
                //int id = int.Parse(db.ExecuteScalar(CommandType.Text, "select top 2 VehicleID from Vehicle").ToString());
                //return id;
            }
            catch (Exception ex)
            {

                throw ex;
            }
        }