private void timerShowLog_Tick(object sender, EventArgs e) { if (ShareMem.GetCounter() > 0) { //这里打开,用于防止界面最小化后,显示不正确的问题 this.richTextBoxExLog.HideSelection = true; if (this.richTextBoxExLog.Text.Length >= 1024 * 100) { this.richTextBoxExLog.Text = ""; } string strMsg = ShareMem.GetMessage(); this.richTextBoxExLog.ForeColor = Color.Black; int iP1 = this.richTextBoxExLog.TextLength; this.richTextBoxExLog.AppendText(strMsg); this.richTextBoxExLog.AppendText(Environment.NewLine); int iP2 = this.richTextBoxExLog.TextLength; this.richTextBoxExLog.Select(iP1, iP2); if (strMsg.IndexOf("#重要#") >= 0) { this.richTextBoxExLog.SelectionColor = Color.Red; } else { this.richTextBoxExLog.SelectionColor = Color.Black; } this.richTextBoxExLog.Select(iP2, iP2); //这里关掉,用于显示最后一行 this.richTextBoxExLog.HideSelection = false; } }
/// <summary> /// 初始化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void mainw_Loaded(object sender, RoutedEventArgs e) { this.update_color = false; this.w_rgb_index = 0; this.w_depth_index = 0; ///初始化共享内存 this.SHrgb = new ShareMem(); this.SHdepth = new ShareMem(); this.SHpointcloud = new ShareMem(); if (0 != this.SHrgb.Init("_sharemem_for_colorpixels_", 921604)) { this.exit("shared memory initial error."); } if (0 != this.SHdepth.Init("_sharemem_for_depthpixels_", 921604)) { this.exit("shared memory initial error."); } if (0 != this.SHpointcloud.Init("_sharemem_for_point_cloud_", 3686404)) { this.exit("shared memory initial error."); } this.SHrgb_py = new ShareMem(); this.SHdepth_py = new ShareMem(); this.SHpointcloud_py = new ShareMem(); if (0 != this.SHrgb_py.Init("_sharemem_for_colorpixels_cspy", 921604)) { this.exit("shared memory initial error."); } if (0 != this.SHdepth_py.Init("_sharemem_for_depthpixels_cspy", 921604)) { this.exit("shared memory initial error."); } if (0 != this.SHpointcloud_py.Init("_sharemem_for_point_cloud_cspy", 3686404)) { this.exit("shared memory initial error."); } string exename = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName; string directoryName = Path.GetDirectoryName(exename); this.Visibility = System.Windows.Visibility.Hidden; this.tr = new tem2rgb(directoryName + "//tem_rgb.txt"); this.rp = new ReadParam(); this.rp.GetTransitMatrix(directoryName + "//installtion_param.txt"); this.fg_flg = this.rp.GetGroundParam(directoryName + "//groundfilter_param.txt"); foreach (var potentialSensor in KinectSensor.KinectSensors) { if (potentialSensor.Status == KinectStatus.Connected) { this.sensor = potentialSensor; break; } } if (null != this.sensor) { this.sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); this.sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30); this.colorPixels = new byte[921604]; this.rwcolorPixels = new byte[this.sensor.ColorStream.FramePixelDataLength]; this.depthPixels = new byte[921604]; this.rawdepthPixels = new DepthImagePixel[this.sensor.DepthStream.FramePixelDataLength]; this.pointcloudbytes = new byte[3686404]; this.cali_points = new ColorImagePoint[640 * 480]; this.camera_calib = new CoordinateMapper(this.sensor); this.sensor.ColorFrameReady += this.SensorColorFrameReady; this.sensor.DepthFrameReady += this.SensorDepthFrameReady; try { this.sensor.Start(); } catch (IOException) { this.sensor = null; this.exit(""); } Thread t = new Thread(new ThreadStart(this.updatecolor)); t.Start(); } else { this.exit("no kinect found. program ended."); } }