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); } }
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 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 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 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); } }
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; } }
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); } }
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]; }
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; } } }
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); } }
/// <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) {} } }
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); } }