Ejemplo n.º 1
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (DrawRegionCheck() == 1)
     {
         PublicData.createNewCheckModel.checkBigLableModel.BigLableAngleRegion2 = HRegion;
         HalconCommonFunc.BigLableblob(PublicData.createNewCheckModel.ModelImage,
                                       PublicData.createNewCheckModel.checkBigLableModel.BigLableAngleRegion2,
                                       out HTuple BigLableAngleNumber2, out PublicData.createNewCheckModel.checkBigLableModel.BigLableAngleSelected2);
         HalconCommonFunc.DisplayRegionOrXld(PublicData.createNewCheckModel.checkBigLableModel.BigLableAngleSelected2, "blue", WindowsHandle, 2);
         PublicData.createNewCheckModel.checkBigLableModel.BigLableAngleNumber2 = BigLableAngleNumber2.D;
     }
 }
 private void button9_Click(object sender, EventArgs e)
 {
     if (DrawRegionCheck() == 1)
     {
         PublicData.createNewCheckModel.chickMineLableModel.LableDistanceRegion2 = HRegion;
         HalconCommonFunc.SmallLabledistance(PublicData.createNewCheckModel.ModelImage, PublicData.createNewCheckModel.chickMineLableModel.LableDistanceRegion2,
                                             out HTuple DistanceMin1, out Eigs);
         HalconCommonFunc.DisplayRegionOrXld(HRegion, "blue", WindowsHandle, 2);
         HalconCommonFunc.DisplayRegionOrXld(Eigs, "blue", WindowsHandle, 2);
         PublicData.createNewCheckModel.chickMineLableModel.DistanceMin1 = DistanceMin1.D;
     }
 }
Ejemplo n.º 3
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (CreatModel == true)
     {
         HalconCommonFunc.CreateModel(PublicData.createNewCheckModel.ModelImage, PublicData.createNewCheckModel.VisualModelRegion,
                                      out PublicData.createNewCheckModel.VisualModelID, out TransContours);
         HalconCommonFunc.DisplayImage(PublicData.createNewCheckModel.ModelImage, WindowsHandle);
         HalconCommonFunc.DisplayRegionOrXld(TransContours, "blue", WindowsHandle, 2);
     }
     else
     {
         MessageBox.Show("还未框定区域");
     }
 }
Ejemplo n.º 4
0
        private void button1_Click(object sender, EventArgs e)
        {
            CreatModel = false;
            pictureBox1.Focus();
            if (PublicData.GetImage == false)
            {
                MessageBox.Show("未获取到图片");
                return;
            }
            switch (comboBox1.SelectedIndex)
            {
            case 0:
                HalconCommonFunc.DrawRegion(WindowsHandle, DrawModel.Rectangle1, out HRegion);
                break;

            case 1:
                HalconCommonFunc.DrawRegion(WindowsHandle, DrawModel.Rectangle2, out HRegion);
                break;

            case 2:
                HalconCommonFunc.DrawRegion(WindowsHandle, DrawModel.Circle, out HRegion);
                break;

            default: return;
            }
            switch (comboBox2.SelectedIndex)
            {
            case 0:
                HalconCommonFunc.RegionOperatorset(PublicData.createNewCheckModel.VisualModelRegion, HRegion, OperatorModel.Union, out PublicData.createNewCheckModel.VisualModelRegion);
                break;

            case 1:
                HalconCommonFunc.RegionOperatorset(PublicData.createNewCheckModel.VisualModelRegion, HRegion, OperatorModel.Difference, out PublicData.createNewCheckModel.VisualModelRegion);
                break;

            case 2:
                HalconCommonFunc.RegionOperatorset(PublicData.createNewCheckModel.VisualModelRegion, HRegion, OperatorModel.Intersection, out PublicData.createNewCheckModel.VisualModelRegion);
                break;

            default: return;
            }
            HalconCommonFunc.DisplayImage(PublicData.createNewCheckModel.ModelImage, WindowsHandle);
            HalconCommonFunc.DisplayRegionOrXld(PublicData.createNewCheckModel.VisualModelRegion, "blue", WindowsHandle, 2);
            CreatModel = true;
        }
Ejemplo n.º 5
0
        private void WorkThread()
        {
            HTuple    Socre = null;
            HTuple    CircleNumber;
            HObject   CircleRegion;
            HObject   DistanceRegion1;
            HObject   DistanceRegion2;
            double    标签尺寸1;
            double    标签尺寸2;
            HObject   Edges1;
            HObject   Edges2;
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Restart();//开始计时
            while (ThreadExit == false)
            {
                if (PublicData.调试模式 == 2 || PublicData.调试模式 == 0)
                {
                    HOperatorSet.GenEmptyObj(out PublicData.CheckModel.ModelImage);
                    PublicData.CheckModel.ModelImage.Dispose();
                    if (0 != PublicData.hkCameraCltr.Capture(out PublicData.CheckModel.ModelImage))
                    {
                        TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                            nResult = 1, sResult = "找不到图片"
                        });
                        break;
                    }
                }
                HalconCommonFunc.DisplayImage(PublicData.CheckModel.ModelImage, PublicData.WindowsHandle);
                HObject TranContours;
                try
                {
                    HalconCommonFunc.FindShapedModel(PublicData.WindowsHandle, PublicData.CheckModel.ModelImage, PublicData.CheckModel.VisualModelID,
                                                     out TranContours, out Socre);
                }
                catch
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 1, sResult = "找不到图片"
                    });
                    break;
                }
                if (stopwatch.ElapsedMilliseconds > 500)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 1, sResult = "找不到大标签"
                    });
                    break;
                }

                HOperatorSet.GenRegionContourXld(TranContours, out HObject region, "filled");
                HOperatorSet.Union1(region, out HObject RegionUnion);
                HOperatorSet.AreaCenter(RegionUnion, out HTuple area, out HTuple row, out HTuple column);
                region.Dispose();
                RegionUnion.Dispose();
                if (Socre < 0.6 || row < 400 || row > 800)
                {
                    Thread.Sleep(10);
                    //TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs { nResult = 1, sResult = "定位失败" });
                    continue;
                }
                HalconCommonFunc.DisplayRegionOrXld(TranContours, "green", PublicData.WindowsHandle, 2);
                HalconCommonFunc.CheckBigLable(PublicData.CheckModel.ModelImage, out HObject AnglehObject, out HObject AnglehObject1,
                                               out HObject IntervalLable, out HTuple AnglehObjectNumber, out HTuple AnglehObjectNumber1, out HTuple IntervalLableNumber);

                if (AnglehObjectNumber < 1 || AnglehObjectNumber1 < 1)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 2, sResult = "没有大标签角"
                    });
                    Thread.Sleep(1000);
                    break;
                }
                HalconCommonFunc.DisplayRegionOrXld(AnglehObject, "green", PublicData.WindowsHandle, 2);
                HalconCommonFunc.DisplayRegionOrXld(AnglehObject1, "green", PublicData.WindowsHandle, 2);
                if (IntervalLableNumber > 0)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 3, sResult = "大标签间隙间有标签"
                    });
                    HalconCommonFunc.DisplayRegionOrXld(IntervalLable, "red", PublicData.WindowsHandle, 2);
                    Thread.Sleep(1000);
                    break;
                }
                HalconCommonFunc.DisplayRegionOrXld(IntervalLable, "green", PublicData.WindowsHandle, 2);
                HalconCommonFunc.AffineModel(PublicData.CheckModel.chickMineLableModel.LableNothingRegion, out HObject NothingRegion);
                HalconCommonFunc.SmallLableNothing(PublicData.CheckModel.ModelImage, NothingRegion, out HTuple NothingRegionMean);
                if (NothingRegionMean > 110)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 4, sResult = "没有小标签"
                    });
                    HalconCommonFunc.DisplayRegionOrXld(NothingRegion, "red", PublicData.WindowsHandle, 2);
                    Thread.Sleep(1000);
                    break;
                }
                HalconCommonFunc.DisplayRegionOrXld(NothingRegion, "green", PublicData.WindowsHandle, 2);
                try
                {
                    HalconCommonFunc.CheckSmallLable(PublicData.CheckModel.ModelImage, out CircleRegion,
                                                     out DistanceRegion1, out DistanceRegion2, out CircleNumber,
                                                     out 标签尺寸1, out 标签尺寸2, out Edges1, out Edges2);
                }
                catch (Exception ex)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 4, sResult = ex.ToString()
                    });
                    break;
                }

                if (CircleNumber > 0)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 5, sResult = "小标签圆弧有未切割好的纸"
                    });
                    HalconCommonFunc.DisplayRegionOrXld(CircleRegion, "red", PublicData.WindowsHandle, 2);
                    Thread.Sleep(1000);
                    break;
                }
                HalconCommonFunc.DisplayRegionOrXld(CircleRegion, "green", PublicData.WindowsHandle, 2);
                if (标签尺寸1 > 10.15 || 标签尺寸1 < 9.42)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 6, sResult = "小标签宽度不对"
                    });
                    HalconCommonFunc.DisplayRegionOrXld(DistanceRegion1, "red", PublicData.WindowsHandle, 2);
                    Thread.Sleep(1000);
                    break;
                }
                if (标签尺寸2 > 10.15 || 标签尺寸2 < 9.42)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 6, sResult = "小标签宽度不对"
                    });
                    HalconCommonFunc.DisplayRegionOrXld(DistanceRegion2, "red", PublicData.WindowsHandle, 2);
                    Thread.Sleep(1000);
                    break;
                }
                if (标签尺寸1 - 标签尺寸2 < -0.3 || 标签尺寸1 - 标签尺寸2 > 0.3)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 6, sResult = "小标签倾斜"
                    });

                    Thread.Sleep(1000);
                    break;
                }
                HalconCommonFunc.DisplayRegionOrXld(DistanceRegion1, "green", PublicData.WindowsHandle, 2);
                HalconCommonFunc.DisplayRegionOrXld(DistanceRegion2, "green", PublicData.WindowsHandle, 2);
                HalconCommonFunc.DisplayRegionOrXld(Edges1, "green", PublicData.WindowsHandle, 2);
                HalconCommonFunc.DisplayRegionOrXld(Edges2, "green", PublicData.WindowsHandle, 2);
                HalconCommonFunc.CheckOtherLable(PublicData.CheckModel.ModelImage, out HObject OtherhObject, out HObject OtherhObject1, out HTuple 左边灰度值, out HTuple 右边灰度值);
                //HalconCommonFunc.DisplayImage(CameraImage, PublicData.WindowsHandle);
                if (左边灰度值 < 253 || 右边灰度值 < 253)
                {
                    TheadWorkResultEvent?.Invoke(this, new TheadWorkResultEventArgs {
                        nResult = 7, sResult = "标签两边有多余的纸"
                    });
                    Thread.Sleep(1000);
                    break;
                }

                HalconCommonFunc.DisplayRegionOrXld(OtherhObject, "green", PublicData.WindowsHandle, 2);
                HalconCommonFunc.DisplayRegionOrXld(OtherhObject1, "green", PublicData.WindowsHandle, 2);

                stopwatch.Restart();
                if (PublicData.调试模式 == 1 || PublicData.调试模式 == 2)
                {
                    break;
                }
            }
        }