public Dictionary<int, Face> GetFaceCustom(ref string errMessage, string str) { Database db = DatabaseFactory.CreateDatabase(); errMessage = ""; Dictionary<int, Face> list = new Dictionary<int, Face>(); try { DataSet ds = FaceDataAccess.GetFaceCustom(db, str); Face face; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { face = new Face(ds.Tables[0].Rows[i]); face.CapturePicture = CapturePictureBusiness.Instance.GetCapturePicture(ref errMessage,face.PictureID); face.CameraInfo = CameraBusiness.Instance.GetCameraInfoByCameraId(ref errMessage, face.CapturePicture.CameraID); face.VideoInfo = VideoBusiness.Instance.GetVideoInfoById(ref errMessage, face.VideoId); list.Add(face.FaceID, face); } return list; } catch (Exception ex) { errMessage = ex.Message + ex.StackTrace; logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace); return null; } }
public static int InsertFace(Database db, Face oFace) { StringBuilder sbField = new StringBuilder(); StringBuilder sbValue = new StringBuilder(); sbField.Append("INSERT INTO [Face]("); sbValue.Append("values ("); //sbField.Append("[FaceID]"); //sbValue.AppendFormat("'{0}'", oFace.FaceID); sbField.Append("[score]"); sbValue.AppendFormat("'{0}'", oFace.score); sbField.Append(",[RectID]"); sbValue.AppendFormat(",{0}", oFace.RectID); sbField.Append(",[PictureID])"); sbValue.AppendFormat(",{0})", oFace.PictureID); 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('Face')").ToString()); return id; } catch (Exception ex) { throw ex; } }
public Dictionary<int, Face> GetFaceCustom(ref string errMessage, string str) { Database db = DatabaseFactory.CreateDatabase(); errMessage = ""; Dictionary<int, Face> list = new Dictionary<int, Face>(); try { DataSet ds = AnalysisXMLDataAccess.GetFaceCustom(db, str); Face face; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { face = new Face(ds.Tables[0].Rows[i]); list.Add(face.FaceID, face); } return list; } catch (Exception ex) { errMessage = ex.Message + ex.StackTrace; logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace); return null; } }
public Face GetFace(ref string errMessage, int cameraId, DateTime captureDataTime) { Database db = DatabaseFactory.CreateDatabase(); errMessage = ""; Face face=null; try { DataSet ds = AnalysisXMLDataAccess.GetFaceCustom(db, string.Format(" and CapturePicture.CameraId={0} and CapturePicture.DateTime='{1}'",cameraId,captureDataTime)); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { face = new Face(ds.Tables[0].Rows[i]); break; } return face; } catch (Exception ex) { errMessage = ex.Message + ex.StackTrace; logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace); return null; } }
public Face GetFace(ref string errMessage, int cameraId, DateTime captureDataTime) { Database db = DatabaseFactory.CreateDatabase(); errMessage = ""; Face face = null; try { DataSet ds = FaceDataAccess.GetFaceCustom(db, string.Format(" and CapturePicture.CameraId={0} and CapturePicture.DateTime='{1}'", cameraId, captureDataTime)); face = new Face(ds.Tables[0].Rows[0]); face.CapturePicture = CapturePictureBusiness.Instance.GetCapturePicture(ref errMessage, face.PictureID); face.CameraInfo = CameraBusiness.Instance.GetCameraInfoByCameraId(ref errMessage, face.CapturePicture.CameraID); face.VideoInfo = VideoBusiness.Instance.GetVideoInfoById(ref errMessage, face.VideoId); return face; } catch (Exception ex) { errMessage = ex.Message + ex.StackTrace; logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace); return null; } }
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 int InsertFace(ref string errMessage, Face oFace) { Database db = DatabaseFactory.CreateDatabase(); errMessage = ""; try { return AnalysisXMLDataAccess.InsertFace(db, oFace); } catch (Exception ex) { errMessage = ex.Message + ex.StackTrace; logger.Error("Error Message:" + ex.Message + " Trace:" + ex.StackTrace); return -1; } }
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)); } }
private void advBandedGridViewFace_SelectionChanged(object sender, DevExpress.Data.SelectionChangedEventArgs e) { if (advBandedGridViewFace.SelectedRowsCount > 0) { int getSelectedRow = this.advBandedGridViewFace.GetSelectedRows()[0]; _selectedFace = (Face)(this.advBandedGridViewFace.GetRowCellValue(getSelectedRow, "��������")); FillPicVideo(_selectedFace); } }
private void advBandedGridViewFace_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e) { if (advBandedGridViewFace.SelectedRowsCount > 0) { int getSelectedRow = this.advBandedGridViewFace.GetSelectedRows()[0]; _selectedFace = (Face)(this.advBandedGridViewFace.GetRowCellValue(getSelectedRow, "��������")); FillPicVideo(_selectedFace); } }
private void FillPicVideo(Face face) { if (File.Exists(face.CapturePicture.FilePath)) { pictureEditFace.Image = Image.FromFile(face.CapturePicture.FilePath); } if (File.Exists(face.VideoInfo.FilePath)) { if (_lastVideoPort != -1) { bool ret = HikPlayer.PlayM4_CloseFile(_lastVideoPort); } if (File.Exists(face.VideoInfo.FilePath)) { _lastVideoPort = 1; splitContainerControlFaceVideo.Visible = true; HikPlayer.PlayM4_OpenFile(_lastVideoPort, face.VideoInfo.FilePath); HikPlayer.PlayM4_Play(_lastVideoPort, splitContainerControlFaceVideo.Panel1.Handle); } } }