Ejemplo n.º 1
0
        private void Init()
        {
            String fileName = "patras";
            HImage image;

            try
            {
                image = new HImage(fileName);
            }
            catch (HOperatorException)
            {
                MessageBox.Show("Problem occured while reading file!",
                                "SmartWindow1",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            hWndControl.addIconicVar(image);
            hWndControl.repaint();

            hWndControl.setGUICompRangeX(new int[] { XTrackBar.Minimum,
                                                     XTrackBar.Maximum },
                                         XTrackBar.Value);
            hWndControl.setGUICompRangeY(new int[] { YTrackBar.Minimum,
                                                     YTrackBar.Maximum },
                                         YTrackBar.Maximum - YTrackBar.Value);
        }
Ejemplo n.º 2
0
        private void OpenImageFile()
        {
            string strHeadImagePath;
            HImage image;

            OpenImageDialog.Title    = "Open Image file";
            OpenImageDialog.ShowHelp = true;
            OpenImageDialog.Filter   = "(*.gif)|*.gif|(*.jpg)|*.jpg|(*.JPEG)|*.JPEG|(*.bmp)|*.bmp|(*.png)|*.png|All files (*.*)|*.*";
            DialogResult result = OpenImageDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    strHeadImagePath = OpenImageDialog.FileName;
                    image            = new HImage(strHeadImagePath);
                    myHalcon.myImage = image;
                    hWndCtrl.ClearResult();
                    hWndCtrl.addIconicVar(image);
                    hWndCtrl.repaint();
                }
                catch
                {
                    MessageBox.Show("format not correct");
                }
            }
        }
Ejemplo n.º 3
0
        private void Init()
        {
            String fileName = "particle";

            try
            {
                image = new HImage(fileName);
            }
            catch (HOperatorException)
            {
                MessageBox.Show("Problem occured while reading file!",
                                "GraphicsStack",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }


            locked   = false;
            procList = new Hashtable(10);

            IconiclistBox.Enabled = true;
            performIPTask();
            IconiclistBox.SelectedIndex = 1;
            viewControl.repaint();
        }
Ejemplo n.º 4
0
 private void ReviewLine()
 {
     try
     {
         HWndCtrl.repaint();
     }
     catch (Exception)
     { }
 }
Ejemplo n.º 5
0
 public void Refresh()
 {
     if (this == null || Hwnd == null)
     {
         return;
     }
     lock (globalLock){
         try{
             viewController.clearList();
             viewController.repaint();
         }
         catch
         { }
     }
 }
Ejemplo n.º 6
0
        public bool Run_Region(ExecuteBuffer _executeBuffer, out 字符串GVName_halcon outResult, HWndCtrl hWndCtrl)
        {
            //   outexecutebuffer = _executeBuffer;

            HObject outImage;

            outResult = new 字符串GVName_halcon();
            HOperatorSet.GenEmptyObj(out outImage);
            if (!_executeBuffer.imageBuffer.ContainsKey(this.cbb_image.SelectedItem.ToString() + ".img"))
            {
                MessageBox.Show("感兴趣区域:无法找到输入图像");
                return(false);
            }
            if (_executeBuffer.imageBuffer[this.cbb_image.SelectedItem.ToString() + ".img"] == null)
            {
                MessageBox.Show("感兴趣区域:无法找到输入图像");
                return(false);
            }
            HTuple  DataCodeHandle, DecodedDataStrings;
            HObject SymbolXLDs;

            HOperatorSet.GenEmptyObj(out SymbolXLDs);

            HOperatorSet.CreateBarCodeModel(new HTuple(), new HTuple(), out DataCodeHandle);
            HOperatorSet.FindBarCode(_executeBuffer.imageBuffer[this.cbb_image.SelectedItem.ToString() + ".img"], out SymbolXLDs, DataCodeHandle, this.comboBox_type.SelectedItem.ToString(), out DecodedDataStrings);
            outResult.字符串 = DecodedDataStrings;
            hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, "green");
            hWndCtrl.addIconicVar(SymbolXLDs);
            hWndCtrl.repaint();
            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Defines the initial settings for the window
        /// control. In the very beginning, the window control needs
        /// to know the view mode of the application form to perform
        /// the right behavior for incoming mouse events on the
        /// HALCON window.
        /// </summary>
        private void InteractiveForm_Load(object sender, System.EventArgs e)
        {
            String fileName = "patras";
            HImage image;

            viewController = new HWndCtrl(viewPort);
            roiController  = new ROIController();
            viewController.useROIController(roiController);
            viewController.setViewState(HWndCtrl.MODE_VIEW_NONE);

            try
            {
                image = new HImage(fileName);
            }
            catch (HOperatorException)
            {
                MessageBox.Show("Problem occured while reading file!",
                                "InteractROIForm",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            viewController.addIconicVar(image);
            viewController.repaint();
        }
        /*******************************************************************/
        private void ResetButton_Click(object sender, System.EventArgs e)
        {
            locked = true;
            zoomImgComboBox.SelectedIndex = 3;
            viewControl.resetWindow();
            locked = false;

            if (zoomWndComboBox.SelectedIndex != 3)
            {
                zoomWndComboBox.SelectedIndex = 3;
            }
            else
            {
                viewControl.repaint();
            }
        }
Ejemplo n.º 9
0
 public void SetROIList(ArrayList ROIList)
 {
     if (ROIList.Count > 0)
     {
         roiController.ROIList = ROIList;
         viewController.repaint();
     }
 }
Ejemplo n.º 10
0
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (hWindow == null)
            {
                return;
            }
            switch (this.tabControl1.SelectedIndex)
            {
            case 1:
                this.tabCurrent.Controls.Clear();
                this.tabCurrent.Controls.Add(hWindow);
                HImage hImage = Machine.Instance.Camera.Executor.CurrentBytes.ToHImage(
                    Machine.Instance.Camera.Executor.ImageWidth,
                    Machine.Instance.Camera.Executor.ImageHeight);
                this.currentImage = hImage;
                this.tempImage    = this.currentImage;
                break;

            case 2:
                this.tabReference.Controls.Clear();
                this.tabReference.Controls.Add(hWindow);
                this.tempImage = this.referenceImage;
                break;
            }
            this.slectedTabIndex = this.tabControl1.SelectedIndex;
            mView.resetWindow();
            mView.HRegionList.Clear();
            mView.setImage(this.tempImage);
            mView.repaint();
        }
Ejemplo n.º 11
0
        public static string[] GetBarcode2()
        {
            string[] res = new string[2];
            DataCodeHandle2 = new HDataCode2D("Data Matrix ECC 200", new HTuple(), new HTuple());

            HObject image1, image2;
            HObject Roi1, Roi2;
            HObject symbolXLD1, symbolXLD2;

            HOperatorSet.ReadObject(out Roi1, System.Environment.CurrentDirectory + "\\rectangle3.hobj");
            HOperatorSet.ReadObject(out Roi2, System.Environment.CurrentDirectory + "\\rectangle4.hobj");
            HOperatorSet.ReduceDomain(Camera2.CurrentImage, Roi1, out image1);
            HOperatorSet.ReduceDomain(Camera2.CurrentImage, Roi2, out image2);
            HOperatorSet.FindDataCode2d(new HImage(image1), out symbolXLD1, DataCodeHandle2, new HTuple(), new HTuple(), out ResultHandles2, out DecodedDataStrings2);
            res[0] = new HTuple((new HTuple(DecodedDataStrings2.TupleLength())).TupleEqual(1)) == 1 ? DecodedDataStrings2.TupleSelect(0).ToString().Replace("\"", "") : "error";
            HOperatorSet.FindDataCode2d(new HImage(image2), out symbolXLD2, DataCodeHandle2, new HTuple(), new HTuple(), out ResultHandles2, out DecodedDataStrings2);
            res[1] = new HTuple((new HTuple(DecodedDataStrings2.TupleLength())).TupleEqual(1)) == 1 ? DecodedDataStrings2.TupleSelect(0).ToString().Replace("\"", "") : "error";

            viewController2.addIconicVar(symbolXLD1);
            viewController2.addIconicVar(symbolXLD2);
            viewController2.addIconicVar(Roi1);
            viewController2.addIconicVar(Roi2);

            viewController2.viewPort.HalconWindow.SetColor("green");
            viewController2.repaint();
            HTuple area, rows, columns;

            HOperatorSet.AreaCenter(Roi1, out area, out rows, out columns);
            int[] co = GetCorinWindow(viewController2.viewPort.HalconWindow, Camera2.CurrentImage, (int)rows.D, (int)columns.D);
            HOperatorSet.DispText(viewController2.viewPort.HalconWindow, "① " + res[0], "window", co[0], co[1], "black", "box", "true");
            HOperatorSet.AreaCenter(Roi2, out area, out rows, out columns);
            co = GetCorinWindow(viewController2.viewPort.HalconWindow, Camera2.CurrentImage, (int)rows.D, (int)columns.D);
            HOperatorSet.DispText(viewController2.viewPort.HalconWindow, "② " + res[1], "window", co[0], co[1], "black", "box", "true");

            image1.Dispose();
            image2.Dispose();

            DataCodeHandle2.Dispose();
            return(res);
        }
        /// <summary>
        /// Performs event handling of the HMouseWheel event of
        /// HWindowControl, so that the dipslayed image  part and scroll bars
        /// of HDisplayControl can be adapted to the current zoom value.
        /// </summary>
        private void viewPort_HMouseWheel(object sender, HMouseEventArgs e)
        {
            hWndControl.mouseWheel(sender, e);
            ManageScrollBars();
            hWndControl.repaint();

            this.Invalidate();
        }
Ejemplo n.º 13
0
        public HalconInterface(String name, Panel parentPnl, HalconVision halVis, HWindowControl myHalconWin)
        {
            InitializeComponent();
            ModuleNameLbl.Text = name;
            this.Parent        = parentPnl;
            myHalcon           = halVis;
            m_lockShowpicture  = new object();
            HalconWin          = myHalconWin;
            hWndCtrl           = new HWndCtrl(HalconWin);
            hWndCtrl.setViewState(HWndCtrl.MODE_VIEW_NONE);
            hWndCtrl.repaint();
            myHalcon.OnImageReadyFunction += OnImgReady;

            CaliXLbl.Text = myHalcon.CaliValue.X.ToString("F3");
            CaliYLbl.Text = myHalcon.CaliValue.Y.ToString("F3");
        }
Ejemplo n.º 14
0
        private void button2_Click(object sender, EventArgs e)
        {
            sortedRegions = mlpOCR.GetSortedRegions(mlpOCR.image);
            txt           = new System.Windows.Forms.TextBox[sortedRegions.CountObj()];
            HView         = new HWindowControl[sortedRegions.CountObj()];
            //
            int wndSize = 100;
            int c       = sortedRegions.CountObj();

            for (int i = 0; i < c; i++)
            {
                HRegion selectedRegion = sortedRegions.SelectObj(i + 1);

                HView[i] = new HWindowControl();
                HWndCtrl hWndControl = new HWndCtrl(HView[i]);

                HView[i].Size = new System.Drawing.Size(wndSize, wndSize);
                panelCharClass.Controls.Add(HView[i]);
                HView[i].Location = new System.Drawing.Point(15, 30 + (wndSize + 5) * i);

                int     row1, row2;
                int     col1, col2;
                int     imgH, imgW;
                HObject imgO;

                selectedRegion.SmallestRectangle1(out row1, out col1, out row2, out col2);
                mlpOCR.image.GetImageSize(out imgH, out imgW);
                HImage img = selectedRegion.RegionToBin(255, 0, imgH, imgW);
                HOperatorSet.CropPart(img, out imgO, row1, col1, row2, col2);
                //HOperatorSet.GetImageSize(imgO,out imgH, out imgW);


                hWndControl.addIconicVar(imgO);
                hWndControl.repaint();
                //
                txt[i]           = new System.Windows.Forms.TextBox();
                txt[i].Size      = new System.Drawing.Size(wndSize, wndSize);
                txt[i].MaxLength = 1;
                panelCharClass.Controls.Add(txt[i]);
                txt[i].Location = new System.Drawing.Point(15 + wndSize + 5, 30 + (wndSize + 5) * i);
            }
            button1.Enabled = true;
        }
Ejemplo n.º 15
0
        ///<summary>
        ///程序初始化
        ///</summary>
        public void Initialization()
        {
            //实例化:检测画面子菜单
            LineDetect                 = new LineDetect();
            LineDetect.TopLevel        = false;
            LineDetect.Dock            = DockStyle.Fill;
            LineDetect.FormBorderStyle = FormBorderStyle.None;
            LineDetect.Size            = TLPCheckParam.Size;
            ROIRectangle2              = new ROIRectangle2();
            ho_Image       = null;
            hv_ImageWindow = HWControl1.HalconID;

            InspectionStandard                 = new InspectionStandard();
            InspectionStandard.TopLevel        = false;
            InspectionStandard.Dock            = DockStyle.Fill;
            InspectionStandard.FormBorderStyle = FormBorderStyle.None;
            InspectionStandard.Size            = TLPCheckParam.Size;
            SendMessage(this.TLPanel_Bottom.Handle, WM_SETREDRAW, 0, IntPtr.Zero);//禁止重绘
            TLPCheckParam.Controls.Clear();
            TLPCheckParam.Controls.Add(InspectionStandard);
            InspectionStandard.Show();
            SendMessage(TLPanel_Bottom.Handle, WM_SETREDRAW, 1, IntPtr.Zero); //取消禁止
            TLPanel_Bottom.Refresh();                                         //刷新控件
            //

            //画面缩放
            roiController = new ROIController();
            HWndCtrl      = new HWndCtrl(HWControl1);
            HWndCtrl.useROIController(roiController);
            HWndCtrl.setViewState(HWndCtrl.MODE_VIEW_ZOOM);
            HWndCtrl.setViewState(HWndCtrl.MODE_VIEW_MOVE);
            HWndCtrl.ReDrawEvent          += new HWndCtrl.ReDrawDelegate(ReDraw);           //更改测量矩形,重绘直线
            LineDetect.ReviewLineEvent    += new LineDetect.ReviewLineDelegate(ReviewLine); //参数更改,重绘直线
            HWndCtrl.ImageProcessingEvent += HWndCtrl_ImageProcessingEvent;

            if (ho_Image != null)
            {
                HWndCtrl.addIconicVar(ho_Image);
                HWndCtrl.repaint();
            }
            //
        }
Ejemplo n.º 16
0
        private void GetHimage_Click(object sender, EventArgs e)
        {
            HObject ho_Image = null, ho_Regions = null;

            HOperatorSet.GenEmptyObj(out ho_Regions);
            if (icImagingControl1.LiveVideoRunning == true)
            {
                icImagingControl1.LiveStop();
            }
            //Bitmap btm = new Bitmap(icImagingControl1.ImageActiveBuffer.Bitmap);
            Bitmap btm = (Bitmap)icImagingControl1.ImageActiveBuffer.Bitmap.Clone();

            //viewController.addIconicVar(ImageConventer.ConvertBitmapToHalconImage(btm));
            ho_Image = Bitmap2HImage_24(btm);
            HOperatorSet.Threshold(ho_Image, out ho_Regions, 129, 170);
            viewController.addIconicVar(ho_Image);
            viewController.addIconicVar(ho_Regions);
            viewController.repaint();
            btm.Dispose();
            GC.Collect();
        }
        /// <summary>
        /// 更新畫面 (影像, ROI, 量測結果)
        /// </summary>
        /// <param name="contour"></param>
        private void updateView(HObject contour)
        {
            var image = contour as HImage;

            if (image != null)
            {
                _curImage = image;
                mAssistant.setImage(image);
            }

            if (_curImage == null)
            {
                mView.clearList();
            }
            else
            {
                mView.addIconicVar(_curImage);
            }
            showMeasureResult();
            mView.repaint();
        }
        /**************************************************************************/

        /* Setup the GUI for the SmartWindow application
         **************************************************************************/
        private void SmartWindowForm_Load(object sender, System.EventArgs e)
        {
            hWndControl = new HWndCtrl(viewPort);
            String fileName = "patras";
            HImage image;

            try
            {
                image = new HImage(fileName);
            }
            catch (HOperatorException)
            {
                MessageBox.Show("Problem occured while reading file!",
                                "SmartWindow2",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }

            hWndControl.addIconicVar(image);
            hWndControl.repaint();
        }
Ejemplo n.º 19
0
        public bool CalibrationMake(SourceBuffer _sourceBuffer, ExecuteBuffer _executeBuffer, out SourceBuffer outsourcebuffer, out ExecuteBuffer outexecutebuffer, HWndCtrl hWndCtrl, out string result_info)
        {
            outsourcebuffer  = _sourceBuffer;
            outexecutebuffer = _executeBuffer;
            result_info      = "";
            HTuple  hv_PixelSize = 0.00001;
            HTuple  hv_Message = new HTuple(), hv_Row = new HTuple();
            HTuple  hv_Column = new HTuple(), hv_Index = new HTuple();
            HTuple  hv_Error = null;
            HObject ho_Contours = null, ho_Cross = null, hv_outimage = null;
            HTuple  hv_HomMat3DIdentity = null;
            HTuple  hv_cp1Hur1 = null, hv_cam2Hcp2 = null, hv_cam2Hul2 = null;
            HTuple  hv_PoseNewOrigin2 = null, hv_ULX = null, hv_ULY = null, hv_PoseNewOrigin = null;

            double[] Get_actual_pixel = new double[7];
            HTuple   WorldPixelx, WorldPixely;
            HTuple   Heightx = new HTuple(), Widthx = new HTuple();

            Heightx.Append(Height / 2);
            Heightx.Append(Height / 2);
            Heightx.Append(Height / 2 + 1);
            Widthx.Append(Width / 2);
            Widthx.Append(Width / 2 + 1);
            Widthx.Append(Width / 2);
            HTuple WorldLength1, WorldLength2;
            HTuple ScaleForSimilarPixelSize = 0;

            HOperatorSet.GenEmptyObj(out ho_Contours);
            HOperatorSet.GenEmptyObj(out ho_Cross);
            HOperatorSet.GenEmptyObj(out hv_outimage);

            if (!_executeBuffer.imageBuffer.ContainsKey(this.Input_image.SelectedItem.ToString() + ".img"))
            {
                MessageBox.Show("二值化处理: 输入图像已经不存在,请重置设置输入图像");
                result_info = " 二值化处理: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }
            if (_executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"] == null)
            {
                MessageBox.Show("二值化处理: image参数为空或者未赋值");
                result_info = " 二值化处理: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }
            string comboBox_imageoutname = this.Output_image.Text.ToString() + ".img";

            if (_executeBuffer.imageBuffer[comboBox_imageoutname] != null)
            {
                if (_executeBuffer.imageBuffer[comboBox_imageoutname].IsInitialized())
                {
                    _executeBuffer.imageBuffer[comboBox_imageoutname].Dispose();
                }
            }
            HTuple width, height;
            int    m = _executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"].CountObj();

            HOperatorSet.GetImageSize(_executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"], out width, out height);
            int number = Convert.ToInt32(this.textBox1.Text.ToString());

            if (!this.checkBox1.Checked)
            {
                if (Get_Cal_pixel)
                {
                    Get_Cal_pixel = false;
                }
                if (number == 0)
                {
                    hv_StartCamPar = new HTuple();
                    if (this.checkBox_focalize.Checked)
                    {
                        hv_StartCamPar.Append(0);
                    }
                    else
                    {
                        hv_StartCamPar.Append(Convert.ToDouble(this.textbox_lens.Text.ToString()) / 100);
                    }
                    hv_StartCamPar.Append(0);
                    hv_StartCamPar.Append(Convert.ToDouble(this.textBox_width.Text.ToString()) / 10000000);
                    hv_StartCamPar.Append(Convert.ToDouble(this.textBox_height.Text.ToString()) / 10000000);
                    hv_StartCamPar.Append(width / 2);
                    hv_StartCamPar.Append(height / 2);
                    hv_StartCamPar.Append(width);
                    hv_StartCamPar.Append(height);
                    hv_CalTabDescrFile = this.textBox_file.Text;
                    HOperatorSet.CreateCalibData("calibration_object", 1, 1, out CalibDataID);
                    if (this.checkBox_focalize.Checked)
                    {
                        HOperatorSet.SetCalibDataCamParam(CalibDataID, 0, "area_scan_telecentric_division", hv_StartCamPar);
                    }
                    else
                    {
                        HOperatorSet.SetCalibDataCamParam(CalibDataID, 0, "area_scan_division", hv_StartCamPar);
                    }
                    HOperatorSet.SetCalibDataCalibObject(CalibDataID, 0, hv_CalTabDescrFile);
                }
                try
                {
                    HOperatorSet.FindCalibObject(_executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"], CalibDataID, 0, 0, number, new HTuple(), new HTuple());
                    HOperatorSet.GetCalibData(CalibDataID, "camera", 0, "init_params", out hv_StartCamPar);
                    HOperatorSet.GetCalibDataObservPoints(CalibDataID, 0, 0, number, out hv_Row, out hv_Column, out hv_Index, out hv_Pose);
                    HOperatorSet.GetCalibDataObservContours(out ho_Contours, CalibDataID, "caltab", 0, 0, number);
                    HOperatorSet.GenCrossContourXld(out ho_Cross, hv_Row, hv_Column, 6, 0.785398);
                    hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, "orange");
                    hWndCtrl.addIconicVar(ho_Cross);
                    hWndCtrl.addIconicVar(ho_Contours);
                    hWndCtrl.repaint();
                }
                catch
                {
                    MessageBox.Show("找不到标定板");
                    ho_Contours.Dispose();
                    ho_Cross.Dispose();

                    return(false);
                }

                if (number == hv_NumImages - 1)
                {
                    Read_file = false;
                    HOperatorSet.CalibrateCameras(CalibDataID, out hv_Error);
                    HOperatorSet.GetCalibData(CalibDataID, "camera", 0, "params", out hv_CamParam);
                    HOperatorSet.GetCalibData(CalibDataID, "calib_obj_pose", (new HTuple(0)).TupleConcat(6), "pose", out hv_Pose);
                    HOperatorSet.HomMat3dIdentity(out hv_HomMat3DIdentity);
                    HOperatorSet.HomMat3dRotateLocal(hv_HomMat3DIdentity, ((-(hv_Pose.TupleSelect(5)))).TupleRad(), "z", out hv_cp1Hur1);
                    HOperatorSet.PoseToHomMat3d(hv_Pose, out hv_cam2Hcp2);
                    HOperatorSet.HomMat3dCompose(hv_cam2Hcp2, hv_cp1Hur1, out hv_cam2Hul2);
                    HOperatorSet.HomMat3dToPose(hv_cam2Hul2, out hv_PoseNewOrigin2);
                    HOperatorSet.ImagePointsToWorldPlane(hv_CamParam, hv_PoseNewOrigin2, 0, 0, "m", out hv_ULX, out hv_ULY);
                    HOperatorSet.SetOriginPose(hv_PoseNewOrigin2, hv_ULX, hv_ULY, 0, out hv_PoseNewOrigin);

                    HOperatorSet.ImagePointsToWorldPlane(hv_CamParam, hv_Pose, Heightx, Widthx, 1, out WorldPixelx, out WorldPixely);
                    HOperatorSet.DistancePp(WorldPixely[0], WorldPixelx[0], WorldPixely[1], WorldPixelx[1], out WorldLength1);
                    HOperatorSet.DistancePp(WorldPixely[0], WorldPixelx[0], WorldPixely[2], WorldPixelx[2], out WorldLength2);
                    ScaleForSimilarPixelSize = (WorldLength1 + WorldLength2) / 2;
                    HOperatorSet.GenImageToWorldPlaneMap(out ho_MapSingle1, hv_CamParam,
                                                         hv_PoseNewOrigin, width, height, width, height, ScaleForSimilarPixelSize, "bilinear");
                    HOperatorSet.WriteObject(ho_MapSingle1, this.textBox2.Text.ToString());
                    Read_file              = true;
                    Get_Calibration        = true;
                    this.checkBox1.Checked = true;
                    result_info            = " 校正参数: 设置完成";
                }

                this.textBox1.Text = (number + 1).ToString();
            }

            if (this.checkBox1.Checked)
            {
                if (Read_file)
                {
                    if (File.Exists(this.textBox2.Text))
                    {
                        HOperatorSet.ReadObject(out ho_MapSingle1, this.textBox2.Text);
                    }
                    else
                    {
                        MessageBox.Show("校正文件不存在 ,请检查");
                        return(false);
                    }
                }

                HOperatorSet.MapImage(_executeBuffer.imageBuffer[this.Input_image.SelectedItem.ToString() + ".img"], ho_MapSingle1, out hv_outimage);
                _executeBuffer.imageBuffer[comboBox_imageoutname] = hv_outimage;
                outexecutebuffer = _executeBuffer;
                result_info      = " 校正: 完成";
                HTuple Distance;
                if (!Get_Cal_pixel)
                {
                    try
                    {
                        double all_number = 0;
                        HOperatorSet.FindCalibObject(hv_outimage, CalibDataID, 0, 0, 0, new HTuple(), new HTuple());
                        HOperatorSet.GetCalibDataObservPoints(CalibDataID, 0, 0, 0, out hv_Row, out hv_Column, out hv_Index, out hv_Pose);
                        for (int i = 0; i < 7; i++)
                        {
                            HOperatorSet.DistancePp(hv_Row[i * 7], hv_Column[i * 7], hv_Row[i * 7 + 6], hv_Column[i * 7 + 6], out Distance);
                            Get_actual_pixel[i] = Distance.D;
                            all_number          = all_number + Get_actual_pixel[i];
                        }
                        Pixel_number          = (Convert.ToDouble(this.textBox_pixel.Text)) / (all_number / 7);
                        Get_Cal_pixel         = true;
                        this.label_pixel.Text = Pixel_number.ToString();
                        Pixel_Trans           = Convert.ToDouble(Pixel_number.ToString());
                    }
                    catch
                    {
                        MessageBox.Show("请再次添加图像寻找计算像素比");
                    }
                }
                if (Read_file)
                {
                    ho_MapSingle1.Dispose();
                }
            }



            return(true);
        }
Ejemplo n.º 20
0
        public bool Genshape(ExecuteBuffer _executeBuffer, out ExecuteBuffer outexecutebuffer, HWndCtrl hWndCtrl, 模板GVName_halcon Model_result, Dictionary <int, PointName> Point_temp_result, List <直线GVName> newline)
        {
            outexecutebuffer = _executeBuffer;
            int    x_get = 0, y_get = 0;
            double angle_get   = 0;
            bool   Model_check = false;

            HObject new_type;

            if (!_executeBuffer.imageBuffer.ContainsKey(this.cbb_image.SelectedItem.ToString() + ".img"))
            {
                MessageBox.Show("感兴趣区域:无法找到输入图像");
                return(false);
            }
            if (this.checkBox1.Checked)
            {
                if (Button_press)
                {
                    new_type = sou_regions[0].getRegion();
                }
                else
                {
                    new_type = _executeBuffer.imageBuffer[this.cbb_image.SelectedItem.ToString() + ".img"];
                }
            }
            else
            {
                if (this.checkBox_get.Checked)
                {
                    if (this.cbb_point.SelectedIndex == 0)
                    {
                        if (Model_result == null)
                        {
                            MessageBox.Show("生成ROI:匹配列表为空,请设置");
                            return(false);
                        }
                        if (Model_result.点X.TupleLength() < 1)
                        {
                            MessageBox.Show("生成ROI:匹配列表为空,请设置");
                            // result_info = " 查找直线: 匹配列表为空,请设置";
                            return(false);
                        }
                        x_get       = Convert.ToInt32(Model_result.点Y[0].D);
                        y_get       = Convert.ToInt32(Model_result.点X[0].D);
                        Model_check = true;
                    }
                    else
                    {
                        int number1 = Convert.ToInt32(this.tb_no.Text);
                        if (!Point_temp_result.ContainsKey(number1))
                        {
                            MessageBox.Show("生成ROI:全局列表点无此点,请设置");

                            return(false);
                        }
                        else
                        {
                            x_get = Convert.ToInt32(Point_temp_result[number1].点Y.D);
                            y_get = Convert.ToInt32(Point_temp_result[number1].点X.D);
                        }
                    }



                    if (this.cbb_angle.SelectedIndex == 0)
                    {
                        if (Model_check)
                        {
                            angle_get = Model_result.模板Angle[0] - Model_result.角度Angle[0];
                        }
                        else
                        {
                            if (Model_result == null)
                            {
                                MessageBox.Show("生成ROI:匹配列表为空,请设置");
                                return(false);
                            }
                            if (Model_result.点X.TupleLength() < 1)
                            {
                                MessageBox.Show("生成ROI:匹配列表为空,请设置");
                                // result_info = " 查找直线: 匹配列表为空,请设置";
                                return(false);
                            }
                            angle_get = Model_result.模板Angle[0] - Model_result.角度Angle[0];
                        }
                    }
                    else if (this.cbb_angle.SelectedIndex == 1)
                    {
                        if (newline == null)
                        {
                            MessageBox.Show("生成ROI:直线为空,请设置");
                            return(false);
                        }
                        if (newline.Count < 1)
                        {
                            MessageBox.Show("生成ROI:直线为空,请设置");
                            return(false);
                        }
                        double xrow1 = Convert.ToDouble(newline[0].点1X);
                        double xcol1 = Convert.ToDouble(newline[0].点1Y);
                        double xrow2 = Convert.ToDouble(newline[0].点2X);
                        double xcol2 = Convert.ToDouble(newline[0].点2Y);
                        angle_get = Getangle1(xrow1, xcol1, xrow2, xcol2);
                    }
                    else
                    {
                        angle_get = Convert.ToDouble(this.txt_rec2phi.Text.ToString());
                    }
                }


                outexecutebuffer = _executeBuffer;


                if (this.comboBox1.SelectedIndex == 1)
                {
                    if (!this.checkBox_get.Checked)
                    {
                        x_get = Convert.ToInt32(this.textBox_rec2row1.Text.ToString());
                        y_get = Convert.ToInt32(this.textBox_rec2col1.Text.ToString());
                    }
                    HOperatorSet.GenRectangle2(out new_type, x_get, y_get, -angle_get, Convert.ToInt32(this.textBox_rec2len1.Text.ToString()), Convert.ToInt32(this.textBox_rec2len2.Text.ToString()));
                }
                else
                {
                    if (!this.checkBox_get.Checked)
                    {
                        x_get = Convert.ToInt32(this.textBox_circlerow.Text.ToString());
                        y_get = Convert.ToInt32(this.textBox_circlecolumn.Text.ToString());
                    }
                    HOperatorSet.GenCircle(out new_type, x_get, y_get, Convert.ToInt32(this.textBox_circleradius.Text.ToString()));
                }


                if (_executeBuffer.imageBuffer[this.shape_name.Text + ".region"] != null)
                {
                    if (_executeBuffer.imageBuffer[this.shape_name.Text + ".region"].IsInitialized())
                    {
                        _executeBuffer.imageBuffer[this.shape_name.Text + ".region"].Dispose();
                    }
                }
            }

            hWndCtrl.addIconicVar(new_type);
            hWndCtrl.repaint();
            _executeBuffer.imageBuffer[this.shape_name.Text + ".region"] = new_type;
            outexecutebuffer = _executeBuffer;

            return(true);
        }
 public void UpdateWindow()
 {
     HalconCtrl.repaint();
 }
Ejemplo n.º 22
0
        public bool Find_halcon_circle(ExecuteBuffer _executeBuffer, HWndCtrl hWndCtrl, 模板GVName_halcon Model_result, Dictionary <int, PointName> Point_temp_result, out string result_info, out HTuple Row, out HTuple Column, out HTuple Radius, bool show_info)
        {
            HTuple MetrologyHandle;
            HTuple pic_wid, pic_height;

            Row         = new HTuple();
            Column      = new HTuple();
            Radius      = new HTuple();
            result_info = "";
            HOperatorSet.CreateMetrologyModel(out MetrologyHandle);
            if (!_executeBuffer.imageBuffer.ContainsKey(this.Threshold_image.SelectedItem.ToString() + ".img"))
            {
                MessageBox.Show("查找圆: 输入图像已经不存在,请重置设置输入图像");
                result_info = " 查找圆: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }
            if (_executeBuffer.imageBuffer[this.Threshold_image.SelectedItem.ToString() + ".img"] == null)
            {
                MessageBox.Show("查找圆: image参数为空或者未赋值");
                result_info = " 查找圆: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }

            /*
             * if (xrow == null || xcol == null || xradius == null)
             * {
             *  MessageBox.Show("查找圆: 未确定圆位置");
             *  result_info = " 查找圆: 未确定圆位置";
             *  return false;
             * }*/
            HObject imagein = _executeBuffer.imageBuffer[this.Threshold_image.SelectedItem.ToString() + ".img"];

            HOperatorSet.GetImageSize(imagein, out pic_wid, out pic_height);
            HOperatorSet.SetMetrologyModelImageSize(MetrologyHandle, pic_wid, pic_height);
            HTuple Index;

            HTuple trow, tcol, tradius;

            if (this.checkBox_circle.Checked)
            {
                if (xrow == null || xcol == null || xradius == null)
                {
                    MessageBox.Show("查找直线:未确认线位置");
                    result_info = " 查找直线: 未确认线位置";
                    return(false);
                }
                else if (xrow.D == 0 && xcol.D == 0 && xradius.D == 0)
                {
                    MessageBox.Show("查找直线:未确认线位置");
                    result_info = " 查找直线: 未确认线位置";
                    return(false);
                }
                else
                {
                    trow    = xrow;
                    tcol    = xcol;
                    tradius = xradius;
                }
            }
            else
            {
                tradius = Convert.ToDouble(this.textBox_radius.Text);
                if (this.cbb_source1.SelectedIndex == 0)
                {
                    if (Model_result == null)
                    {
                        MessageBox.Show("查找圆:匹配列表为空,请设置");
                        result_info = " 查找圆: 匹配列表为空,请设置";
                        return(false);
                    }
                    if (Model_result.点X.TupleLength() < 1)
                    {
                        MessageBox.Show("查找圆:匹配列表为空,请设置");
                        result_info = " 查找圆: 匹配列表为空,请设置";
                        return(false);
                    }
                    trow = Model_result.点Y[0];
                    tcol = Model_result.点X[0];
                }
                else
                {
                    int number1 = Convert.ToInt32(this.tb_value1.Text);
                    if (!Point_temp_result.ContainsKey(number1))
                    {
                        MessageBox.Show("查找圆:全局列表点无此点,请设置");
                        result_info = " 查找圆: 全局列表无此点,请设置";
                        return(false);
                    }
                    else
                    {
                        trow = Point_temp_result[number1].点Y;
                        tcol = Point_temp_result[number1].点X;
                    }
                }
            }



            HOperatorSet.AddMetrologyObjectCircleMeasure(MetrologyHandle, trow, tcol, tradius, Convert.ToInt32(this.measure_length1.Text.ToString()), Convert.ToInt32(this.measure_length2.Text.ToString()), 1, Convert.ToInt32(this.measure_threshold.Text.ToString()), new HTuple(), new HTuple(), out Index);
            //    HOperatorSet.SetMetrologyObjectParam(MetrologyHandle,"all","measure_transition","negative");
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_transition", this.cbb_transition.SelectedItem.ToString());
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_select", this.cbb_measure_select.SelectedItem.ToString());
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "num_measures", Convert.ToInt32(this.num_measure.Text.ToString()));
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "num_instances", 40);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_sigma", 1);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_interpolation", "bicubic");
            //HOperatorSet.SetMetrologyObjectParam(MetrologyHandle,"all","measure_select","all");
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "min_score", 0.4);
            HOperatorSet.ApplyMetrologyModel(imagein, MetrologyHandle);
            HObject Contours, Cross;

            HOperatorSet.GetMetrologyObjectMeasures(out Contours, MetrologyHandle, "all", "all", out Row, out Column);
            HOperatorSet.GenCrossContourXld(out Cross, Row, Column, 6, 0.785398);
            HTuple hv_Parameter = null;

            //得到线的起点和终点坐标并显示出来
            HOperatorSet.GetMetrologyObjectResult(MetrologyHandle, "all", "all", "result_type",
                                                  "all_param", out hv_Parameter);
            if (hv_Parameter.TupleLength() == 0)
            {
                result_info = " 查找圆: 在指定位置,找圆失败";
                MessageBox.Show("未找到圆");
                return(false);
            }
            int Circle_number = hv_Parameter.TupleLength() / 3;

            double[] Row_out    = new double[Circle_number];
            double[] Column_out = new double[Circle_number];
            double[] Radius_out = new double[Circle_number];
            for (int i = 0; i < Circle_number; i++)
            {
                Row_out[i]    = hv_Parameter[i * 3 + 1].D;
                Column_out[i] = hv_Parameter[i * 3].D;
                Radius_out[i] = hv_Parameter[i * 3 + 2].D;
            }
            Row    = (HTuple)Row_out;
            Column = (HTuple)Column_out;
            Radius = (HTuple)Radius_out;

            HObject ho_Contour;

            HOperatorSet.GenEmptyObj(out ho_Contour);
            ho_Contour.Dispose();
            HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour, MetrologyHandle,
                                                         "all", "all", 1.5);


            HOperatorSet.ClearMetrologyModel(MetrologyHandle);
            if (show_info)
            {
                hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                hWndCtrl.addIconicVar(Cross);
                hWndCtrl.addIconicVar(Contours);
            }
            hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
            hWndCtrl.addIconicVar(ho_Contour);
            hWndCtrl.repaint();
            return(true);
        }
Ejemplo n.º 23
0
        public bool Find_halcon_line(ExecuteBuffer _executeBuffer, HWndCtrl hWndCtrl, 模板GVName_halcon Model_result, Dictionary <int, PointName> Point_temp_result, out string result_info, out HTuple Row1, out HTuple Column1, out HTuple Row2, out HTuple Column2, bool show_info)
        {
            HTuple MetrologyHandle;
            HTuple pic_wid, pic_height;

            Row1        = new HTuple();
            Column1     = new HTuple();
            Row2        = new HTuple();
            Column2     = new HTuple();
            result_info = "";
            HOperatorSet.CreateMetrologyModel(out MetrologyHandle);
            if (!_executeBuffer.imageBuffer.ContainsKey(this.Threshold_image.SelectedItem.ToString() + ".img"))
            {
                //     MessageBox.Show("查找直线: 输入图像已经不存在,请重置设置输入图像");
                result_info = " 查找直线: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }
            if (_executeBuffer.imageBuffer[this.Threshold_image.SelectedItem.ToString() + ".img"] == null)
            {
                //     MessageBox.Show("查找直线: image参数为空或者未赋值");
                result_info = " 查找直线: 输入图像已经不存在,请重置设置输入图像";
                return(false);
            }
            HObject imagein = _executeBuffer.imageBuffer[this.Threshold_image.SelectedItem.ToString() + ".img"];

            HOperatorSet.GetImageSize(imagein, out pic_wid, out pic_height);
            HOperatorSet.SetMetrologyModelImageSize(MetrologyHandle, pic_wid, pic_height);
            HTuple Index;
            HTuple trow1, trow2, tcol1, tcol2;

            if (checkBox_line.Checked)
            {
                if (xrow1 == null || xrow2 == null || xcol1 == null || xcol2 == null)
                {
                    //    MessageBox.Show("查找直线:未确认线位置");
                    result_info = " 查找直线: 未确认线位置";
                    return(false);
                }
                else
                {
                    trow1 = xrow1;
                    tcol1 = xcol1;
                    trow2 = xrow2;
                    tcol2 = xcol2;
                }
            }
            else
            {
                if (this.cbb_source1.SelectedIndex == 0)
                {
                    if (Model_result == null)
                    {
                        //      MessageBox.Show("查找直线:匹配列表为空,请设置");
                        result_info = " 查找直线: 匹配列表为空,请设置";
                        return(false);
                    }
                    if (Model_result.点X.TupleLength() < 1)
                    {
                        //    MessageBox.Show("查找直线:匹配列表为空,请设置");
                        result_info = " 查找直线: 匹配列表为空,请设置";
                        return(false);
                    }
                    trow1 = Model_result.点Y[0];
                    tcol1 = Model_result.点X[0];
                }
                else
                {
                    int number1 = Convert.ToInt32(this.tb_value1.Text);
                    if (!Point_temp_result.ContainsKey(number1))
                    {
                        //           MessageBox.Show("查找直线:全局列表点无此点,请设置");
                        result_info = " 查找直线: 全局列表无此点,请设置";
                        return(false);
                    }
                    else
                    {
                        trow1 = Point_temp_result[number1].点Y;
                        tcol1 = Point_temp_result[number1].点X;
                    }
                }
                int number2 = Convert.ToInt32(this.tb_value2.Text);
                if (!Point_temp_result.ContainsKey(number2))
                {
                    //      MessageBox.Show("查找直线:全局列表点无此点,请设置");
                    result_info = " 查找直线: 全局列表无此点,请设置";
                    return(false);
                }
                else
                {
                    trow2 = Point_temp_result[number2].点Y;
                    tcol2 = Point_temp_result[number2].点X;
                }
            }

            HOperatorSet.AddMetrologyObjectLineMeasure(MetrologyHandle, trow1, tcol1, trow2, tcol2, Convert.ToInt32(this.measure_length1.Text.ToString()), Convert.ToInt32(this.measure_length2.Text.ToString()),
                                                       1, Convert.ToInt32(this.measure_threshold.Text.ToString()), new HTuple(), new HTuple(), out Index);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_transition", this.cbb_transition.SelectedItem.ToString());
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "num_measures", Convert.ToInt32(this.num_measure.Text.ToString()));
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "num_instances", 40);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_sigma", 1);

            //HOperatorSet.SetMetrologyObjectParam(MetrologyHandle,"all","measure_threshold",50);
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_interpolation", "bicubic");
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "measure_select", this.cbb_measure_select.SelectedItem.ToString());
            HOperatorSet.SetMetrologyObjectParam(MetrologyHandle, "all", "min_score", Convert.ToDouble(this.min_score.Text));
            HOperatorSet.ApplyMetrologyModel(imagein, MetrologyHandle);
            HObject Contours, Cross;
            HTuple  Rowx, Columnx;

            HOperatorSet.GetMetrologyObjectMeasures(out Contours, MetrologyHandle, "all", "all", out Rowx, out Columnx);
            HOperatorSet.GenCrossContourXld(out Cross, Rowx, Columnx, 6, 0.785398);
            HTuple hv_Parameter = null;

            //得到线的起点和终点坐标并显示出来
            HOperatorSet.GetMetrologyObjectResult(MetrologyHandle, "all", "all", "result_type",
                                                  "all_param", out hv_Parameter);
            if (hv_Parameter.TupleLength() == 0)
            {
                result_info = " 查找直线: 在指定位置,找直线失败";
                //      MessageBox.Show("未找到直线");
                return(false);
            }
            int line_count = hv_Parameter.TupleLength() / 4;

            double[] Row_1    = new double[line_count];
            double[] Column_1 = new double[line_count];
            double[] Row_2    = new double[line_count];
            double[] Column_2 = new double[line_count];

            for (int imx = 0; imx < line_count; imx++)
            {
                Row_1[imx]    = hv_Parameter[imx * 4 + 1].D;
                Column_1[imx] = hv_Parameter[imx * 4].D;
                Row_2[imx]    = hv_Parameter[imx * 4 + 3].D;
                Column_2[imx] = hv_Parameter[imx * 4 + 2].D;
            }
            Row1    = (HTuple)Row_1;
            Column1 = (HTuple)Column_1;
            Row2    = (HTuple)Row_2;
            Column2 = (HTuple)Column_2;

            HObject ho_Contour;

            HOperatorSet.GenEmptyObj(out ho_Contour);
            ho_Contour.Dispose();
            HOperatorSet.GetMetrologyObjectResultContour(out ho_Contour, MetrologyHandle,
                                                         "all", "all", 1.5);


            HOperatorSet.ClearMetrologyModel(MetrologyHandle);
            if (show_info)
            {
                hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                hWndCtrl.addIconicVar(Cross);
                hWndCtrl.addIconicVar(Contours);
            }
            hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
            hWndCtrl.addIconicVar(ho_Contour);
            hWndCtrl.repaint();
            return(true);
        }
Ejemplo n.º 24
0
 /// <summary>Resets the application; invoked by the corresponding button.</summary>
 private void resetButton_Click(object sender, System.EventArgs e)
 {
     viewController.resetAll();
     viewController.repaint();
 }
Ejemplo n.º 25
0
        public bool Run_show(ExecuteBuffer _executeBuffer, 模板GVName_halcon Model_result, Dictionary <int, PointName> Pointlist, HWndCtrl hWndCtrl, out string out_info)
        {
            int number_source = this.cbb_Inputsource.SelectedIndex;

            out_info = "";
            if (number_source == 0)
            {
                if (Model_result == null)
                {
                    MessageBox.Show("点位显示:  输入为空,其中没有点位");
                    out_info = "点位显示:  输入为空,其中没有点位";
                    return(false);
                }
                HTuple size = 10;

                if (Model_result.点X.TupleLength() > 0)
                {
                    if (linecheck.Checked)
                    {
                        HObject line_match;
                        HOperatorSet.GenEmptyObj(out line_match);
                        // HOperatorSet.GenRegionLine(out line_match, (double)Model_result.点Y[0], (double)Model_result.点X[0], (double)Model_result.点Y[1], (double)Model_result.点X[1]);
                        HOperatorSet.GenContourPolygonXld(out line_match, Model_result.点X, Model_result.点Y);
                        hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                        hWndCtrl.addIconicVar(line_match);
                        hWndCtrl.repaint();
                        out_info = "点位显示:  完成";
                        return(true);
                    }
                    else
                    {
                        HObject cross;
                        HOperatorSet.GenEmptyObj(out cross);
                        HOperatorSet.GenCrossContourXld(out cross, Model_result.点Y, Model_result.点X, size, Model_result.角度Angle);

                        hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                        hWndCtrl.addIconicVar(cross);
                        hWndCtrl.repaint();
                        out_info = "点位显示:  完成";
                        return(true);
                    }
                }
                else
                {
                    out_info = "点位显示:  没有可以显示的点位";
                }
            }
            else
            {
                int number_check = Convert.ToInt32(this.textBox1.Text.ToString());
                if (!Pointlist.ContainsKey(number_check))
                {
                    MessageBox.Show("点位显示:  输入为空,其中没有点位");
                    out_info = "点位显示:  输入为空,其中没有点位";
                    return(false);
                }
                HTuple size1 = 20;

                if (Pointlist[number_check].点X.TupleLength() > 0)
                {
                    if (linecheck.Checked)
                    {
                        HObject line;
                        HOperatorSet.GenEmptyObj(out line);
                        // HOperatorSet.GenRegionLine(out line, (double)Pointlist[number_check].点Y[0], (double)Pointlist[number_check].点X[0], (double)Pointlist[number_check].点Y[1], (double)Pointlist[number_check].点X[1]);
                        HOperatorSet.GenContourPolygonXld(out line, Pointlist[number_check].点X, Pointlist[number_check].点Y);
                        hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                        hWndCtrl.addIconicVar(line);
                        hWndCtrl.repaint();
                        out_info = "点位显示:  完成";
                        return(true);
                    }
                    else
                    {
                        HObject cross;
                        HOperatorSet.GenEmptyObj(out cross);
                        HOperatorSet.GenCrossContourXld(out cross, Pointlist[number_check].点Y, Pointlist[number_check].点X, size1, 0);

                        hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, this.comboBox1.SelectedItem.ToString());
                        hWndCtrl.addIconicVar(cross);
                        hWndCtrl.repaint();
                        out_info = "点位显示:  完成";
                        return(true);
                    }
                }
                else
                {
                    out_info = "点位显示:  没有可以显示的点位";
                }
            }



            return(false);
        }
 /* reset the view to the initial display dimensions */
 private void resetButton_Click(object sender, System.EventArgs e)
 {
     hWndControl.resetWindow();
     hWndControl.repaint();
 }
 private void GrabImageButtonClick(object sender, RoutedEventArgs e)
 {
     Camera.GrabImage();
     viewController1.addIconicVar(Camera.CurrentImage);
     viewController1.repaint();
 }
Ejemplo n.º 28
0
        public bool Run_show(string color_set, 圆GVName_halcon Circle_result, 圆弧GVName_halcon Circlearc_result, 直线GVName_halcon Line_result, HWndCtrl hWndCtrl, out string out_info)
        {
            out_info = "";
            if (color_set == "")
            {
                color_set = "red";
            }
            HObject Circle1;
            HObject CircleArc1;
            HObject Line1;

            if (Circle_result == null)
            {
                MessageBox.Show("轮廓显示:  显示圆列表为空");
                out_info = "轮廓显示:  圆为空";
            }
            else
            {
                int Circle_result_number = Circle_result.圆心X.TupleLength();
                for (int j = 0; j < Circle_result_number; j++)
                {
                    //HOperatorSet.GenCircle(out Circle1, Circle_result.圆心X[j], Circle_result.圆心Y[j], Circle_result.半径R[j]);
                    HOperatorSet.GenCircleContourXld(out Circle1, Circle_result.圆心X[j], Circle_result.圆心Y[j], Circle_result.半径R[j], 0, 2 * Math.PI, "positive", 1);
                    hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, color_set);
                    hWndCtrl.addIconicVar(Circle1);
                }
            }

            if (Circlearc_result == null)
            {
                MessageBox.Show("轮廓显示:  圆弧为空");
                out_info = out_info + " 圆弧为空";
            }
            else
            {
                int Circlearc_result_number = Circlearc_result.半径R.TupleLength();
                for (int m = 0; m < Circlearc_result_number; m++)
                {
                    //HOperatorSet.GenCircleSector(out CircleArc1, Circlearc_result.圆心X[m], Circlearc_result.圆心Y[m], Circlearc_result.半径R[m], Circlearc_result.圆弧Start[m], Circlearc_result.圆弧End[m]);
                    HOperatorSet.GenCircleContourXld(out CircleArc1, Circlearc_result.圆心X[m], Circlearc_result.圆心Y[m], Circlearc_result.半径R[m], Circlearc_result.圆弧Start[m], Circlearc_result.圆弧End[m], "positive", 1);
                    hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, color_set);
                    hWndCtrl.addIconicVar(CircleArc1);
                }
            }

            if (Line_result == null)
            {
                MessageBox.Show("轮廓显示:  直线为空");
                out_info = out_info + "直线为空";
            }
            else
            {
                int line_result_number = Line_result.点1X.TupleLength();
                for (int l = 0; l < line_result_number; l++)
                {
                    HOperatorSet.GenContourPolygonXld(out Line1, ((HTuple)Line_result.点1X[l]).TupleConcat(
                                                          (HTuple)Line_result.点2X[l]), ((HTuple)Line_result.点1Y[l]).TupleConcat((HTuple)Line_result.点2Y[l]));

                    hWndCtrl.changeGraphicSettings(GraphicsContext.GC_COLOR, color_set);
                    hWndCtrl.addIconicVar(Line1);
                }
            }
            hWndCtrl.repaint();

            return(true);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// 单击打开生产详细数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listView1_MouseClick(object sender, MouseEventArgs e)
        {
            string filename = listView1.FocusedItem.SubItems[0].Text;//获取鼠标当前行

            double[] ChartMin_In  = new double[5];
            double[] ChartMin_Out = new double[5];
            double   Min_In       = new double();
            double   Min_Out      = new double();

            //查看当前电芯数据
            if (filename == "当前电芯数据")
            {
                //触发回调函数更新当前电芯数据
                RefreshChartFlag = true;
                if (RefreshInformationForm_Chart_Event != null)
                {
                    RefreshInformationForm_Chart_Event();
                }
            }
            //查看历史生产电芯数据
            else
            {
                RefreshChartFlag = false;
                string Path_csv = CSV_Directory + "\\" + CB_CSVFileName.Text + "\\" + filename;
                Path_NG_Pic = AppDomain.CurrentDomain.BaseDirectory + "Screen\\" + CB_CSVFileName.Text + "\\" + filename.Substring(0, 8);
                foreach (var series in Chart_Inside.Series)
                {
                    series.Points.Clear();
                }
                foreach (var series in Chart_Outside.Series)
                {
                    series.Points.Clear();
                }
                if (System.IO.File.Exists(Path_csv))
                {
                    listView2.Items.Clear();
                    List <String[]> ls = CsvWrite.ReadCSV(Path_csv);


                    for (int i = 1; i < ls.Count; i++)
                    {
                        if (ls[i][0] != "")
                        {
                            ListViewItem lvi = new ListViewItem();
                            lvi.Text = ls[i][0];
                            lvi.SubItems.Add(ls[i][5]);
                            lvi.SubItems.Add(ls[i][6]);
                            lvi.SubItems.Add(ls[i][7]);
                            lvi.SubItems.Add(ls[i][8]);

                            lvi.SubItems.Add(ls[i][13]);
                            lvi.SubItems.Add(ls[i][14]);
                            lvi.SubItems.Add(ls[i][15]);
                            lvi.SubItems.Add(ls[i][16]);

                            lvi.SubItems.Add(ls[i][17]);
                            //lvi.SubItems.Add(path_csv);
                            listView2.BeginUpdate();
                            listView2.Items.Add(lvi);
                            //listView1.Items[listView1.Items.Count - 1].EnsureVisible();
                            listView2.EndUpdate();

                            double CD_In     = Convert.ToDouble(ls[i][1]);
                            double AD_In     = Convert.ToDouble(ls[i][2]);
                            double UpSD_In   = Convert.ToDouble(ls[i][3]);
                            double DownSD_In = Convert.ToDouble(ls[i][4]);

                            double CD_Out     = Convert.ToDouble(ls[i][9]);
                            double AD_Out     = Convert.ToDouble(ls[i][10]);
                            double UpSD_Out   = Convert.ToDouble(ls[i][11]);
                            double DownSD_Out = Convert.ToDouble(ls[i][12]);


                            Chart_Inside.Series["正极"].Points.AddXY(CD_In, i);
                            Chart_Inside.Series["负极"].Points.AddXY(AD_In, i);
                            Chart_Inside.Series["上隔膜"].Points.AddXY(UpSD_In, i);
                            Chart_Inside.Series["下隔膜"].Points.AddXY(DownSD_In, i);


                            Chart_Outside.Series["正极"].Points.AddXY(CD_Out, i);
                            Chart_Outside.Series["负极"].Points.AddXY(AD_Out, i);
                            Chart_Outside.Series["上隔膜"].Points.AddXY(UpSD_Out, i);
                            Chart_Outside.Series["下隔膜"].Points.AddXY(DownSD_Out, i);

                            if (i == 1)
                            {
                                ChartMin_In  = new double[] { CD_In, AD_In, UpSD_In, DownSD_In };
                                ChartMin_Out = new double[] { CD_Out, AD_Out, UpSD_Out, DownSD_Out };
                                Min_In       = ChartMin_In.Min();
                                Min_Out      = ChartMin_Out.Min();
                            }
                            else
                            {
                                ChartMin_In  = new double[] { CD_In, AD_In, UpSD_In, DownSD_In, Min_In };
                                ChartMin_Out = new double[] { CD_Out, AD_Out, UpSD_Out, DownSD_Out, Min_Out };
                                Min_In       = ChartMin_In.Min();
                                Min_Out      = ChartMin_Out.Min();
                            }

                            Chart_Inside.ChartAreas[0].AxisY.MajorGrid.Interval     = 5;
                            Chart_Inside.ChartAreas[0].AxisY.MajorTickMark.Interval = 5;
                            Chart_Inside.ChartAreas[0].AxisY.MajorGrid.Enabled      = true;
                            Chart_Inside.ChartAreas[0].AxisY.MajorGrid.Enabled      = true;

                            Chart_Inside.ChartAreas[0].AxisX.Minimum                = Convert.ToInt16(Min_In) - 1;
                            Chart_Inside.ChartAreas[0].AxisX.MajorGrid.Interval     = 1;
                            Chart_Inside.ChartAreas[0].AxisX.MajorTickMark.Interval = 1;
                            Chart_Inside.ChartAreas[0].AxisX.MajorGrid.Enabled      = true;
                            Chart_Inside.ChartAreas[0].AxisX.MajorTickMark.Enabled  = true;


                            Chart_Outside.ChartAreas[0].AxisY.MajorGrid.Interval     = 5;
                            Chart_Outside.ChartAreas[0].AxisY.MajorTickMark.Interval = 5;
                            Chart_Outside.ChartAreas[0].AxisY.MajorGrid.Enabled      = true;
                            Chart_Outside.ChartAreas[0].AxisY.MajorTickMark.Enabled  = true;

                            Chart_Outside.ChartAreas[0].AxisX.Minimum                = Convert.ToInt16(Min_Out) - 1;
                            Chart_Outside.ChartAreas[0].AxisX.MajorGrid.Interval     = 1;
                            Chart_Outside.ChartAreas[0].AxisX.MajorTickMark.Interval = 1;
                            Chart_Outside.ChartAreas[0].AxisX.MajorGrid.Enabled      = true;
                            Chart_Outside.ChartAreas[0].AxisX.MajorTickMark.Enabled  = true;
                        }
                        else
                        {
                            i = ls.Count;
                        }
                    }
                }
                else
                {
                }
                //显示对应的NG图片
                if (Directory.Exists(Path_NG_Pic))
                {
                    var files = Directory.GetFiles(Path_NG_Pic, "*.png");
                    if (files.Length != 0)
                    {
                        NG1_ho_Image = new HImage(files[0]);

                        //画面缩放
                        HWndCtrl1.addIconicVar(NG1_ho_Image);
                        HWndCtrl1.resetAll();
                        HWndCtrl1.repaint();
                        Index_Pic.Text      = "1/" + files.Length.ToString();
                        Btn_nextpic.Enabled = true;
                    }
                    else
                    {
                        HOperatorSet.ClearWindow(H_WControl1.HalconID);
                        Index_Pic.Text = "0/0";
                    }
                }
                else
                {
                    HOperatorSet.ClearWindow(H_WControl1.HalconID);
                    Index_Pic.Text = "0/0";
                }
            }
        }