コード例 #1
0
 private void OrientationModelDlg_Load(object sender, EventArgs e)
 {
     HOperatorSet.OpenWindow(0, 0, pictureBox1.Width, pictureBox1.Height, pictureBox1.Handle, "visible", "", out WindowsHandle);
     HalconCommonFunc.SetPart(WindowsHandle, 1920, 1200, pictureBox1.Width, pictureBox1.Height);
     //Image.Dispose();
     //HOperatorSet.GenEmptyObj(out Image);
 }
コード例 #2
0
        private void 打开本地图片ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (label2.Text == "xxxx")
            {
                MessageBox.Show("未选择模板");
                return;
            }
            if (StartCheckButon.Text != "开 始 检 测")
            {
                MessageBox.Show("当前检测未停止");
                return;
            }
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = true;//该值确定是否可以选择多个文件
            dialog.Title       = "请选择文件夹";
            dialog.Filter      = "图片文件(*.jpg,*.gif,*.bmp)|*.jpg;*.gif;*.bmp";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                for (int i = 0; i < dialog.FileNames.Length; i++)
                {
                    string file = dialog.FileNames[i];
                    PublicData.CheckModel.ModelImage.Dispose();
                    HOperatorSet.ReadImage(out PublicData.CheckModel.ModelImage, file);
                    HalconCommonFunc.DisplayImage(PublicData.CheckModel.ModelImage, PublicData.WindowsHandle);
                }


                PublicData.调试模式 = 1;//1是本地单次检测
                runthread.StartWork();
            }
        }
コード例 #3
0
        public int DrawRegionCheck()
        {
            pictureBox1.Focus();
            if (PublicData.GetImage == false)
            {
                MessageBox.Show("未获取到图片");
                return(0);
            }
            else
            {
                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;
                }
                return(1);
            }
        }
コード例 #4
0
        public int DrawRegionCheck()
        {
            pictureBox1.Focus();
            if (PublicData.GetImage == false)
            {
                MessageBox.Show("未获取到图片");
                return(0);
            }
            else
            {
                switch (comboBox1.SelectedIndex)
                {
                case 0:
                    HalconCommonFunc.DrawRegion(WindowsHandle, DrawModel.Rectangle1, out HRegion);
                    break;

                case 1:
                    HalconCommonFunc.DrawRegion(WindowsHandle, DrawModel.Rectangle2, out HRegion);
                    //HOperatorSet.GenRectangle2(out HRegion, 488.094, 1483.98, -1.59531, 302.478, 27.5584);
                    break;

                case 2:
                    HalconCommonFunc.DrawRegion(WindowsHandle, DrawModel.Circle, out HRegion);
                    break;
                }
                return(1);
            }
        }
コード例 #5
0
 private void 获取相机图片测试ToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (label2.Text == "xxxx")
     {
         MessageBox.Show("未选择模板");
         return;
     }
     if (StartCheckButon.Text != "开 始 检 测")
     {
         MessageBox.Show("当前检测未停止");
         return;
     }
     if (PublicData.OpenCrame != 0)
     {
         MessageBox.Show("相机未开启");
     }
     else
     {
         PublicData.CheckModel.ModelImage.Dispose();
         int Res2 = PublicData.hkCameraCltr.Capture(out PublicData.CheckModel.ModelImage);
         if (Res2 == 0)
         {
             HalconCommonFunc.DisplayImage(PublicData.CheckModel.ModelImage, PublicData.WindowsHandle);
             PublicData.调试模式 = 2;//获取相机单次检测
             runthread.StartWork();
         }
         else
         {
             MessageBox.Show("相机图像获取失败");
         }
     }
 }
コード例 #6
0
 private void OtherLocationDlg_VisibleChanged(object sender, EventArgs e)
 {
     if (this.Visible == true)
     {
         HalconCommonFunc.DisplayImage(PublicData.createNewCheckModel.ModelImage, WindowsHandle);
     }
 }
コード例 #7
0
 private void button6_Click(object sender, EventArgs e)
 {
     if (DrawRegionCheck() == 1)
     {
         PublicData.createNewCheckModel.chickMineLableModel.LableCircleRegion = HRegion;
         HalconCommonFunc.SmallLableCircle(PublicData.createNewCheckModel.ModelImage, PublicData.createNewCheckModel.chickMineLableModel.LableCircleRegion,
                                           out HTuple SmallLableMean);
         //PublicData.createNewCheckModel.chickMineLableModel.SmallLableMean = SmallLableMean.D;
     }
 }
コード例 #8
0
        //private void button4_Click(object sender, EventArgs e)
        //{
        //    PublicData.createNewCheckModel.chickMineLableModel.SmallLableImage.Dispose();
        //    HalconCommonFunc.ReadImage(out PublicData.createNewCheckModel.ModelImage, WindowsHandle, pictureBox1);
        //}

        private void button1_Click(object sender, EventArgs e)
        {
            if (DrawRegionCheck() == 1)
            {
                PublicData.createNewCheckModel.chickMineLableModel.LableNothingRegion = HRegion;
                HalconCommonFunc.SmallLableNothing(PublicData.createNewCheckModel.ModelImage, PublicData.createNewCheckModel.chickMineLableModel.LableNothingRegion,
                                                   out HTuple LableNothingMean /*out PublicData.createNewCheckModel.chickMineLableModel.SmallSelectedRegions*/);
                HalconCommonFunc.DisplayRegionOrXld(PublicData.createNewCheckModel.chickMineLableModel.LableNothingRegion, "blue", WindowsHandle, 2);
                PublicData.createNewCheckModel.chickMineLableModel.LableNothingMean = LableNothingMean.D;
            }
        }
コード例 #9
0
 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;
     }
 }
コード例 #10
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (DrawRegionCheck() == 1)
     {
         // HOperatorSet.GenRectangle2(out HRegion, 710.906, 1428.38, -1.59505, 305.66, 11.2292);
         PublicData.createNewCheckModel.checkOtherModel.OtherRegion1 = HRegion;
         HalconCommonFunc.四周bleblob(PublicData.createNewCheckModel.ModelImage,
                                    PublicData.createNewCheckModel.checkOtherModel.OtherRegion1, out HTuple OtherNumber
                                    );
         HalconCommonFunc.DisplayRegionOrXld(PublicData.createNewCheckModel.checkOtherModel.OtherRegion1, "blue", WindowsHandle, 2);
     }
 }
コード例 #11
0
 private void button7_Click(object sender, EventArgs e)
 {
     if (DrawRegionCheck() == 1)
     {
         PublicData.createNewCheckModel.checkBigLableModel.BigLableRegion = HRegion;
         HalconCommonFunc.BigLablIntervalLable(PublicData.createNewCheckModel.ModelImage,
                                               PublicData.createNewCheckModel.checkBigLableModel.BigLableRegion,
                                               out HTuple BigLableNumber, out PublicData.createNewCheckModel.checkBigLableModel.BigLableSelect);
         HalconCommonFunc.DisplayRegionOrXld(PublicData.createNewCheckModel.checkBigLableModel.BigLableSelect, "blue", WindowsHandle, 2);
         PublicData.createNewCheckModel.checkBigLableModel.BigLableNumber = BigLableNumber.D;
     }
 }
コード例 #12
0
 private void button1_Click(object sender, EventArgs e)
 {
     if (DrawRegionCheck() == 1)
     {
         //HOperatorSet.GenRectangle2(out HRegion, 698.174, 420.195, -1.58345, 292.862, 11.1591);
         PublicData.createNewCheckModel.checkOtherModel.OtherRegion = HRegion;
         HalconCommonFunc.四周bleblob(PublicData.createNewCheckModel.ModelImage,
                                    PublicData.createNewCheckModel.checkOtherModel.OtherRegion, out HTuple OtherNumber);
         HalconCommonFunc.DisplayRegionOrXld(PublicData.createNewCheckModel.checkOtherModel.OtherRegion, "blue", WindowsHandle, 2);
         PublicData.createNewCheckModel.checkOtherModel.OtherNumber = OtherNumber.D;
     }
 }
コード例 #13
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;
     }
 }
コード例 #14
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("还未框定区域");
     }
 }
コード例 #15
0
 private void Form1_Load(object sender, EventArgs e)
 {
     HOperatorSet.OpenWindow(0, 0, pictureBox1.Width, pictureBox1.Height, pictureBox1.Handle, "visible", "", out PublicData.WindowsHandle);
     HalconCommonFunc.SetPart(PublicData.WindowsHandle, 1920, 1200, pictureBox1.Width, pictureBox1.Height);
     PublicData.settingMessage = IniManager.ReadFromIni <SettingMessage>(Application.StartupPath + "\\Config" + "\\SettingMessage.Jason");
     HkCameraCltr.EnumDevices();
     PublicData.OpenCrame = PublicData.hkCameraCltr.OpenDevices(PublicData.settingMessage.CaremerName);
     if (0 == PublicData.OpenCrame)
     {
         MessageBox.Show("相机连接成功");
     }
     else
     {
         MessageBox.Show("相机连接失败");
     }
 }
コード例 #16
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;
        }
コード例 #17
0
        private void button4_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Multiselect = true;//该值确定是否可以选择多个文件
            dialog.Title       = "请选择文件夹";
            dialog.Filter      = "图片文件(*.jpg,*.gif,*.bmp)|*.jpg;*.gif;*.bmp";
            if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                for (int i = 0; i < dialog.FileNames.Length; i++)
                {
                    string file = dialog.FileNames[i];
                    PublicData.createNewCheckModel.ModelImage.Dispose();
                    HOperatorSet.ReadImage(out PublicData.createNewCheckModel.ModelImage, file);
                    HalconCommonFunc.DisplayImage(PublicData.createNewCheckModel.ModelImage, WindowsHandle);
                }
            }
            PublicData.GetImage = true;
        }
コード例 #18
0
 private void button3_Click(object sender, EventArgs e)
 {
     //Image.Dispose();
     if (PublicData.OpenCrame != 0)
     {
         MessageBox.Show("相机未开启");
     }
     else
     {
         PublicData.createNewCheckModel.ModelImage.Dispose();
         int Res2 = PublicData.hkCameraCltr.Capture(out PublicData.createNewCheckModel.ModelImage);
         if (Res2 == 0)
         {
             HalconCommonFunc.DisplayImage(PublicData.createNewCheckModel.ModelImage, WindowsHandle);
             PublicData.GetImage = true;
         }
         else
         {
             MessageBox.Show("相机图像获取失败");
         }
     }
 }
コード例 #19
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;
                }
            }
        }
コード例 #20
0
 private void OtherLocationDlg_Load(object sender, EventArgs e)
 {
     HOperatorSet.OpenWindow(0, 0, pictureBox1.Width, pictureBox1.Height, pictureBox1.Handle, "visible", "", out WindowsHandle);
     HalconCommonFunc.SetPart(WindowsHandle, 1920, 1200, pictureBox1.Width, pictureBox1.Height);
     HalconCommonFunc.DisplayImage(PublicData.createNewCheckModel.ModelImage, WindowsHandle);
 }