// 添加设备按钮
        private void buttonAppend_Click(object sender, EventArgs e)
        {
            comBoxItem comtype = (comBoxItem)comboBoxType.SelectedItem;
            comBoxItem comsub1 = (comBoxItem)comboBoxsub1.SelectedItem;
            TaskInfo   task    = new TaskInfo(comtype.Value, comsub1.Value, (int)numericUpDownnum.Value);

            ROIInfo roi = new ROIInfo((int)numericUpDownStartX.Value, (int)numericUpDownStartY.Value, 0, 0, (int)numericUpDownwidth.Value, (int)numericUpDownheight.Value);

            string devicename = textBoxgetname.Text;

            // 需要另外增添的文本
            string AddtitionCnotext = null;

            if (DLLDefine.sg_task_pointer == comtype.Value)
            {
                AddtitionCnotext = ((int)numericUpDownpointerLow.Value).ToString() + "," + ((int)numericUpDownPointerhigh.Value).ToString() + "," + textBoxpointerUnit.Text;
            }
            else if (DLLDefine.sg_task_knob == comtype.Value)
            {
                AddtitionCnotext = richTextBoxKnobitem.Text;
            }

            string order = numericUpDownOrder.Value.ToString();

            xmlProcess.appendDevice(textBoxXMLpath.Text, devicename, task, roi, AddtitionCnotext, order, QRCodeRefer);

            loadXML(textBoxXMLpath.Text);

            MessageBox.Show("添加成功");
        }
Example #2
0
 public DetectInfo(string devicename, ROIInfo roi, TaskInfo task, ReferInfo refer)
 {
     this.deviceName = devicename;
     this.ROIINFO    = roi;
     this.TASKINFO   = task;
     this.REFERINFO  = refer;
 }
Example #3
0
        /// <summary>
        /// 寻找指定区域内的二维码
        /// </summary>
        /// <param name="srcPath"></param>
        /// <param name="searchArea"></param>
        /// <param name="qrcode"></param>
        /// <param name="qrcontent"></param>
        /// <param name="cameraOption"></param>
        public void searchQRwithregion(string srcPath, ROIInfo searchArea, ref QRCodeInfo qrcode, ref string qrcontent, int cameraOption)
        {
            StringBuilder CONTENT = new StringBuilder(20);
            int           resp    = visionAlgorithm.findQRcodeinRegion(srcPath, cameraOption, searchArea, ref qrcode, CONTENT);

            if (resp != DLLDefine.sg_OK)
            {
                Console.WriteLine("检测二维码出错");
                return;
            }

            qrcontent = CONTENT.ToString();
        }
        // 增加仪表项
        // 现在变为计算相对位置
        public void appendDevice(string xmlPath, string deviveName, TaskInfo task, ROIInfo roi, string addtionText, string order, QRCodeInfo qrRefer)
        {
            XElement xdoc = XElement.Load(xmlPath);

            XElement xeDevice = new XElement("device");

            xeDevice.SetAttributeValue("type", task.type);

            // 增加一项名字
            XElement xeName = new XElement("name", deviveName);

            xeDevice.Add(xeName);

            XElement xeTask = new XElement("taskinfo");

            xeTask.Add(new XElement("type", task.type),
                       new XElement("subtype", task.subtype),
                       new XElement("number", task.number),
                       new XElement("order", order));   //增加序号供C++层返回结果

            xeDevice.Add(xeTask);

            XElement xeROI = new XElement("roiinfo");

            xeROI.Add(new XElement("startX", roi.startX),
                      new XElement("startY", roi.startY),
                      new XElement("distX", roi.startX - qrRefer.startX),
                      new XElement("distY", roi.startY - qrRefer.startY),
                      new XElement("width", roi.width),
                      new XElement("height", roi.height));

            xeDevice.Add(xeROI);

            if (DLLDefine.sg_task_pointer == task.type)
            {
                XElement pointerInfo = new XElement("unitinfo");    //TODO 此处获取指针额外配置
                getElementFromText(addtionText, task.type, ref pointerInfo);
                xeDevice.Add(pointerInfo);
            }
            else if (DLLDefine.sg_task_knob == task.type)
            {
                XElement knobInfo = new XElement("unitinfo");   // TODO 此处解析旋钮额外配置
                getElementFromText(addtionText, task.type, ref knobInfo);
                xeDevice.Add(knobInfo);
            }


            xdoc.Add(xeDevice);

            xdoc.Save(xmlPath);
        }
Example #5
0
        // 确认二维码位置 //用检测来做
        private void buttonQR_Click(object sender, EventArgs e)
        {
            QRCodeInfo qrcodeinfo = new QRCodeInfo();

            //visiondll.GetQRregion(xmlimagepath, ref qrcodeinfo);

            numericUpDownStartX.Value = qrcodeinfo.startX;
            numericUpDownStartY.Value = qrcodeinfo.startY;
            numericUpDownwidth.Value  = qrcodeinfo.width;
            numericUpDownheight.Value = qrcodeinfo.height;

            ROIInfo roi = new ROIInfo((uint)numericUpDownStartX.Value, (uint)numericUpDownStartY.Value, (uint)numericUpDownwidth.Value, (uint)numericUpDownheight.Value);

            xmlProcess.appendQRPosition(textBoxXMLpath.Text, roi);
        }
        // 确认添加二维码信息
        private void confirmQR_Click(object sender, EventArgs e)
        {
            ROIInfo    roi       = new ROIInfo((int)numericUpDownStartX.Value, (int)numericUpDownStartY.Value, 0, 0, (int)numericUpDownwidth.Value, (int)numericUpDownheight.Value);
            QRCodeInfo realQR    = new QRCodeInfo();
            string     QRcontent = "";

            visiondll.searchQRwithregion(imgInBoxPath, roi, ref realQR, ref QRcontent, cameraside);

            MessageBox.Show("二维码的位置为:" + "(" + realQR.startX + "," + realQR.startY + "), w= " + realQR.width + ", h= " + realQR.height + "\n"
                            + "二维码的内容为: " + QRcontent + "\n"
                            + "已添加至配置表");

            QRCodeRefer = realQR;

            xmlProcess.appendQRPosition(textBoxXMLpath.Text, realQR, QRcontent);
        }
        // 由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);
        }
Example #8
0
        /// <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);
        }
Example #9
0
        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是为了界面更新
            }
        }
Example #10
0
 public static extern int findQRcodeinRegion(string filename, int cameraType, ROIInfo searchArea, ref QRCodeInfo QRcode, StringBuilder content);
Example #11
0
 public static extern int DetectTask(string filename, ROIInfo roi, TaskInfo taskinfo, string processedName, ref ResultTemp resultTemp, int cameraType);