/// <summary> /// 一个总的图像处理逻辑 /// </summary> public void Run() { //清楚上一次的所有结果 Global.AllFrameReslut.Clear(); Global.startTime = DateTime.Now; //记录开始时间 Global.lotGUID = Guid.NewGuid().ToString("N").ToUpper(); //得到一个新GUID Global.FrameNum = 0; //frameNum清0 while (Global.FrameNum < Global.TotalFrame) { //复制远程电脑上的图片文件夹到自己电脑的目录下 // GetImages(); //获取托盘号 GetTrayID(); List <int[]> TrayResult = new List <int[]>(); //用来记录该托盘结果数据 //获取本次托盘有几个frame //frame总数减去当前检测过的frame数,除以每个托盘能容纳的frame数,得到temp1,余数是temp2 //如果temp1>0,那这个num就是托盘所能容纳的数 //等于0就是余数了 int temp1 = (Global.TotalFrame - Global.FrameNum) / Global.FrameNumPerTray; int temp2 = (Global.TotalFrame - Global.FrameNum) % Global.FrameNumPerTray; int tempFrameNum; //代表那个文件夹包含了几个frame if (temp1 > 0) { tempFrameNum = Global.FrameNumPerTray; } else { tempFrameNum = temp2; } //图片 名字命名1_1_1.jpg 第一个1是指frameNum 第二个是1, 第三个是序号 目前这个产品是2*3的 一张图六个,得做成通用的 //循环各个frame 就是第一个序号 for (int imageFrameNum = 1; imageFrameNum < tempFrameNum + 1; imageFrameNum++) { //进度条作用,每次文件夹里处理图像的百分比 Global.WorkProgressLabel = "处理图像"; Global.WorkProgressNum = imageFrameNum * 100 / tempFrameNum; //new一个n=0 用来存结果保存在int数组里 长度为每个图片数量乘以每个图片里的产品数量 int[] FrameResultArr = new int[Global.FrameImageNum * Global.ImageRegionNum]; //上面那个数组的序号 int numFrameResultArr = 0; //循环各个frame下的每张图片 就是最后一个序号 for (int imageNum = 1; imageNum < Global.FrameImageNum + 1; imageNum++) { //得到图片名字 string ImageName = imageFrameNum.ToString() + "_" + "1" + "_" + imageNum.ToString() + ".jpg"; string ImageFullName = Global.TempImagePath + "\\" + ImageName; if (File.Exists(ImageFullName)) { //读取图像 HImage hImage = new HImage(ImageFullName); //循环读取region,并处理 foreach (HObject hRegion in Global.imageRegions) { //处理图像,调用图像处理方法,获取返回结果,填入一个int数组里 int index; string message; HObject xld; HOperatorSet.GenEmptyObj(out xld); xld.Dispose(); //HObject tempRegion; //HOperatorSet.GenEmptyObj(out tempRegion); //tempRegion.Dispose(); //tempRegion = hRegion.Clone(); bool isOK = ImageProcess.run(hImage, hRegion, out xld, out index, out message); //显示图像 videofrm.showImage(hImage, 1); //显示region的框 if (hRegion != null) { videofrm.showImage(hRegion, 1); } //在界面上展示xld if (xld != null) { videofrm.showImage(xld, 1); } //在界面上展示NG信息 videofrm.showNGMeaage(message); videofrm.showPostion((Global.FrameNum + 1).ToString() + "/" + Global.TotalFrame.ToString()); //判断是否为NG if (index != 1) { //显示NG 还没想好怎么显示 //这里判是否要弹出一个对话框,人工判断 if (Global.needLook) { //这里弹对话框,让人工选择 using (CheckFrm checkFrm = new CheckFrm()) { if (checkFrm.ShowDialog() == DialogResult.OK) { index = Global.needLookNum; //这边index等于人工选择的num } } } } else { //显示OK } //这边填写那个int数组 FrameResultArr[numFrameResultArr] = index; numFrameResultArr++; //判断是否暂停 if (Global.mySwitch1) { Global.mySwitch2 = true; while (Global.mySwitch2 && Global.mySwitch1) { Thread.Sleep(100); } } //释放xld if (xld != null) { xld.Dispose(); } } //释放图像 hImage.Dispose(); } else { foreach (HObject hRegion in Global.imageRegions) { numFrameResultArr++; } } } //把结果保存到托盘数据里 TrayResult.Add(FrameResultArr); ////这里是一个fram处理完成,可以保存数据了 将那个填充好的数组加入到list里 //Global.AllFrameReslut.Add(FrameResultArr); //FrameNum+1 Global.FrameNum++; } //这里是一个Tray处理完成,把数据保存到大list里 Global.AllFrameReslut.Add(TrayResult); //这里是写每个托盘的结束处理,对AllFrameResult进行处理 EndTray方法 把trayresult结果给它,它显示下东西 EndTray(TrayResult); } //这里是整个lot处理完了 EndLot方法 EndLot(); }
private void Confirm_Btn_Click(object sender, EventArgs e) { try { //先测试这些值是否满足条件 bool tempFlag = true; if (textBox1.Text.Trim() == "") { tempFlag = false; } if (textBox2.Text.Trim() == "") { tempFlag = false; } if (textBox3.Text.Trim() == "") { tempFlag = false; } if (textBox4.Text.Trim() == "") { tempFlag = false; } if (tempFlag) { //测试是否有相应的receipt string rpt = D2RManager.QueryReceipt(textBox2.Text); if (rpt != null) { //加载receipt 读取regions 和 图像处理的dll,就图像处理类初始化一下就行 HOperatorSet.SetSystem("clip_region", "false"); string regionFilesPath = Global.RecipePath + "\\" + rpt + @"\regions\"; string[] regionFiles = Directory.GetFiles(regionFilesPath, "*.hobj"); Global.imageRegions.Clear(); foreach (var name in regionFiles) { HObject reg; HOperatorSet.GenEmptyObj(out reg); reg.Dispose(); HOperatorSet.ReadRegion(out reg, name); Global.imageRegions.Add(reg); } string processDllPath = Global.RecipePath + "\\" + rpt; string[] processDlls = Directory.GetFiles(processDllPath, "*.dll"); ImageProcess.init(processDlls[0]); //加载dll //都满足则就运行下面的。 Global.LotNum = textBox1.Text; Global.Device = textBox2.Text; Global.OperatorID = textBox3.Text; Global.TotalFrame = int.Parse(textBox4.Text); Global.RecipeName = rpt; Global.ready2Go = true; //准备就绪,开始按钮可以跑 DialogResult = DialogResult.OK; } else { MessageBox.Show("未查询到该Device对应的Receipt"); } } else { MessageBox.Show("有空的"); } } catch (Exception ee) { MessageBox.Show(ee.ToString()); } }