コード例 #1
0
        private void Button_Click_D_Measure(object sender, RoutedEventArgs e)
        {
            HObject ho_Rectange_Again = null;

            HOperatorSet.SetDraw(this.CamSetting.HalconID, "margin");
            HOperatorSet.SetColor(this.CamSetting.HalconID, "#FF00FF");
            HTuple hv_r2r = null, hv_r2c = null, hv_r2phi = null, hv_r2w = null, hv_r2h = null;

            HOperatorSet.DrawRectangle2(this.CamSetting.HalconID, out hv_r2r, out hv_r2c, out hv_r2phi, out hv_r2w, out hv_r2h);
            HOperatorSet.GenRectangle2(out ho_Rectange_Again, hv_r2r, hv_r2c, hv_r2phi, hv_r2w, hv_r2h);
            HTuple hv_c = null, hv_r = null;

            try
            {
                /*
                 * switch (global.GetIns().CamSel)
                 * {
                 *  case 0: CameraADisp.Measure_Diameter(Obj[0], hv_r2r, hv_r2c, hv_r2phi, hv_r2w, hv_r2h, out hv_c, out hv_r, this.CamSetting.HalconID); break;
                 *  case 1: CameraBDisp.Measure_Diameter(Obj[1], hv_r2r, hv_r2c, hv_r2phi, hv_r2w, hv_r2h, out hv_c, out hv_r, this.CamSetting.HalconID); break;
                 *  case 2: CameraCDisp.Measure_Diameter(Obj[2], hv_r2r, hv_r2c, hv_r2phi, hv_r2w, hv_r2h, out hv_c, out hv_r, this.CamSetting.HalconID); break;
                 * // case 3: CameraDDisp.Measure_Diameter(Obj[3], hv_r2r, hv_r2c, hv_r2phi, hv_r2w, hv_r2h, this.CamSetting.HalconID); break;
                 *  default: break;
                 * }
                 */
                Info_Ctrl Infc = new Info_Ctrl();
                ImageOperate.Measure_Diameter(Obj[global.GetIns().CamSel], hv_r2r, hv_r2c, hv_r2phi, hv_r2w, hv_r2h, out Infc, this.CamSetting.HalconID, ImageOperate.Track_Model);
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d1_r1  = hv_r2r - Infc.pos_y;
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d1_c1  = hv_r2c - Infc.pos_x;
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d1_r2  = hv_r2w;
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d1_c2  = hv_r2h;
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d1_phi = hv_r2phi - Infc.pos_angle;
                try
                {
                    HTuple hv_Angle = null;
                    HOperatorSet.AngleLx(Infc.pos_y, Infc.pos_x, hv_r2r, hv_r2c, out hv_Angle);
                    INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d1_relative_phi = hv_Angle;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.ToString());
                }



                HOperatorSet.DispObj(ho_Rectange_Again, this.CamSetting.HalconID);
                INI.writting();
            }
            catch (Exception ex)
            {
                history.HistoryNotify += ex.ToString() + "\r\n";
                return;
            }
        }
コード例 #2
0
        private void Button_Click_Slot_Measure(object sender, RoutedEventArgs e)
        {
            HObject ho_Rectange_Again = null;

            HOperatorSet.SetDraw(this.CamSetting.HalconID, "margin");
            HOperatorSet.SetColor(this.CamSetting.HalconID, "green");
            HTuple hv_r2r = null, hv_r2c = null, hv_r2phi = null, hv_r2w = null, hv_r2h = null;

            HOperatorSet.DrawRectangle2(this.CamSetting.HalconID, out hv_r2r, out hv_r2c, out hv_r2phi, out hv_r2w, out hv_r2h);
            HOperatorSet.GenRectangle2(out ho_Rectange_Again, hv_r2r, hv_r2c, hv_r2phi, hv_r2w, hv_r2h);
            HTuple hv_r = null, hv_c = null;

            try
            {
                Info_Ctrl Infc = new Info_Ctrl();
                ImageOperate.Measure_Diameter(Obj[global.GetIns().CamSel], hv_r2r, hv_r2c, hv_r2phi, hv_r2w, hv_r2h, out Infc, this.CamSetting.HalconID, ImageOperate.Track_Model);
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d2_r1  = hv_r2r - Infc.pos_y;
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d2_c1  = hv_r2c - Infc.pos_x;
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d2_r2  = hv_r2w;
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d2_c2  = hv_r2h;
                INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d2_phi = hv_r2phi - Infc.pos_angle;

                try
                {
                    HTuple hv_Angle = null;
                    HOperatorSet.AngleLx(Infc.pos_y, Infc.pos_x, hv_r2r, hv_r2c, out hv_Angle);
                    INI.axis_roi.ElementAt(global.GetIns().CamSel).axis_d2_relative_phi = hv_Angle;
                }
                catch (Exception exe)
                {
                    MessageBox.Show(exe.ToString());
                }



                HOperatorSet.DispObj(ho_Rectange_Again, this.CamSetting.HalconID);
                INI.writting();
            }
            catch (HalconException ex)
            {
                history.HistoryNotify += ex.ToString() + "\r\n";
                return;
            }
        }
コード例 #3
0
        private void Button_Click_Height_Measure(object sender, RoutedEventArgs e)
        {
            int       Cam_idx = global.GetIns().CamSel;
            Info_Ctrl Infc    = new Info_Ctrl();

            if (false == ImageOperate.FindTrackPos(Obj[Cam_idx], this.CamSetting.HalconID, out Infc, ImageOperate.Track_Model, false))
            {
                return;
            }

            HObject Ho_Image;
            HTuple  hv_c = null, hv_r = null;

            HOperatorSet.GenEmptyObj(out Ho_Image);
            try
            {
                double Angle = CameraADisp.Disp_Adjust_Line(Obj[Cam_idx], INI.axis_roi[Cam_idx].adjust_r1, INI.axis_roi[Cam_idx].adjust_c1, INI.axis_roi[Cam_idx].adjust_phi, INI.axis_roi[Cam_idx].adjust_r2,
                                                            INI.axis_roi[Cam_idx].adjust_c2, this.CamSetting.HalconID, false);
                //HOperatorSet.RotateImage(Obj[Cam_idx], out Ho_Image, Angle, "constant");
                HOperatorSet.DispObj(Obj[Cam_idx], this.CamSetting.HalconID);

                //恢复信息
                double r1 = INI.axis_roi[Cam_idx].axis_d1_r1 + Infc.pos_y;
                double c1 = INI.axis_roi[Cam_idx].axis_d1_c1 + Infc.pos_x;
                CameraADisp.Measure_Diameter(Obj[Cam_idx], r1, c1, new HTuple(-Angle).TupleRad(), INI.axis_roi[Cam_idx].axis_d1_r2, INI.axis_roi[Cam_idx].axis_d1_c2, out hv_c, out hv_r, this.CamSetting.HalconID, false);

                //找到垂直线和找到图像的高度和宽度,来找到在哪儿画横线和纵线
                HTuple hv_Width, hv_Height, hv_HalfHeight, hv_HalfWidth;
                HOperatorSet.GetImageSize(Obj[Cam_idx], out hv_Width, out hv_Height);
                hv_HalfHeight = hv_Height / 2;
                hv_HalfWidth  = hv_c;
                CameraADisp.draw_line(hv_HalfHeight, 0, hv_HalfHeight, hv_Width, this.CamSetting.HalconID, "blue");


                //操作系统,操作系统本身自带选择功能,qt做映射
                //win api


                double x = 0;
                double y = 0;
                CameraADisp.GetPoint(hv_c, hv_r, Angle, out x, out y);
                Console.WriteLine("hv_c:" + hv_c.ToString() + " hv_r:" + hv_r.ToString() + " end x:" + x.ToString() + " end y;" + y.ToString());
                CameraADisp.draw_line(hv_r, hv_c, y, x, this.CamSetting.HalconID, "green");
                CameraADisp.GetPoint(hv_c, hv_r, Angle + 180, out x, out y);
                CameraADisp.draw_line(hv_r, hv_c, y, x, this.CamSetting.HalconID, "green");

                //INI.axis_roi[Cam_idx].d3_min = hv_c;
                INI.axis_roi[Cam_idx].axis_d3_r1           = hv_r;
                INI.axis_roi[Cam_idx].axis_d3_c1           = hv_c;
                INI.axis_roi[Cam_idx].axis_d3_relative_phi = Angle;


                //this.D3_Min.Text = INI.axis_roi[Cam_idx].d3_min.ToString();
                INI.writting();
            }
            catch (HalconException ex)
            {
                Console.WriteLine(ex.ToString());
            }

            Ho_Image.Dispose();
        }