private void radioChangeColour(object sender, EventArgs e)
 {
     try
     {
         if (channelMax == 3)
         {
             if (radioButtonColour.Checked == true)
             {
                 Svision.GetMe().baslerCamera.setChannelNumber(3);
                 if (checkBoxWhiteBalanceAuto.Checked)
                 {
                     Svision.GetMe().baslerCamera.setWhiteBalanceAuto(true);
                     groupBoxWhiteBalance.Enabled = false;
                 }
                 else
                 {
                     Svision.GetMe().baslerCamera.setWhiteBalanceAuto(false);
                     numericUpDownBlueBalance.Value  = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent() * 100);
                     numericUpDownRedBalance.Value   = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent() * 100);
                     numericUpDownGreenBalance.Value = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent() * 100);
                 }
             }
         }
         else
         {
             radioButtonColour.Checked = false;
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #2
0
 public GetAndSaveImageTool()
 {
     try
     {
         InitializeComponent();
     }
     catch (System.Exception ex)
     {
         System.Threading.Thread.Sleep(100);
         if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
         {
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
             MessageBox.Show(ex.Message);
         }
         else
         {
             Cursor = Cursors.WaitCursor;
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
             MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
             Svision.GetMe().cameraRefresh();
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
             Cursor = Cursors.Default;
         }
     }
 }
예제 #3
0
        private void buttonGetImage_Click(object sender, EventArgs e)
        {
            if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
            {
                Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                try
                {
                    if (image != null)
                    {
                        image.Dispose();
                    }
                    Svision.GetMe().baslerCamera.getFrameImageWithStart(out image);
                    if (ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag)
                    {
                        HOperatorSet.MapImage(image, ConfigInformation.GetInstance().tCalCfg.ho_MapFixed, out image);
                    }
                    basicClass.getImageSize(image, out rowNumber, out columnNumber);
                    double widRat = pictureBoxGetAndSaveImage.Width / ((double)columnNumber);
                    double heiRat = pictureBoxGetAndSaveImage.Height / ((double)rowNumber);
                    resizerate = widRat < heiRat ? widRat : heiRat;
                    if (img != null)
                    {
                        img.Dispose();
                    }
                    basicClass.resizeImage(image, out img, resizerate);
                    if (oriPictureBoxShowImageWidth != pictureBoxGetAndSaveImage.Width)
                    {
                        basicClass.displayClear(GetAndSaveImageHWHandle);
                    }
                    if (oriPictureBoxShowImageHeight != pictureBoxGetAndSaveImage.Height)
                    {
                        basicClass.displayClear(GetAndSaveImageHWHandle);
                    }
                    basicClass.displayhobject(img, GetAndSaveImageHWHandle);
                }
                catch (Exception ex)
                {
                    System.Threading.Thread.Sleep(100);
                    if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    else
                    {
                        groupBoxManual.Enabled = false;
                        groupBoxAuto.Enabled   = false;

                        Cursor = Cursors.WaitCursor;
                        Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
                        MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
                        Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
                        Svision.GetMe().cameraRefresh();
                        Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                        Cursor = Cursors.Default;
                        groupBoxManual.Enabled = true;
                        groupBoxAuto.Enabled   = true;
                    }
                }
            }
        }
 private void numericUpDownGamma_ValueChanged(object sender, EventArgs e)
 {
     try
     {
         Svision.GetMe().baslerCamera.setGammaPercent((double)numericUpDownGamma.Value / 100.0);
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void numericValueChangeYOffset(object sender, EventArgs e)
 {
     try
     {
         Svision.GetMe().baslerCamera.setOffsetY((int)numericUpDownYOffset.Value);
         trackBarYOffset.Value = (int)numericUpDownYOffset.Value;
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #6
0
        public SurfaceBasedMatchFBDForm(int idx)
        {
            InitializeComponent();
            rowOriNum    = Svision.GetMe().oriRowNumber;
            columnOriNum = Svision.GetMe().oriColumnNumber;
            //rowOriNum = 1234;
            //columnOriNum = 1624;
            double widRat = 256 / ((double)columnOriNum);
            double heiRat = 192 / ((double)rowOriNum);

            resRat         = widRat < heiRat ? widRat : heiRat;
            CSMParaDefault = true;
            currentIndex   = idx;
        }
 private void radioChangeGray(object sender, EventArgs e)
 {
     try
     {
         if (radioButtonGray.Checked == true)
         {
             Svision.GetMe().baslerCamera.setChannelNumber(1);
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void numericUpDownGain_ValueChanged(object sender, EventArgs e)
 {
     try
     {
         if (Svision.GetMe().baslerCamera.getIsGainAuto() == false)
         {
             Svision.GetMe().baslerCamera.setGainPercent((double)numericUpDownGain.Value / 100.0);
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void numericUpDownRedBalance_ValueChanged(object sender, EventArgs e)
 {
     try
     {
         if (Svision.GetMe().baslerCamera.getIsWhiteBalanceAuto() == false)
         {
             Svision.GetMe().baslerCamera.setWhiteBalanceRed((double)numericUpDownRedBalance.Value / 100.0);
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #10
0
        private void buttonGetImage_Click(object sender, EventArgs e)
        {
            try
            {
                //oriRowNumber = rowNumber;
                //oriColumnNumber = columnNumber;
                if (image != null)
                {
                    image.Dispose();
                }
                //Svision.GetMe().baslerCamera.getFrameImage(out image);
                UserCode.GetInstance().getImageFromProcess(out image, currentIndex);
                basicClass.getImageSize(image, out rowNumber, out columnNumber);
                double widRat = pictureBoxBackgroundRemove.Width / ((double)columnNumber);
                double heiRat = pictureBoxBackgroundRemove.Height / ((double)rowNumber);
                resizerate = widRat < heiRat ? widRat : heiRat;


                if (oriPictureBoxShowImageWidth != pictureBoxBackgroundRemove.Width)
                {
                    basicClass.displayClear(BackgroundRemoveHWHandle);
                }
                if (oriPictureBoxShowImageHeight != pictureBoxBackgroundRemove.Height)
                {
                    basicClass.displayClear(BackgroundRemoveHWHandle);
                }
                showResultImage();
            }
            catch (System.Exception ex)
            {
                System.Threading.Thread.Sleep(100);
                if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
                {
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                    MessageBox.Show(ex.Message);
                }
                else
                {
                    Cursor = Cursors.WaitCursor;
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
                    MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
                    Svision.GetMe().cameraRefresh();
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                    Cursor = Cursors.Default;
                }
            }
        }
 private void trackBarChangedHeight(object sender, EventArgs e)
 {
     try
     {
         int rowIncrement;
         Svision.GetMe().baslerCamera.getRowIncrement(out rowIncrement);
         if (trackBarHeight.Value % rowIncrement != 0)
         {
             trackBarHeight.Value = trackBarHeight.Value / rowIncrement * rowIncrement;
         }
         numericUpDownheight.Value = trackBarHeight.Value;
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void trackBarChangeWidth(object sender, EventArgs e)
 {
     try
     {
         int columnIncrement;
         Svision.GetMe().baslerCamera.getColumnIncrement(out columnIncrement);
         if (trackBarWidth.Value % columnIncrement != 0)
         {
             trackBarWidth.Value = trackBarWidth.Value / columnIncrement * columnIncrement;
         }
         numericUpDownWidth.Value = trackBarWidth.Value;
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
 private void trackBarChangeYOffset(object sender, EventArgs e)
 {
     try
     {
         int xOffsetIncrement, yOffsetIncrement;
         Svision.GetMe().baslerCamera.getOffsetIncrement(out xOffsetIncrement, out yOffsetIncrement);
         if (trackBarYOffset.Value % yOffsetIncrement != 0)
         {
             trackBarYOffset.Value = trackBarYOffset.Value / yOffsetIncrement * yOffsetIncrement;
         }
         numericUpDownYOffset.Value = trackBarYOffset.Value;
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        unsafe static void OnImageGrabbed(Object sender, ImageGrabbedEventArgs e)
        {
            // The grab result is automatically disposed when the event call back returns.
            // The grab result can be cloned using IGrabResult.Clone if you want to keep a copy of it (not shown in this sample).
            try
            {
                IGrabResult grabResult = e.GrabResult;
                // Image grabbed successfully?
                if (grabResult.GrabSucceeded)
                {
                    byte[] buffer = grabResult.PixelData as byte[];
                    fixed(byte *dataGray = buffer)
                    {
                        if (hoImage != null)
                        {
                            hoImage.Dispose();
                        }

                        HOperatorSet.GenImage1(out hoImage, "byte", (HTuple)Svision.GetMe().baslerCamera.columnNumber, (HTuple)Svision.GetMe().baslerCamera.rowNunber, new IntPtr(dataGray));
                    }
                    if (grabResult != null)
                    {
                        grabResult.Dispose();
                    }

                    //camera.StreamGrabber.Stop();
                    if (Svision.GetMe().baslerCamera.channelNumber != 1)
                    {
                        HOperatorSet.CfaToRgb(hoImage, out hoImage, "bayer_bg", "bilinear");
                    }
                    isImageOk = true;
                }
                else
                {
                    throw new Exception(grabResult.ErrorCode.ToString() + grabResult.ErrorDescription);
                }
            }
            catch (Exception ex)
            {
                errorImageCode = true;
                errorImageStr  = ex.Message;
            }
        }
예제 #15
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (0 == gCurrentDataGridRow)
                {
                    MessageBox.Show("首行为图像输入,不可修改");
                    return;
                }
                UserCode.GetInstance().isOverFlag[gCurrentDataGridRow] = 0;
                if ((string)this.DgvMainCode.Rows[gCurrentDataGridRow].Cells[1].Value !=
                    UserCode.GetInstance().codeInfoValToKey[ProCodeCls.MainFunction.NullFBD])
                {
                    if (Svision.GetMe().listBoxProcess.Items[gCurrentDataGridRow].ToString() == "")
                    {
                    }
                    else if (int.Parse(Svision.GetMe().listBoxProcess.Items[gCurrentDataGridRow].ToString().Split('.')[0]) == gCurrentDataGridRow)
                    {
                        Svision.GetMe().listBoxProcess.SelectedIndex = 0;
                        Svision.GetMe().listBoxProcess.Items.RemoveAt(gCurrentDataGridRow);
                        Svision.GetMe().listBoxProcess.Items.Insert(gCurrentDataGridRow, "");
                    }

                    UserCode.GetInstance().gProCd[gCurrentDataGridRow].clear();
                    this.DgvMainCode.Rows[gCurrentDataGridRow].Cells[1].Value = "";
                    UserCode.GetInstance().gProCd[gCurrentDataGridRow].FuncID = ProCodeCls.MainFunction.NullFBD;
                }
                for (int i = 19; i >= 0; i--)
                {
                    if (UserCode.GetInstance().gProCd[i].FuncID != ProCodeCls.MainFunction.NullFBD &&
                        UserCode.GetInstance().gProCd[i].FuncID != ProCodeCls.MainFunction.OutputSerialOutputFBD)
                    {
                        UserCode.GetInstance().showCurIdx = i;
                        break;
                    }
                }
                Svision.GetMe().listBoxProcess.SelectedIndex = UserCode.GetInstance().showCurIdx;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void numericValueChangeWidth(object sender, EventArgs e)
        {
            try
            {
                numericUpDownXOffset.Value = trackBarXOffset.Value = 0;
                basicClass.displayClear(cameraParaHWHandle);
                basicClass.displayClear(cameraParaPartHWHandle);
                Svision.GetMe().baslerCamera.setColumnNumber((int)numericUpDownWidth.Value);
                trackBarWidth.Value = (int)numericUpDownWidth.Value;

                Svision.GetMe().baslerCamera.getCameraOffsetRange(out XOffsetRange, out YOffsetRange);
                numericUpDownXOffset.Maximum = XOffsetRange[1];
                trackBarXOffset.Maximum      = XOffsetRange[1];
                Svision.GetMe().oriColumnNumber = (int)numericUpDownWidth.Value;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
예제 #17
0
        public NewProcessEdit()
        {
            try
            {
                InitializeComponent();
                FuncName            = new String[20];
                mDt                 = new DataTable();
                gCurrentDataGridRow = 0xFF;
                gCurrentTreeViewStr = "";

                UIInit();

                String tCode = "";
                for (int i = 0; i < 20; i++)
                {
                    if (UserCode.GetInstance().gProCd[i].FuncID == ProCodeCls.MainFunction.NullFBD)
                    {
                        continue;
                    }

                    this.DgvMainCode.Rows[i].Cells[1].Value =
                        UserCode.GetInstance().codeInfoValToKey[UserCode.GetInstance().gProCd[i].FuncID];
                }
                this.DgvMainCode.Rows[0].ReadOnly = true;
                if (Svision.GetMe().checkBoxIsFile.Checked)
                {
                    UserCode.GetInstance().gProCd[0].FuncID = ProCodeCls.MainFunction.InputFileInputFBD;
                    this.DgvMainCode.Rows[0].Cells[1].Value = UserCode.GetInstance().codeInfoValToKey[ProCodeCls.MainFunction.InputFileInputFBD];
                }
                else
                {
                    UserCode.GetInstance().gProCd[0].FuncID = ProCodeCls.MainFunction.InputCameraInputFBD;
                    this.DgvMainCode.Rows[0].Cells[1].Value = UserCode.GetInstance().codeInfoValToKey[ProCodeCls.MainFunction.InputCameraInputFBD];
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
 private void checkBoxChangeExposureAuto(object sender, EventArgs e)
 {
     try
     {
         if (checkBoxExposureAuto.Checked == true)
         {
             Svision.GetMe().baslerCamera.setExposureAuto(true);
             numericUpDownExposure.Value = (decimal)(Svision.GetMe().baslerCamera.getExposurePercent() * 100);
             groupBoxExposure.Enabled    = false;
         }
         else
         {
             Svision.GetMe().baslerCamera.setExposureAuto(false);
             numericUpDownExposure.Value = (decimal)(Svision.GetMe().baslerCamera.getExposurePercent() * 100);
             groupBoxExposure.Enabled    = true;
         }
     }
     catch (System.Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
예제 #19
0
        public BackgroundRemoveFBDForm(int idx)
        {
            InitializeComponent();
            currentIndex = idx;
            numericUpDownMaxGray.Value = (decimal)UserCode.GetInstance().gProCd[currentIndex].gBRP.grayValue[0];
            numericUpDownMinGray.Value = (decimal)UserCode.GetInstance().gProCd[currentIndex].gBRP.grayValue[1];
            if (Svision.GetMe().baslerCamera.getChannelNumber() == 1)
            {
                isColor = false;
            }
            else
            {
                isColor = true;//isColor
            }
            //isColor = UserCode.GetInstance().gProCd[currentIndex].boolData[0];
            checkBoxAllColor.Checked = UserCode.GetInstance().gProCd[currentIndex].gBRP.isAllColor;

            numericUpDownRedMaxGray.Value   = (decimal)UserCode.GetInstance().gProCd[currentIndex].gBRP.grayValue[2];
            numericUpDownRedMinGray.Value   = (decimal)UserCode.GetInstance().gProCd[currentIndex].gBRP.grayValue[3];
            numericUpDownGreenMaxGray.Value = (decimal)UserCode.GetInstance().gProCd[currentIndex].gBRP.grayValue[4];
            numericUpDownGreenMinGray.Value = (decimal)UserCode.GetInstance().gProCd[currentIndex].gBRP.grayValue[5];
            numericUpDownBlueMaxGray.Value  = (decimal)UserCode.GetInstance().gProCd[currentIndex].gBRP.grayValue[6];
            numericUpDownBlueMinGray.Value  = (decimal)UserCode.GetInstance().gProCd[currentIndex].gBRP.grayValue[7];
        }
        /// <summary>
        /// 处理客户端数据
        /// </summary>
        /// <param name="ar"></param>
        private void HandleDataReceived(IAsyncResult ar)
        {
            if (IsRunning)
            {
                Session session = (Session)ar.AsyncState;
                Socket  client  = session.ClientSocket;
                try
                {
                    //如果两次开始了异步的接收,所以当客户端退出的时候
                    //会两次执行EndReceive
                    int recv = client.EndReceive(ar);
                    session.recvLen = recv;
/* */
                    if (recv == 0 || SocketConnected(session.ClientSocket) == false && _clients.Count == 1 && _clientCount == 1)
                    {
                        //TODO 触发事件 (关闭客户端)
                        Svision.GetMe().tcpStr = "客户端已断开" + DateTime.Now.ToLongTimeString().ToString() + System.Environment.NewLine;
                        Svision.GetMe().ShowTCPMessage();
                        CloseSession(session);
                        RaiseNetError(session);
                        return;
                    }
                    /*  */
                    //TODO 处理已经读取的数据 ps:数据在session的RecvDataBuffer中

                    RaiseDataReceived(session);
                    //TODO 触发数据接收事件
                    if (SocketConnected(session.ClientSocket) == false && _clients.Count == 1 && _clientCount == 1)
                    {
                        //TODO 触发事件 (关闭客户端)
                        Svision.GetMe().tcpStr = "客户端已断开" + DateTime.Now.ToLongTimeString().ToString() + System.Environment.NewLine;
                        Svision.GetMe().ShowTCPMessage();
                        CloseSession(session);
                        RaiseNetError(session);
                        return;
                    }
                }
                catch (SocketException ex)//
                {
                    //TODO 异常处理
                    Svision.GetMe().tcpStr = "客户端已断开" + DateTime.Now.ToLongTimeString().ToString() + System.Environment.NewLine;
                    Svision.GetMe().ShowTCPMessage();
                    RaiseNetError(session);
                    if (ex.ErrorCode == 10054 && _clients.Count == 1 && _clientCount == 1)
                    {
                        CloseSession(session);
                        RaiseNetError(session);
                        return;
                    }
                }

                finally
                {
                    //继续接收来自来客户端的数据
                    if (IsRunning && client.Connected && SocketConnected(session.ClientSocket)) ///////////////////////////////////////////////////////////2016/8/23/Add by ZY
                    {                                                                           ///////////////////////////////////////////////////////////////////////////////////////////////////
                        client.BeginReceive(session.RecvDataBuffer, 0, session.RecvDataBuffer.Length, SocketFlags.None,
                                            new AsyncCallback(HandleDataReceived), session);
                    }//////////////////////////////////////////////////////////////////////////////////////////////////////
                }
            }
        }
        private void HandleAcceptConnected(IAsyncResult ar)
        {
            if (IsRunning)
            {
                //Socket server;
                // client;
                try
                {
                    Socket server = (Socket)ar.AsyncState;
                    Socket client = server.EndAccept(ar);
                    //检查是否达到最大的允许的客户端数目
                    if (_clientCount == _maxClient)
                    {
                        //TODO 触发事件
                        RaiseServerException(null);
                        //Session session = new Session(client);
                        //session.Close();
                        //return;
                    }
                    else if (SocketConnected(client) == false)
                    {
                        RaiseServerException(null);
                    }
                    else
                    {
                        Session session = new Session(client);
                        try
                        {
                            if (SocketConnected(client))
                            {
                                lock (_clients)
                                {
                                    if (SocketConnected(client))
                                    {
                                        _clients.Add(session);
                                        if (SocketConnected(client))
                                        {
                                            _clientCount++;
                                            if (SocketConnected(client))
                                            {
                                                RaiseClientConnected(session); //触发客户端连接事件
                                            }
                                            else
                                            {
                                                _clientCount--;
                                                session.Close();
                                            }
                                        }
                                        else
                                        {
                                            _clients.Remove(session);
                                            session.Close();
                                        }
                                    }
                                }
                                if (SocketConnected(client))
                                {
                                    session.RecvDataBuffer = new byte[client.ReceiveBufferSize];
                                    //开始接受来自该客户端的数据
                                    if (SocketConnected(client))
                                    {
                                        client.BeginReceive(session.RecvDataBuffer, 0, session.RecvDataBuffer.Length, SocketFlags.None,
                                                            new AsyncCallback(HandleDataReceived), session);
                                        Svision.GetMe().tcpStr = "客户端已连接" + DateTime.Now.ToLongTimeString().ToString() + System.Environment.NewLine;
                                        Svision.GetMe().ShowTCPMessage();
                                    }
                                    else
                                    {
                                        session.Datagram       = null;
                                        session.RecvDataBuffer = null;
                                        session.recvLen        = 0;
                                        if (_clients.Count == 1)
                                        {
                                            _clients.Remove(session);
                                        }
                                        if (_clientCount == 1)
                                        {
                                            _clientCount--;
                                        }
                                        session.Close();
                                    }
                                }
                                else
                                {
                                    if (_clients.Count == 1)
                                    {
                                        _clients.Remove(session);
                                        if (_clientCount == 1)
                                        {
                                            _clientCount--;
                                        }
                                    }
                                    session.Close();
                                }
                            }
                        }
                        catch (SocketException ex)
                        {
                            session.Datagram       = null;
                            session.RecvDataBuffer = null;
                            if (_clients.Count == 1)
                            {
                                _clients.Remove(session);
                            }
                            if (_clientCount == 1)
                            {
                                _clientCount--;
                            }
                            session.Close();
                        }
                    }

                    //接受下一个请求
                    server.BeginAccept(new AsyncCallback(HandleAcceptConnected), ar.AsyncState);
                }
                catch (SocketException ex)
                {}
            }
        }
예제 #22
0
        private void btnInsert_Click(object sender, EventArgs e)
        {
            try
            {
                if (0 == gCurrentDataGridRow)
                {
                    MessageBox.Show("首行为图像输入,不可修改");
                    return;
                }

                if ((gCurrentDataGridRow != 0xFF) && (gCurrentTreeViewStr != "Null"))
                {
                    UserCode.GetInstance().isOverFlag[gCurrentDataGridRow] = 1;
                    this.DgvMainCode.Rows[gCurrentDataGridRow].Cells[1].Value = gCurrentTreeViewStr;
                    UserCode.GetInstance().gProCd[gCurrentDataGridRow].FuncID = UserCode.GetInstance().codeInfo[gCurrentTreeViewStr];
                    if (Svision.GetMe().listBoxProcess.Items.Count > gCurrentDataGridRow)
                    {
                        if (Svision.GetMe().listBoxProcess.Items[gCurrentDataGridRow].ToString() == "")
                        {
                            Svision.GetMe().listBoxProcess.SelectedIndex = 0;
                            Svision.GetMe().listBoxProcess.Items.RemoveAt(gCurrentDataGridRow);
                            Svision.GetMe().listBoxProcess.Items.Insert(gCurrentDataGridRow, gCurrentDataGridRow.ToString() + "." + gCurrentTreeViewStr);
                        }
                        else if (int.Parse(Svision.GetMe().listBoxProcess.Items[gCurrentDataGridRow].ToString().Split('.')[0]) == gCurrentDataGridRow)
                        {
                            Svision.GetMe().listBoxProcess.SelectedIndex = 0;
                            Svision.GetMe().listBoxProcess.Items.RemoveAt(gCurrentDataGridRow);
                            Svision.GetMe().listBoxProcess.Items.Insert(gCurrentDataGridRow, gCurrentDataGridRow.ToString() + "." + gCurrentTreeViewStr);
                        }
                        else
                        {
                            Svision.GetMe().listBoxProcess.Items.Insert(gCurrentDataGridRow, gCurrentDataGridRow.ToString() + "." + gCurrentTreeViewStr);
                        }
                    }
                    else
                    {
                        Svision.GetMe().listBoxProcess.Items.Insert(gCurrentDataGridRow, gCurrentDataGridRow.ToString() + "." + gCurrentTreeViewStr);
                    }

                    switch (UserCode.GetInstance().gProCd[gCurrentDataGridRow].FuncID)
                    {
                    case ProCodeCls.MainFunction.CalibrationBackgroundRemoveFBD:
                        UserCode.GetInstance().CalibrationBackgroundRemoveInit(gCurrentDataGridRow);
                        break;

                    case ProCodeCls.MainFunction.CalibrationMedianFilterFBD:
                        UserCode.GetInstance().CalibrationMedianFilterInit(gCurrentDataGridRow);
                        break;

                    case ProCodeCls.MainFunction.CalibrationMorphologyProcessingFBD:
                        UserCode.GetInstance().CalibrationMorphologyProcessingInit(gCurrentDataGridRow);
                        break;

                    case ProCodeCls.MainFunction.MeasureBlobAnalysisFBD:
                        UserCode.GetInstance().isOverFlag[gCurrentDataGridRow] = 10;
                        UserCode.GetInstance().BlobAnalysisInit(gCurrentDataGridRow);
                        break;

                    case ProCodeCls.MainFunction.CalibrationThresholdFBD:
                        UserCode.GetInstance().CalibrationThresholdInit(gCurrentDataGridRow);
                        break;

                    case ProCodeCls.MainFunction.OutputSerialOutputFBD:
                        UserCode.GetInstance().isOverFlag[gCurrentDataGridRow] = 31;
                        UserCode.GetInstance().OutputSerialOutputInit(gCurrentDataGridRow);
                        break;

                    case ProCodeCls.MainFunction.MeasureShapeSearchFBD:
                        UserCode.GetInstance().isOverFlag[gCurrentDataGridRow] = 11;
                        UserCode.GetInstance().ShapeSearchInit(gCurrentDataGridRow);
                        break;

                    case ProCodeCls.MainFunction.MeasureAnisoShapeSearchFBD:
                        UserCode.GetInstance().isOverFlag[gCurrentDataGridRow] = 12;
                        UserCode.GetInstance().AnisoShapeSearchInit(gCurrentDataGridRow);
                        break;

                    case ProCodeCls.MainFunction.MeasureSurfaceBasedMatchFBD:    //新添加的三维模板匹配
                        //UserCode.GetInstance().isOverFlag[gCurrentDataGridRow] = 19;
                        UserCode.GetInstance().SurfaceBasedMatchInit(gCurrentDataGridRow);
                        break;
                    }
                }
                for (int i = 19; i >= 0; i--)
                {
                    if (UserCode.GetInstance().gProCd[i].FuncID != ProCodeCls.MainFunction.NullFBD &&
                        UserCode.GetInstance().gProCd[i].FuncID != ProCodeCls.MainFunction.OutputSerialOutputFBD)
                    {
                        UserCode.GetInstance().showCurIdx = i;
                        break;
                    }
                }
                Svision.GetMe().listBoxProcess.SelectedIndex = UserCode.GetInstance().showCurIdx;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public BaslerClass()
        {
            HOperatorSet.GenEmptyObj(out hoImage);
            rowNunber          = 480;
            columnNumber       = 640;
            channelNumber      = 1;
            xOffset            = 0;
            yOffset            = 0;
            gainPercent        = 0;
            isGainAuto         = false;
            isExposureAuto     = false;
            isWhiteBalanceAuto = false;

            try
            {
                if (Svision.GetMe().cameraStr != null)
                {
                    camera = new Camera(Svision.GetMe().cameraStr);
                }
                else
                {
                    camera = new Camera();
                }


                //软件触发
                camera.CameraOpened += Configuration.SoftwareTrigger;
                camera.Open();
                camera.StreamGrabber.ImageGrabbed += OnImageGrabbed;


                camera.Parameters[PLTransportLayer.HeartbeatTimeout].TrySetValue(1000, IntegerValueCorrection.Nearest);  // 1000 ms timeout
                camera.Parameters[PLCamera.PixelFormat].TrySetValue(PLCamera.PixelFormat.BayerBG8);
                string oldPixelFormat = camera.Parameters[PLCamera.PixelFormat].GetValue();
                if (oldPixelFormat == "BayerBG8")
                {
                    channelNumberMax = 3;
                }
                else
                {
                    channelNumberMax = 1;
                }
                if (channelNumber > channelNumberMax)
                {
                    channelNumber = channelNumberMax;
                }
                rowIncrement = (int)camera.Parameters[PLCamera.Height].GetIncrement();
                camera.Parameters[PLCamera.OffsetY].SetValue(0);
                camera.Parameters[PLCamera.Height].TrySetToMinimum();
                rowNunberRange[0] = (int)camera.Parameters[PLCamera.Height].GetValue();
                camera.Parameters[PLCamera.Height].TrySetToMaximum();
                rowNunberRange[1] = (int)camera.Parameters[PLCamera.Height].GetValue();

                if (rowNunber > rowNunberRange[1])
                {
                    rowNunber = rowNunberRange[1];
                }
                if (rowNunber < rowNunberRange[0])
                {
                    rowNunber = rowNunberRange[0];
                }
                if (rowNunber - rowNunberRange[0] % rowIncrement != 0)
                {
                    rowNunber = (rowNunber - rowNunberRange[0]) / rowIncrement * rowIncrement + rowNunberRange[0];
                }

                columnIncrement = (int)camera.Parameters[PLCamera.Width].GetIncrement();
                camera.Parameters[PLCamera.OffsetX].SetValue(0);

                camera.Parameters[PLCamera.Width].TrySetToMinimum();
                columnNumberRange[0] = (int)camera.Parameters[PLCamera.Width].GetValue();
                camera.Parameters[PLCamera.Width].TrySetToMaximum();
                columnNumberRange[1] = (int)camera.Parameters[PLCamera.Width].GetValue();
                if (columnNumber > columnNumberRange[1])
                {
                    columnNumber = columnNumberRange[1];
                }
                if (columnNumber < columnNumberRange[0])
                {
                    columnNumber = columnNumberRange[0];
                }
                if (columnNumber - columnNumberRange[0] % columnIncrement != 0)
                {
                    columnNumber = (columnNumber - columnNumberRange[0]) / columnIncrement * columnIncrement + columnNumberRange[0];
                }
                xOffsetIncrement = (int)camera.Parameters[PLCamera.OffsetX].GetIncrement();
                yOffsetIncrement = (int)camera.Parameters[PLCamera.OffsetY].GetIncrement();
                if (xOffset > (columnNumberRange[1] - columnNumber))
                {
                    xOffset = (columnNumberRange[1] - columnNumber);
                }
                if (xOffset % xOffsetIncrement != 0)
                {
                    xOffset = xOffset / xOffsetIncrement * xOffsetIncrement;
                }
                if (yOffset > (rowNunberRange[1] - rowNunber))
                {
                    yOffset = (rowNunberRange[1] - rowNunber);
                }
                if (yOffset % yOffsetIncrement != 0)
                {
                    yOffset = yOffset / yOffsetIncrement * yOffsetIncrement;
                }
                gainPercentRange    = new double[2];
                gainPercentRange[0] = 0;
                gainPercentRange[1] = 1;
                GammaPercentRange   = new double[2];
                camera.Parameters[PLCamera.GammaEnable].TrySetValue(true);
                GammaPercentRange[0]             = 0;
                GammaPercentRange[1]             = 1;
                exposurePercentRange             = new double[2];
                exposurePercentRange[0]          = 0;
                exposurePercentRange[1]          = 1;
                whiteBalanceBluePercentRange     = new double[2];
                whiteBalanceBluePercentRange[0]  = 0;
                whiteBalanceBluePercentRange[1]  = 1;
                whiteBalanceGreenPercentRange    = new double[2];
                whiteBalanceGreenPercentRange[0] = 0;
                whiteBalanceGreenPercentRange[1] = 1;
                whiteBalanceRedPercentRange      = new double[2];
                whiteBalanceRedPercentRange[0]   = 0;
                whiteBalanceRedPercentRange[1]   = 1;
                // The parameter MaxNumBuffer can be used to control the amount of buffers
                // allocated for grabbing. The default value of this parameter is 10.
                camera.Parameters[PLCameraInstance.MaxNumBuffer].SetValue(5);
                camera.Parameters[PLCamera.OffsetX].SetValue((long)xOffset);
                camera.Parameters[PLCamera.OffsetY].SetValue((long)yOffset);
                // Some parameters have restrictions. You can use GetIncrement/GetMinimum/GetMaximum to make sure you set a valid value.
                // Here, we let pylon correct the value if needed.
                camera.Parameters[PLCamera.Width].SetValue(columnNumber, IntegerValueCorrection.Nearest);
                camera.Parameters[PLCamera.Height].SetValue(rowNunber, IntegerValueCorrection.Nearest);
                if (channelNumber == 1)
                {
                    camera.Parameters[PLCamera.PixelFormat].TrySetValue(PLCamera.PixelFormat.Mono8);
                }
                else
                {
                    camera.Parameters[PLCamera.PixelFormat].TrySetValue(PLCamera.PixelFormat.BayerBG8);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
 private void cameraParaTimer_Tick(object sender, EventArgs e)
 {
     try
     {
         if (image != null)
         {
             image.Dispose();
         }
         int rowNum, columnNum;
         numericUpDownExposure.Value = (decimal)(Svision.GetMe().baslerCamera.getExposurePercent() * 100);
         numericUpDownGain.Value     = (decimal)(Svision.GetMe().baslerCamera.getGainPercent() * 100);
         Svision.GetMe().baslerCamera.getFrameImage(out image);
         if (ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag)
         {
             HOperatorSet.MapImage(image, ConfigInformation.GetInstance().tCalCfg.ho_MapFixed, out image);
         }
         //HOperatorSet.WriteImage(image, "bmp", 0, "H:/vision_dll/trunk/C#_CODE/UI/Svision/a.bmp");
         basicClass.getImageSize(image, out rowNum, out columnNum);
         double widRat    = 256 / ((double)columnNum);
         double heiRat    = 192 / ((double)rowNum);
         double resRatNew = widRat < heiRat ? widRat : heiRat;
         if (resRat != resRatNew)
         {
             basicClass.displayClear(cameraParaHWHandle);
             resRat = resRatNew;
         }
         rectLocationX = preLocation.X;
         rectLocationY = preLocation.Y;
         if (preLocation.X <= 0)
         {
             rectLocationX = 0;
         }
         if (preLocation.Y <= 0)
         {
             rectLocationY = 0;
         }
         if (preLocation.X + cameraParaPartpictureBox.Width * resRat > Math.Min((columnNum - 1) * resRat - 1, 255))
         {
             rectLocationX = Math.Min((columnNum - cameraParaPartpictureBox.Width - 1) * resRat - 1, 255 - cameraParaPartpictureBox.Width * resRat);
         }
         if (preLocation.Y + cameraParaPartpictureBox.Height * resRat > Math.Min((rowNum - 1) * resRat - 1, 191))
         {
             rectLocationY = Math.Min((rowNum - cameraParaPartpictureBox.Height - 1) * resRat - 1, 191 - cameraParaPartpictureBox.Height * resRat);
         }
         double widRatPart    = cameraParaPartpictureBox.Width / ((double)columnNum);
         double heiRatPart    = cameraParaPartpictureBox.Height / ((double)rowNum);
         double resRatPartNew = widRatPart < heiRatPart ? widRatPart : heiRatPart;
         if (resRatPart != resRatPartNew)
         {
             basicClass.displayClear(cameraParaPartHWHandle);
             resRatPart = resRatPartNew;
         }
         if (img != null)
         {
             img.Dispose();
         }
         basicClass.resizeImage(image, out img, resRat);
         HOperatorSet.DispObj(img, cameraParaHWHandle);
         if (resRatPart > 1)
         {
             if (imgPart != null)
             {
                 imgPart.Dispose();
             }
             HOperatorSet.CopyImage(image, out imgPart);
             HOperatorSet.DispObj(imgPart, cameraParaPartHWHandle);
         }
         else
         {
             if (rowNum * resRat > 6 && columnNum * resRat > 8)
             {
                 basicClass.displayRectangle1XldScreen(cameraParaHWHandle, Math.Max(rectLocationY, 1), Math.Max(rectLocationX, 1), rectLocationY + cameraParaPartpictureBox.Height * resRat - 2, rectLocationX + cameraParaPartpictureBox.Width * resRat - 2);
                 basicClass.genRectangle1(out rectDomain, rectLocationY / resRat, rectLocationX / resRat, Math.Min(rectLocationY / resRat + cameraParaPartpictureBox.Height - 1, rowNum - 1), Math.Min(rectLocationX / resRat + cameraParaPartpictureBox.Width - 1, columnNum - 1));
                 if (imgPart != null)
                 {
                     imgPart.Dispose();
                 }
                 basicClass.reduceDomain(image, rectDomain, out imgPart);
                 HOperatorSet.CropDomain(imgPart, out imgPart);
                 HOperatorSet.DispObj(imgPart, cameraParaPartHWHandle);
             }
         }
     }
     catch (System.Exception ex)
     {
         cameraParaTimer.Enabled = false;
         System.Threading.Thread.Sleep(100);
         if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
         {
             MessageBox.Show(ex.Message);
         }
         else
         {
             Cursor = Cursors.WaitCursor;
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
             MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
             Svision.GetMe().cameraRefresh();
             Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
             Cursor = Cursors.Default;
             cameraParaTimer.Enabled = true;
         }
     }
 }
        private void buttonCamParaSetCancel_Click(object sender, EventArgs e)
        {
            try
            {
                cameraParaTimer.Enabled    = false;
                numericUpDownheight.Value  = prvRow;
                numericUpDownWidth.Value   = prvColumn;
                numericUpDownXOffset.Value = prvXoffset;
                numericUpDownYOffset.Value = prvYoffset;
                ConfigInformation.GetInstance().tCamCfg.rows = (int)numericUpDownheight.Value;
                ConfigInformation.GetInstance().tCamCfg.columns = (int)numericUpDownWidth.Value;
                ConfigInformation.GetInstance().tCamCfg.xOffset = (int)numericUpDownXOffset.Value;
                ConfigInformation.GetInstance().tCamCfg.yOffset = (int)numericUpDownYOffset.Value;
                //channel


                if (prvChannelNum == 1)
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(1);

                    ConfigInformation.GetInstance().tCamCfg.channelNum = 1;
                }
                else if (prvChannelNum == 3 && channelMax == 3)
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(3);
                    ConfigInformation.GetInstance().tCamCfg.channelNum = 3;
                }
                else
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(1);
                    ConfigInformation.GetInstance().tCamCfg.channelNum = 1;
                }

                //gamma
                numericUpDownGamma.Value = (decimal)(prvGammaPercent * 100);
                ConfigInformation.GetInstance().tCamCfg.gammaPercent = prvGammaPercent;

                //gain
                if (prvIsGainAuto)
                {
                    ConfigInformation.GetInstance().tCamCfg.isGainAuto = true;
                    checkBoxGainAuto.CheckState = CheckState.Checked;
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isGainAuto = false;
                    checkBoxGainAuto.CheckState = CheckState.Unchecked;
                    numericUpDownGain.Value     = (decimal)(prvGainPercent * 100);
                    ConfigInformation.GetInstance().tCamCfg.gainPercent = prvGainPercent;
                }

                //exposure
                if (prvIsExposureAuto)
                {
                    checkBoxExposureAuto.CheckState = CheckState.Checked;
                    ConfigInformation.GetInstance().tCamCfg.isExposureAuto = true;
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isExposureAuto = false;
                    checkBoxExposureAuto.CheckState = CheckState.Unchecked;
                    numericUpDownExposure.Value     = (decimal)(prvExposurePercent * 100);
                    ConfigInformation.GetInstance().tCamCfg.exposurePercent = prvExposurePercent;
                }

                //white balance
                if (prvIsWhiteBalanceAuto)
                {
                    checkBoxWhiteBalanceAuto.CheckState = CheckState.Checked;
                    ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = true;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = prvWhiteBalanceBluePercent;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = prvWhiteBalanceGreenPercent;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = prvWhiteBalanceRedPercent;
                    }
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = false;
                    checkBoxWhiteBalanceAuto.CheckState = CheckState.Unchecked;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = prvWhiteBalanceBluePercent;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = prvWhiteBalanceGreenPercent;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = prvWhiteBalanceRedPercent;
                        numericUpDownBlueBalance.Value  = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent() * 100);
                        numericUpDownRedBalance.Value   = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent() * 100);
                        numericUpDownGreenBalance.Value = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent() * 100);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.Close();
        }
        private void buttonCamParaSetConfirm_Click(object sender, EventArgs e)
        {
            try
            {
                cameraParaTimer.Enabled = false;

                ConfigInformation.GetInstance().tCamCfg.rows = (int)numericUpDownheight.Value;
                ConfigInformation.GetInstance().tCamCfg.columns = (int)numericUpDownWidth.Value;
                ConfigInformation.GetInstance().tCamCfg.xOffset = (int)numericUpDownXOffset.Value;
                ConfigInformation.GetInstance().tCamCfg.yOffset = (int)numericUpDownYOffset.Value;
                ConfigInformation.GetInstance().tCamCfg.channelNum = Svision.GetMe().baslerCamera.getChannelNumber();
                ConfigInformation.GetInstance().tCamCfg.gammaPercent = ((double)numericUpDownGamma.Value) / 100;
                if (checkBoxGainAuto.Checked)
                {
                    ConfigInformation.GetInstance().tCamCfg.isGainAuto = true;
                    ConfigInformation.GetInstance().tCamCfg.gainPercent = Svision.GetMe().baslerCamera.getGainPercent();
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isGainAuto = false;
                    ConfigInformation.GetInstance().tCamCfg.gainPercent = Svision.GetMe().baslerCamera.getGainPercent();
                }
                if (checkBoxExposureAuto.Checked)
                {
                    ConfigInformation.GetInstance().tCamCfg.isExposureAuto = true;
                    ConfigInformation.GetInstance().tCamCfg.exposurePercent = Svision.GetMe().baslerCamera.getExposurePercent();
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isExposureAuto = false;
                    ConfigInformation.GetInstance().tCamCfg.exposurePercent = Svision.GetMe().baslerCamera.getExposurePercent();
                }
                if (checkBoxWhiteBalanceAuto.Checked)
                {
                    ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = true;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = ((double)numericUpDownBlueBalance.Value) / 100;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = ((double)numericUpDownGreenBalance.Value) / 100;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = ((double)numericUpDownRedBalance.Value) / 100;
                    }
                }
                else
                {
                    ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = false;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = ((double)numericUpDownBlueBalance.Value) / 100;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = ((double)numericUpDownGreenBalance.Value) / 100;
                        ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = ((double)numericUpDownRedBalance.Value) / 100;
                    }
                }
                this.Close();
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //Svision.GetMe().Enabled = tru;
        }
예제 #27
0
        public void LoadCfgInfo(String tmpPath)
        {
            XmlDocument tXmlDoc = new XmlDocument();

            try
            {
                tXmlDoc.Load(tmpPath);
                XmlNode rootNode = tXmlDoc.SelectSingleNode("Configuration");
                //load com config
                {
                    XmlNode ComNode = rootNode.SelectSingleNode("CommunicateConfig");

                    if (ComNode.SelectSingleNode("ComMainType").Attributes["ComMainType"].InnerText ==
                        ConfigInformation.GetInstance().tComCfg.ComTypeDic[CComConfig.ComTypeEnum.TCP_SERVER])
                    {
                        ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.TCP_SERVER;
                    }
                    else if (ComNode.SelectSingleNode("ComMainType").Attributes["ComMainType"].InnerText ==
                             ConfigInformation.GetInstance().tComCfg.ComTypeDic[CComConfig.ComTypeEnum.TCP_CLIENT])
                    {
                        ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.TCP_CLIENT;
                    }
                    else if (ComNode.SelectSingleNode("ComMainType").Attributes["ComMainType"].InnerText ==
                             ConfigInformation.GetInstance().tComCfg.ComTypeDic[CComConfig.ComTypeEnum.UDP])
                    {
                        ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.UDP;
                    }
                    else if (ComNode.SelectSingleNode("ComMainType").Attributes["ComMainType"].InnerText ==
                             ConfigInformation.GetInstance().tComCfg.ComTypeDic[CComConfig.ComTypeEnum.MODBUS_TCP])
                    {
                        ConfigInformation.GetInstance().tComCfg.ComMainType = CComConfig.ComTypeEnum.MODBUS_TCP;
                    }

                    ConfigInformation.GetInstance().tComCfg.ComTCPServer =
                        bool.Parse(ComNode.SelectSingleNode("ComTCPServer").Attributes["ComTCPServer"].InnerText);

                    ConfigInformation.GetInstance().tComCfg.TCPServerIP =
                        ComNode.SelectSingleNode("TCPServerIP").Attributes["TCPServerIP"].InnerText;
                    ConfigInformation.GetInstance().tComCfg.TCPServerPort =
                        ComNode.SelectSingleNode("TCPServerPort").Attributes["TCPServerPort"].InnerText;
                    ConfigInformation.GetInstance().tComCfg.TCPLocalIP =
                        ComNode.SelectSingleNode("TCPLocalIP").Attributes["TCPLocalIP"].InnerText;
                    ConfigInformation.GetInstance().tComCfg.TCPLocalPort =
                        ComNode.SelectSingleNode("TCPLocalPort").Attributes["TCPLocalPort"].InnerText;

                    if (ComNode.SelectSingleNode("TrigMode").Attributes["TrigMode"].InnerText ==
                        ConfigInformation.GetInstance().tComCfg.TrigModeDic[CComConfig.TrigModeEnum.COM_TRIG])
                    {
                        ConfigInformation.GetInstance().tComCfg.TrigMode = CComConfig.TrigModeEnum.COM_TRIG;
                    }
                    else if (ComNode.SelectSingleNode("TrigMode").Attributes["TrigMode"].InnerText ==
                             ConfigInformation.GetInstance().tComCfg.TrigModeDic[CComConfig.TrigModeEnum.TIME_TRIG])
                    {
                        ConfigInformation.GetInstance().tComCfg.TrigMode = CComConfig.TrigModeEnum.TIME_TRIG;
                    }

                    ConfigInformation.GetInstance().tComCfg.TrigStr =
                        ComNode.SelectSingleNode("TrigStr").Attributes["TrigStr"].InnerText;
                    ConfigInformation.GetInstance().tComCfg.TrigTime =
                        int.Parse(ComNode.SelectSingleNode("TrigTime").Attributes["TrigTime"].InnerText);
                }
                //load camera config
                {
                    XmlNode CameraNode = rootNode.SelectSingleNode("CameraConfig");
                    //Row
                    int   rowTest = int.Parse(CameraNode.SelectSingleNode("Rows").Attributes["Rows"].InnerText);
                    int[] rowRange;
                    Svision.GetMe().baslerCamera.getCameraRowRange(out rowRange);
                    if (rowTest > rowRange[1])
                    {
                        throw new Exception("错误!当前导入工程设置的相机行数大于当前使用相机行数的最大值!相机配置、标定配置和文件配置部分内容导入失败!");
                    }
                    Svision.GetMe().baslerCamera.setRowNumber(int.Parse(CameraNode.SelectSingleNode("Rows").Attributes["Rows"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.rows = int.Parse(CameraNode.SelectSingleNode("Rows").Attributes["Rows"].InnerText);
                    Svision.GetMe().oriRowNumber = ConfigInformation.GetInstance().tCamCfg.rows;
                    //Column
                    int   columnTest = int.Parse(CameraNode.SelectSingleNode("Columns").Attributes["Columns"].InnerText);
                    int[] columnRange;
                    Svision.GetMe().baslerCamera.getCameraColumnRange(out columnRange);
                    if (columnTest > columnRange[1])
                    {
                        throw new Exception("错误!当前导入工程设置的相机行数大于当前使用相机列数的最大值!相机配置、标定配置和文件配置部分内容导入失败!");
                    }
                    Svision.GetMe().baslerCamera.setColumnNumber(int.Parse(CameraNode.SelectSingleNode("Columns").Attributes["Columns"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.columns = int.Parse(CameraNode.SelectSingleNode("Columns").Attributes["Columns"].InnerText);
                    Svision.GetMe().oriColumnNumber = ConfigInformation.GetInstance().tCamCfg.columns;
                    //XOffset
                    int   XOffsetTest = int.Parse(CameraNode.SelectSingleNode("XOffset").Attributes["XOffset"].InnerText);
                    int[] XOffsetRange;
                    Svision.GetMe().baslerCamera.getCameraXOffsetRange(out XOffsetRange);
                    if (XOffsetTest > XOffsetRange[1])
                    {
                        throw new Exception("错误!当前导入工程设置的相机行偏移大于当前使用相机行偏移的最大值!相机配置、标定配置和文件配置部分内容导入失败!");
                    }
                    Svision.GetMe().baslerCamera.setOffsetX(int.Parse(CameraNode.SelectSingleNode("XOffset").Attributes["XOffset"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.xOffset = int.Parse(CameraNode.SelectSingleNode("XOffset").Attributes["XOffset"].InnerText);
                    //YOffset
                    int   YOffsetTest = int.Parse(CameraNode.SelectSingleNode("YOffset").Attributes["YOffset"].InnerText);
                    int[] YOffsetRange;
                    Svision.GetMe().baslerCamera.getCameraYOffsetRange(out YOffsetRange);
                    if (YOffsetTest > YOffsetRange[1])
                    {
                        throw new Exception("错误!当前导入工程设置的相机列偏移大于当前使用相机列偏移的最大值!相机配置、标定配置和文件配置部分内容导入失败!");
                    }
                    Svision.GetMe().baslerCamera.setOffsetY(int.Parse(CameraNode.SelectSingleNode("YOffset").Attributes["YOffset"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.yOffset = int.Parse(CameraNode.SelectSingleNode("YOffset").Attributes["YOffset"].InnerText);
                    //ChannelNum
                    int channelMax;
                    Svision.GetMe().baslerCamera.getCameraMaxChannel(out channelMax);
                    if (int.Parse(CameraNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText) == 1)
                    {
                        Svision.GetMe().baslerCamera.setChannelNumber(1);
                        ConfigInformation.GetInstance().tCamCfg.channelNum = int.Parse(CameraNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText);
                    }
                    else if (int.Parse(CameraNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText) == 3 && channelMax == 3)
                    {
                        Svision.GetMe().baslerCamera.setChannelNumber(3);
                        ConfigInformation.GetInstance().tCamCfg.channelNum = int.Parse(CameraNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText);
                    }
                    else
                    {
                        throw new Exception("导入相机通道设置失败!当前相机为黑白相机,无法设置获取彩色图像!");
                    }

                    //Gamma
                    Svision.GetMe().baslerCamera.setGammaPercent(double.Parse(CameraNode.SelectSingleNode("GammaPercent").Attributes["GammaPercent"].InnerText));
                    ConfigInformation.GetInstance().tCamCfg.gammaPercent = double.Parse(CameraNode.SelectSingleNode("GammaPercent").Attributes["GammaPercent"].InnerText);

                    //Gain
                    if (bool.Parse(CameraNode.SelectSingleNode("IsGainAuto").Attributes["IsGainAuto"].InnerText))
                    {
                        Svision.GetMe().baslerCamera.setGainAuto(true);
                        ConfigInformation.GetInstance().tCamCfg.isGainAuto = bool.Parse(CameraNode.SelectSingleNode("IsGainAuto").Attributes["IsGainAuto"].InnerText);
                        ConfigInformation.GetInstance().tCamCfg.gainPercent = Svision.GetMe().baslerCamera.getGainPercent();
                    }
                    else
                    {
                        Svision.GetMe().baslerCamera.setGainAuto(false);
                        ConfigInformation.GetInstance().tCamCfg.isGainAuto = bool.Parse(CameraNode.SelectSingleNode("IsGainAuto").Attributes["IsGainAuto"].InnerText);
                        Svision.GetMe().baslerCamera.setGainPercent(double.Parse(CameraNode.SelectSingleNode("GainPercent").Attributes["GainPercent"].InnerText));
                        ConfigInformation.GetInstance().tCamCfg.gainPercent = double.Parse(CameraNode.SelectSingleNode("GainPercent").Attributes["GainPercent"].InnerText);
                    }

                    //Exposure
                    if (bool.Parse(CameraNode.SelectSingleNode("IsExposureAuto").Attributes["IsExposureAuto"].InnerText))
                    {
                        Svision.GetMe().baslerCamera.setExposureAuto(true);
                        ConfigInformation.GetInstance().tCamCfg.exposurePercent = Svision.GetMe().baslerCamera.getExposurePercent();
                        ConfigInformation.GetInstance().tCamCfg.isExposureAuto = bool.Parse(CameraNode.SelectSingleNode("IsExposureAuto").Attributes["IsExposureAuto"].InnerText);
                    }
                    else
                    {
                        Svision.GetMe().baslerCamera.setExposureAuto(false);
                        ConfigInformation.GetInstance().tCamCfg.isExposureAuto = bool.Parse(CameraNode.SelectSingleNode("IsExposureAuto").Attributes["IsExposureAuto"].InnerText);
                        Svision.GetMe().baslerCamera.setExposurePercent(double.Parse(CameraNode.SelectSingleNode("ExposurePercent").Attributes["ExposurePercent"].InnerText));
                        ConfigInformation.GetInstance().tCamCfg.exposurePercent = double.Parse(CameraNode.SelectSingleNode("ExposurePercent").Attributes["ExposurePercent"].InnerText);
                    }

                    //WhiteBalance
                    if (bool.Parse(CameraNode.SelectSingleNode("IsWhiteBalanceAuto").Attributes["IsWhiteBalanceAuto"].InnerText))
                    {
                        Svision.GetMe().baslerCamera.setWhiteBalanceAuto(true);
                        ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = bool.Parse(CameraNode.SelectSingleNode("IsWhiteBalanceAuto").Attributes["IsWhiteBalanceAuto"].InnerText);
                    }
                    else
                    {
                        Svision.GetMe().baslerCamera.setWhiteBalanceAuto(false);
                        ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto = bool.Parse(CameraNode.SelectSingleNode("IsWhiteBalanceAuto").Attributes["IsWhiteBalanceAuto"].InnerText);
                        if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                        {
                            Svision.GetMe().baslerCamera.setWhiteBalanceBlue(double.Parse(CameraNode.SelectSingleNode("WhiteBalanceBluePercent").Attributes["WhiteBalanceBluePercent"].InnerText));
                            Svision.GetMe().baslerCamera.setWhiteBalanceGreen(double.Parse(CameraNode.SelectSingleNode("WhiteBalanceGreenPercent").Attributes["WhiteBalanceGreenPercent"].InnerText));
                            Svision.GetMe().baslerCamera.setWhiteBalanceRed(double.Parse(CameraNode.SelectSingleNode("WhiteBalanceRedPercent").Attributes["WhiteBalanceRedPercent"].InnerText));

                            ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent = double.Parse(CameraNode.SelectSingleNode("WhiteBalanceBluePercent").Attributes["WhiteBalanceBluePercent"].InnerText);
                            ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent = double.Parse(CameraNode.SelectSingleNode("WhiteBalanceGreenPercent").Attributes["WhiteBalanceGreenPercent"].InnerText);
                            ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent = double.Parse(CameraNode.SelectSingleNode("WhiteBalanceRedPercent").Attributes["WhiteBalanceRedPercent"].InnerText);
                        }
                    }
                }
                //load file config
                {
                    XmlNode FileNode = null;
                    bool    isFileOK = true;
                    try
                    {
                        FileNode = rootNode.SelectSingleNode("FileConfig");
                    }
                    catch (System.Exception ex)
                    {
                        isFileOK = false;
                    }
                    if (isFileOK && FileNode != null)
                    {
                        ConfigInformation.GetInstance().tFileCfg.rows = int.Parse(FileNode.SelectSingleNode("Rows").Attributes["Rows"].InnerText);
                        ConfigInformation.GetInstance().tFileCfg.columns = int.Parse(FileNode.SelectSingleNode("Columns").Attributes["Columns"].InnerText);
                        ConfigInformation.GetInstance().tFileCfg.channelNum = int.Parse(FileNode.SelectSingleNode("ChannelNum").Attributes["ChannelNum"].InnerText);
                        Svision.GetMe().checkBoxIsFile.Checked = bool.Parse(FileNode.SelectSingleNode("IsFileInput").Attributes["IsFileInput"].InnerText);
                        if (Svision.GetMe().checkBoxIsFile.Checked)
                        {
                            Svision.GetMe().oriRowNumber    = ConfigInformation.GetInstance().tFileCfg.rows;
                            Svision.GetMe().oriColumnNumber = ConfigInformation.GetInstance().tFileCfg.columns;
                        }
                    }
                }
                //load calibration config
                {
                    XmlNode CalNode = rootNode.SelectSingleNode("CalibrationConfig");

                    ConfigInformation.GetInstance().tCalCfg.calibrationDistance = double.Parse(CalNode.SelectSingleNode("calibrationDistance").Attributes["calibrationDistance"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.calibrationPoint = int.Parse(CalNode.SelectSingleNode("calibrationPoint").Attributes["calibrationPoint"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.focus = int.Parse(CalNode.SelectSingleNode("focus").Attributes["focus"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.calibrationRate = double.Parse(CalNode.SelectSingleNode("calibrationRate").Attributes["calibrationRate"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.pixelSize = double.Parse(CalNode.SelectSingleNode("pixelSize").Attributes["pixelSize"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.isCheckBoxRadialDistortion = bool.Parse(CalNode.SelectSingleNode("isCheckBoxRadialDistortion").Attributes["isCheckBoxRadialDistortion"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.calibrationParaConfirmFlag = bool.Parse(CalNode.SelectSingleNode("calibrationParaConfirmFlag").Attributes["calibrationParaConfirmFlag"].InnerText);
                    ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag = bool.Parse(CalNode.SelectSingleNode("calibrationIsRadialDistortionFlag").Attributes["calibrationIsRadialDistortionFlag"].InnerText);
                    if (ConfigInformation.GetInstance().tCalCfg.calibrationIsRadialDistortionFlag)
                    {
                        HOperatorSet.ReadImage(out ConfigInformation.GetInstance().tCalCfg.ho_MapFixed, (HTuple)tmpPath.Remove(tmpPath.LastIndexOf("\\") + 1) + "_calibrationMap.tiff");
                    }
                    XmlNode useThreePointCalibrationNode = null;
                    bool    isuseThreePointCalibrationOK = true;
                    try
                    {
                        useThreePointCalibrationNode = CalNode.SelectSingleNode("useThreePointCalibration");
                    }
                    catch (System.Exception ex)
                    {
                        isuseThreePointCalibrationOK = false;
                    }
                    if (isuseThreePointCalibrationOK && useThreePointCalibrationNode != null)
                    {
                        ConfigInformation.GetInstance().tCalCfg.useThreePointCalibration = bool.Parse(CalNode.SelectSingleNode("useThreePointCalibration").Attributes["useThreePointCalibration"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p1x = double.Parse(CalNode.SelectSingleNode("p1x").Attributes["p1x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p2x = double.Parse(CalNode.SelectSingleNode("p2x").Attributes["p2x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p3x = double.Parse(CalNode.SelectSingleNode("p3x").Attributes["p3x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r1x = double.Parse(CalNode.SelectSingleNode("r1x").Attributes["r1x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r2x = double.Parse(CalNode.SelectSingleNode("r2x").Attributes["r2x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r3x = double.Parse(CalNode.SelectSingleNode("r3x").Attributes["r3x"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p1y = double.Parse(CalNode.SelectSingleNode("p1y").Attributes["p1y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p2y = double.Parse(CalNode.SelectSingleNode("p2y").Attributes["p2y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.p3y = double.Parse(CalNode.SelectSingleNode("p3y").Attributes["p3y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r1y = double.Parse(CalNode.SelectSingleNode("r1y").Attributes["r1y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r2y = double.Parse(CalNode.SelectSingleNode("r2y").Attributes["r2y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.r3y = double.Parse(CalNode.SelectSingleNode("r3y").Attributes["r3y"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.Sx = double.Parse(CalNode.SelectSingleNode("Sx").Attributes["Sx"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.Sy = double.Parse(CalNode.SelectSingleNode("Sy").Attributes["Sy"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.thea = double.Parse(CalNode.SelectSingleNode("thea").Attributes["thea"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.Tx = double.Parse(CalNode.SelectSingleNode("Tx").Attributes["Tx"].InnerText);
                        ConfigInformation.GetInstance().tCalCfg.Ty = double.Parse(CalNode.SelectSingleNode("Ty").Attributes["Ty"].InnerText);
                        if (ConfigInformation.GetInstance().tCalCfg.useThreePointCalibration)
                        {
                            double[][] a = { new double[] { double.Parse(CalNode.SelectSingleNode("mx1").Attributes["mx1"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx2").Attributes["mx2"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx3").Attributes["mx3"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx4").Attributes["mx4"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx5").Attributes["mx5"].InnerText) },
                                             new double[] { double.Parse(CalNode.SelectSingleNode("mx6").Attributes["mx6"].InnerText) } };
                            ConfigInformation.GetInstance().tCalCfg.mx = Matrix.Create(a);
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
예제 #28
0
        private void buttonGetImageFrame_Click(object sender, EventArgs e)
        {
            try
            {
                //oriRowNumber = rowNumber;
                //oriColumnNumber = columnNumber;
                if (image != null)
                {
                    image.Dispose();
                }
                //Svision.GetMe().baslerCamera.getFrameImage(out image);
                UserCode.GetInstance().getImageFromProcess(out image, currentIdx);
                basicClass.getImageSize(image, out rowNumber, out columnNumber);
                double widRat = pictureBoxThreshold.Width / ((double)columnNumber);
                double heiRat = pictureBoxThreshold.Height / ((double)rowNumber);
                resizerate = widRat < heiRat ? widRat : heiRat;
                if (img != null)
                {
                    img.Dispose();
                }
                basicClass.resizeImage(image, out img, resizerate);
                //if (oriRowNumber != rowNumber || oriColumnNumber != columnNumber)
                //{
                //    basicClass.displayClear(ThresholdHWHandle);
                //}

                if (oriPictureBoxShowImageWidth != pictureBoxThreshold.Width)
                {
                    basicClass.displayClear(ThresholdHWHandle);
                }
                if (oriPictureBoxShowImageHeight != pictureBoxThreshold.Height)
                {
                    basicClass.displayClear(ThresholdHWHandle);
                }
                int rown, columnn;
                basicClass.thresholdImage(img, out imgRegionResult, (float)numericUpDownMinGray.Value, (float)numericUpDownMaxGray.Value);
                basicClass.getImageSize(img, out rown, out columnn);
                if (imgResult != null)
                {
                    imgResult.Dispose();
                }
                HOperatorSet.RegionToBin(imgRegionResult, out imgResult, 255, 0, columnn, rown);
                basicClass.displayhobject(imgResult, ThresholdHWHandle);
                panelenable.Enabled = true;
            }
            catch (System.Exception ex)
            {
                System.Threading.Thread.Sleep(100);
                if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
                {
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                    MessageBox.Show(ex.Message);
                }
                else
                {
                    Cursor = Cursors.WaitCursor;
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
                    MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
                    Svision.GetMe().cameraRefresh();
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                    Cursor = Cursors.Default;
                }
            }
        }
        private void buttongetImageFrame_Click(object sender, System.EventArgs e)
        {
            try
            {
                //oriRowNumber = rowNumber;
                //oriColumnNumber = columnNumber;
                if (image != null)
                {
                    image.Dispose();
                }
                //Svision.GetMe().baslerCamera.getFrameImage(out image);
                UserCode.GetInstance().getImageFromProcess(out image, currentIndex);
                basicClass.getImageSize(image, out rowNumber, out columnNumber);
                double widRat = pictureBoxMedian.Width / ((double)columnNumber);
                double heiRat = pictureBoxMedian.Height / ((double)rowNumber);
                resizerate = widRat < heiRat ? widRat : heiRat;
                if (img != null)
                {
                    img.Dispose();
                }
                basicClass.resizeImage(image, out img, resizerate);
                //if (oriRowNumber != rowNumber || oriColumnNumber != columnNumber)
                //{
                //    basicClass.displayClear(MedianHWHandle);
                //}

                if (oriPictureBoxShowImageWidth != pictureBoxMedian.Width)
                {
                    basicClass.displayClear(MedianHWHandle);
                }
                if (oriPictureBoxShowImageHeight != pictureBoxMedian.Height)
                {
                    basicClass.displayClear(MedianHWHandle);
                }
                if (imgResult != null)
                {
                    imgResult.Dispose();
                }
                HOperatorSet.MedianImage(img, out imgResult, "square", maskLength, "mirrored");
                basicClass.displayhobject(imgResult, MedianHWHandle);
                groupBoxMedianFilterFBDMaskSize.Enabled = true;
            }
            catch (System.Exception ex)
            {
                System.Threading.Thread.Sleep(100);
                if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
                {
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                    MessageBox.Show(ex.Message);
                }
                else
                {
                    Cursor = Cursors.WaitCursor;
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
                    MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
                    Svision.GetMe().cameraRefresh();
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                    Cursor = Cursors.Default;
                }
            }
        }
        private void CameraParaSet_Load(object sender, EventArgs e)
        {
            try
            {
                HOperatorSet.OpenWindow(0, 0, 256, 192, cameraParapictureBox.Handle, "visible", "", out cameraParaHWHandle);
                HOperatorSet.SetPart(cameraParaHWHandle, 0, 0, 191, 255);
                HDevWindowStack.Push(cameraParaHWHandle);
                HOperatorSet.SetLineWidth(cameraParaHWHandle, 1);
                HOperatorSet.SetColor(cameraParaHWHandle, "green");
                HOperatorSet.OpenWindow(0, 0, cameraParaPartpictureBox.Width, cameraParaPartpictureBox.Height, cameraParaPartpictureBox.Handle, "visible", "", out cameraParaPartHWHandle);
                HOperatorSet.SetPart(cameraParaPartHWHandle, 0, 0, cameraParaPartpictureBox.Height - 1, cameraParaPartpictureBox.Width - 1);
                HDevWindowStack.Push(cameraParaPartHWHandle);

                //Load Camera Config from configInformation and set these to the camera
                //row
                //  numericUpDownheight.Value = trackBarHeight.Value = Svision.GetMe().baslerCamera.getRowNumber();

                int[] rowRange;
                int   rowIncrement;
                Svision.GetMe().baslerCamera.getCameraRowRange(out rowRange);
                Svision.GetMe().baslerCamera.getRowIncrement(out rowIncrement);
                numericUpDownheight.Maximum            = rowRange[1];
                numericUpDownheight.Minimum            = rowRange[0];
                numericUpDownheight.Increment          = rowIncrement;
                numericUpDownheight.InterceptArrowKeys = true;
                trackBarHeight.Maximum     = rowRange[1];
                trackBarHeight.Minimum     = rowRange[0];
                trackBarHeight.SmallChange = rowIncrement;
                trackBarHeight.LargeChange = rowIncrement * 10;
                numericUpDownheight.Value  = ConfigInformation.GetInstance().tCamCfg.rows;
                prvRow = trackBarHeight.Value;
                //column
                //       numericUpDownWidth.Value = trackBarWidth.Value = Svision.GetMe().baslerCamera.getColumnNumber();

                int[] columnRange;
                int   columnIncrement;
                Svision.GetMe().baslerCamera.getCameraColumnRange(out columnRange);
                Svision.GetMe().baslerCamera.getColumnIncrement(out columnIncrement);
                numericUpDownWidth.Maximum            = columnRange[1];
                numericUpDownWidth.Minimum            = columnRange[0];
                numericUpDownWidth.Increment          = columnIncrement;
                numericUpDownWidth.InterceptArrowKeys = true;
                trackBarWidth.Maximum     = columnRange[1];
                trackBarWidth.Minimum     = columnRange[0];
                trackBarWidth.SmallChange = columnIncrement;
                trackBarWidth.LargeChange = columnIncrement * 10;
                numericUpDownWidth.Value  = ConfigInformation.GetInstance().tCamCfg.columns;
                prvColumn = trackBarWidth.Value;
                //Offset

                int XOffsetIncrement, YOffsetIncrement;
                Svision.GetMe().baslerCamera.getCameraOffsetRange(out XOffsetRange, out YOffsetRange);
                Svision.GetMe().baslerCamera.getOffsetIncrement(out XOffsetIncrement, out YOffsetIncrement);
                numericUpDownXOffset.Maximum            = XOffsetRange[1];
                numericUpDownXOffset.Minimum            = XOffsetRange[0];
                numericUpDownXOffset.Increment          = XOffsetIncrement;
                numericUpDownXOffset.InterceptArrowKeys = true;
                numericUpDownYOffset.Maximum            = YOffsetRange[1];
                numericUpDownYOffset.Minimum            = YOffsetRange[0];
                numericUpDownYOffset.Increment          = YOffsetIncrement;
                numericUpDownYOffset.InterceptArrowKeys = true;
                trackBarXOffset.Maximum     = XOffsetRange[1];
                trackBarXOffset.Minimum     = XOffsetRange[0];
                trackBarXOffset.SmallChange = XOffsetIncrement;
                trackBarXOffset.LargeChange = XOffsetIncrement * 10;
                trackBarYOffset.Maximum     = YOffsetRange[1];
                trackBarYOffset.Minimum     = YOffsetRange[0];
                trackBarYOffset.SmallChange = YOffsetIncrement;
                trackBarYOffset.LargeChange = YOffsetIncrement * 10;
                numericUpDownXOffset.Value  = ConfigInformation.GetInstance().tCamCfg.xOffset;
                numericUpDownYOffset.Value  = ConfigInformation.GetInstance().tCamCfg.yOffset;
                //        numericUpDownXOffset.Value = trackBarXOffset.Value = Svision.GetMe().baslerCamera.getXOffsetNumber();
                prvXoffset = trackBarXOffset.Value;
                //     numericUpDownYOffset.Value = trackBarYOffset.Value = Svision.GetMe().baslerCamera.getYOffsetNumber();
                prvYoffset = trackBarYOffset.Value;
                //channel

                Svision.GetMe().baslerCamera.getCameraMaxChannel(out channelMax);
                if (ConfigInformation.GetInstance().tCamCfg.channelNum == 1)
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(1);
                    radioButtonGray.Checked = true;
                    prvChannelNum           = 1;
                }
                else if (ConfigInformation.GetInstance().tCamCfg.channelNum == 3 && channelMax == 3)
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(3);
                    radioButtonColour.Checked = true;
                    prvChannelNum             = 3;
                }
                else
                {
                    Svision.GetMe().baslerCamera.setChannelNumber(1);
                    radioButtonGray.Checked = true;
                    prvChannelNum           = 1;
                }

                if (channelMax == 1)
                {
                    radioButtonColour.Enabled = false;
                }
                //gamma
                numericUpDownGamma.Value = (decimal)(ConfigInformation.GetInstance().tCamCfg.gammaPercent * 100);
                prvGammaPercent          = ConfigInformation.GetInstance().tCamCfg.gammaPercent;

                //gain
                if (ConfigInformation.GetInstance().tCamCfg.isGainAuto)
                {
                    prvIsGainAuto = true;
                    checkBoxGainAuto.CheckState = CheckState.Checked;
                    groupBoxGain.Enabled        = false;
                }
                else
                {
                    prvIsGainAuto = false;
                    Svision.GetMe().baslerCamera.setGainAuto(false);
                    checkBoxGainAuto.CheckState = CheckState.Unchecked;
                    numericUpDownGain.Value     = (decimal)(ConfigInformation.GetInstance().tCamCfg.gainPercent * 100);
                    prvGainPercent       = ConfigInformation.GetInstance().tCamCfg.gainPercent;
                    groupBoxGain.Enabled = true;
                }

                //exposure
                if (ConfigInformation.GetInstance().tCamCfg.isExposureAuto)
                {
                    checkBoxExposureAuto.CheckState = CheckState.Checked;
                    groupBoxExposure.Enabled        = false;
                    prvIsExposureAuto = true;
                }
                else
                {
                    prvIsExposureAuto = false;
                    Svision.GetMe().baslerCamera.setExposureAuto(false);
                    checkBoxExposureAuto.CheckState = CheckState.Unchecked;
                    numericUpDownExposure.Value     = (decimal)(ConfigInformation.GetInstance().tCamCfg.exposurePercent * 100);
                    prvExposurePercent       = ConfigInformation.GetInstance().tCamCfg.exposurePercent;
                    groupBoxExposure.Enabled = true;
                }

                //white balance
                if (ConfigInformation.GetInstance().tCamCfg.isWhiteBalanceAuto)
                {
                    checkBoxWhiteBalanceAuto.CheckState = CheckState.Checked;
                    groupBoxWhiteBalance.Enabled        = false;
                    prvIsWhiteBalanceAuto = true;
                }
                else
                {
                    prvIsWhiteBalanceAuto = false;
                    Svision.GetMe().baslerCamera.setWhiteBalanceAuto(false);
                    checkBoxWhiteBalanceAuto.CheckState = CheckState.Unchecked;
                    if (Svision.GetMe().baslerCamera.getChannelNumber() == 3)
                    {
                        groupBoxWhiteBalance.Enabled = true;
                        prvWhiteBalanceBluePercent   = ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent;
                        prvWhiteBalanceGreenPercent  = ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent;
                        prvWhiteBalanceRedPercent    = ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent;

                        //prvWhiteBalanceBluePercent = ConfigInformation.GetInstance().tCamCfg.whiteBalanceBluePercent;
                        //prvWhiteBalanceGreenPercent = ConfigInformation.GetInstance().tCamCfg.whiteBalanceGreenPercent;
                        //prvWhiteBalanceRedPercent = ConfigInformation.GetInstance().tCamCfg.whiteBalanceRedPercent;


                        numericUpDownBlueBalance.Value  = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent() * 100);
                        numericUpDownRedBalance.Value   = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent() * 100);
                        numericUpDownGreenBalance.Value = (decimal)(Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent() * 100);
                    }
                    else
                    {
                        groupBoxWhiteBalance.Enabled = false;
                        //numericUpDownBlueBalance.Value = (int)(Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent() * 100);
                        //numericUpDownRedBalance.Value = (int)(Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent() * 100);
                        //numericUpDownGreenBalance.Value = (int)(Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent() * 100);
                        //prvWhiteBalanceBluePercent = Svision.GetMe().baslerCamera.getWhiteBalanceBluePercent();
                        //prvWhiteBalanceGreenPercent = Svision.GetMe().baslerCamera.getWhiteBalanceGreenPercent();
                        //prvWhiteBalanceRedPercent = Svision.GetMe().baslerCamera.getWhiteBalanceRedPercent();
                    }
                }


                panelDetail.Enabled = false;
                //camera information
                string modelNameStr, deviceVendorNameStr, deviceModelNameStr, deviceFirmwareVersionStr;
                Svision.GetMe().baslerCamera.getCameraInformation(out modelNameStr, out deviceVendorNameStr, out deviceModelNameStr, out deviceFirmwareVersionStr);
                textBoxCameraInformation.Text = "相机型号: " + modelNameStr + "\r\n" + "\r\n" + "供应商: " + deviceVendorNameStr + "\r\n" + "\r\n" + "设备型号: " + deviceModelNameStr + "\r\n" + "\r\n" + "设备固件版本:" + deviceFirmwareVersionStr + "\r\n";
                cameraParaTimer.Enabled       = true;
            }
            catch (System.Exception ex)
            {
                cameraParaTimer.Enabled = false;
                System.Threading.Thread.Sleep(100);
                if (Svision.GetMe().baslerCamera != null && Svision.GetMe().baslerCamera.camera.IsOpen&& Svision.GetMe().baslerCamera.camera.IsConnected)
                {
                    MessageBox.Show(ex.Message);
                }
                else
                {
                    Cursor = Cursors.WaitCursor;
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "否";
                    MessageBox.Show("相机连接已断开,请检查连接网线!开始自动刷新相机状态!");
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "正在刷新";
                    Svision.GetMe().cameraRefresh();
                    Svision.GetMe().textBoxIsCameraOpenedAndConnected.Text = "是";
                    Cursor = Cursors.Default;
                    cameraParaTimer.Enabled = true;
                }
            }
        }