// 由XML文件生成检测任务序列 public List <DetectInfo> xmlToTaskList(string xmlPath) { // 1. 加载XML文件 XElement xe = XElement.Load(xmlPath); // 2. 获取XML Device 信息 IEnumerable <XElement> devices = xe.Elements("device"); // 3. 遍历并生成任务信息,同时添加到任务序列中 List <DetectInfo> DetectList = new List <DetectInfo>(); foreach (XElement element in devices) { XElement eleRoi = element.Element("roiinfo"); int startX = Convert.ToInt16(eleRoi.Element("startX").Value); int startY = Convert.ToInt16(eleRoi.Element("startY").Value); int disX = Convert.ToInt16(eleRoi.Element("distX").Value); int disY = Convert.ToInt16(eleRoi.Element("distY").Value); int width = Convert.ToInt16(eleRoi.Element("width").Value); int height = Convert.ToInt16(eleRoi.Element("height").Value); ROIInfo roi = new ROIInfo(startX, startY, disX, disY, width, height); XElement eleTask = element.Element("taskinfo"); int type = Convert.ToInt16(eleTask.Element("type").Value); int subtype = Convert.ToInt16(eleTask.Element("subtype").Value); int num = Convert.ToInt16(eleTask.Element("number").Value); TaskInfo task = new TaskInfo(type, subtype, num); XElement eleName = element.Element("name"); string devicename = eleName.Value; // 此处添加参考信息,用以检测结果对应语义 ReferInfo refer = new ReferInfo(); XMLToTaskRefer(element, type, ref refer); DetectInfo detect = new DetectInfo(devicename, roi, task, refer); DetectList.Add(detect); } // 4. 返回任务序列 return(DetectList); }
/// <summary> /// 检测任务传递函数,抛弃 /// </summary> /// <param name="srcPath"></param> /// <param name="PrcdPath"></param> /// <param name="detectinfo"></param> /// <returns></returns> public int DetectTaskSend(string srcPath, ref string PrcdPath, ref DetectInfo detectinfo, int cameraOption) { //处理结束的图像保存路径 PrcdPath = DLLDefine.ImgDBFolder + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + "_Detect_" + ".jpg"; TaskInfo task = detectinfo.TASKINFO; //直接将Taskinfo输入,关于赋值是在解析配置文件时赋值 ROIInfo roi = detectinfo.ROIINFO; //直接将ROIinfo输入,关于赋值是在解析配置文件时赋值 ResultTemp resultTemp = new ResultTemp(); //处理结果临时变量 visionAlgorithm.DetectTask(srcPath, roi, task, PrcdPath, ref resultTemp, cameraOption); //调用DLL接口进行图像处理 // 数据转换 detectinfo.RESULTINFO = detectinfo.ResultTempToResultInfo(resultTemp); // 释放内存,指针传值的地方(如果申请了内存) if (resultTemp.arrayResult != IntPtr.Zero) { visionAlgorithm.ReleaseMemoryFromC(resultTemp.arrayResult); } return(DLLDefine.sg_OK); }
private void processXML(string xmlpath) { // 1. 获取电柜信息,更新到UI ,此处可以另开线程 string house = null, cabin = null, side = null; xmlProcess.XMLtoCabinInfo(xmlpath, ref house, ref cabin, ref side); labelRom.Text = house; labelCab.Text = cabin; labelFac.Text = side; dataGridViewStatus.Rows.Clear(); // 圆形进度条结束,定位信息显示 panelLocationDetail.Show(); circularProgressBarLocation.Value = 100; circularProgressBarLocation.Text = "定位成功......"; circularProgressBarLocation.Style = ProgressBarStyle.Continuous; circularProgressBarLocation.MarqueeAnimationSpeed = 0; Delay(100); //delay是为了界面更新 // 1.2 获取新的和旧的二维码位置 //QRCodeInfo qrcode = new QRCodeInfo(); //visiondll.GetQRregion(imgPath, ref qrcode); //QRCodeInfo qrcodeOrigin = new QRCodeInfo(); //xmlProcess.GetQRregionorigin(xmlpath, ref qrcodeOrigin); // 1.2 int cameraSide = 0; if (side.Equals("远侧FarFace")) { cameraSide = DLLDefine.sg_Camera_Far; } else if (side.Equals("近侧NearFace")) { cameraSide = DLLDefine.sg_Camera_Near; } else { MessageBox.Show("相机远近侧参数确实,请确认!"); return; } // 2. 分析任务序列 List <DetectInfo> detectList = xmlProcess.xmlToTaskList(xmlpath); int detectSize = detectList.Count(); // 2.01 根据任务序列绘制ROI数组,并显示图像 ROIInfo[] roiarray = new ROIInfo[detectSize]; string roiPath = null; dataflow.GetROIArrayFormDetectList(detectList, ref roiarray); //获取ROI数组 //dataflow.GetROIArrayFormDetectListwithQRCode(detectList, ref roiarray, qrcode, qrcodeOrigin); //获取换算之后的ROI数组,顺便把Detect的ROI也改了 visiondll.ROIArrayDraw(imgPath, roiarray, ref roiPath, cameraSide); //绘制ROI区域 pictureBoxProcessed.Image = Image.FromFile(roiPath); //显示绘制ROI后的图像 Delay(200); //delay是为了界面更新 // 2.1 分别进行检测,并更新界面进度信息 int detectNow = 0; processUpdateUI(detectNow, detectSize); //重置UI foreach (DetectInfo item in detectList) { string procdpath = null; DetectInfo detect = item; visiondll.DetectTaskSend(imgPath, ref procdpath, ref detect, cameraSide); //这一步得到检测结果,下一步应该是对检测结果进行一下数据的换算,需要从配置表中获取语义 // UI 结果显示 小表格(仪表名称和检测结果),显示语义,调用自身类的转换功能实现数据到语义的转换 dataGridViewStatus.Rows.Add(detect.deviceName, detect.GetResultWithRefer()); // UI 结果显示 大表格(巡检数据结果),显示序号、时间、设备名称、检测结果、报警类型,并保存到数据库 // TODO: 对检测结果进行报警判断 detectResultSave(house, cabin, detect.deviceName, detect.GetResultWithRefer(), "正常", detect.GetDetectClass()); // TODO 结果显示2. 大表格,大表格涉及到数据库的传入。暂不涉及 // UI 进度更新 detectNow = detectNow + 1; processUpdateUI(detectNow, detectSize); //更新UI Delay(500); //delay是为了界面更新 } }